TeX inserts \relax when it suddenly finds \else or \fi while expanding a conditional (eg, looking for a number). TeX by Topic says much. But how do you get rid of the \relax in a situation like the following fictitious example? eTeX's \dimexpr and \numexpr do vanish \relax but perhaps not in a situation like the following.
\edef\x{%
\ifnum0=0\fi\ifnum\z@=\z@
\expandafter\@firstoftwo\else
\expandafter\@secondoftwo\fi{x}{y}%
}
(Edited in from 'answer')
Martin, The \@empty may linger even in full expansion contexts: \noexpand makes expandable commands recoverable \relax. Moreover, at least 1/2 of the time one is not interested in full expansion or printing, but in a one- or two-step expansion. The outcome may even be immediately detokenized. So any extra \@empty or \space intended as an 'artificial' stopper will linger in the definition in situations where a non-expandable token is found before the artificial stopper. The following illustrates the point of Bruno, which I had been aware of:
\def\test@cond#1\fi{%
#1\noexpand\@empty
\expandafter\@firstoftwo\else
\expandafter\@secondoftwo\fi{x}{y}%
}
\edef\x{\test@cond\ifnum\z@=\z@\fi}
\edef\x{\test@cond\if xx\fi}
\edef\x{\test@cond\ifnum0=0\fi}
I have found a tricky solution involving \iffirstisspace macro, and \romannumeral too offers a way out.
\relaxin some circumstances, but it says nothing about how to get rid of the\relaxin an\edefcontext. Then I saw somewhere in an issue of TUGBoat that\dimexprand\numexprdo remove\relaxafter evaluating the dimension or number. That is indeed true, but they fail in the above example. – Ahmed Musa Mar 25 '11 at 16:05