There are contexts where \relax
is ignored during the scan for the argument to a primitive command, but this is not one of them.
The TeXbook defines a ⟨filler⟩ as any sequence of space and \relax
tokens; when it is scanning for {
, a ⟨filler⟩ is ignored. Note, however that the TeXbook uses {
to denote an explicit or implicit character token of category code 1. So a ⟨filler⟩ is ignored when looking for the argument in a token register assignment or in a \lowercase
operation (see Get the lion to run in loops. Tersely for a peculiar aspect).
Another case when \relax
is ignored is when it is used for ending an expression to be passed to \numexpr
, \dimexpr
, \glueexpr
or \muexpr
.
When TeX wants to determine the argument for an assignment to a \count
register, it looks for an optional =
and then expands tokens (if expandable, of course) as long as it finds something that can be interpreted as an integer (which may include a prefix for the radix). At the first token that cannot be interpreted as valid input for a number in the chosen radix, the search stops and the number is evaluated for storing.
Important exception: when TeX has determined that an integer is in alphabetic format, that is, when the prefix is `
(backquote), it stops expanding tokens and takes the next character token or length one control sequence to be the alphabetic constant, translating it into ASCII code (or Unicode, for Unicode engines). An error would be raised if the input is incorrect.
Let's examine your attempts
\count10=\iftrue'\fi10 \the\count10
\count10='\iftrue\fi10 \the\count10
\count10='\relax10
In the first case TeX finds something expandable after =
and expands it. Well, the expansion of \iftrue
is empty and then '
is scanned because it's part or the “true text”; now TeX knows that it wants to look for an octal constant. Next it finds \fi
, whose expansion is empty and next 1
, then 0
and finally a space that ends the scanning process. The number is computed and the value stored in the register; the space is ignored and processing continues, in this case printing the value stored in the register.
The second case is completely similar. But the third one has a problem: after '
there's \relax
that's not ignored. It is an unexpandable token that cannot be interpreted as an octal digit and TeX stops with an error, because just the radix prefix is not a valid number.
Out of curiosity, here's another case that fails:
\chardef\foo=10
\count10='\foo
A \chardef
token can be used in the context of a number, but not with a radix prefix: it is an “abstract” number, just like in
\count10=\count255
The prefixes '
and "
can only be used in front of an explicit number, that is, a sequence of digits in the appropriate range.
x
there.\relax
, then, and I just happened to pick the expandable that didn't work like the if clause?\relax
is the "most popular" nonexpandable command though? (in the sense that its only purpose to exist is to be unexpandable) If you try\empty
it would work.