\foo会吃掉一个二维数组参数,让listofitems包读取数组,并使用该包的功能输出每一行的元素个数(列数),经过比较后,将数组中最大列数传递给\@columnnum.\listlen\@foo[1]和\listlen\@foo[1]会分别获取数组中第一行和第二行的元素个数(列数).\ifnum比较大小这种foolish的方法获取其中的最大值并传递给\@columnnuma,在\begin{document}后使用\@columnnuma成功输出该数组的最大列数.expl3的\int_max:nn{express1}{express2}进行比较并把输出结果传递给\@columnnumb后,正文中\@columnnumb则无法正常输出列数最大值. 报错为`Missing $ inserted.<inserted text>`(我ExplSyntaxOn也没落下啊😫)
The following is MWE:
\documentclass{minimal}
\usepackage{listofitems}
\setsepchar{;/,}
\ignoreemptyitems
\makeatletter
\NewDocumentCommand{\foo}{m}{
\readlist*\@foo{#1}
\ifnum \listlen\@foo[1]<\listlen\@foo[2]
\gdef\@columnnuma{\listlen\@foo[2]}
\else
\gdef\@columnnuma{\listlen\@foo[1]}
\fi
\gdef\@columnnumb{
\ExplSyntaxOn
\int_max:nn{\listlen\@foo[1]}{\listlen\@foo[2]}
\ExplSyntaxOff
}
}
\begin{document}
\foo{1,2,3,4,5;6,7,8,9}
There are \@columnnuma{} columns in the group.
% There are \@columnnumb{} columns in the group.
\ExplSyntaxOn
There~are~\int_max:nn{\listlen\@foo[1]}{\listlen\@foo[2]} ~columns~in~the~group.
\ExplSyntaxOff
\makeatother
\end{document}