\ifcase
\ifx\version\@undefined\@ne\else\ifnum\version<\tw@\@ne\fi\fi\z@
\else
\@latex@error{Version 2 required}\@ehc
\fi
but the following fails
\ifcase\z@%
\ifx\version\@undefined\@ne\else\ifnum\version<\tw@\@ne\fi\fi
\else
\@latex@error{Version 2 required}\@ehc
\fi
The latter gives
! LaTeX Error: Missing \begin{document}.
Why does the above fail where the following works
\begingroup % Heiko Oberdiek
\expandafter\let\expandafter\x\csname v...@kvsetkeys.sty\endcsname
\ifcase 0\ifx\x\relax\else\ifx\x\empty\else 1\fi\fi
\else
\PackageInfo{kvsetkeys}{The package is already loaded}%
\fi
\endgroup
In your case \z@ is not expandable, so the search for a number
by \ifcase ends there. In Heiko's code, the search for a number
does not end with the 0: TeX looks ahead expanding macros in order
to see if a digit follows. Typical trick of Heiko's.
Your first code causes the expansion of \ifx.
Ciao
Enrico
Many thanks! Revision time for me: the list of expandables as given in
the TeXbook.
> In your case \z@ is not expandable, so the search for a number
> by \ifcase ends there.
Is it just a case of expansion of \z@? I replaced \z@ by 0 (as in
Heko's code) but the problem persisted.
> Is it just a case of expansion of \z@? I replaced \z@ by 0 (as in
> Heko's code) but the problem persisted.
The same problem of nonexpansion applies to \@ne. Replacing it by 1
solves the problem. Thanks.
> Is it just a case of expansion of \z@? I replaced \z@ by 0 (as in
> Heko's code) but the problem persisted.
Let's have a look:
\ifcase0%
ÔøΩ \ifx\version\@undefined\@ne\else\ifnum\version<\tw@\@ne\fi\fi
\else
ÔøΩ \@latex@error{Version 2 required}\@ehc
\fi
TeX expands what is after the 0 to see if other digits come along.
Suppose that \version is not defined: then the expansion of \ifx...\fi
produces \@ne which is /not/ a digit. If \version is defined and
expands to a number less than 1, the TeX will find again \@ne.
You should use
\ifcase0%
\ifx\version\@undefined 1\else\ifnum\version<\tw@ 1\fi\fi\relax
\else
\@latex@error{Version 2 required}\@ehc
\fi
If \version is not defined, the number after \ifcase will be 01
(and the search for a number continues until finding \relax
The same if \version is defined by \def\version{1} or \def\version{0}.
If \version is defined by \def\version{2} (or a bigger integer),
the number found will be 0 and \relax will be executed.
Of course you can use also \chardef\version=<number>
Ciao
Enrico
>> > Please why does the following work
>>
>> > \ifcase
>> > \ifx\version\@undefined\@ne\else\ifnum\version<\tw@\@ne\fi\fi\z@
>> > \else
>> > \@latex@error{Version 2 required}\@ehc
>> > \fi
>>
>> > but the following fails
>>
>> > \ifcase\z@%
>> > \ifx\version\@undefined\@ne\else\ifnum\version<\tw@\@ne\fi\fi
>> > \else
>> > \@latex@error{Version 2 required}\@ehc
>> > \fi
>
>Is it just a case of expansion of \z@? I replaced \z@ by 0 (as in
>Heko's code) but the problem persisted.
A leading 0 also is a character-token. Thus the number-argument
of \ifcase is considered to consist of a sequence of character-
tokens (0,1,2,3,4,5,6,7,8,9). When TeX expands tokens following
that 0 in order to find out if more such character-tokens follow
which would be considered part of the numerical value, it also
expands the \ifx construct and hereby finds \@ne which in turn
neither is a character-token nor does expand to a sequence
of character-tokens but is a chardef-token and therefore will not
be considered part of \ifcase's number-argument.
(\show\@ne yields: \@ne=\char"1.)
> Revision time for me: the list of expandables as given in
> the TeXbook.
The synopsis of numbers in TeX (TeXbook, Chapter 24:
Summary of Vetical Mode) might also be of interest.
Sincerely
Ulrich
> The synopsis of numbers in TeX (TeXbook, Chapter 24:
> Summary of Vetical Mode) might also be of interest.
Many thanks!
>> The synopsis of numbers in TeX (TeXbook, Chapter 24:
>> Summary of Vetical Mode) might also be of interest.
I should have written "Vertical Mode". Sorry.
> Many thanks!
You're welcome.
Ulrich