[texhax] defin'd?

Uwe Lueck uwe.lueck at web.de
Fri Dec 25 04:24:05 CET 2015


On 2015-12-23 at 13:30 UTC, Joseph Wright 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.)

It's right, during pure expansion, \begingroup and \endgroup 

    (a) do not restore undefinedness and 

    (b) remain in the final expansion.

(a) means that \@IfUndefined cannot show its advantage over 
\@undefined, in this respect \@ifundefined's expandability
is not an advantage.  (b) may be harmless in usual LaTeX
"moving arguments", \{begin,end}group may wander around until 
they finally get into TeX's stomach, what effect could they 
have there? (b) may be really ugly when the expansion result is 
meant to be text to be read on screen or HTML code with blog.sty. 
Then \@ifundefined is superior to \@IfUndefined. Demonstration:

    \def\funnytest{+\ifx\funnycs\@undefined U\else D\fi+}
    \@IfUndefined{funnycs}{\message{u}}{\message{d}}
    \message{\funnytest}
    \message{>\@IfUndefined{funnycs}ud<}
    \message{\funnytest}

On my screen, the \message's form the string

    u +U+ >\begingroup \endgroup u< +D+

So the first application of \@IfUndefined restores 
\funnycs's undefinedness, the second inside \message{...}
doesn't. Funny, and the display is ugly.

In latex.ltx however, \@ifundefined is used in connection 
with assignments and/or for throwing error messages. 
So assignments are cases where \@IfUndefined could be useful.

For throwing error messages, there is a problem with all of 
\@ifundefined, \@IfUndefined, \ifcsname, and \iftoken at 
pure expansion: How to do it?

    \@ifundefined{<funny>}{<errmess-code>}{} 

then does not execute <errmess-code>, but pastes it into 
some string, so in some cases, no error is thrown at all, 
you only may occasionally discover its code or just 
something strange somewhere.  For HTML, it may paint a 
large red error message for the reader, but even this 
often is not discovered, cf. bad <ref> code in Wikipedia. 
What I have done is 

    \@ifundefined{<funny>}{\UNDEFINED}{} 

So I get a fake error message, but at least I get one.
Other users than myself may be puzzled, so almost none.
One could also do an \edef before \write'ing something 
and search the result for error code -- slow.

I almost sent the previous, but then tried to improve 
the \UNDEFINED thing. With \ifundefcsnameerror{<funny>},
the token named <funny> is reported to be undefined:

    \def\ifundefcsnameerror#1{%
        \ifcsname#1\endcsname\else
          \expandafter\let\csname#1\expandafter
            \endcsname\expandafter\@undefined
              \csname#1\endcsname\fi}

Still not great, but better than really bad. A user may 
have no idea why that token should be defined and what 
(s)he could do about it. It would be better to have some 
specific \errhelp. -- My first usage of \ifcsname, 
after two mistakes.

>> P.S.: I have ignored \varepsilon-\TeX\ until very recently ...
>> sympathizing with minimalistic implementations of \TeX. On
>> the other hand, I don't agree much when I read that the NTS
>> project "failed" -- \varepsilon-\TeX\ has been a useful result.
>
> Given that other than "tex", all widely-used binaries in use nowadays
> feature the extensions, I think e-TeX is clearly a success. Whether it
> achieved everything desirable is a different matter, of course.

My note also was motivated by having learnt of Peter Breitenlohner's 
death incidentally.

Merry Christmas

 -- Uwe.


More information about the texhax mailing list