Debian Codegraph @

texmf-dist/source/latex/mdwtools/mdwlist.dtx

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