Le 22/05/2013 09:22, Ulrich D i e z a �crit :
Yes this is exactly the same since \ifcase<number> expands everything
until it can evaluate <number> : \expandafter is useless here.
(a) \ifcase\iffalse 0\else 1 zero\else larger\else test\fi \fi
=> no error
all the same :
(b) \ifnum 0=\iffalse 0\else 1 zero\else larger\fi \fi
(c) But :\ifnum 1=\iffalse 0\else 1 zero\else larger\fi \fi
leads to an error : "extra \else"
This is because \else is both a delimiter and a command :
* As a delimiter, \else is checked by TeX to decide if it corresponds
to the very conditional that asked for an \else.
If so, it simply disappears updating the "currentifbranch".
the delimiter is "gobbled": \else branch to be executed.
If not, it is simply ignored and not executed as a command.
in true words: it does nothing.
* As a command, it is checked by TeX to decide if it is an
"extra \else" or not.
If not, \else is executed, looking forward for a matching \fi delimiter
that corresponds to the very conditional that asked for \fi.
This explains the noticed behaviour :
Case (b) for memory: \ifnum 0=\iffalse 0\else 1 zero\else larger\fi \fi
The first expansion is: \ifnum 0=1 zeros\else larger\fi \fi
\ifnum (false) goes until to the /delimiter/ \else which is
checked as "\else (iffalse)" since \iffalse is the nested
active conditional and therefore, \ifnum ignores it (nested
\else that don't correspond to \ifnum) : \else does nothing
and \ifnum still requires a matching \else (or \fi) and looks
forward for another candidate : it its way it sees the delimiter
\fi which is checked as \fi (iffalse) and is executed (end of the
nested conditional : "currentiflevel--")
but \ifnum is still requiring its matching \else (or \fi)
and looks forward, finds \fi which is checked as \fi (\ifnum)
and is executed ("currentiflevel--").
Case (a) is the same:
for memory \ifcase\iffalse 0\else 1 zero\else larger\else test\fi \fi
\ifcase evaluates to {case 1} and looks for the matching /delimiter/
\or (or \else or \fi ) and finds \else which is checked as \else
(iffalse) and ignored by \ifcase as a nested conditional : \else really
does nothing at all and \ifcase goes further still looking for a
matching \or, \else or \fi and finds \else again which is checked
as \else (iffalse) for the same reason and does nothing. Thus \ifcase
is still requiring a matching \or or \else (or \fi) and looks forward
again and reaches \fi which as a delimiter is checked as \fi (iffalse)
and executed ("currentiflevel--") and \ifcase is still requiring its
matching stuff, looking forward until to \fi, checked as \fi (\ifcase)
and executed as such ("currentiflevel--").
In case (c):
for memory \ifnum 1=\iffalse 0\else 1 \else larger\else error\fi \fi
First expansion: \ifnum 1=1 \else larger\else error\fi \fi
\ifnum evaluates to true and disappears then \else is executed as a
command : it is checked to be \else (iffalse) which is an error since
\else (iffalse) has been executed (currentifbranch is -1).
Regards