One sometimes defines macro's for TikZ as:
\newcommand{\foo}[1]{
\foreach \x in {#1} {
%do something
}
}
Thus where the argument given to \foo is used in a \foreach loop.
Sometimes, one wants to know the number of items in advance, for instance to divide the width of an object among the given items. You can do this using a counter:
\newcommand{\foo}[1]{
\setcounter{tmpA}{0}
\foreach \x in {#1} {
\stepcounter{tmpA}
}
\foreach \x in {#1} {
%do something
}
}
Thus using a counter tmpA and increment it the first time, and then iterate a second time over the list and use the value of the counter if necessary. One can of course abstract the counting away in a virtual call, but that's not really the problem: one needs to define a counter and there is always a small chance someone else defines a counter with the same name such that they interact.
I was wondering if there are some utility functions defined for TikZ foreach items: counting, merging, crossproduct,...
\foreach \i [count=\ino] in {...} ...? – cfr May 02 '15 at 21:54count=trick, many thanks. – willeM_ Van Onsem May 02 '15 at 21:55