I need to update a variable defined in a pgfmathsetmacro command inside a foreach loop. Apparently, the var is only updated when it is used after the update command. Here is a MWE:
\begin{tikzpicture}
\draw [help lines] (0,0) grid (3,3);
\pgfmathsetmacro{\a}{1}
\foreach \b in {2,3} {
\node [blue] at (\a,0) {\a};
\pgfmathsetmacro{\a}{\b}
\node [red] at (0,\a) {\a};
}
\end{tikzpicture}
The red nodes are printed at updated positions and the value printed is also updated; the blue nodes are not: they keep their initial value (1) and are located at the initial position (0,1). Why is this? Thanks José