I've looked around and can't seem to find anywhere, but I was wondering if there is somewhere you can do something like the following:
\newcommand{\loopy}[1]{
\begin{tikzpicture}
\foreach \x in #1 {
\foreach \y in \x {
\node at (\y_1,\y_2);
}
}
\end{tikzpicture}
}
\loopy{{{1,2},{2,3}}}
Then the 'loopy' command would go through and plot nodes at (1,2) and (2,3). I'm not sure this is even possible or how you would go about doing it?
Additionally, would there be a way to see the number of elements within a number? So say I pass in
\loopy{{{1,2,3},{2,3}}}
Is there a way to know that the first set has 3 elements and the second set has 2?
Edit (Adding more description)
The above example was to simplistic, so I'll make a more 'complex' example to show kinda what I'm trying to do:
\newcommand{\loopy}[1]{
\begin{tikzpicture}
\foreach \x in #1 {
\if \x has 2 elements {
\foreach \y in \x {
\node at (\y_1,\y_2);
}
}
\else if \x has 3 elements {
\foreach \y in \x {
\node at (\y_1,\y_2) {\y_3};
}
}
\else if \x has 4 elements {
\foreach \y in \x {
\node at (\y_1,\y_2);
\node at (\y_3,\y_4);
}
}
}
\end{tikzpicture}
}
\loopy{{{1,2},{1,2,3},{2,3,4,5}}}
Best Answer
The question seems a bit ill-defined, but one can indeed parse a general list in a nested way, and do different things based on the list length of each successive rank-1 list. Here
will place a
2
at location (1,2), since it was a 2-element list. It will place a3_7
at location (2,3), since7
was the third element of the list starting with the coordinates (2,3). Finally, it will place a4_1
and4_2
at (2,4) and (4,5) since the 4 element list began with2,4
and concluded with4,5
.