# A question about \ifcase syntax

The command \today has been defined as follows:

\def\today{\ifcase\month\or
January\or February\or March\or April\or May\or June\or
July\or August\or September\or October\or November\or December\fi
\space\number\day, \number\year}


My problem is about \ifcase <number><case0>\or<case1>\or...\else<defaultcase>\fi. what is the <case0> in the above example? \month or {}? What does it means?

• \ifcase<integer> <case 0> \or <case 1> \or ... \fi selects the case according to the integer. So yes, this does nothing if \month equals 0. – user194703 Nov 6 '19 at 6:02
• Is is possible that \month equals 0? – user108724 Nov 6 '19 at 6:04
• No, probably not. But still you want to make sure that you get January for \month=1, and \ifcase starts counting at 0. – user194703 Nov 6 '19 at 6:06
• And isn't \month return month name or its number? – user108724 Nov 6 '19 at 6:08
• By default \month is an internal count register that on program startup is populated with the number of the current month (between 1 and 12, obviously). – Henri Menke Nov 6 '19 at 7:29

The <case 0> text is empty.

Indeed, \month is an “internal integer”, so \ifcase\month is a complete conditional test (in the sense that TeX will not do a look ahead with expansion in order to see whether a space follows).

TeX processes \ifcase as follows; suppose there are m \or tokens.

1. the <integer> value is determined, either by looking up the value of a register or by evaluating an explicit constant, let's say it's n;
2. if n < 0 or n > m, then TeX skips tokens up to (and including) \else or up to (and excluding) \fi if no \else comes along;
3. if 0 ≤ nm, tokens are skipped up to (and including) the n-th \or.

Since there is no “0-th” \or, no text at all is skipped when the <integer> evaluates to 0.

What happens to the following \or tokens and text between them? The expansion of \or consists in skipping tokens (without expansion) up to (and including) the matching \fi. Text between \else and \fi disappears in the same way, when n = m.

Can \month be zero or negative? Certainly so. The register's value is computed and assigned to at the beginning of the job with the number corresponding to the current month, but the register is writable and saying \month=0 (or any other integer value) would simply change the stored value (with obvious impact on dates, but that's another matter).

Assuming \month holds the value 11, upon expansion of \today, the input stream will contain

\ifcase\month\or
January\or February\or March\or April\or May\or June\or
July\or August\or September\or October\or November\or December\fi
\space\number\day, \number\year


TeX will now look at the value of \month and skip the first eleven \or, after removing \ifcase\month; this leaves

November\or December\fi\space\number\day, \number\year


Next November is passed to the next stage of processing (usually for printing) and the input stream will have

\or December\fi\space\number\day, \number\year


The expansion of \or consists in removing (without expansion) all tokens up to \fi:

\space\number\day, \number\year


and processing will go on by expanding \space.

In the (unlikely) event that \month has the value 0, nothing would be skipped after removal of \ifcase\month; the text up to \fi will be removed by the expansion of \or as in the previous case.

• Such a nice explanation...thanks a lot... – MadyYuvi Nov 6 '19 at 10:57