我最近开始使用 xparse,我想用 xparse 命令的输出来更新计数器的值。xparse 命令使用参数处理,这似乎会带来问题。示例代码:
\documentclass{article}
\usepackage{xparse}
\newcounter{counterA}
\newcounter{counterB}
\newcounter{counterC}
\newcommand\StandardAdd[2]{\the \numexpr #1 + #2}
\NewDocumentCommand\xparseAdd{mm}{\the \numexpr #1 + #2}
\NewDocumentCommand\xparseProcessAndAdd{ >{\SplitArgument{1}{:}} m}{\xparseAdd #1 }
\begin{document}
Without xparse: \addtocounter{counterA}{\StandardAdd{2}{3}} \arabic{counterA}\\
With xparse: \addtocounter{counterB}{\xparseAdd{2}{3}} \arabic{counterB}\\
%With xparse argument processing: \addtocounter{counterC}{\xparseProcessAndAdd{2:3}} \arabic{counterC}\\
\end{document}
输出:
Without xparse: 5
With xparse: 5
! Missing number, treated as zero. \xparse function is not expandable
当我在计数器的更新中使用参数处理(将参数拆分为标记)时,Latex 无法编译。错误消息是上一段中描述的。