%%
%% This is file `tocvsec2.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% tocvsec2.dtx  (with options: `usc')
%% 
%% -----------------------------------------------------------------
%%   Author: Peter Wilson, Herries Press
%%   Maintainer: Will Robertson (will dot robertson at latex-project dot org)
%%   Copyright 1998 -- 2004 Peter R. Wilson
%%   Copyright 2010 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.
%% -----------------------------------------------------------------
\ProvidesPackage{tocvsec2}
    [2011/08/07 v1.3 variable ToC section entries]
\RequirePackage{ifthen}
\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}

\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
}
\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
}
\newcounter{max@tocdepth}
\setcounter{max@tocdepth}{\value{tocdepth}}
\newcommand{\maxtocdepth}[1]{%
  \save@tocdepth
  \@setseccntt@c{#1}{max@tocdepth}%
  \@setseccntt@c{#1}{tocdepth}%
}
\g@addto@macro\tableofcontents{%
  \setcounter{tocdepth}{\value{max@tocdepth}}%
}
\newcommand{\setsecnumdepth}[1]{%
  \save@secnumdepth
  \@setseccntt@c{#1}{secnumdepth}}
\newcounter{max@secnumdepth}
\setcounter{max@secnumdepth}{\value{secnumdepth}}
\newcommand{\maxsecnumdepth}[1]{%
  \save@secnumdepth
  \@setseccntt@c{#1}{max@secnumdepth}%
  \@setseccntt@c{#1}{secnumdepth}%
}
\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}}
\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
  }
}
\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}}
\newcommand\resettocdepth{\@ifstar
  {\addtocontents{toc}{\remax@tocdepth}}
  {\addtocontents{toc}{\reset@tocdepth}}%
}
\protected\def\remax@tocdepth{%
  \setcounter{tocdepth}{\value{max@tocdepth}}%
  \edef\stack@secnumdepth{\the\c@tocdepth\relax}%
}
\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
}
\addtocontents{toc}{%
  \@ifundefined{save@tocdepth}{%
    \let\save@tocdepth\relax
    \let\reset@tocdepth\relax
    \let\remax@tocdepth\relax
  }{}%
}
\endinput
%%
%% End of file `tocvsec2.sty'.
