# [texhax] defin'd?

Reinhard Kotucha reinhard.kotucha at web.de
Sun Dec 27 00:27:00 CET 2015

On 2015-12-24 at 17:34:08 +0100, Uwe Lueck wrote:

> A few hours ago, Reinhard Kotucha wrote:
> >> >     \def\@IfUndefined#1{%
> >> >         \begingroup\expandafter\expandafter\expandafter\endgroup
> >> >         \expandafter\ifx\csname #1\endcsname\relax
> >> >               \expandafter\@firstoftwo
> >> >         \else \expandafter\@secondoftwo \fi}
> >>
> >> Noting that this is not expandable, in contrast to LaTeX's \@ifundefined
> >> and \ifcsname. (The latter is clearly the best approach when allowed.)
> >
> > ... and the macro above doesn't prevent anything from going into the
> > hash table.
>
> Should anybody have believed that the \csname in the definition of
> \@IfUndefined worked differently from how it works in \@ifundefined?
> Of course it creates a hash table entry in the case of non-definedness.
> Besides resetting the meaning to "undefined" (I believe Bernd Raichle
> wrote that this was the motivation, and this has been Phil's point,
> which I addressed), however, it would be nice if the \endgroup /removed/
> the hash table entry. Can the quotes in Phil's

Hash table entries cannot be removed and \endgroup doesn't help
because hash tables are not maintained in TeX's mouth or stomach but
in TeX's heart.

The only way to avoid that these "if undefined" tests pollute the
string pool is to use \ifcsname.

Regarding german.sty, the package defines \@ifundefined if it's not
defined already.  This means that it's supposed to work with plain TeX
too.  And plain TeX users usually write \ifx\foo\undefined and don't
expect that the meaning of an undefined macro is \relax.

LaTeX's \@ifundefined supports all kinds of control sequence names,
such as strings of letters (\catcode 11), single punctuation marks,
and names consisting of arbitrary characters.

In LaTeX it works fine iff \@ifundefined is used consistently.

In order to support plain TeX too, it's necessary to avoid that
undefined cs names are set to \relax.  I'm sure that _this_ was
Bernd's intention.

Regards,
Reinhard

--
------------------------------------------------------------------
Reinhard Kotucha                            Phone: +49-511-3373112
Marschnerstr. 25
D-30167 Hannover                    mailto:reinhard.kotucha at web.de
------------------------------------------------------------------