I'd like to understand how to properly use variables in TikZ. I've read a large number of Q&A's and, so far, I've encountered \{g,x,e,}def, \newcommand, \pgfmathsetmacro, and \let.
The objective is to parameterise a drawing without repercussions to the rest of the document.
Additionally, the \foreach and [evaluate = <> as <>…] commands seem also to be creating (local? global?) variables.
tikzpictureshould be local to it, unless you explicitly make it\globalin scope. ie: don't use\gdef,\xdef. then it won't affect the rest of the code. As can be seen from\newcommand{\Foo}{7} Before:\Foo \begin{tikzpicture} \def\Foo{11}% \end{tikzpicture} After:\Foo. The output before and after thetikzpictureis7even thought it was defined to be11in thetikzpicture. If you want to define\Foobefore and use it in thetikzpicture, then don't redefine it within thetikzpicture-- sounds obvious, but I was once bitten by this bug.\def,\newcommand,\pgfmathsetmacro, and\letwork. Can you point me in the direction for learning about the{g,x,e}variants of\def? I'll compile a small summary as a self-answer to my question and ask for review / feedback. Moreover, any idea about the local / global behaviour of\foreachand[evaluatemacros?edef(\defwith expansion) is still local. The\gdefis the equivalent to\global\defand\xdefis equivalent to\global\edef. More details on those can be found at What are the differences between \def, \edef, \gdef and \xdef? and When to use \edef, \noexpand, and \expandafter?. The\foreachloop keep everything local.