1 % \iffalse meta-comment
5 % The LaTeX3 Project and any individual authors listed elsewhere
8 % This file is part of the Standard LaTeX `Tools Bundle'.
9 % -------------------------------------------------------
11 % It may be distributed and/or modified under the
12 % conditions of the LaTeX Project Public License, either version 1.3c
13 % of this license or (at your option) any later version.
14 % The latest version of this license is in
15 % http://www.latex-project.org/lppl.txt
16 % and version 1.3c or later is part of all distributions of LaTeX
17 % version 2005/12/01 or later.
19 % The list of all files belonging to the LaTeX `Tools Bundle' is
20 % given in the file `manifest.txt'.
24 %% File: enumerate.dtx Copyright 1993 1994 1999 David Carlisle
27 \ProvidesFile{enumerate.dtx}
29 %<package>\NeedsTeXFormat{LaTeX2e}
30 %<package>\ProvidesPackage{enumerate}
31 %<driver> \ProvidesFile{enumerate.drv}
33 % \ProvidesFile{enumerate.dtx}
34 [2015/07/23 v3.00 enumerate extensions (DPC)]
38 \documentclass{ltxdoc}
39 \usepackage{enumerate}
41 \DocInput{enumerate.dtx}
46 % \GetFileInfo{enumerate.dtx}
47 % \title{The \textsf{enumerate} package\thanks{This file
48 % has version number \fileversion, last
49 % revised \filedate.}}
50 % \author{David Carlisle}
52 % \MaintainedByLaTeXTeam{tools}
55 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 % \changes{v1.00}{1990/00/00}{First version (since lost)}
60 % \changes{v2.00}{1991/07/25}{New Algorithm}
61 % \changes{v2.01}{1992/06/26}{Re-issue for the new doc and docstrip.}
62 % \changes{v2.02}{1994/01/31}{Update for LaTeX2e}
63 % \changes{v3.00}{1999/03/05}{Add extension hook for tools/2916}
64 % \changes{v3.00}{2015/07/23}{Documentation fixes tools/2916}
67 % This package gives the enumerate environment an optional argument
68 % which determines the style in which the counter is printed.
70 % An occurrence of one of the tokens |A a I i| or |1| produces the value
71 % of the counter printed with (respectively) |\Alph \alph \Roman \roman|
74 % These letters may be surrounded by any strings involving any other
75 % \TeX\ expressions, however the tokens |A a I i 1| must be inside a
76 % |{ }| group if they are not to be taken as special.
83 % \parbox{2.2in}{\hbadness2000
84 % \begin{enumerate}[EX i.]
85 % \item one one one one one one one
86 % one one one one one\label{LA}
88 % \begin{enumerate}[{example} a)]
89 % \item one of two one of two one of two\label{LB}
93 % \begin{enumerate}[{A}-1]
98 % \vcenter{\hsize=2.4in
100 % \begin{enumerate}[EX i.]
101 % \item one one one one one one one
102 % one one one one\label{LA}
104 % \begin{enumerate}[{example} a)]
105 % \item one of two one of two
106 % one of two\label{LB}
111 % \begin{enumerate}[{A}-1]
112 % \item one\label{LC}
118 % |\label| and |\ref| may be used as with the standard {\tt
119 % enumerate} environment. |\ref| only produces the counter value,
120 % not the whole label. |\ref| prints the value in the same style
121 % as |\item|, as determined by the presence of one of the tokens
122 % |A a I i 1| in the optional argument. In the above example
123 % |\ref{LA}|, |\ref{LB}| and |\ref{LC}| produce
124 % `\ref{LA}', `\ref{LB}' and `\ref{LC}' respectively.
134 % \begin{macro}{\@enlab}
135 % Internal token register used to build up the label command from the
142 % \begin{macro}{\@enQmark}
143 % This just expands to a `?'. |\ref| will produce this, if no counter
150 % The next four macros build up the command that will print the item
151 % label. They each gobble one token or group from the optional argument,
152 % and add corresponding tokens to the register |\@enLab|. They each end
153 % with a call to |\@enloop|, which starts the processing of the next
155 % \begin{macro}{\@enLabel}
156 % Add the counter to the label. |#2| will be one of the `special'
157 % tokens |A a I i 1|, and is thrown away. |#1| will be a command
161 \edef\@enThe{\noexpand#1{\@enumctr}}%
162 \@enLab\expandafter{\the\@enLab\csname the\@enumctr\endcsname}%
167 % \begin{macro}{\@enSpace}
168 % \begin{macro}{\@enSp@ce}
169 % Add a space to the label. The tricky bit is to gobble the space token,
170 % as you can not do this with a macro argument.
172 \def\@enSpace{\afterassignment\@enSp@ce\let\@tempa= }
173 \def\@enSp@ce{\@enLab\expandafter{\the\@enLab\space}\@enloop}
178 % \begin{macro}{\@enGroup}
179 % Add a |{ }| group to the label.
181 \def\@enGroup#1{\@enLab\expandafter{\the\@enLab{#1}}\@enloop}
185 % \begin{macro}{\@enOther}
186 % Add anything else to the label
188 \def\@enOther#1{\@enLab\expandafter{\the\@enLab#1}\@enloop}
192 % \begin{macro}{\@enloop}
193 % \begin{macro}{\@enloop@}
194 % The body of the main loop.
195 % Eating tokens this way instead of using |\@tfor| lets you see
196 % spaces and {\bf all} braces. |\@tfor| would treat {\tt a} and
197 % |{a}| as special, but not |{{a}}|.
199 \def\@enloop{\futurelet\@entemp\@enloop@}
203 \ifx A\@entemp \def\@tempa{\@enLabel\Alph }\else
204 \ifx a\@entemp \def\@tempa{\@enLabel\alph }\else
205 \ifx i\@entemp \def\@tempa{\@enLabel\roman }\else
206 \ifx I\@entemp \def\@tempa{\@enLabel\Roman }\else
207 \ifx 1\@entemp \def\@tempa{\@enLabel\arabic}\else
208 \ifx \@sptoken\@entemp \let\@tempa\@enSpace \else
209 \ifx \bgroup\@entemp \let\@tempa\@enGroup \else
210 \ifx \@enum@\@entemp \let\@tempa\@gobble \else
213 % Hook for possible extensions
219 \fi\fi\fi\fi\fi\fi\fi\fi
222 % Process the current token, then look at the next.
228 % \begin{macro}{\@enhook}
229 % Hook for possible extensions.
230 % Some packages may want to extend the number of special characters
231 % that are associated with counter representations. This feature
232 % was requested to enable Russian alphabetic counting, but here
233 % I give an example of a footnote symbol counter, triggered by |*|.
235 % To enable a new counter type based on a letter, you just need
236 % to add a new |\ifx| clause by analogy with the code above.
237 % So for example to make |*| trigger footnote symbol counting.
238 % a package should do the following.
240 % Initialise the hook, in case the package is loaded before
241 % \textsf{enumerate}.
243 % \providecommand\@enhook{}
246 % Add to the hook a new |\ifx| clause that associates |*| with the
247 % |\fnsymbol| counter command.
249 % \g@addto@macro\@enhook{%
251 % \def\@tempa{\@enLabel\fnsymbol}%
254 % This code sequence should work whether it is loaded before or after
255 % this enumerate package. Any number of new counter types may be added
258 % At this point we just need initialise the hook, taking care not
259 % to over write any definitions another package may already have added.
261 \providecommand\@enhook{}
265 % \begin{macro}{\enumerate}
266 % The new {\tt enumerate} environment. This is the first half of the
267 % original enumerate environment. If there is an optional argument, call
268 % |\@@enum@| to define the label commands, otherwise call
269 % |\@enum@| which is the second half of the original definition.
272 \ifnum \@enumdepth >3 \@toodeep\else
273 \advance\@enumdepth \@ne
274 \edef\@enumctr{enum\romannumeral\the\@enumdepth}\fi
275 \@ifnextchar[{\@@enum@}{\@enum@}}
279 % \begin{macro}{\@@enum@}
280 % Handle the optional argument..
284 % Initialise the loop which will break apart the optional argument.
285 % The command to print the label is built up in |\@enlab|.
286 % |\@enThe| will be used to define |\theenum|\,$n$.
288 \@enLab{}\let\@enThe\@enQmark
290 % The |\@enum@| below is never expanded, it is used to detect the end
295 % Issue a warning if we did not find one of the `special' tokens.
297 \ifx\@enThe\@enQmark\@warning{The counter will not be printed.%
298 ^^J\space\@spaces\@spaces\@spaces The label is: \the\@enLab}\fi
300 % Define |\labelenum|$\,n$ and |\theenum|$\,n$.
302 \expandafter\edef\csname label\@enumctr\endcsname{\the\@enLab}%
303 \expandafter\let\csname the\@enumctr\endcsname\@enThe
305 % Set the counter to 7 so that we get the width of `vii' if roman
306 % numbering is in force then set |\leftmargin|$\,n$. to the width of the
307 % label plus |\labelsep|.
309 \csname c@\@enumctr\endcsname7
310 \expandafter\settowidth
311 \csname leftmargin\romannumeral\@enumdepth\endcsname
312 {\the\@enLab\hspace{\labelsep}}%
314 % Finally call |\@enum@| which is the second half of the original
321 % \begin{macro}{\@enum@}
322 % All the list parameters have now been defined, so call |\list|. This
323 % is taken straight from the original definition of |\enumerate|.
325 \def\@enum@{\list{\csname label\@enumctr\endcsname}%
326 {\usecounter{\@enumctr}\def\makelabel##1{\hss\llap{##1}}}}