The stdenum package^{∗}

Andrew D. Lewis

1998/03/05

1 Why stdenum?

The L^{A}TEX tools bundle provides a useful enumerate package which provides the facilities for making customised lists. I use this package frequently, found it useful to make certain hacks to it for my special purposes. I basically found myself frequently making lists with commands like

     \begin{enumerate}[string1.]
     \item Item one.
     \item Item two.
     \end{enumerate}

which makes a list looking something like

string1. Item one.

string2. Item two.

(Here I am using the power of the enumerate package!)

Well, I wanted to make two hacks. First I wanted to make the font for the headings “string1.” and “string2.” changeable. This requires a minor change to the enumerate macros. In long documents there is a possibility of assigning the same string to more than one list. For example, you might type \begin{enumerate}[{AM}1.] to enumerate both the properties of amplitude modulated radio signals and the properties of a mechanics book with authors, say, Abraham and Marsden. I wanted to be warned if I tried to make two lists like this as it leads to potential confusion.

2 How to use the stdenum macros

The basic usage of stdenum is straightforward. If you want a list that looks like

string1. Item one.

string2. Item two.

stdenum type
     \begin{stdenum}{string}
     \item Item one.
     \item Item two.
     \end{stdenum}

\stdenumfont Note the font for the headers. This is set with the command \stdenumfont (the default is {\normalfont\sffamily}). You may use for string any L^{A}TEX text string you choose, including math symbols, etc.

You may wish to label string so you can refer to it later. To do this type \begin{stdenum}[label]{string}. This will give you string when you type \ref{label}. Of course, you will in all likelihood only want to use this reference

\enumref when talking about an item in the list. To facilitate this the command \enumref is provided. Its syntax is

\enumref{header-label}{item-label}

For example, if you type

     \begin{stdenum}[header-label]{string}
     \item Item one.\label{list-label}
     \item Item two.
     \end{stdenum}

then typing \enumref{header-label}{item-label} will produce “string1” in the correct font.

The enumerate macros do not always do what you want with the left margin. This is especially true if you are working with long strings or if you invoke the stdenum environment with in another list environment. For this reason I have added the facility for making hacks to the left margin. The syntax for this is

     \begin{stdenum}{string}[indent]

where indent is any valid TEX length. Of course, this is also possible when using the optional header-label.

Finally, there might be times, for example when you want to continue a list, that you actually want a stdenum list to have the same header as another. In

stdenum* this case, use the environment as you would the stdenum environment. Since it would make no sense to do so, you are not allowed to specify a header-label with a stdenum* list. In other words, the syntax is \begin{stdenum*}{string}.

3 Implementation

We heavily modify the macros in the enumerate package to the point where, to maintain the original packages full functionality, we bacically do it from scratch (i.e., change macro names). However, since we do use a few things from enumerate, we need to load it. Also set the default font. Note that if the option pdflatex is selected then the writing of the label is compatible with hyperref (although the hyperlink goes to the wrong place, for reasons I do not understand).

∗This file has version number v1.0a, last revised 1998/03/05.

1 ⟨∗package⟩

