I can use the \foreach
loop to iterate over an array of strings:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\foreach \v in {A, B}{
\input{the\v file.txt}
}
\end{document}
Now, I would like to compose a string as a macro as in:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\newcommand\var{A, B} % <<< macro
\foreach \v in \var{
\input{the\v file.txt}
}
\end{document}
Then I get a problem:
! LaTeX Error: File `theA, Bfile.txt' not found.
Using \def
instead of \newcommand
creates the same problem using Latex version pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
.
How to solve?
\def
instead of\newcommand
?! LaTeX Error: File 'theAfile.txt' not found.
and! LaTeX Error: File 'theBfile.txt' not found.
which would not occur if those files existed on my system.theA, Bfile.txt
if you call\foreach \v in {\var}{...}
; not with your code.pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
I have the problem without the braces{
. InpdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian)
I need to add the braces to generate the problem.\expandafter\foreach\expandafter i\expandafter n\expandafter{\var}{...}