I want to make a macro that will take \testfunc{1,2,3}{4,5,6} and generate
\begin{bmatrix}
1 & 2 & 3\\
4 & 5 & 6
\end{bmatrix}
Here's the code:
\def\testfunc#1{
\ExplSyntaxOn
\NewDocumentCommand \countItems { m } {
\clist_count:N #1
}
\ExplSyntaxOff
\begin{bmatrix}
\foreach #1 \do {
\def\length{\countItems{##1}}
\foreach \col [count=\i] in {##1} {
\ifx\i\length
\col
\else
\col &
\fi
\ifx&##1& \else \\ \fi
}
}
\end{bmatrix}
}
However, I keep getting Paragraph ended before \pgffor@@vars was complete., though if I add a new line before the \end{document} a lot more errors pop up.


\ifx\i\lengthis always false as\inever has the same definition as\length– David Carlisle Aug 25 '22 at 20:06\foreachbut if that is from pgf each iteration is in a group so you can not insert&within the loop – David Carlisle Aug 25 '22 at 20:08