The enumerate package^{∗}

David Carlisle carlisle@cs.man.ac.uk

1994/01/31

Abstract

This package gives the enumerate environment an optional argument which determines the style in which the counter is printed.

An occurence of one of the tokens A a I i or 1 produces the value of the counter printed with (respectively) \Alph \alph \Roman \roman or

\arabic.

These letters may be surrounded by any strings involving any other TEX expressions, however the tokens A a I i 1 must be inside a { } group if they are not to be taken as special.

1 Examples

EX i. one one one one one one one one one one one one

EX ii. two

example a) one of two one of two one of two

example b) two of two

A-1 one

A-2 two

\begin{enumerate}[EX i.]
\item one one one one one one one
       one one one one\label{LA}
\item two
    \begin{enumerate}[{example} a)]
    \item one of two  one of two
          one of two\label{LB}
    \item two of two
    \end{enumerate}
    \item two of two
    \end{enumerate}
\end{enumerate}
\begin{enumerate}[{A}-1]
\item one\label{LC}
\item two
\end{enumerate}

∗This file has version number v2.02, last revised 1994/01/31.

\label and \ref may be used as with the standard enumerate environment. \ref only produces the counter value, not the whole label. \ref prints the value in the same style as \item, as determined by the presence of one of the tokens A a I i 1 in the optional argument. In the above example \ref{LA}, \ref{LB} and \ref{LC} produce ‘i’, ‘iia’ and ‘1’ respectively.

2 Macros

1 ⟨∗package⟩

\@enlab Internal token register used to build up the label command from the optional argument.

 2 \newtoks\@enLab

\@enQmark This just expands to a ‘?’. \ref will produce this, if no counter is printed.

 3 \def\@enQmark{?}

The next four macros build up the command that will print the item label. They each gobble one token or group from the optional argument, and add corresponding tokens to the register \@enLab. They each end with a call to \@enloop, which starts the processing of the next token.

\@enLabel Add the counter to the label. #2 will be one of the ‘special’ tokens A a I i 1, and is thrown away. #1 will be a command like \Roman.

 4 \def\@enLabel#1#2{%
 5 \edef\@enThe{\noexpand#1{\@enumctr}}%
 6 \@enLab\expandafter{\the\@enLab\csname the\@enumctr\endcsname}%
 7 \@enloop}

\@enSpace \@enSp@ce Add a space to the label. The tricky bit is to gobble the space token, as you can not do this with a macro argument.

 8 \def\@enSpace{\afterassignment\@enSp@ce\let\@tempa= }
 9 \def\@enSp@ce{\@enLab\expandafter{\the\@enLab\space}\@enloop}

\@enGroup Add a { } group to the label.

10 \def\@enGroup#1{\@enLab\expandafter{\the\@enLab{#1}}\@enloop}

\@enOther Add anything else to the label

11 \def\@enOther#1{\@enLab\expandafter{\the\@enLab#1}\@enloop}

\@enloop \@enloop@ The body of the main loop. Eating tokens this way instead of using \@tfor lets you see spaces and all braces. \@tfor would treat a and {a} as special, but not

{{a}}.
12 \def\@enloop{\futurelet\@entemp\@enloop@}

13 \def\@enloop@{%
14 \ifx A\@entemp         \def\@tempa{\@enLabel\Alph  }\else
15 \ifx a\@entemp         \def\@tempa{\@enLabel\alph  }\else
16 \ifx i\@entemp         \def\@tempa{\@enLabel\roman }\else
17 \ifx I\@entemp         \def\@tempa{\@enLabel\Roman }\else
18 \ifx 1\@entemp         \def\@tempa{\@enLabel\arabic}\else
19 \ifx \@sptoken\@entemp \let\@tempa\@enSpace         \else
20 \ifx \bgroup\@entemp   \let\@tempa\@enGroup         \else
21 \ifx \@enum@\@entemp   \let\@tempa\@gobble          \else
22  \let\@tempa\@enOther
23  \fi\fi\fi\fi\fi\fi\fi\fi

Process the current token, then look at the next.

24 \@tempa}

\enumerate The new enumerate environment. This is the first half of the original enumerate environment. If there is an optional argument, call \@@enum@ to define the label commands, otherwise call \@enum@ which is the second half of the original definition.