2

 3 \@ifundefined{@ADL@@usepdflatex}{\def\@ADL@@usepdflatex{\z@}}{}
 4 \DeclareOption{pdflatex}{\def\@ADL@@usepdflatex{\@ne}}
 5 \ProcessOptions
 6 \RequirePackage{enumerate}
 7 \newcommand\stdenumfont[1]{\def\@ADL@stdenumfont{#1}}
 8 \stdenumfont{\normalfont\sffamily}

Here is the basic environment and the first level of operations. These write the necessary things to the .aux file and then pass the arguments to \@@stdenum@ which performs the operations of the enumerate package.

9

10 \newenvironment{stdenum}{\@ifnextchar[{\@ADL@stdenum}{\@ADL@@stdenum}}
11 {\endenumerate}
12 \def\@ADL@stdenum[#1]#2{\protected@write\@auxout{}{\string\newenum{#2}}%
13 \ifnum\@ADL@@usepdflatex=\z@%
14  \protected@write\@auxout{}{\string\newlabel{#1}{{#2}{\thepage}}}%
15 \else%
16  \protected@write\@auxout{}{\string\newlabel{#1}{{#2}{\thepage}{\relax}{list.#2}{}}}%
17 \fi%
18 \@ADL@@@stdenum{{#2}1.}}
19 \def\@ADL@@stdenum#1{\protected@write\@auxout{}{\string\newenum{#1}}%
20 \@ADL@@@stdenum{{#1}1.}}
21 \def\@ADL@@@stdenum#1{%
22 \ifnum \@enumdepth >3 \@toodeep\else
23  \advance\@enumdepth \@ne
24  \edef\@enumctr{enum\romannumeral\the\@enumdepth}\fi
25 \@ADL@@stdenum@{#1}}

Here’s the stdenum* environment. Don’t allow labels here.

26

27 \expandafter\def\csname stdenum*\endcsname#1{\@ADL@@@stdenum{{#1}1.}}
28 \@namedef{endstdenum*}{\endenumerate}

These commands take care of checking whether there are multiply defined headers. The idea is much like that used by L^{A}TEX for checking multiple labels. At the end of the document we need to undefine \@ADL@newen@m so that we don’t get spurious warning messages. We also print a message if there are any warnings generated when the .aux file is read the first time.

29

30 \newcommand\newenum{\@ADL@newen@m{@ADL@@emum}}
31 \newcommand\@ADL@newen@m[2]{%
32 \@ifundefined{#1@#2}\relax%
33 {\gdef\@ADL@multipleenums{%
34 \@latex@warning@no@line{There were multiply-defined `stdenum' prefixes}}%
35 \@latex@warning@no@line{`stdenum' prefix `#2' multiply defined}}%

36 \global\@namedef{#1@#2}{{#2}{\thepage}}}
37 \let\@ADL@multipleenums\relax

38

39 \def\@ADL@enumtestdef#1#2{\relax}
40 \AtEndDocument{\let\@ADL@newen@m\@ADL@enumtestdef%
41 \ifx\@ADL@multipleenums\relax\else\@ADL@multipleenums\fi}

The \enumref command.

42

43 \newcommand\enumref[2]{\mbox{\@ADL@stdenumfont\ref{#1}\ref{#2}}}

Here are the enumerate macros modified for use with stdenum.

44

45 \def\@ADL@stdenLabel#1#2{%
46 \edef\@enThe{\noexpand#1{\@enumctr}}%
47 \@enLab\expandafter{\the\@enLab\csname the\@enumctr\endcsname}%
48 \@ADL@stdenloop}
49 \def\@ADL@stdenSpace{\afterassignment\@ADL@stdenSp@ce\let\@tempa= }
50 \def\@ADL@stdenSp@ce{\@enLab\expandafter{\the\@enLab\space}\@ADL@stdenloop}
51 \def\@ADL@stdenGroup#1{\@enLab\expandafter{\the\@enLab{#1}}\@ADL@stdenloop}
52 \def\@ADL@stdenOther#1{\@enLab\expandafter{\the\@enLab#1}\@ADL@stdenloop}
53 \def\@ADL@stdenloop{\futurelet\@entemp\@ADL@stdenloop@}
54 \def\@ADL@stdenloop@{%
55 \ifx A\@entemp         \def\@tempa{\@ADL@stdenLabel\Alph  }\else
56 \ifx a\@entemp         \def\@tempa{\@ADL@stdenLabel\alph  }\else
57 \ifx i\@entemp         \def\@tempa{\@ADL@stdenLabel\roman }\else
58 \ifx I\@entemp         \def\@tempa{\@ADL@stdenLabel\Roman }\else
59 \ifx 1\@entemp         \def\@tempa{\@ADL@stdenLabel\arabic}\else
60 \ifx \@sptoken\@entemp \let\@tempa\@ADL@stdenSpace         \else
61 \ifx \bgroup\@entemp   \let\@tempa\@ADL@stdenGroup         \else
62 \ifx \@ADL@stdenum@\@entemp   \let\@tempa\@gobble          \else
63  \let\@tempa\@ADL@stdenOther
64  \fi\fi\fi\fi\fi\fi\fi\fi
65 \@tempa}

66

67 \def\@ADL@@stdenum@#1{\@ifnextchar[{\@ADL@@stdenumskip@{#1}}
68 {\@ADL@@stdenumskip@{#1}[\z@]}}
69 \def\@ADL@@stdenumskip@#1[#2]{%
70 \@enLab{}\let\@enThe\@enQmark
71 \@ADL@stdenloop#1\@ADL@stdenum@
72 \ifx\@enThe\@enQmark\@warning{The counter will not be printed.%
73 ^^J\space\@spaces\@spaces\@spaces The label is: \the\@enLab}\fi
74 \expandafter\edef\csname label\@enumctr\endcsname{\the\@enLab}%
75 \expandafter\let\csname the\@enumctr\endcsname\@enThe
76 \csname c@\@enumctr\endcsname7
77 \expandafter\settowidth
78  \csname leftmargin\romannumeral\@enumdepth\endcsname
79  {\@ADL@stdenumfont\the\@enLab\hspace{\labelsep}}%
80 \begingroup\advance\@enumdepth by1%
81 \global\expandafter\advance\csname leftmargin\romannumeral\@enumdepth
82 \endcsname by#2\endgroup%

83 \@ADL@stdenum@{#2}}
84 \def\@ADL@stdenum@#1{\list{\csname label\@enumctr\endcsname}%
85  {\usecounter{\@enumctr}%
86  \def\makelabel##1{\hss\hspace{#1}\llap{\@ADL@stdenumfont##1}}}}

87

88 ⟨/package⟩