I am trying to build up tabular data using the solution at How do I use the ampersand (&) inside a foreach or conditional (or other group/environment) when building tables?, but not having any success.

There is some expansion issue that I am not able to figure out. I have counters which are declared based on the content of a list and I need to output the value of these counters in the output and hence trying to use \eAddTableTokens. The MWE below yields:

 Undefined control sequence.
 \\  ->\let \reserved@e 
                        \relax \let \reserved@f \relax \@ifstar {\let \reserv...
 l.47 ^^I}



%% This is based on:
%%     https://tex.stackexchange.com/questions/165126
    %%% assignments to \@tabtoks must be global, because they are done in \foreach
    %%% variable should always be operated on always locally or always globally

\newcommand*{\MyList}{ABC, DE, FG}%

    % Confirm basic functionality
    \foreach \Entry in \MyList {%
        \AddTableTokens{22 & 44 \\}%
        \multicolumn{2}{c}{Basic Testing} \\

    %%% Processing:
    %%%    Counters get declared and appropriate values are computed, 
    %%%    but for MWE these are all just a fixed number.
    \foreach \Entry in \MyList {%
    %%% Printing
    \foreach \Entry in \MyList {%
        \eAddTableTokens{\Entry & \TempCountExpanded \\}%
        \multicolumn{2}{c}{Actual Use Case} \\

1 Answer 1


Commands such as \\ or \textbf don't survive \edef; you need \protected@edef:

  • Well, this certainly fixed it for the MWE. But, in my actual use case I had to eliminate the \\ in the call to \eAddTableTokens and instead add the \\ to definition of \eAddTableTokens. But, I am unable to determine what the actual difference between my actual use case and MWE is that could be causing this. May 8, 2014 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.