This is the third and final post in the line of questioning regarding the order of execution of options, pdfextra code and other elements along a TikZ path. The other posts being this and this.
Consider the following LaTeX manuscript
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def\x{outside}
\path[draw=blue,font=\Huge]
\pgfextra{ \def\x{inside}
\draw (2,2) circle(5pt)
node[anchor=south west]{xtra};}
(0,0) node[draw] {\x}
;
\end{tikzpicture}
\end{document}
The manuscript features a TikZ picture. The first action to be executed inside the picture is defining the TeX macro \x
to be the string 'outside'. Then a TikZ path is defined with two options: the draw color is set to 'blue', and the font size is set to '\Huge'. The path is composed of two elements: (1) a \pgfextra
block. The block redefines the macro \x
as the string 'inside'. It then draws a circle and next to it - a node with the display text 'xtra'. (2) A node whose display text is \x
's replacement text. The node's outline is drawn.
This manuscript typesets thus:
Note that the path's font
option applied to both the \pdfextra
code as well as the node, however the draw
options applied only to the node. Why?
One possible theory in answer to this question is that, for whatever reasons, the code is executed in the following order: 1. font
option, 2. \pdfextra
, 3. draw
option, 4. node.
Let's put this theory to the test by moving the \pgfextra
element to after the node:
\path[draw=blue,font=\Huge]
(0,0) node[draw] {\x}
\pgfextra{ \def\x{inside}
\draw (2,2) circle(5pt)
node[anchor=south west]{xtra};}
;
I expect the node's display text to be 'outside', and the circle's stroke color to be blue. However, I'm only partly right:
\path
option resets the colors locally hence if a new path is started colors are reset to black. There is no execution order in TeX. Only the scope that the macros are defined are valid. Current values of the macros are the only thing that matters. That's why expansion is central to TeX language.\pgfextra
with an equivalent code in PGF:\def\x{inside}\pgftransformshift{\pgfpoint{2cm}{2cm}}\pgfpathcircle{\pgfpointorigin}{5pt}\pgfusepath{stroke}\pgfnode{rectangle}{south west}{xtra}{}{\pgfusepath{discard}}\pgftransformshift{\pgfpoint{-2cm}{-2cm}}
\path node
command. No keys are invoked in PGF in that code and it's not a theory. Again, you can see it in the source code.\pgfinterruptpath
: insert\let\orig\pgfinterruptpath\def\pgfinterruptpath{\typeout{pgfinterruptpath}\orig}
in your preamble...