\documentclass{article}
\usepackage{tikz}
\def\firstlist{0,1,2}
\def\secondlist{0,1,2}
\newcommand{\testa}{
\foreach \x/\y in {\firstlist/\secondlist} {
\draw(0,\x)--(1,\y);
}
}
\newcommand{\testb}{
\foreach \x/\y in {0/0,1/1,2/2} {
\draw(0,\x)--(1,\y);
}
}
\begin{document}
\begin{tikzpicture}
\testa
\end{tikzpicture}
\end{document}
How can I make the output of the \testa
command equal to the output of the \testb
command?
Best Answer
Here is a very simple solution:
An extended solution defining the new style
parallel foreach
. You can use multiple parallel lists:Both methods use the array features of pgfmath: they evaluate each element as a math formula. If you want string elements, use quotes (
"..."
).