Fix dates and version numbers in the package files.
[mdwtools] / mdwlist.dtx
CommitLineData
86f6a31e 1% \begin{meta-comment} <general public licence>
2%%
3%% mdwlist package -- various list-related things
8bc5bdd2 4%% Copyright (c) 1996, 2002, 2003 Mark Wooding
86f6a31e 5%%
6%% This program is free software; you can redistribute it and/or modify
7%% it under the terms of the GNU General Public License as published by
8%% the Free Software Foundation; either version 2 of the License, or
9%% (at your option) any later version.
10%%
11%% This program is distributed in the hope that it will be useful,
12%% but WITHOUT ANY WARRANTY; without even the implied warranty of
13%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14%% GNU General Public License for more details.
15%%
16%% You should have received a copy of the GNU General Public License
17%% along with this program; if not, write to the Free Software
18%% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19%%
20% \end{meta-comment}
21%
22% \begin{meta-comment} <Package preambles>
23%<+package>\NeedsTeXFormat{LaTeX2e}
24%<+package>\ProvidesPackage{mdwlist}
af8af7eb 25%<+package> [2020/09/06 1.14.0 Various list-related things]
86f6a31e 26% \end{meta-comment}
27%
93e82ea5 28% \CheckSum{183}
86f6a31e 29%% \CharacterTable
30%% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
31%% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
32%% Digits \0\1\2\3\4\5\6\7\8\9
33%% Exclamation \! Double quote \" Hash (number) \#
34%% Dollar \$ Percent \% Ampersand \&
35%% Acute accent \' Left paren \( Right paren \)
36%% Asterisk \* Plus \+ Comma \,
37%% Minus \- Point \. Solidus \/
38%% Colon \: Semicolon \; Less than \<
39%% Equals \= Greater than \> Question mark \?
40%% Commercial at \@ Left bracket \[ Backslash \\
41%% Right bracket \] Circumflex \^ Underscore \_
42%% Grave accent \` Left brace \{ Vertical bar \|
43%% Right brace \} Tilde \~}
44%%
45%
46% \begin{meta-comment}
47%
48%<*driver>
49\input{mdwtools}
50\describespackage{mdwlist}
51\def\defaultdesc{%
52 \desclabelwidth{80pt}%
53 \desclabelstyle\nextlinelabel%
54 \def\makelabel{\bfseries}%
55}
56\newenvironment{cmdlist}
57 {\basedescript{\let\makelabel\cmd}}
58 {\endbasedescript}
59\mdwdoc
60%</driver>
61%
62% \end{meta-comment}
63%
64% \section{User guide}
65%
66% This package provides some vaguely useful list-related commands and
67% environments:
68% \begin{itemize*}
69% \item A way of building \env{description}-like environments.
70% \item Commands for making `compacted' versions of list environments
71% \item A method for suspending and resuming enumerated lists.
72% \end{itemize*}
73%
74% \subsection{Description list handling}
75%
76% Different sorts of description-type lists require different sorts of
77% formatting: I think that's fairly obvious. There are essentially three
78% different attributes which should be changable:
79% \begin{itemize*}
80% \item the indentation of the items being described,
81% \item the handling of labels which don't fit properly, and
82% \item the style used to typeset the label text.
83% \end{itemize*}
84% The first two items should usually be decided for all description-like
85% lists in the document, to ensure consistency of appearance. The last
86% depends much more on the content of the labels.
87%
88% \DescribeEnv{basedescript}
89% The \env{basedescript} environment acts as a `skeleton' for description
90% environments. It takes one argument, which contains declarations to
91% be performed while constructing the list. I'd consider it unusual for
92% the \env{basedescript} environment to be used in the main text: it's
93% intended to be used to build other environments.
94%
95% The declarations which can be used to define description-type environments
96% include all of those which are allowed when setting up a list (see the
97% \LaTeX\ book for information here). Some others, which apply specifically
98% to description lists, are also provided:
99%
100% \begin{itemize}
101%
102% \item \DescribeMacro{\desclabelwidth}
103% The \syntax{"\\desclabelwidth{"<length>"}"} declaration sets labels
104% to be left-aligned, with a standard width of \<length>; the item
105% text is indented by \<length> plus the value of |\labelsep|.
106%
107% \item \DescribeMacro{\desclabelstyle}
108% The label style determines how overlong labels are typeset. A style
109% may be set using the \syntax{"\\desclabelstyle{"<style>"}"}
110% declaration. The following \<style>s are provided:
111% \begin{cmdlist}
112% \item [\nextlinelabel] If the label is too wide to fit next to the
113% first line of text, then it is placed on a line by itself;
114% the main text is started on the next line with the usual
115% indentation.
116% \item [\multilinelabel] The label is typeset in a parbox with the
117% appropriate width; if it won't fit on one line, then the
118% text will be split onto subsequent lines.
119% \item [\pushlabel] If the label is too wide to fit in the space
120% allocated to it, the start of the item's text will be `pushed'
121% over to the right to provide space for the label. This is
122% the standard \LaTeX\ \env{description} behaviour.
123% \end{cmdlist}
124%
125% \item \DescribeMacro{\makelabel}
126% The |\makelabel| command is responsible for typesetting a label.
127% It is given one argument, which is the text given as an argument
128% to the |\item| command; it should typeset it appropriately. The
129% text will then be arranged appropriately according to the chosen
130% label style. This command should be redefined using |\renewcommand|.
131%
132% \end{itemize}
133%
134% \begin{figure}
135% \begin{demo}[w]{Various labelling styles}
136%\begin{basedescript}{\desclabelstyle{\nextlinelabel}}
137%\item [Short label] This is a short item, although it has quite a
138% lot of text attached to it.
139%\item [Slightly longer label text] This is a rather longer piece
140% of text, with a correspondingly slightly longer label.
141%\end{basedescript}
142%\medskip
143%\begin{basedescript}{\desclabelstyle{\multilinelabel}}
144%\item [Short label] This is a short item, although it has quite a
145% lot of text attached to it.
146%\item [Slightly longer label text] This is a rather longer piece
147% of text, with a correspondingly slightly longer label.
148%\end{basedescript}
149%\medskip
150%\begin{basedescript}{\desclabelstyle{\pushlabel}}
151%\item [Short label] This is a short item, although it has quite a
152% lot of text attached to it.
153%\item [Slightly longer label text] This is a rather longer piece
154% of text, with a correspondingly slightly longer label.
155%\end{basedescript}
156% \end{demo}
157% \end{figure}
158%
159% \DescribeMacro{\defaultdesc}
160% To allow document designers to control the global appearance of description
161% lists, the |\defaultdesc| command may be redefined; it is called while
162% setting up a new \env{basedescript} list, before performing the user's
163% declarations. By default, it attempts to emulate the standard \LaTeX\
164% \env{description} environment:\footnote{^^A
165% This is a slightly sanitised version of the real definition, which is
166% given in the implementation section of this document.}
167% \begin{listing}
168%\providecommand{\defaultdesc}{%
169% \desclabelstyle{\pushlabel}%
170% \renewcommand{\makelabel}[1]{\bfseries##1}%
171% \setlength{\labelwidth}{0pt}%
172%}
173% \end{listing}
174% Unfortunately, \LaTeX\ doesn't provide a means for overriding a command
175% which may or may not have been defined yet; in this case, I'd probably
176% recommend using the \TeX\ primitive |\def| to redefine |\defaultdesc|.
177%
178% If you want to redefine the \env{description} environment in terms of
179% the commands in this package, the following method is recommended:
180% \begin{listing}
181%\renewenvironment{description}{%
182% \begin{basedescript}{%
183% \renewcommand{\makelabel}[1]{\bfseries##1}%
184% }%
185%}{%
186% \end{basedescript}%
187%}
188% \end{listing}
189% This ensures that labels are typeset in bold, as is usual, but other
190% properties of the list are determined by the overall document style.
191%
192% \subsection{Compacted lists}
193%
194% \LaTeX\ tends to leave a certain amount of vertical space between list
195% items. While this is normally correct for lists in which the items are
196% several lines long, it tends to look odd if all or almost all the items
197% are only one line long.
198%
199% \DescribeMacro{\makecompactlist}
200% The command
201% \syntax{"\\makecompactlist{"<new-env-name>"}{"<old-env-name>"}"}
202% defines a new environment \<new-env-name> to be a `compacted' version of
203% the existing environment \<old-env-name>; i.e., the two environments are
204% the same except that the compacted version leaves no space between items
205% or paragraphs within the list.
206%
207% \DescribeEnv{itemize*}
208% \DescribeEnv{enumerate*}
209% \DescribeEnv{description*}
210% So that the most common cases are already handled, the package creates
211% compacted $*$-variants of the \env{itemize}, \env{enumerate} and
212% \env{description} environments. These were created using the commands
213% \begin{listing}
214%\makecompactlist{itemize*}{itemize}
215%\makecompactlist{enumerate*}{enumerate}
216%\makecompactlist{description*}{description}
217% \end{listing}
218%
219% Some list environments accept arguments. You can pass an argument to a
220% list environment using an optional argument to its compact variant. For
221% example,
222% \begin{listing}
223%\begin{foolist*}[{someargument}]
224% \end{listing}
225%
226% \subsection{Suspending and resuming list environments}
227%
228% \DescribeMacro{\suspend}
229% \DescribeMacro{\resume}
230% The |\suspend| and |\resume| commands allow you to temporarily end a list
231% environment and then pick it up where you left off. The syntax is fairly
232% simple:
233%
234% \begin{grammar}
235%
236% <suspend-cmd> ::= \[[
237% "\\suspend"
238% \begin{stack} \\ "[" <name> "]" \end{stack} "{" <env-name> "}"
239% \]]%
240%
241% <resume-cmd> ::= \[[
242% "\\resume"
243% \begin{stack} \\ "[" <name> "]" \end{stack} "{" <env-name> "}"
244% \begin{stack} \\ "[" <text> "]" \end{stack}
245% \]]%
246%
247% \end{grammar}
248%
249% The \<env-name> is the name of the environment; this will more often than
250% not be the \env{enumerate} environment. The \<name> is a magic name you
251% can use to identify the suspended environment; if you don't specify this,
252% the environment name is used instead.
253%
254% \begin{demo}{Suspended environments}
255%Here's some initial text. It's
256%not very interesting.
257%\begin{enumerate*}
258%\item This is an item.
259%\item This is another.
260%\suspend{enumerate*}
261%Some more commentry text.
262%\resume{enumerate*}
263%\item Another item.
264%\end{enumerate*}
265% \end{demo}
266%
267% You can pass arguments to a resumed list environment through the second
268% optional argument of the |\resume| command. If, for example, you're using
269% David Carlisle's \package{enumerate} package, you could say something like
270% \begin{listing}
271%\begin{enumerate}[\bfseries{Item} i]
272%\item An item
273%\item Another item
274%\suspend{enumerate}
275%Some intervening text.
276%\resume{enumerate}[{[\bfseries{Item} i]}]
277%\item Yet another item
278%\end{enumerate}
279% \end{listing}
280%
281% \implementation
282%
283% \section{Implementation}
284%
285% \begin{macrocode}
286%<*package>
287% \end{macrocode}
288%
289% \subsection{Description lists}
290%
291% \subsubsection{Label styles}
292%
293% \begin{macro}{\nextlinelabel}
294%
295% The idea here is that if the label is too long to fit in its box, we put
296% it on its own line and start the text of the item on the next. I've
297% used |\sbox| here to capture colour changes properly, even though I have
298% deep moral objections to the use of \LaTeX\ boxing commands. Anyway,
299% I capture the text in box~0 and compare its width to the amount of space
300% I have in the label box. If there's enough, I can just unbox the box;
301% otherwise I build a vbox containing the label text and an empty hbox --
302% |\baselineskip| glue inserted between the two boxes makes sure we get
303% the correct spacing between the two lines, and the vboxness of the vbox
304% ensures that the baseline of my strange thing is the baseline of the
305% \emph{bottom} box. I then bash the vbox on the nose, so as to make its
306% width zero, and leave that as the result. Either way, I then add glue
307% to left align whatever it is I've created.
308%
309% \begin{macrocode}
310\def\nextlinelabel#1{%
311 \sbox\z@{#1}%
312 \ifdim\wd\z@>\labelwidth%
313 \setbox\z@\vbox{\box\z@\hbox{}}%
314 \wd\z@\z@%
315 \box\z@%
316 \else%
317 \unhbox\z@%
318 \fi%
319 \hfil%
320}
321% \end{macrocode}
322%
323% \end{macro}
324%
325% \begin{macro}{\multilinelabel}
326%
327% A different idea -- make the label text wrap around onto the next line if
328% it's too long. This is really easy, actually. I use a parbox to contain
329% the label text, set to be ragged right, because there won't be enough
330% space to do proper justification. There's also a funny hskip there --
331% this is because \TeX\ only hyphenates things it finds sitting \emph{after}
332% glue items. The parbox is top-aligned, so the label text and the item
333% run downwards together. I put the result in box~0, and remove the depth,
334% so as not to make the top line of the item text look really strange.
335%
336% All this leaves a little problem, though: if the item text isn't very long,
337% the label might go further down the page than the main item, and possibly
338% collide with the label below. I must confess that I'm not actually sure
339% how to deal with this possibility, so I just hope it doesn't happen.
340%
341% By the way, I don't have moral objections to |\parbox|.
342%
343% \begin{macrocode}
344\def\multilinelabel#1{%
345 \setbox\z@\hbox{%
346 \parbox[t]\labelwidth{\raggedright\hskip\z@skip#1}%
347 }%
348 \dp\z@\z@%
349 \box\z@%
350 \hfil%
351}
352% \end{macrocode}
353%
354% \end{macro}
355%
356% \begin{macro}{\pushlabel}
357%
358% Now we implement the old style behaviour -- if the label is too wide, we
359% just push the first line of the item further over to the right. This
360% is really very easy indeed -- we just stick some |\hfil| space on the
361% right hand side (to left align if the label comes up too short). The
362% `push' behaviour is handled automatically by \LaTeX's item handling.
363%
364% \begin{macrocode}
365\def\pushlabel#1{{#1}\hfil}
366% \end{macrocode}
367%
368% \end{macro}
369%
370% \subsubsection{The main environment}
371%
372% \begin{macro}{\desclabelstyle}
373%
374% This is a declaration intended to be used only in the argument to the
375% \env{basedescript} environment. It sets the label style for the list.
376% All we do is take the argument and assign it to a magic control sequence
377% which \env{basedescript} will understand later.
378%
379% \begin{macrocode}
380\def\desclabelstyle#1{\def\desc@labelstyle{#1}}
381% \end{macrocode}
382%
383% \end{macro}
384%
385% \begin{macro}{\desclabelwidth}
386%
387% We set the label width and various other bits of information which will
388% make all the bits of the description line up beautifully. We set
389% |\labelwidth| to the value we're given (using |\setlength|, so that
390% people can use the \package{calc} package if they so wish), and make
391% the |\leftmargin| equal $|\labelwidth|+|\labelsep|$.
392%
393% \begin{macrocode}
394\def\desclabelwidth#1{%
395 \setlength\labelwidth{#1}%
396 \leftmargin\labelwidth%
397 \advance\leftmargin\labelsep%
398}
399% \end{macrocode}
400%
401% \end{macro}
402%
403% \begin{environment}{basedescript}
404%
405% This is the new description environment. It does almost everything you
406% could want from a description environment, I think. The argument is a
407% collection of declarations to be performed while setting up the list.
408%
409% This environment isn't really intended to be used by users -- it's here
410% so that you can define other description environments in terms of it,
411%
412% The environment is defined in two bits -- the `start' bit here simply
413% starts the list and inserts the user declarations in an appropriate
414% point, although sensible details will be inerted if the argument was
415% empty.
416%
417% \begin{macrocode}
418\def\basedescript#1{%
419% \end{macrocode}
420%
421% We must start the list. If the |\item| command's optional argument is
422% missing, we should just leave a blank space, I think.
423%
424% \begin{macrocode}
425 \list{}{%
426% \end{macrocode}
427%
428% So far, so good. Now put in some default declarations. I'll use a
429% separate macro for this, so that the global appearance of lists can be
430% configured.
431%
432% \begin{macrocode}
433 \defaultdesc%
434% \end{macrocode}
435%
436% Now we do the user's declarations.
437%
438% \begin{macrocode}
439 #1%
440% \end{macrocode}
441%
442% Now set up the other parts of the list. We set |\itemindent| so that the
443% label is up against the current left margin. (The standard version
444% actually leaves the label hanging to the left of the margin by a
445% distance of |\labelsep| for a reason I can't quite comprehend -- there's
446% an |\hspace{\labelsep}| in the standard |\makelabel| to compensate for
447% this. Strange\dots)
448%
449% To make the label start in the right place, the text of the item must
450% start a distance of $|\labelwidth|+|\labelsep|$ from the (pre-list) left
451% hand margin; this means that we must set |\itemindent| to be
452% $|\labelwidth|+|\labelsep|-|\leftmargin|$. Time for some \TeX\ arithmetic.
453%
454% \begin{macrocode}
455 \itemindent\labelwidth%
456 \advance\itemindent\labelsep%
457 \advance\itemindent-\leftmargin%
458% \end{macrocode}
459%
460% Now we must set up the label typesetting. We'll take the |\makelabel|
461% provided by the user, remember it, and then redefine |\makelabel| in
462% terms of the |\desclabelstyle| and the saved |\makelabel|.
463%
464% \begin{macrocode}
465 \let\desc@makelabel\makelabel%
466 \def\makelabel##1{\desc@labelstyle{\desc@makelabel{##1}}}%
467% \end{macrocode}
468%
469% I can't think of anything else which needs doing, so I'll call it a day
470% there.
471%
472% \begin{macrocode}
473 }%
474}
475% \end{macrocode}
476%
477% Now we define the `end-bit' of the environment. Since all we need to do
478% is to close the list, we can be ever-so slightly clever and use |\let|.
479%
480% \begin{macrocode}
481\let\endbasedescript\endlist
482% \end{macrocode}
483%
484% Note that with these definitions, the standard \env{description}
485% environment can be emulated by saying simply:
486% \begin{listing}
487%\renewenvironment{description}{%
488% \begin{basedescript}{}%
489%}{%
490% \end{basedescript}
491%}
492% \end{listing}
493%
494% \end{environment}
495%
496% \begin{macro}{\defaultdesc}
497%
498% Now to set up the standard description appearance. In the absence
499% of any other declarations, the label will `push' the text out the way if
500% the text is too long. The standard |\labelsep| and |\leftmargin| are not
501% our problem. We typeset the label text in bold by default. Also,
502% |\labelwidth| is cleared to 0\,pt, because this is what \LaTeX's usual
503% \env{description} does.
504%
505% \begin{macrocode}
506\providecommand\defaultdesc{%
507 \desclabelstyle\pushlabel%
508 \def\makelabel##1{\bfseries##1}%
509 \labelwidth\z@%
510}
511% \end{macrocode}
512%
513% \end{macro}
514%
515% \subsubsection{An example}
516%
517% \begin{environment}{note}
518%
519% The \env{note} environment is a simple application of the general
520% description list shown above. It typesets the label (by default, the
521% text `\textbf{note}') at the left margin, and the note text indented by
522% the width of the label.
523%
524% The code is simple -- we take the environment's argument (which may have
525% been omitted), store it in a box (using |\sbox| again, to handle colour
526% changes correctly), set the label width from the width of the box, and
527% then create a single item containing the label text. The text of the
528% environment then appears in exactly the desired place.
529%
530% I've not used |\newcommand| here, for the following reasons:
531% \begin{itemize}
532%
533% \item I don't like it much, to be honest.
534%
535% \item Until very recently, |\newcommand| only allowed you to define
536% `long' commands, where new paragraphs were allowed to be started
537% in command arguments; this removes a useful check which traps
538% common errors like missing out `|}|' characters. I'd prefer to
539% be compatible with older \LaTeX s than to use the new |\newcommand|
540% which provides a $*$-form to work around this restriction.
541%
542% \end{itemize}
543%
544% \begin{macrocode}
93e82ea5 545\ifx\note\@@undefined
546 \def\note{\@ifnextchar[\note@i{\note@i[Note]}}
547 \def\note@i[#1]{%
548 \basedescript{%
549 \sbox\z@{\makelabel{#1}}%
550 \desclabelwidth{\wd\z@}%
551 }%
552 \item[\box\z@]%
553 }
554 \let\endnote\endbasedescript
555\fi
86f6a31e 556% \end{macrocode}
557%
558% \end{environment}
559%
560%
561% \subsection{Compacted environments}
562%
563% Normal lists tend to have rather too much space between items if all or
564% most of the item texts are one line or less each. We therefore define
565% a macro |\makecompactlist| whuch creates `compacted' versions of existing
566% environments.
567%
568% \begin{macro}{\makecompactlist}
569%
570% We're given two arguments: the name of the new environment to create, and
571% the name of the existing list environment to create.
572%
573% The first thing to do is to ensure that the environment we're creating is
574% actually valid (i.e., it doesn't exist already, and it has a sensible
575% name). We can do this with the internal \LaTeX\ macro |\@ifdefinable|.
576%
577% \begin{macrocode}
578\def\makecompactlist#1#2{%
579 \expandafter\@ifdefinable\csname#1\endcsname%
580 {\makecompactlist@i{#1}{#2}}%
581}
582% \end{macrocode}
583%
584% We also ought to ensure that the other environment already exists. This
585% isn't too tricky. We'll steal \LaTeX's error and message for this.
586%
587% \begin{macrocode}
588\def\makecompactlist@i#1#2{%
589 \@ifundefined{#2}{\me@err{Environment `#2' not defined}\@ehc}{}%
590% \end{macrocode}
591%
592% The main work for starting a compact list is done elsewhere.
593%
594% \begin{macrocode}
595 \@namedef{#1}{\@compact@list{#2}}%
596% \end{macrocode}
597%
598% Now to define the end of the environment; this isn't terribly difficult.
599%
600% \begin{macrocode}
601 \expandafter\let\csname end#1\expandafter\endcsname%
602 \csname end#2\endcsname%
603% \end{macrocode}
604%
605% That's a compacted environment created. Easy, no?
606%
607% \begin{macrocode}
608}
609% \end{macrocode}
610%
611% The general case macro has to try slurping some arguments, calling the
612% underlying environment, and removing vertical space.
613%
614% \begin{macrocode}
615\def\@compact@list#1{\@testopt{\@compact@list@i{#1}}{}}
616\def\@compact@list@i#1[#2]{%
617 \@nameuse{#1}#2%
618 \parskip\z@%
619 \itemsep\z@%
620}%
621% \end{macrocode}
622%
623% \end{macro}
624%
625% \begin{environment}{itemize*}
626% \begin{environment}{enumerate*}
627% \begin{environment}{description*}
628%
629% Let's build some compacted environments now. These are easy now that
630% we've done all the work above.
631%
632% \begin{macrocode}
633\makecompactlist{itemize*}{itemize}
634\makecompactlist{enumerate*}{enumerate}
635\makecompactlist{description*}{description}
636% \end{macrocode}
637%
638% \end{environment}
639% \end{environment}
640% \end{environment}
641%
642%
643% \subsection{Suspending and resuming lists}
644%
645% This is nowhere near perfect; it relies a lot on the goodwill of the user,
646% although it seems to work fairly well.
647%
648% \begin{macro}{\suspend}
649%
650% The only thing that needs saving here is the list counter, whose name
651% is stored in |\@listctr|. When I get a request to save the counter, I'll
652% build a macro which will restore it when the environment is restored later.
653%
654% The first thing to do is to handle the optional argument. |\@dblarg| will
655% sort this out, giving me a copy of the mandatory argument if there's no
656% optional one provided.
657%
658% \begin{macrocode}
659\def\suspend{\@dblarg\suspend@i}
660% \end{macrocode}
661%
662% That's all we need to do here.
663%
664% \begin{macrocode}
665\def\suspend@i[#1]#2{%
666% \end{macrocode}
667%
668% Now I have a little problem; when I |\end| the environment, it will close
669% off the grouping level, and the counter value will be forgotten. This is
670% bad. I'll store all my definitions into a macro, and build the |\end|
671% command into it; that way, everything will be expanded correctly. This
672% requires the use of |\edef|, which means I must be a little careful.
673%
674% \begin{macrocode}
675 \edef\@tempa{%
676% \end{macrocode}
677%
678% The first thing to do is to end the environment. I don't want |\end|
679% expanded yet, so I'll use |\noexpand|.
680%
681% \begin{macrocode}
682 \noexpand\end{#2}%
683% \end{macrocode}
684%
685% Now I must define the `resume' macro. I'll use |\csname| to build the
686% named identifier into the name, so it won't go wrong (maybe). There's
687% a little fun here to make the control sequence name but not expand it
688% here.
689%
690% \begin{macrocode}
691 \def\expandafter\noexpand\csname resume.#1\endcsname{%
692% \end{macrocode}
693%
694% The counter name is hidden inside |\@listctr|, so the actual counter is
695% called `|\csname c@\@listctr\endcsname|'. I'll use |\the| to read its
696% current value, and assign it to the counter when the macro is used later.
697%
698% \begin{macrocode}
699 \csname c@\@listctr\endcsname\the\csname c@\@listctr\endcsname%
700% \end{macrocode}
701%
702% That's all we need to do there. Now close the macros and run them.
703%
704% \begin{macrocode}
705 }%
706 }%
707 \@tempa%
708}
709% \end{macrocode}
710%
711% \end{macro}
712%
713% \begin{macro}{\resume}
714%
715% Resuming environments is much easier. Since I use |\csname| to build the
716% name, nothing happens if you try to resume environments which weren't
717% suspended. I'll trap this and raise an error. Provide an optional
718% argument for collecting arguments to the target list.
719%
720% \begin{macrocode}
721\def\resume{\@dblarg\resume@i}
722\def\resume@i[#1]#2{\@testopt{\resume@ii{#1}{#2}}{}}
723\def\resume@ii#1#2[#3]{%
724 \begin{#2}#3%
725 \@ifundefined{resume.#1}{\ml@err@resume}{\@nameuse{resume.#1}}%
726}
727% \end{macrocode}
728%
729% \end{macro}
730%
731% That's all there is.
732%
733% \begin{macrocode}
734%</package>
735% \end{macrocode}
736%
737% \hfill Mark Wooding, \today
738%
739% \Finale
740%
741\endinput