This is a couple of questions that stem from the answer to Problems understanding definition of \newif by @egreg.
In that @egreg says
Let's look at
\expandafter\expandafter\expandafter
\def\@if\iffoo{true}{\let\iffoo=\iftrue}%
recalling the definition of\@if
:
\def\@if#1#2{\csname\expandafter\if@\string#1#2\endcsname}
The first\expandafter
expands the third one, which in turn causes the expansion of\@if
, which has two arguments; in this case they are
#1<-\iffoo
#2<-true
But from my understanding the way that \def
works is that it is sensitive to the non-argument characters (i.e., characters other than #1
,#2
,…,#9
) that follow the command's name, such that (to take from p202 of the TeXbook) if you have \def\cs #1. #2\par{…}
then \cs
will need arguments that are given in the format #1. #2
where you need a .␣
separating the two, such that
\cs You owe \$5.00. Pay it.\par
gives
#1 <- You owe \$5.00
#2 <- Pay it.
Where (to quote the TeXbook)
the period in \5.00 doesn't stop
#1
, because TeX keeps going until finding a period that is immediately followed by a space.
And in the above \def\@if#1#2
is not \def\@if#1{#2}
, and I would imagine that the latter wouldn't work since it would interpret #2
as the definition of \@if#1
thinking that \@if
only took a single argument #1
.
My second difficulty was in understanding the following section
So we're left with
\expandafter\def\csname\expandafter\if@\string\iffoo true\endcsname
Now the remaining\expandafter
triggers the expansion of\csname
that, I recall, does exhaustive expansion until finding the matching\endcsname
. So, in order to know what control sequence name will be produced, we have to follow the expansion of all tokens after\csname
.
The first token is\expandafter
, that causes the expansion of\string
; since\escapechar
is-1
, we're left with
\if@ iffootrue\endcsname
But I do not understand why \string
has that effect both in the situation where \escapechar=-1
or where \escapechar
has not been reassigned.
Acc. to the TeXbook
\string<token>
TeX first reads the<token>
without expansion. If a control sequence token appears, its\string
expansion consists of the control sequence name (including\escapechar
as an escape character, if the control sequence isn't simply an active character).
So I'm left to surmise that if it replaced \
before iffoo
in \iffoo
then
- why does
\string
have that effect when\iffoo
is a control sequence and so (acc. to my likely misunderstanding of the TeXbook) should just be turned into its name, which is\iffoo
(or is itiffoo
, in which case why did the\escapechar
need to be changed). Or, - If
\
was replaced as it is a "control sequence token" as opposed to a "control sequence", per se, where did the-1
go?
And finally, in the next section @egreg says
Because of its definition,
\if@
removesi
andf
and leavesfootrue
; so we have
\def\footrue{\let\iffoo=\iftrue}
I believe that \if@
is defined in the following:
{\uccode‘1=‘i \uccode‘2=‘f \uppercase{\gdef\if@12{}}} % ‘if’ required
And I understand that the first part sets the uppercase value of 1
to be i
and 2
to be f
, but i do not understand why this section is enclosed in a separate set of brackets nor why this definition acts to remove i
and f
since it would seem to either be undefined if \uppercase
was applied initially since \GDEF
is not a valid command or would be expecting 1
and 2
as fixed arguments (not i
and f
) that it would eliminate (in that it returns an empty string).
I apologize if this seems entirely esoteric, but I am really trying to understand why these definitions work as they do, and I genuinely don't know where I'm going awry. I had originally intended to ask this in the comments of the original answer, but @egreg helpfully pointed out that my questions were extensive enough that comments were an inappropriate place for that discussion.