25 \def\enumerate{%
26 \ifnum \@enumdepth >3 \@toodeep\else
27  \advance\@enumdepth \@ne
28  \edef\@enumctr{enum\romannumeral\the\@enumdepth}\fi
29 \@ifnextchar[{\@@enum@}{\@enum@}}

\@@enum@ Handle the optional argument..

30 \def\@@enum@[#1]{%

Initialise the loop which will break apart the optional argument. The command to print the label is built up in \@enlab. \@enThe will be used to define \theenum n.

31 \@enLab{}\let\@enThe\@enQmark

The \@enum@ below is never expanded, it is used to detect the end of the token list.

32 \@enloop#1\@enum@

Issue a warning if we did not find one of the ‘special’ tokens.

33 \ifx\@enThe\@enQmark\@warning{The counter will not be printed.%
34 ^^J\space\@spaces\@spaces\@spaces The label is: \the\@enLab}\fi
Define \labelenum n and \theenum n.
35 \expandafter\edef\csname label\@enumctr\endcsname{\the\@enLab}%
36 \expandafter\let\csname the\@enumctr\endcsname\@enThe

Set the counter to 7 so that we get the width of ‘vii’ if roman numbering is in force then set \leftmargin n. to the width of the label plus \labelsep.

37 \csname c@\@enumctr\endcsname7
38 \expandafter\settowidth
39  \csname leftmargin\romannumeral\@enumdepth\endcsname
40  {\the\@enLab\hspace{\labelsep}}%

Finally call \@enum@ which is the second half of the original definition.

41 \@enum@}

\@enum@ All the list parameters have now been defined, so call \list. This is taken straight from the original definition of \enumerate.

42 \def\@enum@{\list{\csname label\@enumctr\endcsname}%
43  {\usecounter{\@enumctr}\def\makelabel##1{\hss\llap{##1}}}}

44 ⟨/package⟩

Change History

v1.00

General: First version (since lost) . 1

v2.00

General: New Algorithm . . . . . . . 1 v2.01

General: Re-issue for the new doc

and docstrip. . . . . . . . . . . . . . 1 v2.02

General: Update for LaTeX2e …. 1

Index

Numbers written in italic refer to the page where the corresponding entry is described, the ones underlined to the code line of the definition, the rest to the code lines where the entry is used.

Symbols

\@@enum@ . . . . . . . 29, \underline{30} \@enGroup . . . . . . \underline{10}, 20 \@enLab . . . . . . 2, 6,

9–11, 31, 34, 35, 40 \@enLabel …. \underline{4}, 14–18 \@enOther . . . . . . \underline{11}, 22 \@enQmark …. \underline{3}, 31, 33 \@enSp@ce . . . . . . . . . \underline{8} \@enSpace . . . . . . . \underline{8}, 19 \@enThe … 5, 31, 33, 36 \@enlab . . . . . . . . . . . \underline{2} \@enloop . 7, 9–11, \underline{12}, 32 \@enloop@ . . . . . . . . \underline{12} \@entemp …. 12, 14–21 \@enum@ 21, 29, 32, 41, \underline{42}

\@enumctr . . . . . . 5,

6, 28, 35–37, 42, 43

\@enumdepth . . 26–28, 39

\@gobble . . . . . . . . . 21

\@ifnextchar . . . . . . 29

\@ne . . . . . . . . . . . . . 27 \@spaces . . . . . . . . . 34 \@sptoken . . . . . . . . 19 \@tempa … 8, 14–22, 24 \@toodeep . . . . . . . . 26 \@warning . . . . . . . . 33

A \advance . . . . . . . . . 27

                          \afterassignment . . . 8

\Alph . . . . . . . . . . . . 14 \alph . . . . . . . . . . . . 15 \arabic . . . . . . . . . . 18

B \bgroup . . . . . . . . . . 20

C \csname . 6, 35–37, 39, 42

D \def . . . . . . . . . 3, 4,

8–18, 25, 30, 42, 43

E \edef . . . . . . . . 5, 28, 35 \else . . . . . . . 14–21, 26

                                                   \endcsname . . . . . . .

. . 6, 35–37, 39, 42

                                                   \enumerate . . . . . . . \underline{25}
                                                   \expandafter . . . . . .

6, 9–11, 35, 36, 38

F \fi . . . . . . . . 23, 28, 34

                                                   \futurelet . . . . . . . 12

H \hspace . . . . . . . . . . 40 \hss . . . . . . . . . . . . . 43

I \ifnum . . . . . . . . . . . 26 \ifx . . . . . . . . 14–21, 33

L \labelsep . . . . . . . . 40 \let …. 8, 19–22, 31, 36 \list . . . . . . . . . . . . 42 \llap . . . . . . . . . . . . 43

M

\makelabel . . . . . . . 43

N

\newtoks . . . . . . . . . . 2 \noexpand . . . . . . . . . 5

R \Roman . . . . . . . . . . . 17 \roman . . . . . . . . . . . 16

                          \romannumeral . . . 28, 39

S

                          \settowidth . . . . . . . 38

\space . . . . . . . . . . 9, 34

T \the 6, 9–11, 28, 34, 35, 40

U

                                                   \usecounter . . . . . . . 43