summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/ms/multitoc.dtx
blob: a88e69fbe65dd3135be33cdf89c1a34051502b0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
% \iffalse               
\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{multitoc}
%<package>        [1999/06/08 v2.01 MultiToc Package (MS)]
%
%<*driver>
\ProvidesFile{multitoc.drv}
      [1999/06/08 v2.01 Driver for MultiToc Package (MS)]
\documentclass{ltxdoc}
\usepackage{url}
\usepackage{ragged2e}
\usepackage[toc]{multitoc}
\GetFileInfo{multitoc.sty}
\setcounter{IndexColumns}{2}
\EnableCrossrefs
%%\DisableCrossrefs% Say \DisableCrossrefs if index is ready
\CodelineIndex    % Index code by line number
\OnlyDescription  % comment out for implementation details
%%\OldMakeIndex    % use if your MakeIndex is pre-v2.9
\setcounter{IndexColumns}{2}
\setlength{\IndexMin}{30ex}
\setlength{\premulticols}{\IndexMin}
\RaggedRight
\begin{document}
   \DocInput{multitoc.dtx}
\end{document}
%</driver>
%
% Copyright (c) [1998..1999] by Martin Schr\"oder.  All rights reserved.
%
% This program may be redistributed and/or modified under the terms
% of the LaTeX Project Public License, either version 1.0 of this
% license, or (at your option) any later version.
% The latest version of this license is in
%   CTAN:macros/latex/base/lppl.txt.
%
% Happy users are requested to send me a postcard. :-)
%
% For error reports in case of UNCHANGED versions see multitoc.ins
%
% \fi
%
% \CheckSum{83}
%
%% \CharacterTable
%% {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
%%  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
%%  Digits        \0\1\2\3\4\5\6\7\8\9
%%  Exclamation   \!     Double quote  \"     Hash (number) \#
%%  Dollar        \$     Percent       \%     Ampersand     \&
%%  Acute accent  \'     Left paren    \(     Right paren   \)
%%  Asterisk      \*     Plus          \+     Comma         \,
%%  Minus         \-     Point         \.     Solidus       \/
%%  Colon         \:     Semicolon     \;     Less than     \<
%%  Equals        \=     Greater than  \>     Question mark \?
%%  Commercial at \@     Left bracket  \[     Backslash     \\
%%  Right bracket \]     Circumflex    \^     Underscore    \_
%%  Grave accent  \`     Left brace    \{     Vertical bar  \|
%%  Right brace   \}     Tilde         \~}
%%
%% \iffalse meta-comment
%% ===================================================================
%%  @LaTeX-style-file{
%%     author          = {Martin Schr\"oder},
%%     version         = "2.01",
%%     date            = "8 June 1999",
%%     filename        = "multitoc.sty",
%%     address         = {Martin Schr\"oder
%%                        Cr\"usemannallee 3
%%                        D-28213 Bremen
%%     telephone       = "+49-421-2239425",
%%     email           = "Martin.Schroeder@ACM.org",
%%     pgp-Key         = "2048 bit / KeyID 292814E5",
%%     pgp-fingerprint = "7E86 6EC8 97FA 2995 82C3  FEA5 2719 090E",
%      checksum        = "62732 556 2216 19056",
%      codetable       = "ISO/ASCII",
%      keywords        = "LaTeX, multicol, toc, lof, lot",
%      dependences     = "multicol",
%      supported       = "yes",
%%     docstring       = "LaTeX package which automatically sets only 
%%                        the table of contents, list of figures and list
%%                        of tables in two or more columns.
%%                        The number of columns can be configured.
%%                        Uses the multicol package.
%
%                         The checksum field above contains a CRC-16
%                         checksum as the first value, followed by
%                         the equivalent of the standard UNIX wc
%                         (word count) utility output of lines,
%                         words, and characters.  This is produced
%                         by Robert Solovay's checksum utility."
%%  }
%% ===================================================================
%% \fi
%
%  \changes{v0.90}{1998/05/23}{New}
%  \changes{v1.00}{1998/08/09}{Documentation improved}
%  \changes{v2.00}{1998/08/23}{Redesign}
%  \changes{v2.01}{1999/06/08}{Moved to LPPL}
%
%  \newcommand*{\option}[1]{\textnormal{\sffamily#1}}
%  \newcommand*{\package}[1]{\textnormal{\sffamily#1}}
%  \newcommand*{\file}[1]{\textnormal{\texttt{.#1}}}
%  \newcommand*{\env}[1]{\textnormal{\texttt{#1}}}
%
%
% ^^A -----------------------------
%
%  \title{\unskip
%         The \textsf{multitoc} package^^A
%           \thanks{^^A
%              The version number of this file is \fileversion,
%              last revised \filedate.\protect\newline
%              The name \textsf{multitoc} is a tribute to the $8+3$ 
%              file-naming convention of certain ``operating 
%              systems''; strictly speaking it should be
%              \textsf{MulticolumnToc}.}
%        }
%  \author{Martin Schr\"oder\\[0.5ex]
%          \normalsize  Cr\"usemannallee 3\\
%          \normalsize  D-28213 Bremen\\
%          \normalsize  Martin.Schroeder@ACM.org\\
%          \scriptsize \texttt{PGP-Key: 2048 bit / KeyID 292814E5}\\[-0.5em]
%          \scriptsize \texttt{7E86 6EC8 97FA 2995~~82C3 FEA5 2719 090E}}
%  \date{\filedate}
%  \maketitle
%
% ^^A -----------------------------
%
%
%  \begin{abstract}
%     This package allows setting only the table of contents, list of 
%     figures and/or list of tables in two or more columns.
%     The number of columns can be configured via commands; the 
%     multicolumn toc(s) can be selected via package options.
%  \end{abstract}
%
%  \pagestyle{headings}
%
% ^^A -----------------------------
%
%  \tableofcontents
%
% ^^A -----------------------------
%
%  \section{Introduction}
%
%
% ^^A -----------------------------
%
%  \subsection{The problem\label{sec:sec:problem}}
%  ^^A
%  When you want to set only the table of contents of a document in two 
%  (or more columns), there is one known way^^A
%     \footnote{^^A
%        This was first used in the \package{doc} 
%        package\protect\cite{package:doc}.
%     }^^A
%  : Add an
%  \begin{quote}
%  |\addtocontents{toc}{\protect\begin{multicols}{2}}|
%  \end{quote}
%  before the \cs{tableofcontents} and an
%  \begin{quote}
%  |\addtocontents{toc}{\protect\end{multicols}}|
%  \end{quote}
%  at the end of the document.
%  This way your \file{toc} will start with |\begin{multicols}{2}|
%  and end with |\end{multicols}|.
%
%  This can be automised by using \cs{AtBeginDocument} and
%  \cs{AtEndDocument} but this has the drawback that it may
%  collide with other commands inserted using \cs{AtEndDocument} that
%  try to write information to the auxilary file (like the
%  \package{count1to} package\cite{package:count1to}).
%  This is because \TeX{} has two ways to write information to files 
%  \cite[p.\ 226--228]{KnuthTeXa}: immediately (when the \cs{write} is 
%  prefixed by \cs{immediate}) or deferred till the current page is 
%  finished and written out by \TeX{} (at the next \cs{shipout}).
%  \cs{addtocontents} does a deferred \cs{write}, \package{count1to}
%  does an immediate.
%
%  \begin{quote}
%     \small
%     Sidenote: \cs{addtocontents} writes a command to the \file{aux} file
%     to write its information to the \file{toc} file.
%     The \file{aux} is read in and executed by |\end{document}| and at
%     the next run by |\begin{document}|.
%     So the \file{toc} is written by |\end{document}| and at the
%     next run by |\begin{document}|.
%  \end{quote}
%
%  When you use the automised solution with \package{count1to} this may
%  happen:
%  \begin{enumerate}
%     \item The |\addtocontents{toc}{\protect\end{multicols}}| is inserted
%        using \cs{AtEndDocument} somewhere in the preamble.
%     \item \package{count1to} inserts this code
%        \begin{quote}
%        \hfuzz135pt
%        \small
%        |\clearpage|\\
%        |\immediate\write\@auxout{\string\newlabel{TotalPages}{{\the\count1}{\the\count1}}}|
%        \end{quote}
%        via an |\AtBeginDocument{\AtEndDocument{| so it can be sure that
%        this code is the \emph{last} code executed by \cs{AtEndDocument}.
%     \item At the |\end{document}| first the code from step~1 is executed
%        which adds the information to the current page to write the
%        |\@writefile{toc}{\end{multicols}}| to the auxilary file 
%        \emph{when the current page is finished}.
%
%        Then the code from step~2 is executed, which lets \LaTeX{} clear
%        the page (to force all pending writes to be written) and 
%        \emph{immediately} after that write the information for the 
%        |TotalPages| to the auxilary file.
%
%        Now suppose that the |\end{document}| is called \emph{just after}
%        \LaTeX{} has finished the last page.
%        The code from step~1 is never written to the file (since at the
%        \cs{clearpage} \LaTeX{} has no page to finish and so the code 
%        waits for the \cs{shipout} which won't come), but the code from 
%        step~2 is.
%        So you now have an \file{aux} which won't write the
%        |\end{multicols}| to the \file{toc}.
%        This of course produces an error at the next run.
%  \end{enumerate}
%
%
% ^^A -----------------------------
%
%  \subsection{A solution}
%  ^^A
%  \DescribeMacro{\@starttoc}
%  An easy way around this is to simply redefine \cs{@starttoc} from
%  \cite{package:ltsect} which reads in the \file{toc} to wrap a
%  \env{multicol} around it.\footnote{^^A
%     Thanks to Frank Mittelbach for reminding me of this.}^^A
%  $^{,}$^^A
%  \footnote{^^A
%     \raggedright
%     Version~1.00 of this package provided a more elaborate solution
%     to this using \cs{immediateaddtocontents}; this is no longer needed.
%     But the commands from version~1.00 are still provided (see
%     section~\ref{sec:sec:version100}).}
%
%
% ^^A -----------------------------
%
%  \section{Parameters}
%  ^^A
% \DescribeMacro{\multicolumntoc}
% \DescribeMacro{\multicolumnlot}
% \DescribeMacro{\multicolumnlof}
%  The number of columns for the table of contens, list of figures and
%  list of tables can be set by redefining the commands 
%  \cs{multicolumntoc}, \cs{multicolumnlot} and \cs{multicolumnlof}.
%  The default is two columns.
%
%
% ^^A -----------------------------
%
%  \section{Options}
%  ^^A
%  The package has the following options:
%  \nopagebreak
%  \begin{description}
%     \item[\normalfont\option{toc}]
%        The table of contents is set in \cs{multicolumntoc} columns.
%     \item[\normalfont\option{lof}]
%        The list of figures is set in \cs{multicolumnlof} columns.
%     \item[\normalfont\option{lot}]
%        The list of tables is set in \cs{multicolumnlot} columns.
%  \end{description}
%
%
% ^^A -----------------------------
%
%  \section{Required packages}
%  ^^A
%  The package requires the \package{multicol} and the 
%  \package{ifthen} packages.
%
%
% ^^A -----------------------------
%
%  \StopEventually{^^A
%
%
% ^^A -----------------------------
%
%  \begin{thebibliography}{1}
%     \raggedright
%     \bibitem{package:ltfiles}
%        Johannes Braams, David Carlisle, Alan Jeffrey, Leslie Lamport,
%        Frank Mittelbach, Chris Rowley and Rainer Sch\"opf.
%        \newblock \package{ltfiles.dtx}.
%        \newblock \texttt{CTAN: tex-archive/macros/latex/base/ltfiles.dtx}.
%        \newblock \LaTeXe{} kernel.
%     \bibitem{package:ltsect}
%        Johannes Braams, David Carlisle, Alan Jeffrey, Leslie Lamport,
%        Frank Mittelbach, Chris Rowley, Tobias Oetiker and Rainer Sch\"opf.
%        \newblock \package{ltsect.dtx}.
%        \newblock \url{CTAN: tex-archive/macros/latex/base/ltsect.dtx}.
%        \newblock \LaTeXe{} kernel.
%     \bibitem{KnuthTeXa}
%        Donald~E.\ Knuth.
%        \newblock \emph{The {\TeX}Book}, volume~A of \emph{Computers
%           and Typesetting}.
%        \newblock Addison-Wes\-ley, 1986.
%        \newblock Eleventh printing, revised, May 1991.
%     \bibitem{package:doc}
%        Frank Mittelbach.
%        \newblock The \package{doc} and \package{shortvrb} package.
%        \newblock \url{CTAN: tex-archive/macros/latex/base/doc.dtx}.
%        \newblock \LaTeXe{} package.
%     \bibitem{package:count1to}
%        Martin Schr\"oder.
%        \newblock The \package{count1to} package.
%        \newblock \url{CTAN: tex-archive/macros/latex/contrib/supported/ms/count1to.dtx}.
%        \newblock \LaTeXe{} package.
%  \end{thebibliography}
%
%     }
%
%
% ^^A -----------------------------
%
%  \section{The Implementation}
%  ^^A
%  \setlength{\parindent}{0pt}
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
%  We need the \package{multicol} and the \package{ifthen} packages.
%    \begin{macrocode}
\RequirePackage{multicol}
\RequirePackage{ifthen}
%    \end{macrocode}
%
%
% ^^A -----------------------------
%
%  \subsection{The parameters}
%  ^^A
%  \begin{macro}{\multicolumntoc}
%  \begin{macro}{\multicolumnlot}
%  \begin{macro}{\multicolumnlof}
%  \mbox{}
%    \begin{macrocode}
\newcommand{\multicolumntoc}{2}
\newcommand{\multicolumnlot}{2}
\newcommand{\multicolumnlof}{2}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%
% ^^A -----------------------------
%
%  \subsection{Initial Code}
%  ^^A
%  \begin{macro}{@multitoc@toc}
%     \changes{v2.00}{1998/08/23}{new}
%  \cs{if@multitoc@toc} is used to flag the use of the \option{toc}
%  otion.
%    \begin{macrocode}
\newboolean{@multitoc@toc}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{@multitoc@lot}
%     \changes{v2.00}{1998/08/23}{new}
%  \cs{if@multitoc@lot} is used to flag the use of the \option{lot}
%  otion.
%    \begin{macrocode}
\newboolean{@multitoc@lot}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{@multitoc@lof}
%     \changes{v2.00}{1998/08/23}{new}
%  \cs{if@multitoc@lof} is used to flag the use of the \option{lof}
%  otion.
%    \begin{macrocode}
\newboolean{@multitoc@lof}
%    \end{macrocode}
%  \end{macro}
%
%
% ^^A -----------------------------
%
%  \subsection{The options}
%  ^^A
%  The options simply set the corresponding flags.
%  \changes{v2.00}{1998/08/23}{Redesign}
%  \changes{v1.00}{1998/08/09}{\cs{clearpage}}
%    \begin{macrocode}
\DeclareOption{toc}{\setboolean{@multitoc@toc}{true}}
\DeclareOption{lot}{\setboolean{@multitoc@lot}{true}}
\DeclareOption{lof}{\setboolean{@multitoc@lof}{true}}
%    \end{macrocode}
%
%
% ^^A -----------------------------
%
%  \subsection{Executing options}
%  ^^A
%  There are no default options.
%    \begin{macrocode}
\ProcessOptions\relax
%    \end{macrocode}
%
%
% ^^A -----------------------------
%
%  \subsection{Redefining \cs{@starttoc}}
%  ^^A
% \begin{macro}{\@starttoc}
%  From \cite{package:ltsect}:
%  \begin{quote}
% The |\@starttoc|\marg{ext} command is used to define the commands:\\
% |\tableofcontents|, |\listoffigures|, etc.
%
% For example:
% |\@starttoc{lof}| is used in |\listoffigures|.  This command
% reads the |.|\meta{ext} file and sets up to write the new
% |.|\meta{ext} file.
%
% \begin{oldcomments}
% \@starttoc{EXT} ==
%   BEGIN
%     \begingroup
%        \makeatletter
%        read file \jobname.EXT
%        IF @filesw = true
%          THEN  open \jobname.EXT as file \tf@EXT
%        FI
%        @nobreak :=G FALSE  %% added 24 May 89
%     \endgroup
%   END
% \end{oldcomments}
%  \end{quote}
%  We store the current definition in \cs{@multitoc@starttoc}
%  and wrap it in a \env{multicol} environment if the right 
%  option has been selected.
%  We also have to determine the number of columns to use.\footnote{^^A
%     This could probably be coded more effeciently, but this code
%     works\ldots}
%    \begin{macrocode}
\let\@multitoc@starttoc\@starttoc
\renewcommand*{\@starttoc}[1]{%
   \ifthenelse{\boolean{@multitoc@toc}\and\equal{#1}{toc}}{%
      \begin{multicols}{\multicolumntoc}%
         \@multitoc@starttoc{#1}%
      \end{multicols}%
      }{}%
   \ifthenelse{\boolean{@multitoc@lot}\and\equal{#1}{lot}}{%
      \begin{multicols}{\multicolumnlot}%
         \@multitoc@starttoc{#1}%
      \end{multicols}%
      }{}%
   \ifthenelse{\boolean{@multitoc@lof}\and\equal{#1}{lof}}{%
      \begin{multicols}{\multicolumnlof}%
         \@multitoc@starttoc{#1}%
      \end{multicols}%
      }{}%
   }
%    \end{macrocode}
% \end{macro}
%
%
% ^^A -----------------------------
%
%  \subsection{Code from Version~1.00\label{sec:sec:version100}}
%  ^^A
%  The first version of this package took a different approach to
%  solving the problem mentioned in section~\ref{sec:sec:problem} and
%  provided the commands \cs{protected@write@immediate} and 
%  \cs{immediateaddtocontents}.
%  Their code has been retained here for compatibilty reasons.
%
%  \DescribeMacro{\immediateaddtocontents}
%  \cs{immediateaddtocontents} is a version of \cs{addtocontents} which 
%  does just what the name implies: Write the information \cs{immediate}.
%
%  \begin{macro}{\protected@write@immediate}
%  This is a changed version of \cs{protected@write} 
%  from~\cite{package:ltfiles}.
%  It takes three arguments: an output stream, some initialization
%  code, and some text to write.
%  It then writes this \emph{immediately}, with
%  appropriate handling of |\protect| and |\thepage|.
%  \changes{v2.00}{1998/09/06}{retained}
%    \begin{macrocode}
\newcommand*{\protected@write@immediate}[3]{%
      \begingroup
       \let\thepage\relax
       #2%
       \let\protect\string
       \edef\reserved@a{\immediate\write#1{#3}}%
       \reserved@a
      \endgroup
      \if@nobreak\ifvmode\nobreak\fi\fi
   }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\immediateaddtocontents}
%  This is a changed version of \cs{addtocontents} 
%  from~\cite{package:ltsect}.
%  The |\immediateaddtocontents{|\meta{table}|}{|\meta{text}|}| command
%  \emph{immediately} adds \meta{text} to the |.|\meta{table} file, 
%  with no page number.
%  \changes{v2.00}{1998/09/06}{retained}
%    \begin{macrocode}
\newcommand*{\immediateaddtocontents}[2]{%
  \protected@write@immediate\@auxout
      {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
      {\string\@writefile{#1}{#2}}}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% ^^A -----------------------------
%
%  \Finale
%
%   \PrintIndex\PrintChanges
%   ^^A Make sure that the index is not printed twice
%   ^^A (ltxdoc.cfg might have a second \PrintIndex command)
%   \let\PrintChanges\relax
%   \let\PrintIndex\relax