[texhax] [TeXhax] Latex: dumbing down ?

Philip TAYLOR P.Taylor at Rhul.Ac.Uk
Sun Sep 3 09:35:44 CEST 2006



Reinhard Kotucha wrote:

> The definition of \@ifundefined is
> 
>     \expandafter \ifx \csname #1\endcsname \relax \expandafter
>     \@firstoftwo \else \expandafter \@secondoftwo \fi
> 
> Hence, if someone says \@ifundefined{foo}{}{} and tries later
> \ifx\foo\undefined this will always succeed because \@ifundefined sets
> undefined cotrol sequences to \relax.  

> You cannot safely use \ifx in LaTeX.

No no.  It is \csname ... \endcsname that "sets undefined control sequences
to \relax", as every Plain TeX hacker knows (there is a clever
output routine hack that relies on the use of \csname ... \endcsname
to determine whether one is in the left or right column.)  The fact
that La(zy)TeX's implementation of \@ifundefined /uses/ csname is
neither here nor there : /any/ use of \csname ... \endcsname would
have this effect on the CS so constructed ...  So it is not
\ifx that cannot be safely used in LaTeX, it is simply that it cannot
be /assumed/ that everything will work as if on the zeroth line
of an IniTeX run.

LaTeX uses TeX primitives, but so do all Plain TeX hackers, so one
can make no assumptions unless one has written (and remembered)
every line of code oneself.  Thus the unwary should write pure
LaTeX if they are working in a LaTeX environment, but they may
still encounter problems when packages conflict; the more aware
may use IniTeX primitives (rather more foolishly, Plain TeX macros),
but must remain aware of the dangers of so doing.

** Phil.


More information about the texhax mailing list