|
|
\ifcase
The following code is from 'atbegshi' package. Please is it the case
that \ifcase stops searching for number after seeing a nonzero numeral
but continues to search after seeing zero?
\def\checkifdefinable#1{%
\ifcase%
\ifx#1\relax
\@ne
\else
\ifx#1\@undefined
\@ne
\else
\z@
\fi
\fi
\@latex@error{\string#1\space already defined}\@ehc
\fi
}
\def\x{} % case 0
\checkifdefinable\x
% From log file
\checkifdefinable #1->\ifcat $\detokenize {#1}$\else \ifcase
\ifx #1\relax \@ne \else \ifx #1\@undefined \@ne \else \z@
\fi \fi \@latex@error {\string #1\space already defined}\@ehc
\fi \fi
#1<-\x
{false}
{\ifcase}
{\ifx}
{false}
{\ifx}
{false}
{case 0}
{\fi}
\@latex@error #1#2->\GenericError {\space \space \space \@spaces
\@spaces \@spaces }{LaTeX Error: #1}{See the LaTeX manual or LaTeX
Companion for explanation.}{#2}
#1<-\string \x \space already defined
#2<-\@ehc
|
|
0
|
|
|
|
Reply
|
Pluto
|
8/18/2010 4:42:48 PM |
|
On 18 ao=FBt, 18:42, Pluto <a.m...@rocketmail.com> wrote:
> The following code is from 'atbegshi' package. Please is it the case
> that \ifcase stops searching for number after seeing a nonzero numeral
> but continues to search after seeing zero?
>
> \def\checkifdefinable#1{%
> =A0 =A0 =A0\ifcase%
> =A0 =A0 =A0 \ifx#1\relax
> =A0 =A0 =A0 =A0 \@ne
> =A0 =A0 =A0 \else
> =A0 =A0 =A0 =A0 \ifx#1\@undefined
> =A0 =A0 =A0 =A0 =A0 \@ne
> =A0 =A0 =A0 =A0 \else
> =A0 =A0 =A0 =A0 =A0 \z@
> =A0 =A0 =A0 =A0 \fi
> =A0 =A0 =A0 \fi
> =A0 =A0 =A0 \@latex@error{\string#1\space already defined}\@ehc
> =A0 =A0 \fi
>
> }
>
> \def\x{} % case 0
>
> \checkifdefinable\x
>
> % From log file
>
> \checkifdefinable #1->\ifcat $\detokenize {#1}$\else \ifcase
> \ifx #1\relax \@ne \else \ifx #1\@undefined \@ne \else \z@
> \fi \fi \@latex@error {\string #1\space already defined}\@ehc
> \fi \fi
> #1<-\x
> {false}
> {\ifcase}
> {\ifx}
> {false}
> {\ifx}
> {false}
> {case 0}
> {\fi}
>
> \@latex@error #1#2->\GenericError {\space \space \space \@spaces
> \@spaces \@spaces }{LaTeX Error: #1}{See the LaTeX manual or LaTeX
> =A0Companion for explanation.}{#2}
> #1<-\string \x \space already defined
> #2<-\@ehc
No, the first case is zero. So it stops searching after zero. Try
this:
\def\Number#1{%
\ifcase#1
zero
\or one
\or two
\else another number
\fi
}
Paul
|
|
0
|
|
|
|
Reply
|
zappathustra (234)
|
8/18/2010 5:19:51 PM
|
|
On 18 ao=FBt, 18:42, Pluto <a.m...@rocketmail.com> wrote:
> The following code is from 'atbegshi' package. Please is it the case
> that \ifcase stops searching for number after seeing a nonzero numeral
> but continues to search after seeing zero?
>
> \def\checkifdefinable#1{%
> =A0 =A0 =A0\ifcase%
> =A0 =A0 =A0 \ifx#1\relax
> =A0 =A0 =A0 =A0 \@ne
> =A0 =A0 =A0 \else
> =A0 =A0 =A0 =A0 \ifx#1\@undefined
> =A0 =A0 =A0 =A0 =A0 \@ne
> =A0 =A0 =A0 =A0 \else
> =A0 =A0 =A0 =A0 =A0 \z@
> =A0 =A0 =A0 =A0 \fi
> =A0 =A0 =A0 \fi
> =A0 =A0 =A0 \@latex@error{\string#1\space already defined}\@ehc
> =A0 =A0 \fi
>
> }
>
> \def\x{} % case 0
>
> \checkifdefinable\x
>
> % From log file
>
> \checkifdefinable #1->\ifcat $\detokenize {#1}$\else \ifcase
> \ifx #1\relax \@ne \else \ifx #1\@undefined \@ne \else \z@
> \fi \fi \@latex@error {\string #1\space already defined}\@ehc
> \fi \fi
> #1<-\x
> {false}
> {\ifcase}
> {\ifx}
> {false}
> {\ifx}
> {false}
> {case 0}
> {\fi}
>
> \@latex@error #1#2->\GenericError {\space \space \space \@spaces
> \@spaces \@spaces }{LaTeX Error: #1}{See the LaTeX manual or LaTeX
> =A0Companion for explanation.}{#2}
> #1<-\string \x \space already defined
> #2<-\@ehc
And in your example, the \ifx test returns 0, hence:
\ifcase\z@
<error>
\fi
If the command is definable, then 1 is returned, but since no case is
specified for 1, the conditional returns nothing (the first \or would
be case 1, but there isn't any).
|
|
0
|
|
|
|
Reply
|
zappathustra (234)
|
8/18/2010 5:25:40 PM
|
|
Pluto <a.musa@rocketmail.com> wrote:
> The following code is from 'atbegshi' package. Please is it the case
> that \ifcase stops searching for number after seeing a nonzero numeral
> but continues to search after seeing zero?
>
> \def\checkifdefinable#1{%
> \ifcase%
> \ifx#1\relax
> \@ne
> \else
> \ifx#1\@undefined
> \@ne
> \else
> \z@
> \fi
> \fi
> \@latex@error{\string#1\space already defined}\@ehc
> \fi
> }
>
> \def\x{} % case 0
>
> \checkifdefinable\x
>
> % From log file
>
> \checkifdefinable #1->\ifcat $\detokenize {#1}$\else \ifcase
> \ifx #1\relax \@ne \else \ifx #1\@undefined \@ne \else \z@
> \fi \fi \@latex@error {\string #1\space already defined}\@ehc
> \fi \fi
> #1<-\x
> {false}
> {\ifcase}
> {\ifx}
> {false}
> {\ifx}
> {false}
> {case 0}
> {\fi}
>
> \@latex@error #1#2->\GenericError {\space \space \space \@spaces
> \@spaces \@spaces }{LaTeX Error: #1}{See the LaTeX manual or LaTeX
> Companion for explanation.}{#2}
> #1<-\string \x \space already defined
> #2<-\@ehc
From "The TeX book", chapter 20:
| * Conditionals. When an \if... is expanded, TeX reads ahead as far as
| necessary to determine wheter the condition is true or false; and if false,
| it skips ahead (keeping track of \if...\fi nesting) until finding the \else,
| \or, \or \fi that ends the skipped text. Similarly, when \else, \or, or \fi
| is expanded, TeX reads to the end of any text that ought to be skipped.
| [...]
In the example with \ifcase above TeX reads ahead until one of the
numbers \@ne or \z@. The reading of the number is already complete,
because \@ne and \z@ are defined via \chardef and \newdimen. They
are not explicit numbers that needs termination by a space or an
unexpandable non-digit token. Then the status of \ifcase is known
and TeX continues reading in case of \z@. Or it skips to the final
\fi, because this closes the \fi (regarding \if...\fi nesting).
PS: Thanks anyway, reviewing the original definition in package
`atbegshi' I found two bugs generating the error message
(\space might be undefined and a left over \endgroup).
It will be fixed in the next version 1.13, in the next update
of my bundle. Later, because there is no hurry. The bugs aren't
triggered by LaTeX and in plainTeX triggering the bug would mean
a name clash with macros of the package. Because of the
lengthy prefix of the macros, the probability is very low.
--
Heiko Oberdiek
|
|
0
|
|
|
|
Reply
|
Heiko
|
8/18/2010 6:19:44 PM
|
|
|
3 Replies
398 Views
(page loaded in 0.075 seconds)
Similiar Articles:7/15/2012 4:39:47 AM
|
|
|
|
|
|
|
|
|