I am trying to use a loop. The following does not work:

\foreach \a in {no,has}{    
    \toprule \toprule \\
    ~~~~text \\
    \hline \\
    ~~~~text \\
    \caption*{\begin{footnotesize}  \end{footnotesize}}

What I am trying to do is to access four similarly-named files with the loop — two the first time through (named ...no...) and two the second time through (named ...has...).

I get this error:

illegal parameter number in definition of \pgffor@b

Note that the following does work:

This works:

\foreach \a in {no,has}{

What should I try to fix this?

  • 1
    Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a \documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code. – Andrew Sep 10 '18 at 22:12
  • 1
    Related: tex.stackexchange.com/questions/367979/… – Andrew Sep 10 '18 at 22:14
  • 1
    Btw, filenames with underscores in them are problematic in latex... Renaming them as text2-\a-c.tex might solve your problem. If not rather using \foreach from pgffor package you'll probably have more luck with \docsvlist from the etoolbox package. – Andrew Sep 10 '18 at 22:15

Since the definition of \sym occurs in the argument to another command, it should be


in this code.

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.