summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/tocvsec2/tocvsec2.dtx
blob: c40a36b018bdca29c861d7d30addabf9166ca0e0 (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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
% \iffalse meta-comment
%
% tocvsec2.dtx
% Author: Peter Wilson, Herries Press
% Maintainer: Will Robertson (will dot robertson at latex-project dot org)
% Copyright 1999-2004 Peter R. Wilson
% Copyright 2010-2011 Will Robertson
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any 
% later version: <http://www.latex-project.org/lppl.txt>
%
% This work has the LPPL maintenance status "maintained".
% The Current Maintainer of this work is Will Robertson.
%
% This work consists of the files listed in the README file.
%
%
%<*driver>
\ProvidesFile{tocvsec2.dtx}
%</driver>
%<usc>\ProvidesPackage{tocvsec2}
%<*usc>
    [2014/03/10 v1.3a variable ToC section entries]    
%</usc>
% 
%<*driver>
\documentclass{ltxdoc}
\EnableCrossrefs
\CodelineIndex
\setcounter{StandardModuleDepth}{1}
\begin{document}
  \DocInput{tocvsec2.dtx}
\end{document}
%</driver>
%
% \fi
%
% \CheckSum{142}
%
% \DoNotIndex{\',\.,\@M,\@@input,\@addtoreset,\@arabic,\@badmath}
% \DoNotIndex{\@centercr,\@cite}
% \DoNotIndex{\@dotsep,\@empty,\@float,\@gobble,\@gobbletwo,\@ignoretrue}
% \DoNotIndex{\@input,\@ixpt,\@m}
% \DoNotIndex{\@minus,\@mkboth,\@ne,\@nil,\@nomath,\@plus,\@set@topoint}
% \DoNotIndex{\@tempboxa,\@tempcnta,\@tempdima,\@tempdimb}
% \DoNotIndex{\@tempswafalse,\@tempswatrue,\@viipt,\@viiipt,\@vipt}
% \DoNotIndex{\@vpt,\@warning,\@xiipt,\@xipt,\@xivpt,\@xpt,\@xviipt}
% \DoNotIndex{\@xxpt,\@xxvpt,\\,\ ,\addpenalty,\addtolength,\addvspace}
% \DoNotIndex{\advance,\Alph,\alph}
% \DoNotIndex{\arabic,\ast,\begin,\begingroup,\bfseries,\bgroup,\box}
% \DoNotIndex{\bullet}
% \DoNotIndex{\cdot,\cite,\CodelineIndex,\cr,\day,\DeclareOption}
% \DoNotIndex{\def,\DisableCrossrefs,\divide,\DocInput,\documentclass}
% \DoNotIndex{\DoNotIndex,\egroup,\ifdim,\else,\fi,\em,\endtrivlist}
% \DoNotIndex{\EnableCrossrefs,\end,\end@dblfloat,\end@float,\endgroup}
% \DoNotIndex{\endlist,\everycr,\everypar,\ExecuteOptions,\expandafter}
% \DoNotIndex{\fbox}
% \DoNotIndex{\filedate,\filename,\fileversion,\fontsize,\framebox,\gdef}
% \DoNotIndex{\global,\halign,\hangindent,\hbox,\hfil,\hfill,\hrule}
% \DoNotIndex{\hsize,\hskip,\hspace,\hss,\if@tempswa,\ifcase,\or,\fi,\fi}
% \DoNotIndex{\ifhmode,\ifvmode,\ifnum,\iftrue,\ifx,\fi,\fi,\fi,\fi,\fi}
% \DoNotIndex{\input}
% \DoNotIndex{\jobname,\kern,\leavevmode,\let,\leftmark}
% \DoNotIndex{\list,\llap,\long,\m@ne,\m@th,\mark,\markboth,\markright}
% \DoNotIndex{\month,\newcommand,\newcounter,\newenvironment}
% \DoNotIndex{\NeedsTeXFormat,\newdimen}
% \DoNotIndex{\newlength,\newpage,\nobreak,\noindent,\null,\number}
% \DoNotIndex{\numberline,\OldMakeindex,\OnlyDescription,\p@}
% \DoNotIndex{\pagestyle,\par,\paragraph,\paragraphmark,\parfillskip}
% \DoNotIndex{\penalty,\PrintChanges,\PrintIndex,\ProcessOptions}
% \DoNotIndex{\protect,\ProvidesClass,\raggedbottom,\raggedright}
% \DoNotIndex{\refstepcounter,\relax,\renewcommand,\reset@font}
% \DoNotIndex{\rightmargin,\rightmark,\rightskip,\rlap,\rmfamily,\roman}
% \DoNotIndex{\roman,\secdef,\selectfont,\setbox,\setcounter,\setlength}
% \DoNotIndex{\settowidth,\sfcode,\skip,\sloppy,\slshape,\space}
% \DoNotIndex{\symbol,\the,\trivlist,\typeout,\tw@,\undefined,\uppercase}
% \DoNotIndex{\usecounter,\usefont,\usepackage,\vfil,\vfill,\viiipt}
% \DoNotIndex{\viipt,\vipt,\vskip,\vspace}
% \DoNotIndex{\wd,\xiipt,\year,\z@}
%
% \changes{v1.0}{1999/01/17}{First public release}
% \changes{v1.1}{1999/01/24}{Added none and all `sections'}
% \changes{v1.1}{1999/01/24}{Added maxsecnumdepth command}
% \changes{v1.1a}{2004/05/10}{Changed license from LPPL v1.0 to v1.3}
% \changes{v1.2}{2004/05/24}{Eliminated requirement for stdclsdv package}
% \changes{v1.2a}{2009/09/04}{New maintainer (Will Robertson)}
% \changes{v1.3a}{2011/03/10}{Some missing comment chars causing space issues}
%
% \def\dtxfile{tocvsec2.dtx}
% \GetFileInfo{\dtxfile}
% \newcommand*{\Lpack}[1]{\textsf {#1}}           ^^A typeset a package
% \newcommand*{\Lopt}[1]{\textsf {#1}}            ^^A typeset an option
% \newcommand*{\file}[1]{\texttt {#1}}            ^^A typeset a file
% \newcommand*{\Lcount}[1]{\textsl {\small#1}}    ^^A typeset a counter
% \newcommand*{\pstyle}[1]{\textsl {#1}}          ^^A typeset a pagestyle
% \newcommand*{\Lenv}[1]{\texttt {#1}}            ^^A typeset an environment
%
% \title{The \Lpack{tocvsec2} package\thanks{This
%        file (\texttt{\dtxfile}) has version number \fileversion, last revised
%        \filedate.}}
%
% \author{
%   Author: Peter Wilson, Herries Press \\
%   Maintainer: Will Robertson \\
%   \texttt{will dot robertson at latex-project dot org}
% }
% \date{\filedate}
% \maketitle
% \begin{abstract}
%    The \Lpack{tocvsec2} package provides means of controlling the sectional 
% numbering and/or the entries
% in the Table of Contents on a section by section basis.
% It is a replacement for the \Lpack{tocvsec} package, which should 
% not be used.
% Use of the package requires e\TeX\ and the \Lpack{ifthen} package to be available.
% \end{abstract}
% \tableofcontents
%
% ^^A \StopEventually{}
%
% 
%
% \section{Introduction}
%
% In the standard classes two commands are used to control the numbering
% of sectional divisions in a document, and which level of sectional
% headings will be included in the Table of Contents (the ToC). Sometimes
% finer control of these aspects of \LaTeX{} is required. The \Lpack{tocvsec2}
% provides for control over the entries into the ToC on a section by section
% basis. It also provides a means of locally controlling sectional numbering
% without having to resort to the starred version of the sectional commands.
% The package requires the \Lpack{ifthen} package 
% to be available.
% 
% Portions of the package were developed as part of a class
% and package bundle for typesetting ISO standards~\cite{PRW96i}.
% This manual is typeset according to the conventions of the
% \LaTeX{} \textsc{docstrip} utility which enables the automatic
% extraction of the \LaTeX{} macro source files~\cite{GOOSSENS94}.
%
%    Section~\ref{sec:usc} describes the usage of the package.
% Commented source code for the package is in Section~\ref{sec:code}.
%
% \DescribeMacro{secnumdepth}
% The \LaTeX{} \Lcount{secnumdepth} counter specifies the level number
% for the least significant
% sectional heading that will be numbered. In all the standard classes
% |\section| has a level number of 1, |\subsection| has a level number
% of 2, and so on. In the \Lpack{article} class (and its derivatives), 
% |\part| has a level number of 0. In the \Lpack{book} and \Lpack{report}
% classes, |\chapter| is level number 0 and |\part| has level number -1.
%
% The \Lcount{secnumdepth} counter is normally set in the preamble and
% remains constant thereafter. For example:
% \begin{verbatim}
% \setcounter{secnumdepth}{2}
% \end{verbatim}
% specifies that |\subsection|s and above should be numbered and
% |\subsubsections| and below should not be numbered. It turns out
% that \Lcount{secnumdepth} can be changed at any point in a document, not
% just in the preamble, to make a (temporary) change to the section numbering
% level. This is possible because the heading commands check the value
% of \Lcount{secnumdepth} to decide whether or not to number the heading.
%
% \DescribeMacro{tocdepth}
% The \Lcount{tocdepth} counter specifies the level number of the least 
% significant sectional unit that will be listed in the printed Table of
% Contents (ToC). For example:
% \begin{verbatim}
% \setcounter{tocdepth}{1}
% \end{verbatim}
% specifies that the printed ToC should only list sectional headings down
% to the |\section| level. The value of \Lcount{tocdepth} has to be set
% before the |\tableofcontents| command is used. Each sectioning command 
% puts an entry into the \file{.toc} file, irrespective of the \Lcount{tocdepth}
% value. The code implementing the typesetting of the ToC uses 
% \Lcount{tocdepth} to determine whether or not an entry should be printed.
% Thus, unlike \Lcount{secnumdepth} which can be altered at any time and have
% an effect, it is only the value of \Lcount{tocdepth} at the time of 
% printing the entries in the |\tableofcontents| that is used --- 
% any subsequent changes to 
% \Lcount{tocdepth} are immaterial.
%
% Note that \Lcount{tocdepth} only controls what appears in the ToC,
% and \Lcount{secnumdepth} only controls which sectional headings are
% numbered. The effect of changing one has no bearing on the other.
%
% \section{The \Lpack{tocvsec2} package} \label{sec:usc}
%
% The \Lpack{tocvsec} package changed the way in which entries were written
% to the \file{.toc} file, enabling effective changes to be made to
% \Lcount{tocdepth} at any point in a document.
%
% The basis of that package was to ensure that only those sectional elements
% that were required to appear in the printed ToC were written to the \file{.toc}
% file. The sectional commands call the |\addcontentsline| command to
% write an entry to the \file{.toc} file.
% There were two methods to achieve the desired functionality, both of which 
% required
% modifications to the internal \LaTeX{} macros.
% \begin{enumerate}
% \item Modify the sectional commands so that they check the value of
% \Lcount{tocdepth} in order to decide whether or not to put an entry
% into the \file{.toc} file (i.e., call |\addcontentsline|).
% \item Modify |\addcontentsline| so that it decides whether or not to write
% to the \file{.toc} file. This is less efficient in terms of processing
% time than changing the sectional commands.
% \end{enumerate}
%
% Both approaches had disadvantages. If the \Lpack{tocvsec} package
% changed the sectional commands and it was used in conjunction with
% another package that also changes these definitions, then one or the other
% package would not work as expected. On the other hand, changing the 
% |\addcontentsline| command may have had unexpected results if |\addcontentsline|
% was either modified or used in a different manner elsewhere in the document.
%
%    The \Lpack{tocvsec2} package takes a different approach which does
% not have these disadvantages. It provides a means of inserting commands
% into the \file{.toc} file that change the current value of 
% \Lcount{tocdepth} within the body of the file.
%
%
% The package also provides some utility commands so you don't have to remember
% the level numbers of the sectioning commands.
%
% \subsection{Changing ToC appearances}
%
% \DescribeMacro{\maxtocdepth}
% The |\maxtocdepth{|\meta{sec}|}| command can be used after the preamble
% (and before the |\tableofcontents| command) to set the global value
% for the \Lcount{tocdepth}. \meta{sec} is the name of a sectioning
% division (e.g., |part| or |paragraph|). You can also use |all|,
% meaning all sectioning divisions, or |none|, meaning no sectioning divisions.
%
% \textbf{Note well}: after \cs{tableofcontents}, the \Lcount{tocdepth}
% is reset to the value specified by \cs{maxtocdepth} in case that counter is
% used by a subsequent `List of Figures' or `List of Tables', as in the
% standard \LaTeX\ classes.
%
%
% \DescribeMacro{\settocdepth}
% The |\settocdepth{|\meta{sec}|}| command can be used to change the value of
% the \Lcount{tocdepth} counter within the \file{.toc} file, 
% where \meta{sec} is the name of a sectional
% division (e.g., \texttt{chapter} or \texttt{subsection}), or |all| or 
% |none|. For example,
% |\settocdepth{section}| will set \Lcount{tocdepth} to be 1 within the
% \file{.toc} file, until it is altered by another |\settocdepth|
% command. The command
% cannot be used in the preamble (i.e., before |\begin{document}|), but
% can be used any point thereafter.
%
% \Lcount{tocdepth} should be set in the preamble, or immediately after,
% to the least 
% significant sectional unit
% that should be in the printed ToC.
% Later, after the |\tableofcontents| command,  it is possible to
% to use |\settocdepth| to change \Lcount{tocdepth} to a different
% sectional level.
%
% \DescribeMacro{\resettocdepth}
% After \Lcount{tocdepth} has been changed with |\settocdepth|, it is
% possible to reset it to its previous value with |\resettocdepth|.
% In fact, you may use |\resettocdepth| multiple times
% to reset multiple uses of |\settocdepth|. (It behaves like a stack, for
% you computer-science-types.)
% If you wish to reset \Lcount{tocdepth} to its original value completely,
% use |\resettocdepth*|.
%
% As an example, assume that
% the ToC should list subsections and above, but there is one particular
% section in the document which consists of a set of definitions, each of
% which is presented as a subsection, but these should not appear in the
% printed ToC. 
% \begin{verbatim}
% \documentclass{...}
% \usepackage{tocvsec2}
% ...
% \begin{document}
%       \maxtocdepth{subsection}
% ...
% \tableofcontents
% ...
% \section{Definitions}
%       \settocdepth{section}
% \subsection{Definition 1}
%  ...
%       \resettocdepth %% equivalent to "\settocdepth{subsection}"
% \section{After definitions}
% ...
% \end{verbatim}
%
% \section{Changing section numbering}
%
% \DescribeMacro{\setsecnumdepth}
% The |\setsecnumdepth{|\meta{sec}|}| command is similar to |\settocdepth| 
% except
% that it changes the value of \Lcount{secnumdepth} at the point in
% the document where it is called. Like the |\settocdepth|
% command, it cannot be used in the preamble, but can be used as often as
% necessary after that.
%
% \DescribeMacro{\maxsecnumdepth}
% The |\maxsecnumdepth{|\meta{sec}|}| command is similar to |\maxtocdepth|
% except that it is for setting the default value for \Lcount{secnumdepth}
% after the preamble.
% In previous versions of the package if you used |\setsecnumdepth| for this
% purpose you might find an extra blank page in the typeset manuscript, but
% nowadays the two commands are interchangeable.
%
% \DescribeMacro{\resetsecnumdepth}
% Similarly to |\resettocdepth|, this command cycles back through previous
% values for \Lcount{secnumdepth} so you don't have to keep track of them
% yourself if you need to change its value for only a short component of a
% manuscript. By writing |\resetsecnumdepth*|, you can reset entirely back
% to a clean state with \Lcount{secnumdepth} set to its original value.
%
% For example, assume that in a document the sectional divisions are
% normally numbered down to the sub-subsection level, but within a particular
% section, they should only be numbered to the subsection level. Also,
% all sectional divisions within the appendices are to be numbered.
% This can be accomplished like:
% \begin{verbatim}
% \documentclass{...}
% \usepackage{tocvsec2}
% ...
% \begin{document}
%       \maxsecnumdepth{subsubsection}
% ...
% \tableofcontents
% ...
% \section{Normal section}
% ...
% \section{Reduce numbering} 
%       \setsecnumdepth{subsection}
% ...
%       \resetsecnumdepth %% equivalent to "\setsecnumdepth{subsubsection}"
% \section{Another normal section}
%  ...
% \appendix
%       \setsecnumdepth{all}
% ...
% \end{verbatim}
%
%
%
%
% \section{The package code} \label{sec:code}
%
%    \begin{macrocode}
%<*usc>
\RequirePackage{ifthen}
%    \end{macrocode}
%
% In order to try and avoid name clashes with other packages, each internal
% name will include the character string \texttt{t@c}.
%
% Issue warning if there are no recognized sectional divisions. 
%    \begin{macrocode}
\newif\ift@cchapter
  \t@cchapterfalse
\@ifundefined{chapter}{%
  \@ifundefined{section}{%
    \PackageWarning{tocvsec2}{%
       I don't recognize any divisions but I'll do my best}}{}}%
  {\t@cchaptertrue}

%    \end{macrocode}
%
% \begin{macro}{\if@knownsect@c}
% \begin{macro}{\@setseccntt@c}
% A helper macro to set a sectioning-related counter. Call as
% |\@setseccntt@c{|\meta{sec}|}{|\meta{counter}|}| to set
% \Lcount{counter} to the level of \meta{sec}.
%    \begin{macrocode}
\newif\if@knownsect@c
\newcommand{\@setseccntt@c}[2]{%
  \@knownsect@cfalse
  \ifthenelse{\equal{#1}{none}}{\setcounter{#2}{-10}
                                \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{part}}{\ift@cchapter
                                  \setcounter{#2}{-1} 
                                \else
                                  \setcounter{#2}{0}
                                \fi
                                \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{chapter}}{\setcounter{#2}{0}
                                   \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{section}}{\setcounter{#2}{1}
                                   \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{subsection}}{\setcounter{#2}{2}
                                      \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{subsubsection}}{\setcounter{#2}{3}
                                         \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{paragraph}}{\setcounter{#2}{4}
                                     \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{subparagraph}}{\setcounter{#2}{5}
                                        \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{all}}{\setcounter{#2}{100}
                                \@knownsect@ctrue}{}%
  \if@knownsect@c\else
    \PackageError{tocvsec2}{%
      Unknown sectioning command name (#1)
    }{%
      I'll ignore it. Type \space <return> and I'll continue.\MessageBreak
      If you haven't mistyped the name then use \protect\setcounter\space instead.}%
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\settocdepth}
% |\settocdepth{|\meta{sec}|}| is the user command for setting 
% \Lcount{tocdepth} in the \file{.toc} file to the value corresponding 
% to \meta{sec}. 
%    \begin{macrocode}
\newcommand{\settocdepth}[1]{%
  \@knownsect@cfalse
  \ifthenelse{\equal{#1}{none}}{%
    \addtocontents{toc}{\save@tocdepth\protect\setcounter{tocdepth}{-10}}
    \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{part}}{%
    \ift@cchapter
      \addtocontents{toc}{\save@tocdepth\protect\setcounter{tocdepth}{-1}}
    \else
      \addtocontents{toc}{\save@tocdepth\protect\setcounter{tocdepth}{0}}
    \fi
    \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{chapter}}{%
    \addtocontents{toc}{\save@tocdepth\protect\setcounter{tocdepth}{0}}
    \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{section}}{%
    \addtocontents{toc}{\save@tocdepth\protect\setcounter{tocdepth}{1}}
    \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{subsection}}{%
    \addtocontents{toc}{\save@tocdepth\protect\setcounter{tocdepth}{2}}
    \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{subsubsection}}{%
    \addtocontents{toc}{\save@tocdepth\protect\setcounter{tocdepth}{3}}
    \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{paragraph}}{%
    \addtocontents{toc}{\save@tocdepth\protect\setcounter{tocdepth}{4}}
    \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{subparagraph}}{%
    \addtocontents{toc}{\save@tocdepth\protect\setcounter{tocdepth}{5}}
    \@knownsect@ctrue}{}%
  \ifthenelse{\equal{#1}{all}}{%
    \addtocontents{toc}{\save@tocdepth\protect\setcounter{tocdepth}{100}}
    \@knownsect@ctrue}{}%
  \if@knownsect@c\else
    \PackageError{tocvsec2}{%
      Unknown sectioning command name (#1)}%
     {I'll ignore it. Type \space <return> and I'll continue.}%
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\maxtocdepth}
% |\maxtocdepth{|\meta{sec}|}| can be used to initialise \Lcount{tocdepth}
% between the end of the preamble and the |\tableofcontents| command.
%    \begin{macrocode}
\newcounter{max@tocdepth}
\setcounter{max@tocdepth}{\value{tocdepth}}
\newcommand{\maxtocdepth}[1]{%
  \save@tocdepth
  \@setseccntt@c{#1}{max@tocdepth}%
  \@setseccntt@c{#1}{tocdepth}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\tableofcontents}
% \changes{v1.3}{2011/08/07}{Patch to reset \Lcount{tocdepth}}
%    \begin{macrocode}
\g@addto@macro\tableofcontents{%
  \setcounter{tocdepth}{\value{max@tocdepth}}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\setsecnumdepth}
% \changes{v1.2b}{2010/02/27}{Remove occasional extraneous vertical space}
% |\setsecnumdepth{|\meta{sec}|}| is the user command for setting
% \Lcount{secnumdepth} to the value corresponding to \meta{sec}.
%    \begin{macrocode}
\newcommand{\setsecnumdepth}[1]{%
  \save@secnumdepth
  \@setseccntt@c{#1}{secnumdepth}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\maxsecnumdepth}
% |\maxsecnumdepth{|\meta{sec}|}| is the user command to initialise
% \Lcount{secnumdepth} after the preamble
% to the value corresponding to \meta{sec}.
%    \begin{macrocode}
\newcounter{max@secnumdepth}
\setcounter{max@secnumdepth}{\value{secnumdepth}}
\newcommand{\maxsecnumdepth}[1]{%
  \save@secnumdepth
  \@setseccntt@c{#1}{max@secnumdepth}%
  \@setseccntt@c{#1}{secnumdepth}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Resetting and returning to previous values}
%
%
% \begin{macro}{\resetsecnumdepth}
% \changes{v1.3}{2011/08/07}{New command}
% It would be nice to be able to `reset' the tocdepth or secnumdepth
% to a previous value.
% Unfortunately this can't be done with grouping so we use a stack-based
% approach.
%    \begin{macrocode}
\let\stack@secnumdepth\@empty
\newcommand\save@secnumdepth{%
  \edef\stack@secnumdepth{\the\c@secnumdepth\relax\stack@secnumdepth}%
}
\def\gobble@secnumdepth#1\@nil{\edef\stack@secnumdepth{#1}}
%    \end{macrocode}
% The idea of the stack is
%  |{|$x_n$|\relax| $x_{n-1}$|\relax| \dots$x_0$|\relax}|;
% prepending new values with \cs{edef} and using assignment and
% \cs{afterassignment} to push an entry off the front.
%    \begin{macrocode}
\newcommand\resetsecnumdepth{%
  \@ifstar{%
    \setcounter{secnumdepth}{\value{max@secnumdepth}}%
    \edef\stack@secnumdepth{\the\c@secnumdepth\relax}%
  }{%
    \ifx\stack@secnumdepth\@empty
      \PackageWarning{tocvsec2}{There is no previous value for secnumdepth}%
    \else
      \afterassignment\gobble@secnumdepth
      \expandafter\c@secnumdepth\expandafter\numexpr\stack@secnumdepth\@nil
    \fi
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\resettocdepth}
% \changes{v1.3}{2011/08/07}{New command}
% The idea the same is as above but because it all happens inside an auxiliary
% file there's a couple of extra steps.
%    \begin{macrocode}
\let\stack@tocdepth\@empty
\protected\def\save@tocdepth{%
  \edef\stack@tocdepth{\the\c@tocdepth\relax\stack@tocdepth}%
}
\def\gobble@tocdepth#1\@nil{\edef\stack@tocdepth{#1}}
%    \end{macrocode}
% Resetting is done in the \verb|.toc| file:
%    \begin{macrocode}
\newcommand\resettocdepth{\@ifstar
  {\addtocontents{toc}{\remax@tocdepth}}
  {\addtocontents{toc}{\reset@tocdepth}}%
}
%    \end{macrocode}
% Reset back to the initial state (and clear the stack):
%    \begin{macrocode}
\protected\def\remax@tocdepth{%
  \setcounter{tocdepth}{\value{max@tocdepth}}%
  \edef\stack@secnumdepth{\the\c@tocdepth\relax}%
}
%    \end{macrocode}
% Reset to the previous state on the stack:
%    \begin{macrocode}
\protected\def\reset@tocdepth{%
  \ifx\stack@tocdepth\@empty
    \PackageWarning{tocvsec2}{There is no previous value for tocdepth}%
  \else
    \afterassignment\gobble@tocdepth
    \expandafter\c@tocdepth\expandafter\numexpr\stack@tocdepth\@nil
  \fi
}
%    \end{macrocode}
% Ensure errant commands in the ToC won't cause problems:
%    \begin{macrocode}
\addtocontents{toc}{%
  \@ifundefined{save@tocdepth}{%
    \let\save@tocdepth\relax
    \let\reset@tocdepth\relax
    \let\remax@tocdepth\relax
  }{}%
}
%    \end{macrocode}
% \end{macro}
%
%
%    The end of this package.
%    \begin{macrocode}
%</usc>
%    \end{macrocode}
%
%
% \bibliographystyle{alpha}
%
% \begin{thebibliography}{GMS94}
%
% \bibitem[GMS94]{GOOSSENS94}
% Michel Goossens, Frank Mittelbach, and Alexander Samarin.
% \newblock {\em The LaTeX Companion}.
% \newblock Addison-Wesley Publishing Company, 1994.
%
% \bibitem[Wil96]{PRW96i}
% Peter~R. Wilson.
% \newblock {\em {LaTeX for standards: The LaTeX package files user manual}}.
% \newblock NIST Report NISTIR, June 1996.
%
% \end{thebibliography}
%
%
% \Finale
% \PrintIndex
%
\endinput

%% \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         \~}