0

The control-sequence \@undefined appears several times in the pgf/tikz source-code. For instance, in the file <pgf/tikz install dir>/utilities/pgfkeys.code.tex it appears twice:

\expandafter\ifx\csname#1\endcsname\relax%
\else%
    \expandafter\ifx\csname#1\endcsname\@undefined%
    \else\pgfkeys@csname@testtrue%
    \fi%
\fi

and

\ifx\foreach\@undefined

but it appears in other files as well.

Unfortunately, I couldn't find where \@undefined is defined in the pgf/tikz source-code. It is possible that I didn't search properly, because the letters \ and @ are tricky.

  • What does \@undefined mean in the context of the pgf/tikz source-code?
  • Is it defined anywhere in the pgf/tikz source-code, or is it a known TeX control-sequence (or some extension of TeX, e.g. e-TeX) that I'm simply not familiar with?

I've considered the possibility that \@undefined is simply some control-sequence that is assumed to be undefined, and its purpose is to help test whether other control-sequences are defined using the idiom

\ifx\someControlSequence\@undefined ...

However, if this is indeed the intended use, then I don't understand the first example above, since the expression

 \expandafter\ifx\csname#1\endcsname\@undefined

will always evaluate to false: this is obvious if the control-sequence \csname#1\endcsname is defined, and if it isn't defined, then the \csname...\endcsname construct will define it to be \relax (this is just how the \csname...\endcsname construct works -- see exercise 7.7 on p. 40 of the TeXbook, 20th printing 1991).

  • Well, afaik, the expansion shall construct the csname, so that \ifx does not check \csname to be something. – TeXnician Aug 20 '17 at 9:22
  • @TeXnician: Sorry, I didn't get it. Could you please explain another way? – Evan Aad Aug 20 '17 at 9:25
  • 2
    \@undefined is not defined, that is its purpose. – David Carlisle Aug 20 '17 at 10:31
  • 3
    @EvanAad the test will always evaluate to false, so it's dead code. It happens... – David Carlisle Aug 20 '17 at 10:32
  • 1
    Unless #1 is the literal text @undefined, and then \expandafter\ifx\csname#1\endcsname\@undefined evaluates to true and also leaves \@undefined as \relax – Mark Wibrow Aug 20 '17 at 12:29
4

\@undefined is a csname that by convention is never defined. It would be a bad idea to break that convention as several core latex commands (including for example \caption) include tests such as the ones you show, that assume that it is not defined.

So

\ifx\foreach\@undefined

tests if \foreach has been defined

\expandafter\ifx\csname#1\endcsname\@undefined%
\else\pgfkeys@csname@testtrue%
\fi%

is actually just the same as

\pgfkeys@csname@testtrue

as the result of expanding \csname#1\endcsname is never undefined.

  • 1
    Thank you. What about \undefined? Since in the same file where I took the examples that I quoted in my original post, \undefined is used as well as \@undefined. Is \undefined also a control-sequence that is by convention undefined? – Evan Aad Aug 20 '17 at 11:30
  • @EvanAad \undefined is in the TeX Book. – cfr Aug 20 '17 at 13:33
  • @cfr: Are \undefined and \@undefined interchangeable? If they are, why are they both used in the same file? – Evan Aad Aug 20 '17 at 14:35
  • 2
    @EvanAad you can use \EvanAad or \Zzzzzzz they are all the same, any undefined command would work the same way. plain tex uses \undefined but latex uses \@undefined as it is less likely to get defined by a casual user, and because of its convention of using @ named commands for internal uses. – David Carlisle Aug 20 '17 at 15:46

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.