3

The control sequence \scope appears several times in the TikZ scource code, for instance in the following line in the definition of the \tikz@lib@graph@parser@ macro inside the file <tex installation directory>/tex/generic/pgf/frontendlayer/tikz/libraries/graphs/tikzlibrariesgraphs.code.tex:

\scope[graphs/.cd,@graph drawing setup/.try,@operators=,every graph/.try,#1]%

I can't find where it is defined.

I have greped the entire pgf directory tree for \def\scope (grep -rF "\def\scope" pgf) and nothing came up.

I did the same with \let\scope and only two relevant results appeared, inside the macros \tikz@installcommands and \tikz@uninstallcommands (both in the file frontendlayer/tikz/tikz.code.tex). But these macros appear to only be related to tikzpictures, and, more importantly, they seem to already assume that the \scope control sequence is defined somewhere else:

\let\tikz@origscope=\scope

...

\let\scope=\tikz@origscope

So where is this control sequence defined?

  • 2
    \scope is not a macro but an environment in TeX format \scope and \endscope. – percusse Aug 9 '17 at 6:33
  • @percusse: I see. Thanks. Where is it defined? – Evan Aad Aug 9 '17 at 6:39
  • grep for \tikz@@scope@env – percusse Aug 9 '17 at 6:45
  • @percusse: I did, but I still don't get it. Is it like TeX boolean variables, where you declare one control sequence \ifcond, and get two further control sequences \condtrue and \condfalse at no further cost? So if I define the macro \tikz@@scope@env, is the control sequence \scope defined automatically by TeX or by the TikZ engine? – Evan Aad Aug 9 '17 at 6:57
7

In the setup of TikZ environment \tikz@installcommands is invoked.

%
% Main TikZ Environment
%

\def\tikzpicture{%
  \begingroup%
    \tikz@startup@env%
    \pgfutil@ifnextchar[\tikz@picture{\tikz@picture[]}}%}
\def\tikz@picture[#1]{%
  \pgfpicture%
  \let\tikz@atbegin@picture=\pgfutil@empty%
  \let\tikz@atend@picture=\pgfutil@empty%
  \let\tikz@transform=\relax%
  \def\tikz@time{.5}%
  \tikz@installcommands% <==============================This line
  \scope[every picture,#1]%
  \iftikz@handle@active@code%
    \tikz@switchoff@shorthands%
  \fi%
  \expandafter\tikz@atbegin@picture%
  \tikz@lib@scope@check%
}

This in turn has the following structure

%
% Install the abbreviated commands
%
\def\tikz@installcommands{%
  \let\tikz@origscope=\scope% <======== If scope is not yet defined, becomes undefined
  \let\tikz@origscoped=\scoped%
  \let\tikz@origendscope=\endscope%
  .....
  %
  \let\scope=\tikz@scope@env%<======== This is the actual definition
  \let\scoped=\tikz@scoped%
  \let\endscope=\endtikz@scope@env%
  \let\startscope=\scope%
  \let\stopscope=\endscope%
  \let\path=\tikz@command@path%
  \let\againpath=\tikz@command@againpath%
  %
  ......
}
  • OK, thanks. Now I get it. Two things threw me off. Firstly the fact that \scope might be undefined in the beginning of the \tikz@installcommands macro, but I realize now that in TeX it is not an error to use a name that has not yet been defined. Secondly, I mistook \tikzpicture for the handler for pics (chapter 18 in the manual), so I thought that the \tikz@installcommands macro is not even called when no pic is mentioned on the path. – Evan Aad Aug 9 '17 at 7:54
  • @EvanAad Any LaTeX environment someenv is implemented as \someenv and \endsomeenv. (This is not TikZ specific - just how environments always work.) – cfr Aug 9 '17 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.