I would like to make a macro that takes two arguments, the second of which is a comma separated list and then produces a nested commutator of argument1 with each entry of argument2. I've been attempting to do this by looping over the values in argument2 and recursively calling a simple commutator macro, but I keep getting the following error:
! TeX capacity exceeded, sorry [grouping levels=255].
I tried to use etoolbox
's docsvlist
, but couldn't figure out how to make it do what I wanted.
It seems like I have an infinite loop, or some problem with my def scheme, but I don't know what it is.
Details:
Basic commutator macro:
\newcommand{\commut}[2]{\left[{#1},{#2}\right]}
Brute force nested commutator:
\newcommand{\qcommut}[5]{\commut{\commut{\commut{\commut{#1}{#2}}{#3}}{#4}}{#5}}
Attempt at automated version:
\makeatletter
\newcommand{\ncommut}[2]{
\def\mainArg{#1}
\newcommand{\argList}{#2}
\@for\i:=\argList\do{
\def\mainArg{
\commut{\mainArg}{\i}
}
}
}
\makeatother
I can call \commut
and \qcommut
, but \ncommut
produces the error.
\begin{equation}
\commut{A}{B}
\qcommut{A}{B}{C}{D}{E}
\ncommut{A}{B,C,D,E} % desired usage
\end{equation}
Desired output:
\commut{A}{B}
,\qcommut{A}{B}{C}{D}{E}
and (say)\ncommut{A}{B,C,D,E}
?\mainArg
in the definition of\mainArg
. You need to expand it first.{}
groups (which has no obvious terminator for the list)