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 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 % \changes{v1.00}{1990/00/00}{First version (since lost)}
59 % \changes{v2.00}{1991/07/25}{New Algorithm}
60 % \changes{v2.01}{1992/06/26}{Re-issue for the new doc and docstrip.}
61 % \changes{v2.02}{1994/01/31}{Update for LaTeX2e}
62 % \changes{v3.00}{1999/03/05}{Add extension hook for tools/2916}
63 % \changes{v3.00}{2015/07/23}{Documentation fixes tools/2916}
66 % This package gives the enumerate environment an optional argument
67 % which determines the style in which the counter is printed.
69 % An occurrence of one of the tokens |A a I i| or |1| produces the value
70 % of the counter printed with (respectively) |\Alph \alph \Roman \roman|
73 % These letters may be surrounded by any strings involving any other
74 % \TeX\ expressions, however the tokens |A a I i 1| must be inside a
75 % |{ }| group if they are not to be taken as special.
82 % \parbox{2.2in}{\hbadness2000
83 % \begin{enumerate}[EX i.]
84 % \item one one one one one one one
85 % one one one one one\label{LA}
87 % \begin{enumerate}[{example} a)]
88 % \item one of two one of two one of two\label{LB}
92 % \begin{enumerate}[{A}-1]
97 % \vcenter{\hsize=2.4in
99 % \begin{enumerate}[EX i.]
100 % \item one one one one one one one
101 % one one one one\label{LA}
103 % \begin{enumerate}[{example} a)]
104 % \item one of two one of two
105 % one of two\label{LB}
110 % \begin{enumerate}[{A}-1]
111 % \item one\label{LC}
117 % |\label| and |\ref| may be used as with the standard {\tt
118 % enumerate} environment. |\ref| only produces the counter value,
119 % not the whole label. |\ref| prints the value in the same style
120 % as |\item|, as determined by the presence of one of the tokens
121 % |A a I i 1| in the optional argument. In the above example
122 % |\ref{LA}|, |\ref{LB}| and |\ref{LC}| produce
123 % `\ref{LA}', `\ref{LB}' and `\ref{LC}' respectively.
133 % \begin{macro}{\@enlab}
134 % Internal token register used to build up the label command from the
141 % \begin{macro}{\@enQmark}
142 % This just expands to a `?'. |\ref| will produce this, if no counter
149 % The next four macros build up the command that will print the item
150 % label. They each gobble one token or group from the optional argument,
151 % and add corresponding tokens to the register |\@enLab|. They each end
152 % with a call to |\@enloop|, which starts the processing of the next
154 % \begin{macro}{\@enLabel}
155 % Add the counter to the label. |#2| will be one of the `special'
156 % tokens |A a I i 1|, and is thrown away. |#1| will be a command
160 \edef\@enThe{\noexpand#1{\@enumctr}}%
161 \@enLab\expandafter{\the\@enLab\csname the\@enumctr\endcsname}%
166 % \begin{macro}{\@enSpace}
167 % \begin{macro}{\@enSp@ce}
168 % Add a space to the label. The tricky bit is to gobble the space token,
169 % as you can not do this with a macro argument.
171 \def\@enSpace{\afterassignment\@enSp@ce\let\@tempa= }
172 \def\@enSp@ce{\@enLab\expandafter{\the\@enLab\space}\@enloop}
177 % \begin{macro}{\@enGroup}
178 % Add a |{ }| group to the label.
180 \def\@enGroup#1{\@enLab\expandafter{\the\@enLab{#1}}\@enloop}
184 % \begin{macro}{\@enOther}
185 % Add anything else to the label
187 \def\@enOther#1{\@enLab\expandafter{\the\@enLab#1}\@enloop}
191 % \begin{macro}{\@enloop}
192 % \begin{macro}{\@enloop@}
193 % The body of the main loop.
194 % Eating tokens this way instead of using |\@tfor| lets you see
195 % spaces and {\bf all} braces. |\@tfor| would treat {\tt a} and
196 % |{a}| as special, but not |{{a}}|.
198 \def\@enloop{\futurelet\@entemp\@enloop@}
202 \ifx A\@entemp \def\@tempa{\@enLabel\Alph }\else
203 \ifx a\@entemp \def\@tempa{\@enLabel\alph }\else
204 \ifx i\@entemp \def\@tempa{\@enLabel\roman }\else
205 \ifx I\@entemp \def\@tempa{\@enLabel\Roman }\else
206 \ifx 1\@entemp \def\@tempa{\@enLabel\arabic}\else
207 \ifx \@sptoken\@entemp \let\@tempa\@enSpace \else
208 \ifx \bgroup\@entemp \let\@tempa\@enGroup \else
209 \ifx \@enum@\@entemp \let\@tempa\@gobble \else
212 % Hook for possible extensions
218 \fi\fi\fi\fi\fi\fi\fi\fi
221 % Process the current token, then look at the next.
227 % \begin{macro}{\@enhook}
228 % Hook for possible extensions.
229 % Some packages may want to extend the number of special characters
230 % that are associated with counter representations. This feature
231 % was requested to enable Russian alphabetic counting, but here
232 % I give an example of a footnote symbol counter, triggered by |*|.
234 % To enable a new counter type based on a letter, you just need
235 % to add a new |\ifx| clause by analogy with the code above.
236 % So for example to make |*| trigger footnote symbol counting.
237 % a package should do the following.
239 % Initialise the hook, in case the package is loaded before
240 % \textsf{enumerate}.
242 % \providecommand\@enhook{}
245 % Add to the hook a new |\ifx| clause that associates |*| with the
246 % |\fnsymbol| counter command.
248 % \g@addto@macro\@enhook{%
250 % \def\@tempa{\@enLabel\fnsymbol}%
253 % This code sequence should work whether it is loaded before or after
254 % this enumerate package. Any number of new counter types may be added
257 % At this point we just need initialise the hook, taking care not
258 % to over write any definitions another package may already have added.
260 \providecommand\@enhook{}
264 % \begin{macro}{\enumerate}
265 % The new {\tt enumerate} environment. This is the first half of the
266 % original enumerate environment. If there is an optional argument, call
267 % |\@@enum@| to define the label commands, otherwise call
268 % |\@enum@| which is the second half of the original definition.
271 \ifnum \@enumdepth >3 \@toodeep\else
272 \advance\@enumdepth \@ne
273 \edef\@enumctr{enum\romannumeral\the\@enumdepth}\fi
274 \@ifnextchar[{\@@enum@}{\@enum@}}
278 % \begin{macro}{\@@enum@}
279 % Handle the optional argument..
283 % Initialise the loop which will break apart the optional argument.
284 % The command to print the label is built up in |\@enlab|.
285 % |\@enThe| will be used to define |\theenum|\,$n$.
287 \@enLab{}\let\@enThe\@enQmark
289 % The |\@enum@| below is never expanded, it is used to detect the end
294 % Issue a warning if we did not find one of the `special' tokens.
296 \ifx\@enThe\@enQmark\@warning{The counter will not be printed.%
297 ^^J\space\@spaces\@spaces\@spaces The label is: \the\@enLab}\fi
299 % Define |\labelenum|$\,n$ and |\theenum|$\,n$.
301 \expandafter\edef\csname label\@enumctr\endcsname{\the\@enLab}%
302 \expandafter\let\csname the\@enumctr\endcsname\@enThe
304 % Set the counter to 7 so that we get the width of `vii' if roman
305 % numbering is in force then set |\leftmargin|$\,n$. to the width of the
306 % label plus |\labelsep|.
308 \csname c@\@enumctr\endcsname7
309 \expandafter\settowidth
310 \csname leftmargin\romannumeral\@enumdepth\endcsname
311 {\the\@enLab\hspace{\labelsep}}%
313 % Finally call |\@enum@| which is the second half of the original
320 % \begin{macro}{\@enum@}
321 % All the list parameters have now been defined, so call |\list|. This
322 % is taken straight from the original definition of |\enumerate|.
324 \def\@enum@{\list{\csname label\@enumctr\endcsname}%
325 {\usecounter{\@enumctr}\def\makelabel##1{\hss\llap{##1}}}}