Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

\ifcase

56 views
Skip to first unread message

Pluto

unread,
Nov 24, 2009, 10:54:11 AM11/24/09
to
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

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

Enrico Gregorio

unread,
Nov 24, 2009, 11:47:23 AM11/24/09
to
Pluto <a.m...@rocketmail.com> wrote:

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

Pluto

unread,
Nov 24, 2009, 12:26:33 PM11/24/09
to
> Enrico- Hide quoted text -
>
> - Show quoted text -

Many thanks! Revision time for me: the list of expandables as given in
the TeXbook.

Pluto

unread,
Nov 24, 2009, 1:39:29 PM11/24/09
to
On Nov 24, 4:47 pm, Enrico Gregorio <grego...@math.unipd.it> wrote:
> Enrico- Hide quoted text -
>
> - Show quoted text -

> 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.

Pluto

unread,
Nov 24, 2009, 1:56:54 PM11/24/09
to
> Heko's code) but the problem persisted.- Hide quoted text -

>
> - Show quoted text -

> 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.

Enrico Gregorio

unread,
Nov 24, 2009, 2:09:57 PM11/24/09
to
Pluto <a.m...@rocketmail.com> wrote:

> 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

Ulrich D i e z

unread,
Nov 24, 2009, 2:12:06 PM11/24/09
to
Pluto wrote:

>> > 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

Pluto

unread,
Nov 24, 2009, 3:14:30 PM11/24/09
to
> Ulrich- Hide quoted text -

>
> - Show quoted text -

> The synopsis of numbers in TeX (TeXbook, Chapter 24:


> Summary of Vetical Mode) might also be of interest.

Many thanks!

Ulrich D i e z

unread,
Nov 24, 2009, 3:44:28 PM11/24/09
to
Pluto wrote:

>> 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

0 new messages