%% Style file to adjust the spacing in TOC.
%% maintained by Rajesh for WSPC.
%% derived from tocloft.sty.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ws-toc}[2003/09/02 Auto ToC]
\providecommand{\WSPCPackageNote}[2]{%
  \GenericWarning{%
    (#1)\@spaces\@spaces\@spaces\@spaces
  }{%
   Package #1 Note: #2%
   }%
}
\providecommand{\WSPCPackageNoteNoLine}[2]{%
  \WSPCPackageNote{#1}{#2\@gobble}%
}

\newcommand{\@wspquit}{}
\newif\if@wsphaschapter
\newif\if@wspkoma
  \@wspkomafalse
\@ifclassloaded{scrartcl}{\@wspkomatrue}{}
\@ifclassloaded{scrreprt}{\@wspkomatrue}{}
\@ifclassloaded{scrbook}{\@wspkomatrue}{}

\newcommand\@pnumwidth{1.55em}
\newcommand\@tocrmarg{2.55em}
\newcommand\@dotsep{4.5}
\setcounter{tocdepth}{4}
\newdimen\@cnumwidth            %ADDED FOR CONTENT
\setlength\@cnumwidth{5pc}      %ADDED FOR CONTENT

\@ifundefined{chapter}{%
  \@wsphaschapterfalse
  \@ifundefined{section}{%
    \PackageWarning{autotoc}%
      {I don't recognize any sectional divisions so I'll do nothing}
    \renewcommand{\@wspquit}{\endinput}
    }{\WSPCPackageNoteNoLine{autotoc}{The document has section divisions}}
  }{\@wsphaschaptertrue
    \WSPCPackageNoteNoLine{autotoc}{The document has chapter divisions}}
\@wspquit
\newif\if@wsptocbibind
\AtBeginDocument{%
  \@ifpackageloaded{tocbibind}{\@wsptocbibindtrue}{\@wsptocbibindfalse}
  \if@wsptocbibind
    \@ifpackagelater{tocbibind}{1998/11/16}{}{%
      \PackageWarning{autotoc}{%
You are using a version of the tocbibind package\MessageBreak
that is not compatible with autotoc.\MessageBreak
The results may be surprising.\MessageBreak
Consider installing the current version of tocbibind.}}
  \fi
}
\newif\if@wspnctoc\@wspnctocfalse
\DeclareOption{titles}{\@wspnctoctrue}
  %% \ProcessOptions\relax
\newif\if@wspsubfigopt\@wspsubfigoptfalse
\DeclareOption{subfigure}{\@wspsubfigopttrue}

\ProcessOptions\relax

\newcommand{\autotocpagestyle}[1]{%
  \def\@wsppagestyle{\thispagestyle{#1}}}
\autotocpagestyle{plain}

\newcommand\contentsname{}

\newcommand{\wspmarktoc}{%
  \@mkboth{\contentsname}{\contentsname}}

\newcommand{\wspmarklof}{%
  \@mkboth{\MakeUppercase\listfigurename}{\MakeUppercase\listfigurename}}
\newcommand{\wspmarklot}{%
  \@mkboth{\MakeUppercase\listtablename}{\MakeUppercase\listtablename}}
\if@wspkoma
  \renewcommand{\wspmarktoc}{%
    \@mkboth{\contentsname}{\contentsname}}
  \renewcommand{\wspmarklof}{%
    \@mkboth{\listfigurename}{\listfigurename}}
  \renewcommand{\wspmarklot}{%
    \@mkboth{\listtablename}{\listtablename}}
\fi
\providecommand{\@wsptocstart}{%
  \if@wsphaschapter
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
  \fi}
\providecommand{\@wsptocfinish}{%
  \if@wsphaschapter
    \if@restonecol\twocolumn\fi
  \fi}
\providecommand{\phantomsection}{}

\newcommand{\@wspdobibtoc}{%
  \if@dotoctoc
    \if@bibchapter
      \phantomsection
      \addcontentsline{toc}{chapter}{\contentsname}
    \else
      \phantomsection
      \addcontentsline{toc}{\@tocextra}{\contentsname}
    \fi
  \fi}

\newlength{\wspparskip}
\setlength{\wspparskip}{0pt}

\AtBeginDocument{%
\if@wspnctoc\else
  \newcommand{\tableofcontents}{%
    \@wsptocstart
    \par
    \begingroup
      \parindent\z@ \parskip\wspparskip
      \@wspmaketoctitle
      \if@wsptocbibind
        \@wspdobibtoc
      \fi
      \@starttoc{toc}%
    \endgroup
    \@wsptocfinish}
\fi
}
\newcommand{\@wspmaketoctitle}{%
  \addpenalty\@secpenalty
  \if@wsphaschapter
    \vspace*{\wspbeforetoctitleskip}
  \else
    \vspace{\wspbeforetoctitleskip}
  \fi
  \@wsppagestyle
  {\interlinepenalty\@M
  {\chapter{\contentsname}}{\wspaftertoctitle}
  \wspmarktoc
  \par\nobreak
  \vskip \wspaftertoctitleskip
  \@afterheading}}
\newlength{\wspbeforetoctitleskip}
\newlength{\wspaftertoctitleskip}
\if@wsphaschapter
  \setlength{\wspbeforetoctitleskip}{50pt}
  \setlength{\wspaftertoctitleskip}{40pt}
\else
  \setlength{\wspbeforetoctitleskip}{3.5ex \@plus 1ex \@minus .2ex}
  \setlength{\wspaftertoctitleskip}{2.3ex \@plus.2ex}
\fi
\if@wsphaschapter
  \newcommand{\wsptoctitlefont}{\normalfont\Huge\bfseries}
  \if@wspkoma\renewcommand{\wsptoctitlefont}{\size@chapter\sectfont}\fi
\else
  \newcommand{\wsptoctitlefont}{\normalfont\Large\bfseries}
  \if@wspkoma\renewcommand{\wsptoctitlefont}{\size@section\sectfont}\fi
\fi
\newcommand{\wspaftertoctitle}{}
\newcommand{\wspsetpnumwidth}[1]{\renewcommand{\@pnumwidth}{#1}}
\newcommand{\wspsetrmarg}[1]{\renewcommand{\@tocrmarg}{#1}}
\providecommand{\wspdot}{.}
\providecommand{\wspdotfill}[1]{%
  \leaders\hbox{$\m@th\mkern #1 mu\hbox{\wspdot}\mkern #1 mu$}\hfill}
\providecommand{\wspdotsep}{4.5}
\newcommand{\wspnodots}{10000}
\newcommand{\wspparfillskip}{\parfillskip=0pt plus1fil}
\renewcommand{\numberline}[1]{%
  \hb@xt@\@tempdima{\@wspbsnum #1\@wspasnum\hfil}\@wspasnumb}
\newcommand{\@wspbsnum}{}
\newcommand{\@wspasnum}{}
\newcommand{\@wspasnumb}{}
\newif\if@wspdopart
\newif\if@wsphaspart
\@ifundefined{part}{\@wsphaspartfalse}{\@wsphasparttrue}
\if@wsphaspart
\newcommand*{\l@part}[2]{%
  \@wspdopartfalse
  \ifnum \c@tocdepth >-2\relax
    \if@wsphaschapter
      \@wspdoparttrue
    \fi
    \ifnum \c@tocdepth >\m@ne
      \if@wsphaschapter\else
        \@wspdoparttrue
      \fi
    \fi
  \fi
  \if@wspdopart
    \if@wsphaschapter
      \addpenalty{-\@highpenalty}%
    \else
      \addpenalty\@secpenalty
    \fi
    \addvspace{\wspbeforepartskip}%
    \begingroup
      {\leftskip \wsppartindent\relax
       \rightskip \@tocrmarg
       \parfillskip -\rightskip
       \parindent \wsppartindent\relax\@afterindenttrue
       \interlinepenalty\@M
       \leavevmode
       \@tempdima \wsppartnumwidth\relax
       \let\@wspbsnum \wsppartpresnum
       \let\@wspasnum \wsppartaftersnum
       \let\@wspasnumb \wsppartaftersnumb
       \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
       {\wsppartfont \wsppartpresnum #1}%
       \wsppartfillnum{#2}}
      \nobreak
      \if@wsphaschapter
        \global\@nobreaktrue
        \everypar{\global\@nobreakfalse\everypar{}}%
      \else
        \if@compatibility
          \global\@nobreaktrue
          \everypar{\global\@nobreakfalse\everypar{}}%
        \fi
      \fi
    \endgroup
  \fi}
\fi
\if@wsphaspart
  \newlength{\wspbeforepartskip}
    \setlength{\wspbeforepartskip}{2.25em \@plus\p@}
  \newlength{\wsppartnumwidth}
    \setlength{\wsppartnumwidth}{0em}
  \newcommand{\wsppartfont}{\large\bfseries}
  \newcommand{\wsppartpresnum}{}
  \newcommand{\wsppartaftersnum}{}
  \newcommand{\wsppartaftersnumb}{}
  \newcommand{\wsppartleader}{\large\bfseries\wspdotfill{\wsppartdotsep}}
  \newcommand{\wsppartdotsep}{\wspnodots}
  \newcommand{\wsppartpagefont}{\large\bfseries}
  \newcommand{\wsppartafterpnum}{}
  \newlength{\wsppartindent}
    \setlength{\wsppartindent}{0em}
  \newcommand{\wsppartfillnum}[1]{%
    {\wsppartleader}%
    {\hb@xt@\@pnumwidth{\hss {\wsppartpagefont #1}}}\wsppartafterpnum\par}
  \if@wspkoma
    \setlength{\wsppartnumwidth}{2em}
    \renewcommand{\wsppartfont}{\sectfont\large}
    \renewcommand{\wsppartpagefont}{\sectfont\large}
  \fi
\fi

\newcommand*{\l@authors}[2]{%
  \ifnum \c@tocdepth >\@ne
    \vskip \wspbeforeauthorskip
    {\leftskip \wspsubsecindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \wspsubsecindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \wspsubsecnumwidth\relax
     \let\@wspbsnum \wspsubsecpresnum
     \let\@wspasnum \wspsubsecaftersnum
     \let\@wspasnumb \wspsubsecaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\wspsubsecfont #1}\nobreak
     \wspsubsecfillnum{}}
  \fi}

\newlength{\wspbeforeauthorskip}
  \setlength{\wspbeforeauthorskip}{1pt}
\newlength{\wspbeforesubsecskip}
  \setlength{\wspbeforesubsecskip}{0pt}
\newlength{\wspsubsecindent}
\newlength{\wspsubsecnumwidth}
\if@wsphaschapter
  \setlength{\wspsubsecindent}{1em}
  \setlength{\wspsubsecnumwidth}{1em}
\else
  \setlength{\wspsubsecindent}{1.2em}
  \setlength{\wspsubsecnumwidth}{1.2em}
\fi
\newcommand{\wspsubsecfont}{\itshape}
\newcommand{\wspsubsecpresnum}{}
\newcommand{\wspsubsecaftersnum}{}
\newcommand{\wspsubsecaftersnumb}{}
\newcommand{\wspsubsecleader}{\normalfont\wspdotfill{\wspsubsecdotsep}}
\newcommand{\wspsubsecdotsep}{\wspnodots}
\newcommand{\wspsubsecpagefont}{\normalfont}
\newcommand{\wspsubsecafterpnum}{}
\newcommand{\wspsubsecfillnum}[1]{%
  {\wspsubsecleader}\nobreak
  \hb@xt@\@pnumwidth{\hfil\wspsubsecpagefont #1}\wspsubsecafterpnum\par}

\newcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 12pt         %%CONTROL CHAPTER HEADS
    \setlength\@tempdima{0em}%   %CONTROL P1-heads TURNLINES
    \begingroup
      \parindent \z@ \rightskip \@cnumwidth      %ADDED HERE
      \parfillskip -\@cnumwidth                  %ADDED HERE
      \leavevmode %\bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      {#1}\nobreak\hfill \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \vskip0pt    %more space
      \penalty\@highpenalty
    \endgroup
  \fi}
\newcommand\l@section[2]{\relax}
\newcommand\l@subsection[2]{\relax}
\newcommand\l@subsubsection[2]{\relax}
\newcommand\l@paragraph[2]{\relax}
\newcommand\l@subparagraph[2]{\relax}


\newcommand{\@wspdobiblof}{%
  \if@dotoclof
    \if@bibchapter
      \phantomsection
      \addcontentsline{toc}{chapter}{\listfigurename}
    \else
      \phantomsection
      \addcontentsline{toc}{\@tocextra}{\listfigurename}
    \fi
  \fi}

\AtBeginDocument{
\if@wspnctoc\else
\newcommand{\listoffigures}{%
  \@wsptocstart
  \par
  \begingroup
    \parindent\z@ \parskip\wspparskip
    \@wspmakeloftitle
    \if@wsptocbibind
      \@wspdobiblof
    \fi
    \@starttoc{lof}%
  \endgroup
  \@wsptocfinish}
\fi
}

\newcommand{\@wspmakeloftitle}{%
  \addpenalty\@secpenalty
  \if@wsphaschapter
    \vspace*{\wspbeforeloftitleskip}
  \else
    \vspace{\wspbeforeloftitleskip}
  \fi
  \@wsppagestyle
  {\interlinepenalty\@M
  {\wsploftitlefont\listfigurename}{\wspafterloftitle}
  \wspmarklof
  \par\nobreak
  \vskip \wspafterloftitleskip
  \@afterheading}}

\newlength{\wspbeforeloftitleskip}
\newlength{\wspafterloftitleskip}
\if@wsphaschapter
  \setlength{\wspbeforeloftitleskip}{50pt}
  \setlength{\wspafterloftitleskip}{40pt}
\else
  \setlength{\wspbeforeloftitleskip}{3.5ex \@plus 1ex \@minus .2ex}
  \setlength{\wspafterloftitleskip}{2.3ex \@plus.2ex}
\fi
\if@wsphaschapter
  \newcommand{\wsploftitlefont}{\normalfont\Huge\bfseries}
  \if@wspkoma\renewcommand{\wsploftitlefont}{\size@chapter\sectfont}\fi
\else
  \newcommand{\wsploftitlefont}{\normalfont\Large\bfseries}
  \if@wspkoma\renewcommand{\wsploftitlefont}{\size@section\sectfont}\fi
\fi
\newcommand{\wspafterloftitle}{}

\newcommand*{\l@figure}[2]{%
  \ifnum \c@lofdepth >\z@
    \vskip \wspbeforefigskip
    {\leftskip \wspfigindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \wspfigindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \wspfignumwidth\relax
     \let\@wspbsnum \wspfigpresnum
     \let\@wspasnum \wspfigaftersnum
     \let\@wspasnumb \wspfigaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\wspfigfont #1}\nobreak
     \wspfigfillnum{#2}}
   \fi
  }
\newlength{\wspbeforefigskip}
  \setlength{\wspbeforefigskip}{\z@ \@plus.2\p@}
\newlength{\wspfigindent}
  \setlength{\wspfigindent}{1.5em}
\newlength{\wspfignumwidth}
  \setlength{\wspfignumwidth}{2.3em}
\newcommand{\wspfigfont}{\normalfont}
\newcommand{\wspfigpresnum}{}
\newcommand{\wspfigaftersnum}{}
\newcommand{\wspfigaftersnumb}{}
\newcommand{\wspfigleader}{\normalfont\wspdotfill{\wspfigdotsep}}
\newcommand{\wspfigdotsep}{\wspdotsep}
\newcommand{\wspfigpagefont}{\normalfont}
\newcommand{\wspfigafterpnum}{}
\newcommand{\wspfigfillnum}[1]{%
  {\wspfigleader}\nobreak
  \hb@xt@\@pnumwidth{\hfil\wspfigpagefont #1}\wspfigafterpnum\par}

\if@wspsubfigopt\else
  \newcounter{lofdepth}\setcounter{lofdepth}{1}
  \newcounter{lotdepth}\setcounter{lotdepth}{1}
\fi

\newcommand{\@wspdobiblot}{%
  \if@dotoclot
    \if@bibchapter
      \phantomsection
      \addcontentsline{toc}{chapter}{\listtablename}
    \else
      \phantomsection
      \addcontentsline{toc}{\@tocextra}{\listtablename}
    \fi
  \fi}

\AtBeginDocument{
\if@wspnctoc\else
\newcommand{\listoftables}{%
  \@wsptocstart
  \par
  \begingroup
    \parindent\z@ \parskip\wspparskip
    \@wspmakelottitle
    \if@wsptocbibind
      \@wspdobiblot
    \fi
    \@starttoc{lot}%
  \endgroup
  \@wsptocfinish}
\fi
}

\newcommand{\@wspmakelottitle}{%
  \addpenalty\@secpenalty
  \if@wsphaschapter
    \vspace*{\wspbeforelottitleskip}
  \else
    \vspace{\wspbeforelottitleskip}
  \fi
  \@wsppagestyle
  {\interlinepenalty\@M
  {\wsplottitlefont\listtablename}{\wspafterlottitle}
  \wspmarklot
  \par\nobreak
  \vskip \wspafterlottitleskip
  \@afterheading}}

\newlength{\wspbeforelottitleskip}
\newlength{\wspafterlottitleskip}
\if@wsphaschapter
  \setlength{\wspbeforelottitleskip}{50pt}
  \setlength{\wspafterlottitleskip}{40pt}
\else
  \setlength{\wspbeforelottitleskip}{3.5ex \@plus 1ex \@minus .2ex}
  \setlength{\wspafterlottitleskip}{2.3ex \@plus.2ex}
\fi
\if@wsphaschapter
  \newcommand{\wsplottitlefont}{\normalfont\Huge\bfseries}
  \if@wspkoma\renewcommand{\wsplottitlefont}{\size@chapter\sectfont}\fi
\else
  \newcommand{\wsplottitlefont}{\normalfont\Large\bfseries}
  \if@wspkoma\renewcommand{\wsplottitlefont}{\size@section\sectfont}\fi
\fi
\newcommand{\wspafterlottitle}{}

\newcommand*{\l@table}[2]{%
  \ifnum\c@lotdepth >\z@
    \vskip \wspbeforetabskip
    {\leftskip \wsptabindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \wsptabindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \wsptabnumwidth\relax
     \let\@wspbsnum \wsptabpresnum
     \let\@wspasnum \wsptabaftersnum
     \let\@wspasnumb \wsptabaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\wsptabfont #1}\nobreak
     \wsptabfillnum{#2}}
   \fi
  }
\newlength{\wspbeforetabskip}
  \setlength{\wspbeforetabskip}{\z@ \@plus.2\p@}
\newlength{\wsptabindent}
  \setlength{\wsptabindent}{1.5em}
\newlength{\wsptabnumwidth}
  \setlength{\wsptabnumwidth}{2.3em}
\newcommand{\wsptabfont}{\normalfont}
\newcommand{\wsptabpresnum}{}
\newcommand{\wsptabaftersnum}{}
\newcommand{\wsptabaftersnumb}{}
\newcommand{\wsptableader}{\normalfont\wspdotfill{\wsptabdotsep}}
\newcommand{\wsptabdotsep}{\wspdotsep}
\newcommand{\wsptabpagefont}{\normalfont}
\newcommand{\wsptabafterpnum}{}
\newcommand{\wsptabfillnum}[1]{%
  {\wsptableader}\nobreak
  \hb@xt@\@pnumwidth{\hfil\wsptabpagefont #1}\wsptabafterpnum\par}

\newcommand{\@wspl@subfig}{
\renewcommand*{\l@subfigure}[2]{%
  \ifnum \c@lofdepth > \toclevel@subfigure
    \vskip \wspbeforesubfigskip
    {\leftskip \wspsubfigindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \wspsubfigindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \wspsubfignumwidth\relax
     \let\@wspbsnum \wspsubfigpresnum
     \let\@wspasnum \wspsubfigaftersnum
     \let\@wspasnumb \wspsubfigaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\wspsubfigfont ##1}\nobreak
     \wspsubfigfillnum{##2}}
  \fi
  }
}

\newcommand{\@wspsetsubfig}{%
\newlength{\wspbeforesubfigskip}
  \setlength{\wspbeforesubfigskip}{\z@ \@plus.2\p@}
\newlength{\wspsubfigindent}
  \setlength{\wspsubfigindent}{3.8em}
\newlength{\wspsubfignumwidth}
  \setlength{\wspsubfignumwidth}{2.5em}
\newcommand{\wspsubfigfont}{\normalfont}
\newcommand{\wspsubfigpresnum}{}
\newcommand{\wspsubfigaftersnum}{}
\newcommand{\wspsubfigaftersnumb}{}
\newcommand{\wspsubfigleader}{\normalfont\wspdotfill{\wspsubtabdotsep}}
\newcommand{\wspsubfigdotsep}{\wspdotsep}
\newcommand{\wspsubfigpagefont}{\normalfont}
\newcommand{\wspsubfigafterpnum}{}
\providecommand{\toclevel@subfigure}{1}
\newcommand{\wspsubfigfillnum}[1]{%
  {\wspsubfigleader}\nobreak
  \hb@xt@\@pnumwidth{\hfil\wspsubfigpagefont ##1}\wspsubfigafterpnum\par}
}

\newcommand{\@wspl@subtab}{
\renewcommand*{\l@subtable}[2]{%
  \ifnum \c@lotdepth > \toclevel@subtable
    \vskip \wspbeforesubtabskip
    {\leftskip \wspsubtabindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \wspsubtabindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \wspsubtabnumwidth\relax
     \let\@wspbsnum \wspsubtabpresnum
     \let\@wspasnum \wspsubtabaftersnum
     \let\@wspasnumb \wspsubtabaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\wspsubtabfont ##1}\nobreak
     \wspsubtabfillnum{##2}}
  \fi
  }
}
\newcommand{\@wspsetsubtab}{
\newlength{\wspbeforesubtabskip}
  \setlength{\wspbeforesubtabskip}{\z@ \@plus.2\p@}
\newlength{\wspsubtabindent}
  \setlength{\wspsubtabindent}{3.8em}
\newlength{\wspsubtabnumwidth}
  \setlength{\wspsubtabnumwidth}{2.5em}
\newcommand{\wspsubtabfont}{\normalfont}
\newcommand{\wspsubtabpresnum}{}
\newcommand{\wspsubtabaftersnum}{}
\newcommand{\wspsubtabaftersnumb}{}
\newcommand{\wspsubtableader}{\normalfont\wspdotfill{\wspsubtabdotsep}}
\newcommand{\wspsubtabdotsep}{\wspdotsep}
\newcommand{\wspsubtabpagefont}{\normalfont}
\newcommand{\wspsubtabafterpnum}{}
\providecommand{\toclevel@subtable}{1}
\newcommand{\wspsubtabfillnum}[1]{%
  {\wspsubtableader}\nobreak
  \hb@xt@\@pnumwidth{\hfil\wspsubtabpagefont ##1}\wspsubtabafterpnum\par}
}


\if@wspsubfigopt
  \@wspsetsubfig\@wspsetsubtab
  \AtBeginDocument{\@wspl@subfig\@wspl@subtab}
\fi
%%  \AtBeginDocument{\if@wspsubfigopt
%%    \@wspsetsubfig\@wspsetsubtab
%%    \@wspl@subfig\@wspl@subtab
%%  \fi}

\newcommand{\newlistentry}[4][\@empty]{%
  \@ifundefined{c@#2}{%    check & set the counter
    \ifx \@empty#1\relax
      \newcounter{#2}
    \else
      \@ifundefined{c@#1}{\PackageWarning{autotoc}%
                          {#1 has no counter for use as a `within'}
        \newcounter{#2}}%
      {\newcounter{#2}[#1]%
       \expandafter\edef\csname the#2\endcsname{%
         \expandafter\noexpand\csname the#1\endcsname.\noexpand\arabic{#2}}}
    \fi
    \setcounter{#2}{0}
  }
  {\PackageError{autotoc}{#2 has been previously defined}{\@eha}}

  \@namedef{l@#2}##1##2{%
    \ifnum \@nameuse{c@#3depth} > #4\relax
      \vskip \@nameuse{wspbefore#2skip}
      {\leftskip \@nameuse{wsp#2indent}\relax
       \rightskip \@tocrmarg
       \parfillskip -\rightskip
       \parindent \@nameuse{wsp#2indent}\relax\@afterindenttrue
       \interlinepenalty\@M
       \leavevmode
       \@tempdima \@nameuse{wsp#2numwidth}\relax
       \expandafter\let\expandafter\@wspbsnum\csname wsp#2presnum\endcsname
       \expandafter\let\expandafter\@wspasnum\csname wsp#2aftersnum\endcsname
       \expandafter\let\expandafter\@wspasnumb\csname wsp#2aftersnumb\endcsname
       \advance\leftskip\@tempdima \null\nobreak\hskip -\leftskip
       {\@nameuse{wsp#2font}##1}\nobreak
       \@nameuse{wsp#2fillnum}{##2}}
    \fi
  }  % end of \l@#2

  \expandafter\newlength\csname wspbefore#2skip\endcsname
    \setlength{\@nameuse{wspbefore#2skip}}{\z@ \@plus .2\p@}
  \expandafter\newlength\csname wsp#2indent\endcsname
  \expandafter\newlength\csname wsp#2numwidth\endcsname
  \ifcase #4\relax  % 0
    \setlength{\@nameuse{wsp#2indent}}{0em}
    \setlength{\@nameuse{wsp#2numwidth}}{1.5em}
  \or               % 1
    \setlength{\@nameuse{wsp#2indent}}{1.5em}
    \setlength{\@nameuse{wsp#2numwidth}}{2.3em}
  \or               % 2
    \setlength{\@nameuse{wsp#2indent}}{3.8em}
    \setlength{\@nameuse{wsp#2numwidth}}{3.2em}
  \or               % 3
    \setlength{\@nameuse{wsp#2indent}}{7.0em}
    \setlength{\@nameuse{wsp#2numwidth}}{4.1em}
  \else             % anything else
    \setlength{\@nameuse{wsp#2indent}}{10.0em}
    \setlength{\@nameuse{wsp#2numwidth}}{5.0em}
  \fi
  \@namedef{wsp#2font}{\normalfont}
  \@namedef{wsp#2presnum}{}
  \@namedef{wsp#2aftersnum}{}
  \@namedef{wsp#2aftersnumb}{}
  \@namedef{wsp#2dotsep}{\wspdotsep}
  \@namedef{wsp#2leader}{\normalfont\wspdotfill{\@nameuse{wsp#2dotsep}}}
  \@namedef{wsp#2pagefont}{\normalfont}
  \@namedef{wsp#2afterpnum}{}
  \@namedef{toclevel@#2}{#4}
  \@namedef{wsp#2fillnum}##1{%
    {\@nameuse{wsp#2leader}}\nobreak
    \hb@xt@\@pnumwidth{\hfil\@nameuse{wsp#2pagefont}##1}\@nameuse{wsp#2afterpnum}\par}
} % end \newlistentry

\newcommand{\newlistof}[4][\@empty]{%
  \ifx \@empty#1\relax
    \newlistentry{#2}{#3}{0}
  \else
    \newlistentry[#1]{#2}{#3}{0}
  \fi

  \@namedef{ext@#3}{#3}
  \newcounter{#3depth}
  \setcounter{#3depth}{1}

  \if@wspkoma
    \@namedef{wspmark#3}{%
      \@mkboth{#4}{#4}}
  \else
    \@namedef{wspmark#3}{%
      \@mkboth{{#4}}{{#4}}}
  \fi
 \if@wspnctoc
  \@namedef{listof#2}{%
    \@wsptocstart
    \if@wsphaschapter
      \chapter{#4}
    \else
      \section*{#4}
    \fi
    \@nameuse{wspmark#3}
    \@starttoc{#3}%
    \@wsptocfinish}
 \else
  \@namedef{listof#2}{%
    \@wsptocstart
    \par
    \begingroup
      \parindent\z@ \parskip\wspparskip
      \@nameuse{@wspmake#3title}
      \@starttoc{#3}%
    \endgroup
    \@wsptocfinish}
 \fi

  \@namedef{@wspmake#3title}{%
    \addpenalty\@secpenalty
    \if@wsphaschapter
      \vspace*{\@nameuse{wspbefore#3titleskip}}
    \else
      \vspace{\@nameuse{wspbefore#3titleskip}}
    \fi
    \@wsppagestyle
    {\interlinepenalty\@M
    {\@nameuse{wsp#3titlefont}#4}{\@nameuse{wspafter#3title}}
    \@nameuse{wspmark#3}
    \par\nobreak
    \vskip \@nameuse{wspafter#3titleskip}
    \@afterheading}}

   \expandafter\newlength\csname wspbefore#3titleskip\endcsname
   \expandafter\newlength\csname wspafter#3titleskip\endcsname
   \if@wsphaschapter
      \setlength{\@nameuse{wspbefore#3titleskip}}{50pt}
      \setlength{\@nameuse{wspafter#3titleskip}}{40pt}
      \if@wspkoma
        \@namedef{wsp#3titlefont}{\size@chapter\sectfont}
      \else
        \@namedef{wsp#3titlefont}{\normalfont\Huge\bfseries}
      \fi
    \else
      \setlength{\@nameuse{wspbefore#3titleskip}}{3.5ex \@plus 1ex \@minus .2ex}
      \setlength{\@nameuse{wspafter#3titleskip}}{2.3ex \@plus .2ex}
      \if@wspkoma
        \@namedef{wsp#3titlefont}{\size@section\sectfont}
      \else
        \@namedef{wsp#3titlefont}{\normalfont\Huge\bfseries}
      \fi
    \fi
    \@namedef{wspafter#3title}{}
} % end \newlistof

\newcommand{\wspsetindents}[3]{%
  \def\@wspemp{#1}
  \ifx\@wspemp\wspchapname
    \@wspsetindents{chap}{#2}{#3}
  \else
    \ifx\@wspemp\wspsecname \@wspsetindents{sec}{#2}{#3}
    \else
      \ifx\@wspemp\wspsubsecname \@wspsetindents{subsec}{#2}{#3}
      \else
        \ifx\@wspemp\wspsubsubsecname \@wspsetindents{subsubsec}{#2}{#3}
        \else
          \ifx\@wspemp\wspparaname \@wspsetindents{para}{#2}{#3}
          \else
            \ifx\@wspemp\wspsubparaname \@wspsetindents{subpara}{#2}{#3}
            \else
              \ifx\@wspemp\wspfigname \@wspsetindents{fig}{#2}{#3}
              \else
                \ifx\@wspemp\wspsubfigname \@wspsetindents{subfig}{#2}{#3}
                \else
                  \ifx\@wspemp\wsptabname \@wspsetindents{tab}{#2}{#3}
                  \else
                    \ifx\@wspemp\wspsubtabname \@wspsetindents{subtab}{#2}{#3}
                    \else
                      \@wspsetindents{#1}{#2}{#3}
                    \fi
                  \fi
                \fi
              \fi
            \fi
          \fi
        \fi
      \fi
    \fi
  \fi
}

\newcommand{\@wspsetindents}[3]{%
  \setlength{\@nameuse{wsp#1indent}}{#2}
  \setlength{\@nameuse{wsp#1numwidth}}{#3}
}

\newcommand{\@wsppnumoff}[1]{%
  \@namedef{wsp#1fillnum}##1{%
    \wspparfillskip\@nameuse{wsp#1afterpnum}\par}}

\newcommand*{\wspchapname}{chapter}
\newcommand*{\wspsecname}{section}
\newcommand*{\wspsubsecname}{subsection}
\newcommand*{\wspsubsubsecname}{subsubsection}
\newcommand*{\wspparaname}{paragraph}
\newcommand*{\wspsubparaname}{subparagraph}
\newcommand*{\wspfigname}{figure}
\newcommand*{\wspsubfigname}{subfigure}
\newcommand*{\wsptabname}{table}
\newcommand*{\wspsubtabname}{subtable}

\DeclareRobustCommand{\wsppagenumbersoff}[1]{%
  \def\@wspemp{#1}
  \ifx\@wspemp\wspchapname
    \@wsppnumoff{chap}
  \else
    \ifx\@wspemp\wspsecname \@wsppnumoff{sec}
    \else
      \ifx\@wspemp\wspsubsecname \@wsppnumoff{subsec}
      \else
        \ifx\@wspemp\wspsubsubsecname \@wsppnumoff{subsubsec}
        \else
          \ifx\@wspemp\wspparaname \@wsppnumoff{para}
          \else
            \ifx\@wspemp\wspsubparaname \@wsppnumoff{subpara}
            \else
              \ifx\@wspemp\wspfigname \@wsppnumoff{fig}
              \else
                \ifx\@wspemp\wspsubfigname \@wsppnumoff{subfig}
                \else
                  \ifx\@wspemp\wsptabname \@wsppnumoff{tab}
                  \else
                    \ifx\@wspemp\wspsubtabname \@wsppnumoff{subtab}
                    \else
                      \@wsppnumoff{#1}
                    \fi
                  \fi
                \fi
              \fi
            \fi
          \fi
        \fi
      \fi
    \fi
  \fi
}

\DeclareRobustCommand{\wsppagenumberson}[1]{%
  \def\@wspemp{#1}
  \ifx\@wspemp\wspchapname
    \@wsppnumon{chap}
  \else
    \ifx\@wspemp\wspsecname \@wsppnumon{sec}
    \else
      \ifx\@wspemp\wspsubsecname \@wsppnumon{subsec}
      \else
        \ifx\@wspemp\wspsubsubsecname \@wsppnumon{subsubsec}
        \else
          \ifx\@wspemp\wspparaname \@wsppnumon{para}
          \else
            \ifx\@wspemp\wspsubparaname \@wsppnumon{subpara}
            \else
              \ifx\@wspemp\wspfigname \@wsppnumon{fig}
              \else
                \ifx\@wspemp\wspsubfigname \@wsppnumon{subfig}
                \else
                  \ifx\@wspemp\wsptabname \@wsppnumon{tab}
                  \else
                    \ifx\@wspemp\wspsubtabname \@wsppnumon{subtab}
                    \else
                      \@wsppnumon{#1}
                    \fi
                  \fi
                \fi
              \fi
            \fi
          \fi
        \fi
      \fi
    \fi
  \fi
}

\newcommand{\@wsppnumon}[1]{%
  \@namedef{wsp#1fillnum}##1{%
    {\@nameuse{wsp#1leader}}\nobreak
    \hb@xt@\@pnumwidth{\hfil\@nameuse{wsp#1pagefont}##1}\@nameuse{wsp#1afterpnum}\par}}

\newcommand{\wspchapterprecis}[1]{%
  \wspchapterprecishere{#1}
  \wspchapterprecistoc{#1}}
\newcommand{\wspchapterprecishere}[1]{%
  \vspace*{-2\baselineskip}
  \begin{quote}\textit{#1}\end{quote}}
\newcommand{\wspchapterprecistoc}[1]{\addtocontents{toc}{%
  {\leftskip \wspchapindent\relax
   \advance\leftskip \wspchapnumwidth\relax
   \rightskip \@tocrmarg\relax
   \textit{#1}\protect\par}}}
\newcommand{\wsplocalchange}[3]{%
  \addtocontents{#1}{\protect\wspsetpnumwidth{#2} \protect\wspsetrmarg{#3}}}
\newcommand{\wspaddtitleline}[4]{%
  \addtocontents{#1}{\protect\contentsline{#2}{#3}{#4}}}
\newcommand{\wspaddnumtitleline}[5]{%
  \addtocontents{#1}%
    {\protect\contentsline{#2}{\protect\numberline{}{\protect\ignorespaces #4}}{#5}}}
\endinput
%%
