I'm trying to create a dynamic for loop:

\foreach \m in \forinmacro {...}

Note if I change the last line to

\foreach \m in {a,b,c,d} {...}

it works.

Unfortunately the comma's seem to screw up the foreach and it gives errors(changing a,b,c,d to a lets it work).

Why is \def\forinmacro{{a,b,c,d}} breaking the foreach but \def\forinmacro{{a}} not?


You need to remove the extra braces.

\usepackage{xparse, ifthen}
\DeclareDocumentCommand\iftb{m m G{\relax}}{\ifthenelse{\boolean{#1}}{#2}{#3}}
\foreach \m in \forinmacro {This is letter : \m\par}
\foreach \m in \forinmacro {This is letter : \m\par}
| improve this answer | |

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.