<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">% \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: &lt;http://www.latex-project.org/lppl.txt&gt;
%
% 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.
%
%
%&lt;*driver&gt;
\ProvidesFile{tocvsec2.dtx}
%&lt;/driver&gt;
%&lt;usc&gt;\ProvidesPackage{tocvsec2}
%&lt;*usc&gt;
    [2014/03/10 v1.3a variable ToC section entries]    
%&lt;/usc&gt;
% 
%&lt;*driver&gt;
\documentclass{ltxdoc}
\EnableCrossrefs
\CodelineIndex
\setcounter{StandardModuleDepth}{1}
\begin{document}
  \DocInput{tocvsec2.dtx}
\end{document}
%&lt;/driver&gt;
%
% \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}
%&lt;*usc&gt;
\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 &lt;return&gt; 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 &lt;return&gt; 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}
%&lt;/usc&gt;
%    \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     \&amp;
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \&lt;
%%   Equals        \=     Greater than  \&gt;     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}


</pre></body></html>