I try to automate some things with tikz, and I am running into a problem that I do not understand. Nesting scopes with shifts defined as commands does not work as I was expecting.
For example, this works perfectly :
\begin{tikzpicture}
\def\coord{(1,0)}
\begin{scope}[shift={\coord}]
\end{scope}
\begin{scope}[shift={\coord}]
\end{scope}
\end{tikzpicture}
and it works correctly, as one can see by adding some \node[fill,circle] at (0,0) {};
inside and outside the scopes
but the following fails :
\begin{tikzpicture}
\def\coord{(1,0)}
\begin{scope}[shift={\coord}]
\begin{scope}[shift={\coord}]
\end{scope}
\end{scope}
\end{tikzpicture}
However, this
\begin{tikzpicture}
\def\coord{(1,0)}
\begin{scope}[shift={(1,0)}]
\begin{scope}[shift={(1,0)}]
\end{scope}
\end{scope}
\end{tikzpicture}
indeed works. I do not understand what is happening. pdflatex
returns
Package tikz Error: Cannot parse this coordinate.
See the tikz package documentation for explanation. ...
in the problematic case. The question is why does this happen ? I probably did something wrong, but I really do not see what.
Notice that adding length units does not fix the problem. However, a similar problem with xshift
and yshift
does not seem to happen. Also notice that I tried to simplify the code as much as possible ; that's why it draws nothing.
Thanks,
\coord
on its own. The algorithm that is used to parse a coordinate does this if it encounters something that is did not expect (here it does expect a(
but doesn’t find it). Each expansion counts down a counter, if this counter reaches zero, TikZ gives up and presents you this error message. On a path, this counter is usually initialized with100
. This is not the case on ascope
. You can observe the same behavior if you useshift=\ccoord
with\def\ccoord{\coord}
. — Best is to give TikZ the coordinate already expanded and doshift/.expanded=coord
.