% \iffalse meta-comment
%
% tocloft.dtx
% Author: Peter Wilson, Herries Press
% Maintainer: Will Robertson (will dot robertson at latex-project dot org)
% Copyright 1998-2003 Peter R. Wilson
% Copyright 2009-2017 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>
\documentclass{ltxdoc}
\usepackage{hypdoc}
\EnableCrossrefs
\CodelineIndex
\setcounter{StandardModuleDepth}{1}
\begin{document}
  \DocInput{tocloft.dtx}
\end{document}
%</driver>
%
%<*usc>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{tocloft}[2017/08/31 v2.3i parameterised ToC, etc., typesetting]
%</usc>
%
% \fi
%
% \changes{v0.1}{1998/12/31}{First public (alpha) release}
% \changes{v0.1a}{1999/01/15}{Improved documentation}
% \changes{v0.2}{1999/01/17}{Uses the stdclsdv package}
% \changes{v0.2a}{1999/01/17}{Interfaced with the tocbibind package}
% \changes{v0.2b}{1999/03/07}{Corrected failure when used with float package}
% \changes{v0.2c}{1999/06/30}{Added raggedright example}
% \changes{v0.3}{1999/08/22}{Added option to prevent ToC head change}
% \changes{v1.0}{1999/09/19}{Added PackageNote reporting}
% \changes{v1.1}{2000/02/11}{Added cftXpresnum commands}
% \changes{v1.1}{2000/02/11}{Added support for subfigure package}
% \changes{v1.1a}{2000/02/11}{Changed X to Z in section 2.2}
% \changes{v2.0}{2001/03/03}{Added command for new list of...}
% \changes{v2.0}{2001/03/03}{Removed requirement for stdclsdv package}
% \changes{v2.0}{2001/03/15}{Removed requirement for hyperref option}
% \changes{v2.1}{2001/04/08}{Added control over parskip in ToC etc.}
% \changes{v2.2}{2001/04/17}{Another fix for hyperref}
% \changes{v2.3}{2002/06/15}{Made to work with the koma classes}
% \changes{v2.3a}{2002/10/03}{Partial fix for Part changes}
% \changes{v2.3b}{2003/01/20}{More fixes for Part changes}
% \changes{v2.3c}{2003/09/26}{More fixes for hyperref}
% \changes{v2.3d}{2009/09/04}{New maintainer and tiny bug fix}
% \changes{v2.3e}{2010/10/13}{Remove a message from the console output}
%
% \def\dtxfile{\texttt{tocloft.dtx}}
% \def\fileversion{v1.1a} \def\filedate{2000/02/11}
% \def\fileversion{v2.0}  \def\filedate{2001/03/15}
% \def\fileversion{v2.1}  \def\filedate{2001/04/08}
% \def\fileversion{v2.2}  \def\filedate{2001/04/17}
% \def\fileversion{v2.3}  \def\filedate{2002/06/15}
% \def\fileversion{v2.3a} \def\filedate{2002/10/03}
% \def\fileversion{v2.3b} \def\filedate{2003/01/20}
% \def\fileversion{v2.3c} \def\filedate{2003/09/26}
% \def\fileversion{v2.3d} \def\filedate{2009/09/04}
% \def\fileversion{v2.3e} \def\filedate{2010/10/13}
% \def\fileversion{v2.3f} \def\filedate{2013/05/02}
% \def\fileversion{v2.3g} \def\filedate{2014/06/14}
% \def\fileversion{v2.3h} \def\filedate{2017/08/29}
% \def\fileversion{v2.3i} \def\filedate{2017/08/31}
% \def\fileversion{v2.3j} \def\filedate{2020/01/10}
%
% \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@}
%
% \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
% \providecommand{\bs}{\textbackslash}
%
% \title{The \Lpack{tocloft} package\thanks{This
%        file (\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{tocloft} package provides means of controlling the
% typographic design of the Table of Contents, List of Figures and List of
% Tables. New kinds of `List of \ldots' can be defined.
%
% The package has been tested with the
% \Lpack{tocbibind},
% \Lpack{minitoc},
% \Lpack{ccaption},
% \Lpack{subfigure},
% \Lpack{float},
% \Lpack{fncychap}, and
% \Lpack{hyperref}
% packages.
% \end{abstract}
% \tableofcontents
% \makeatletter \renewcommand{\@dotsep}{9.0} \makeatother
% \listoffigures
% \listoftables
% \StopEventually{}
%
%
%
% \section{Introduction}
%
% In the standard classes the typographic design of the Table of Contents
% (ToC), the List of Figures (LoF) and List of Tables (LoT) is fixed or,
% more precisely, it is buried within the class definitions.
% The \Lpack{tocloft} package provides handles for an author to
% change the design to meet the needs of the particular document.
%
% Elements 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}.
%
% The package has been tested in combination with at least
% the \Lpack{tocbibind} package~\cite{TOCBIBIND},
% the \Lpack{minitoc} package~\cite{MINITOC},
% the \Lpack{ccaption} package~\cite{CCAPTION},
% the \Lpack{subfigure} package~\cite{SUBFIGURE} (versions 2.0 and 2.1),
% the \Lpack{algorithm} package~\cite{ALGORITHM} (which, in turn, calls the
% \Lpack{float} package~\cite{FLOAT}) and the \Lpack{fncychap} package~\cite{FNCYCHAP}.
% It also works with the \Lpack{hyperref} package.
% Please send me any comments as to how you think
% that the package can be improved, or of any interesting examples of
% how you have used
% it.\footnote{Thanks to Rowland (\texttt{rebecca@astrid.u-net.com}),
%   John Foster (\texttt{john@isjf.demon.co.uk}),
%   Kasper (\texttt{kbg@dkik.dk}),
%   Lee Nave (\texttt{nave@math.washington.edu}),
%   and Andrew Thurber (\texttt{athurber@emba.uvm.edu})
%   for their suggestions.}
%
% \subsection{\LaTeX 's methods}
%
%    This is a general description of how \LaTeX{} does the processing
% for a Table of Contents. As the processing for List of Figures and
% List of Tables is similar I will, without loss of generality, just
% discuss the ToC.
%
% \DescribeMacro{\addcontentsline}
%    \LaTeX{} generates a \file{.toc} file if the document contains a
% |\tableofcontents| command. The sectioning
% commands\footnote{For figures and tables it is the \texttt{\bs caption} command
% that populates the \file{.lof} and \file{.lot} files.}
% put entries into the \file{.toc} file by calling the \LaTeX{}
% |\addcontentsline{|\meta{file}|}{|\meta{kind}|}{|\meta{title}|}|
% command, where \meta{file} is the file extension (e.g., |toc|),
% \meta{kind} is the kind of entry (e.g., |section| or |subsection|),
% and \meta{title} is the (numberered) title text. In the cases where
% there is a number, the \meta{title} argument is given in the
% form |{\numberline{number} title-text}|.
%
% NOTE: The \Lpack{hyperref} package dislikes authors using
% |\addcontentsline|. To get it to work properly with \Lpack{hyperref}
% you normally have to put |\phantomsection| (a macro defined within
% the \Lpack{hyperref} package) immediately
% before |\addcontentsline|.
%
% \DescribeMacro{\contentsline}
%     The |\addcontentsline| command writes an entry to the given file
% in the form |\contentsline{|\meta{kind}|}{|\meta{title}|}{|\meta{page}|}|
% where \meta{page} is the page number.
%     For each \meta{kind}, \LaTeX{} provides a command
% |\l@kind{|\meta{title}|}{|\meta{page}|}| which performs the actual
% typesetting of the |\contentsline| entry.
%
% \newcommand{\maxx}{120}       ^^A picture width
% \newcommand{\maxxm}{118}      ^^A \maxx - 2\
% \newcommand{\maxy}{55}        ^^A picture height
% \newcommand{\maxym}{53}       ^^A \maxy - 2
% \newcommand{\findent}{20}     ^^A indent
% \newcommand{\findentp}{22}    ^^A \findent + 2
% \newcommand{\fnumwidth}{10}   ^^A numwidth
% \newcommand{\ftocrmarg}{30}   ^^A \@tocrmarg
% \newcommand{\fpnumwidth}{20}  ^^A \@pnumwidth
% \newcommand{\fipn}{30}        ^^A \findent + \fnumwidth
% \newcommand{\frmarg}{90}      ^^A \maxx - \ftocrmarg
% \newcommand{\frnum}{100}      ^^A \maxx - \fpnumwidth
% \newcommand{\fyi}{10}         ^^A 1st y height
% \newcommand{\fyim}{8}         ^^A \fyi - 2
% \newcommand{\fyii}{20}        ^^A 2nd y height
% \newcommand{\fyiii}{25}       ^^A 3rd y height
% \newcommand{\fyiv}{30}        ^^A 4th y height
% \newcommand{\fyv}{40}         ^^A 5th y height
% \newcommand{\fyvp}{42}        ^^A \fyv + 2
% \newcommand{\flin}{4}         ^^A length of leader lines
% \newcommand{\frmargm}{89}     ^^A \frmarg (90) - a little bit
%
% \providecommand{\bs}{\textbackslash}
% \begin{figure}
% \centering
% \setlength{\unitlength}{1mm}
% \begin{picture}(\maxx,\maxy)
%     ^^A side lines and linewidth
%   \put(0,0){\line(0,1){\maxy}}
%   \put(\maxx,0){\line(0,1){\maxy}}
%   \put(0,\maxy){\vector(1,0){\maxx}}
%   \put(2,\maxym){\makebox(0,0)[tl]{\texttt{\bs linewidth}}}
%     ^^A \@pnumwidth
%   \put(\maxx,\fyi){\vector(-1,0){\fpnumwidth}}
%   \put(\maxxm,\fyim){\makebox(0,0)[tr]{\texttt{\bs @pnumwidth}}}
%   \put(\frnum,\fyi){\line(0,1){\flin}}
%     ^^A \@tocrmarg
%   \put(\maxx,\fyv){\vector(-1,0){\ftocrmarg}}
%   \put(\maxxm,\fyvp){\makebox(0,0)[br]{\texttt{\bs @tocrmarg}}}
%   \put(\frmarg,\fyv){\line(0,-1){\flin}}
%     ^^A indent
%   \put(0,\fyv){\vector(1,0){\findent}}
%   \put(2,\fyvp){\makebox(0,0)[bl]{\textit{indent}}}
%   \put(\findent,\fyv){\line(0,-1){\flin}}
%     ^^A numwidth
%   \put(\findent,\fyv){\vector(1,0){\fnumwidth}}
%   \put(\findentp,\fyvp){\makebox(0,0)[bl]{\textit{numwidth}}}
%   \put(\fipn,\fyv){\line(0,-1){\flin}}
%     ^^A last title line
%   \put(\maxx,\fyii){\makebox(0,0)[br]{487}}
%   \put(\fipn,\fyii){title end}
%     ^^A second title line
%   \put(\fipn,\fyiii){continue\ldots}
%   \put(\frmarg,\fyiii){\makebox(0,0)[br]{\ldots title}}
%     ^^A first title line
%   \put(\findent,\fyiv){\textbf{3.5}}
%   \put(\fipn,\fyiv){Heading\ldots}
%   \put(\frmarg,\fyiv){\makebox(0,0)[br]{\ldots title}}
%     ^^A dotted leader
%   \multiput(\frmargm,\fyii)(-\flin,0){12}{.}
%   \multiput(\frmarg,\fyi)(-\flin,0){2}{\line(0,1){\flin}}
%   \put(\frmarg,\fyi){\vector(-1,0){\flin}}
%   \put(\frmarg,\fyi){\vector(1,0){0}}
%   \put(\frmarg,\fyim){\makebox(0,0)[tr]{\texttt{\bs @dotsep}}}
%
% \end{picture}
% \setlength{\unitlength}{1pt}
% \caption{Layout of a ToC (LoF, LoT) entry} \label{fig:ltoc}
% \end{figure}
%
%
% \DescribeMacro{\@pnumwidth}
% \DescribeMacro{\@tocrmarg}
% \DescribeMacro{\@dotsep}
% The general layout of a
% typeset entry is illustrated in Figure~\ref{fig:ltoc}. There are three
% internal \LaTeX{} commands that are used in the typesetting. The page
% number is typeset flushright in a box of width |\@pnumwidth|, and the box
% is at the righthand margin. If the page number is too long to fit into
% the box it will stick out into the righthand margin. The title text
% is indented from the righthand margin by an amount given by |\@tocrmarg|.
% Note that |\@tocrmarg| should be greater than |\@pnumwidth|. Some
% entries are typeset with a dotted leader between the end of the title
% title text and the righthand margin indentation. The distance, in
% \emph{math units}\footnote{There are 18mu to 1em.} between the dots
% in the leader is given by the value of |\@dotsep|. In the standard
% classes the same values are used for the ToC, LoF and the LoT.
%
%    The standard values for these internal commands are:
% \begin{itemize}
% \item |\@pnumwidth| = 1.55em
% \item |\@tocrmarg| = 2.55em
% \item |\@dotsep| = 4.5
% \end{itemize}
% The values can be changed by using |\renewcommand|, in spite of the
% fact that the first two appear to be lengths.
%
%    Dotted leaders are not available for Part and Chapter ToC entries
% (nor for Section entries in the \Lpack{article} class and its derivatives).
%
% \DescribeMacro{\numberline}
%    Each |\l@kind| macro is responsible for setting the general
% \textit{indent} from the lefthand margin, and the \textit{numwidth}.
% The |\numberline{|\meta{number}|}| macro is responsible for typesetting
% the number flushleft in a box of width
% \textit{numwidth}. If the number is too long for the box then it will
% protrude into the title text. The title text is indented by
% (\textit{indent + numwidth}) from the lefthand margin. That is, the title
% text is typeset in a block of width \\
% (|\linewidth| - \textit{indent} - \textit{numwidth} - |\@tocrmarg|).
%
% \begin{table}
% \centering
% \caption[Indents and Numwidths]{Indents and Numwidths (in ems)} \label{tab:indents}
% \begin{tabular}{lcrrrr} \hline
% Entry & Level & \multicolumn{2}{c}{Chaptered} & \multicolumn{2}{c}{Otherwise} \\
%       &       & indent & numwidth & indent & numwidth \\ \hline
% part          & -1 & 0    & --- & 0    & --- \\
% chapter       & 0  & 0    & 1.5 &      &     \\
% section       & 1  & 1.5  & 2.3 & 0    & 1.5 \\
% subsection    & 2  & 3.8  & 3.2 & 1.5  & 2.3 \\
% subsubsection & 3  & 7.0  & 4.1 & 3.8  & 3.2 \\
% paragraph     & 4  & 10.0 & 5.0 & 7.0  & 4.1 \\
% subparagraph  & 5  & 12.0 & 6.0 & 10.0 & 5.0 \\
% figure/table  & (1) & 1.5 & 2.3 & 1.5  & 2.3 \\ \hline
% \end{tabular}
% \end{table}
%
% Table~\ref{tab:indents} lists the standard values for the \textit{indent}
% and \textit{numwidth}. There is no explicit \textit{numwidth} for a
% part; instead a gap of 1em is put between the number and the title text.
% Note that for a sectioning command the values
% depend on whether or not the document class provides the |\chapter|
% command. Also, which somewhat surprises me, the table and figure entries
% are all indented.
%
% \DescribeMacro{\@dottedtocline}
%    Most of the |\l@kind| commands are defined in terms of the
% |\@dottedtocline| command. This command takes three arguments: \\
% |\@dottedtocline{|\meta{seclevel}|}{|\meta{indent}|}{|\meta{numwidth}|}|. \\
% For example, one definition of the |\l@section| command is: \\
% |\newcommand*{\l@section}{\@dottedtocline{1}{1.5em}{2.3em}}| \\
% If it is necessary to change the default typesetting of the entries,
% then it is usually necessary to change these definitions (but the
% \Lpack{tocloft} package gives you handles to easily alter things without
% having to know the \LaTeX{} internals).
%
%    You can use the |\addcontentsline| command to add |\contentsline|
% commands to a file.
%
% \DescribeMacro{\addtocontents}
%    \LaTeX{} also provides the |\addtocontents{|\meta{file}|}{|\meta{text}|}|
% command that will insert \meta{text} into \meta{file}. You can use
% this for adding extra text and/or macros into the file, for processing
% when the file is typeset by |\tableofcontents| (or whatever other
% command is used for \meta{file} processing, such as |\listoftables|
% for a \file{.lot} file).
%
% As |\addcontentsline| and |\addtocontents| write their arguments to a
% file, any fragile commands used in their arguments must be |\protect|ed.
%
%    You can make certain adjustments to the ToC etc., layout without
% using any package. Some examples are:
% \begin{itemize}
% \item If your page numbers stick out into the righthand margin
%  \begin{verbatim}
%  \renewcommand{\@pnumwidth}{3em} \renewcommand{\@tocrmarg}{4em}
%  \end{verbatim}
% but using lengths appropriate to your document.
%
% \item To have the (sectional) titles in the ToC, etc., typeset ragged right with no
% hyphenation
% \begin{verbatim}
% \renewcommand{\@tocrmarg}{2.55em plus1fil}
% \end{verbatim}
% where the value |2.55em| can be changed for whatever margin space you want.
%
% \item The dots in the leaders can be eliminated by increasing |\@dotsep|
% to a large value:
%  \begin{verbatim}
%  \renewcommand{\@dotsep}{10000}
%  \end{verbatim}
%
% \item To have dotted leaders in your ToC and LoF but not in your LoT:
% \begin{verbatim}
% ...
% \tableofcontents
% \makeatletter \renewcommand{\@dotsep}{10000} \makeatother
% \listoftables
% \makeatletter \renewcommand{\@dotsep}{4.5} \makeatother
% \listoffigures
% ...
% \end{verbatim}
% For this document I used this method to double the dot spacing for
% the LoF with respect to that for the ToC. As you can see, it is much
% better that all dot leaders have the same spacing.
%
% \item To add a horizontal line across the whole width of the ToC below
% an entry for a Part:
% \begin{verbatim}
% \part{Part title}
% \addtocontents{toc}{\protect\mbox{}\protect\hrulefill\par}
% \end{verbatim}
% Note that as both |\addtocontents| and |\addcontentsline| write their
% arguments to a file, it means that any \emph{fragile} commands in
% their arguments must be protected
% by preceding each fragile command with |\protect|.
% The result of the example above
% would be the following two lines in the \file{.toc} file (assuming that it
% is the second Part and is on page 34):
% \begin{verbatim}
% \contentsline {part}{II\hspace {1em}Part title}{34}
% \mbox {}\hrulefill \par
% \end{verbatim}
% If the |\protect|s were not used, then the second line would instead be:
% \begin{small}
% \begin{verbatim}
% \unhbox \voidb@x \hbox {}\unhbox \voidb@x \leaders \hrule \hfill \kern \z@ \par
% \end{verbatim}
% \end{small}
%
% \item You may get undesired page breaks in the ToC. For example you
% may have a long multiline section title and in the ToC there is a page
% break between the lines. After your document is stable you can use
% |\addtocontents| at appropriate places in the body of the document
% to adjust the page breaking in the ToC. As examples:
%  \begin{itemize}
%  \item |\addtocontents{toc}{\protect\newpage}| to force a page break.
%  \item |\addtocontents{toc}{\protect\enlargethispage{2\baselineskip}}| to
%        make the page longer.
%  \item |\addtocontents{toc}{\protect\needspace{2\baselineskip}}| to specify
%        that if there is not a vertical space of two baselines left on
%        the page then start a new page (the |\needspace| macro is defined
%        in the \Lpack{needspace} package).
%  \end{itemize}
%
% \end{itemize}
% Remember, if you are modifying any command that includes an |@| sign then this
% must be done in either a \file{.sty} file or if in the document itself
% it must be
% surrounded by |\makeatletter| and |\makeatother|. For example, if you
% want to modify |\@dotsep| in the preamble to your document you have
% to do it like this:
% \begin{verbatim}
% \makeatletter
% \renewcommand{\@dotsep}{9.0}
% \makeatother
% \end{verbatim}
%
%
% \section{The \Lpack{tocloft} package} \label{sec:usc}
%
% The \Lpack{tocloft} package provides means of specifying the
% typography of the Table of Contents (ToC), the List of Figures (LoF)
% and the List of Tables (LoT).
%
% \DescribeMacro{\tableofcontents}
% \DescribeMacro{\listoffigures}
% \DescribeMacro{\listoftables}
% The ToC, LoF, and LoT are printed at the point in the document where
% these commands are called, as per normal \LaTeX. However, there is
% one difference between the standard \LaTeX{} behaviour and the behaviour
% with the \Lpack{tocloft} package. In the standard \LaTeX{} classes
% that have |\chapter| headings, the ToC, LoF and LoT each appear on
% a new page. With the \Lpack{tocloft} package they do not necessarily
% start new pages; if you want them to be on new pages you may have to
% specifically issue an appropriate command beforehand. For example:
% \begin{verbatim}
%  ...
% \clearpage
% \tableofcontents
% \clearpage
% \listoftables
% ...
% \end{verbatim}
%
% \DescribeMacro{\tocloftpagestyle}
% The |\thispagestyle| page style of the ToC, LoF and/or LoT is set
% by the command
% |\tocloftpagestyle{|\meta{style}|}|, where \meta{style} is one of
% the available page styles. The package initially
% sets |\tocloftpagestyle{plain}|.
%
% \subsection{Package options}
%
%    The package takes the following options:
% \begin{itemize}
% \item[\Lopt{subfigure}] This option is required if, and only if,
% the \Lpack{tocloft} and
% \Lpack{subfigure} packages are being used together. The two packages
% can be specified in any order.
%
% \item[\Lopt{titles}]
% The \Lopt{titles} option causes
% the titles of the ToC, LoF, and LoT lists to be typeset using the
% default \LaTeX{} methods. This can be useful, for example, when the
% \Lpack{tocloft} and \Lpack{fncychap} packages are used together and
% the `fancy' chapter styles should be used for the ToC, etc., titles.
%
% \end{itemize}
%
% If you use the \Lopt{titles} option you can ignore the next
% section and continue reading at section~\ref{sec:entries}.
%
% \subsection{Changing the titles} \label{sec:titles}
%
%    Commands are provided for controlling the appearance of the
% titles. Following \LaTeX{} custom, the title texts are the values
% of the |\contentsname|, |\listfigurename| and |\listtablename| commands.
%
% Similar sets of commands are provided for ToC, LoF and LoT title
% typsetting control. For convenience (certainly mine, and hopefully yours)
% in the following
% descriptions I will use |Z| to stand for `toc' or `lof' or `lot'. For
% example, |\cftmarkZ| stands for |\cftmarktoc| or |\cftmarklof| or
% |\cftmarklot|.
%
% \DescribeMacro{\cftmarkZ}
% These macros set the appearance of the running heads on the ToC, LoF, and
% LoT pages. You probably don't need to change these.
%
% \DescribeMacro{\cftbeforeZtitleskip}
% \DescribeMacro{\cftafterZtitleskip}
% These lengths control the vertical spacing before and after the titles.
% You can change them from their default values by using |\setlength|.
%
% \DescribeMacro{\cftZtitlefont}
% \DescribeMacro{\cftafterZtitle}
% The code used for typesetting the ToC title looks like
% \begin{verbatim}
% {\cfttoctitlefont \contentsname}{\cftaftertoctitle}\par
% \end{verbatim}
% By default, |\cftZtitlefont| is defined as a font specification
% (e.g., |\Large\bfseries|), and |\cftafterZtitle| is empty.
% These commands can be changed (via |\renewcommand|) to change
% the typesetting. As examples:
% \begin{itemize}
% \item |\renewcommand{\cftZtitlefont}{\hfill\Large\itshape}| will
%       result in a Large italic title typeset flushright.
% \item |\renewcommand{\cftZtitlefont}{\hfill\Large\bfseries}| together
%       with |\renewcommand{\cftafterZtitle}{\hfill}| will give
%       a centered Large bold title.
% \item Doing
% \begin{verbatim}
% \renewcommand{\cftafterZtitle}{%
%   \\[\baselineskip]\mbox{}\hfill{\normalfont Page}}
% \end{verbatim}
%       will put the word `Page' flushright on the line following the title.
%       (If you do this, then you may need to decrease
%        |\cftafterZtitleskip|).
% \item |\renewcommand{\cftafterZtitle}{\thispagestyle{empty}}| will
%       make the page with the title empty (i.e., the page
%       number will not be printed).
% \end{itemize}
%
%
% \subsection{Typesetting the entries} \label{sec:entries}
%
% Commands are also provided to enable finer control over the typesetting
% of the different kinds of entries. The parameters defining the default
% layout of the entries are illustrated as part of the \Lpack{layouts}
% package or in~\cite[page 34]{GOOSSENS94}, and are repeated in
% Figure~\ref{fig:ltoc}.
%
% \DescribeMacro{\Zdepth}
% The command |\Zdepth{|\meta{number}|}| is analogous to the standard
% |\tocdepth{|\meta{number}|}| command, in that it specifies that entries
% in the new listing should not be typeset if their numbering level
% is greater
% than \meta{number}. The default definition is
% |\setcounter{Zdepth}{1}|.
% These commands are needed, for instance by users of packages such as |subcaption|,
% which will generate subfigure and subtable captions corresponding to a |lofdepth| and
% |lotdepth| of |2|.
%
% \DescribeMacro{\cftdot}
%  In the default ToC typesetting only the more minor entries have dotted
% leader lines between the sectioning title and the page number. The
% \Lpack{tocloft} package provides for general leaders for all entries.
% The `dot' in a leader is given by the value of |\cftdot|. Its default
% definition is |\newcommand{\cftdot}{.}| which gives the default
% dotted leader. By changing |\cftdot| you can use symbols other than
% a period in the leader. For example
% \begin{verbatim}
% \renewcommand{\cftdot}{\ensuremath{\ast}}
% \end{verbatim}
% will result in a dotted leader using asterisks as the symbol.
%
% \DescribeMacro{\cftdotsep}
% \DescribeMacro{\cftnodots}
%    Each kind of entry can control the separation between the dots
% in its leader (see below). For consistency though, all dotted leaders
% should use the same spacing. The macro |\cftdotsep| specifies the
% default spacing. Its value is a number.
% However, if the separation is too large
% then no dots will be actually typeset. The macro |\cftnodots| is
% a separation value that is `too large'.
%
% \DescribeMacro{\cftsetpnumwidth}
% \DescribeMacro{\cftsetrmarg}
% The page numbers are typeset in a fixed width box. The command
% |\cftsetpnumwidth{|\meta{length}|}| can be used to change the width
% of the box (\LaTeX 's internal |\@pnumwidth|).
% The title texts will end before reaching the righthand margin.
% |\cftsetrmarg{|\meta{length}|}| can be used to set this distance
% (\LaTeX 's internal |\@tocrmarg|).
% Note that the length used in |\cftsetrmarg| should be greater
% than the length set in |\cftsetpnumwidth|. These values should remain
% constant in any given document.
%
% \DescribeMacro{\cftpnumalign}
% The page numbers are typeset in a box as described above.
% By default they are right-aligned which is suitable when the page numbers are aligned vertically on the page so their digits line up.
% For a design with fixed width between a ToC entry and its page number, say, a left alignment may be more suitable.
% This can be controlled by setting the \cs{cftpnumalign} macro to \verb|l|, \verb|c|, or \verb|r| (just like \cs{makebox}):
% \begin{verbatim}
%   \renewcommand{\cftpnumalign}{l}
% \end{verbatim}
%
% \DescribeMacro{\cftparskip}
% Normally the |\parskip| in the ToC, etc., is zero. This may be changed
% by changing the |\cftparskip| length. Note that the current value
% of |\cftparskip| is used for the ToC, LoF and LoT, but you can change
% the value before calling |\tableofcontents| or |\listoffigures| or
% |\listoftables| if one or other of these should have different values
% (which is not a good idea).
%
%
%    In the following I will use |X| to stand for the following:
% \begin{itemize}
% \item |part| for |\part| titles
% \item |chap| for |\chapter| titles
% \item |sec| for |\section| titles
% \item |subsec| for |\subsection| titles
% \item |subsubsec| for |\subsubsection| titles
% \item |para| for |\paragraph| titles
% \item |subpara| for |\subparagraph| titles
% \item |fig| for figure |\caption| titles
% \item |subfig| for subfigure |\caption| titles
% \item |tab| for table |\caption| titles
% \item |subtab| for subtable |\caption| titles
% \end{itemize}
%
% \DescribeMacro{\cftbeforeXskip}
% This controls the vertical space before an entry. It can be changed
% by using |\setlength|.
%
% \DescribeMacro{\cftXindent}
% This controls the indentation of an entry from the left margin
% (\textit{indent} in Figure~\ref{fig:ltoc}). It
% can be changed using |\setlength|.
%
% \DescribeMacro{\cftXnumwidth}
% This controls the space allowed for typesetting title numbers
% (\textit{numwidth} in Figure~\ref{fig:ltoc}). It can
% be changed using |\setlength|. Second and subsequent lines of a multiline
% title will be indented by this amount.
%
% The remaining commands are related to the specifics of typesetting
% an entry.
% This is a simplified pseudo-code version for the typesetting of numbered
% and unnumbered entries.
% \begin{verbatim}
% {\cftXfont {\cftXpresnum SNUM\cftXaftersnum\hfil} \cftXaftersnumb TITLE}%
%         {\cftXleader}{\cftXpagefont PAGE}\cftXafterpnum\par
%
% {\cftXfont TITLE}{\cftXleader}{\cftXpagefont PAGE}\cftXafterpnum\par
% \end{verbatim}
% where |SNUM| is the section number, |TITLE| is the title text and |PAGE|
% is the page number. In the numbered entry the pseudo-code \\
% |{\cftXpresnum SNUM\cftaftersnum\hfil}| \\
% is typeset within a box of width |\cftXnumwidth|.
%
% \DescribeMacro{\cftXfont}
% This controls the appearance of the title (and its preceding number,
% if any). It may be changed using |\renewcommand|.
%
% \DescribeMacro{\cftXpresnum}
% \DescribeMacro{\cftXaftersnum}
% \DescribeMacro{\cftXaftersnumb}
% \changes{v1.1}{2000/02/11}{Added description of \cs{cftXpresnum}}
% Normally the section number is typeset within a box of width |\cftXnumwidth|.
% Within the box the macro |\cftXpresnum| is first called, then the
% number is typeset, and next the |\cftXaftersnum|
% macro is called after the number is typeset. The last command
% within the box is |\hfil| to make the box contents flushleft.
% After the box is
% typeset the |\cftXaftersnumb| macro is called before typesetting
% the title text. All three of these can be changed by |\renewcommand|.
% By default they are defined to do nothing.
%
% In the standard classes the ToC entry for a |\part| is just typeset as
% the number and title, followed by the page number, with the
% |\cftpartpresnum|
% macro being called before typesetting the number and title.
% Due to \LaTeX\ ideosyncracies, |\cftpartpresnum| may become doubled in the output
% if a third-party package behaves differently to that of the default internal \LaTeX\ commands.
% The |tocloft| package contains specific code to prevent this in the case of
% the KomaScript classes and for the |titlesec| package; please contact the maintainer
% to add further corrections if you discover other packages which also exhibit this mis-behaviour.
%
% When a standard class is used the |\cftpartaftersnum| and
% |\cftpartaftersnumb| macros have no effect, but they may do something
% if a non-standard class is used.
%
%
% \DescribeMacro{\cftXleader}
% \DescribeMacro{\cftXdotsep}
% |\cftXleader| defines the leader between the title and the page number;
% it can be changed by |\renewcommand|.
% The spacing between any dots in the leader is controlled by |\cftXdotsep|
% (|\@dotsep| in Figure~\ref{fig:ltoc}).
% It can be changed by |\renewcommand| and its value must be either a
% number (e.g., 6.6 or |\cftdotsep|) or |\cftnodots| (to disable the dots).
% The spacing
% is in terms of \emph{math units} where there are 18mu to 1em.
%
% \DescribeMacro{\cftXpagefont}
% This defines the font to be used for typesetting the page number. It
% can be changed by |\renewcommand|.
%
% \DescribeMacro{\cftXafterpnum}
% This macro is called after the page number has been typeset. Its default
% is to do nothing. It can be changed by |\renewcommand|.
%
% \DescribeMacro{\cftsetindents}
% The command
% |\cftsetindents{|\meta{entry}|}{|\meta{indent}|}{|\meta{numwidth}|}|
% sets the \meta{entry}'s \textit{indent} to the length \meta{indent} and its
% \textit{numwidth} to the length \meta{numwidth}. The \meta{entry} argument
% is the name of one of the standard entries (e.g., |subsection|) or the name of
% entry that has been defined with the \Lpack{tocloft} package.
% For example \\
% |\cftsetindents{figure}{0em}{1.5em}| \\
% will make figure entries left justified.
%
%
% Various effects can be achieved by changing the definitions of |\cftXfont|,
% |\cftXaftersnum|, |\cftXaftersnumb|, |\cftXleader| and |\cftXafterpnum|,
% either singly or in combination.
% For the sake of some examples, assume that we have the following initial
% definitions
% \begin{verbatim}
% \newcommand{\cftXfont}{}
% \newcommand{\cftXaftersnum}{}
% \newcommand{\cftXaftersnumb}{}
% \newcommand{\cftXleader}{\cftdotfill{\cftXdotsep}}
% \newcommand{\cftXdotsep}{\cftdotsep}
% \newcommand{\cftXpagefont}{}
% \newcommand{\cftXafterpnum}{}
% \end{verbatim}
% (Note that the same font should be used for the title, leader and page
% number to provide a coherent appearance).
%
% \begin{itemize}
% \item To eliminate the dots in the leader:
% \begin{verbatim}
% \renewcommand{\cftXdotsep}{\cftnodots}
% \end{verbatim}
%
% \item To put something (e.g., a name) before the title (number):
% \begin{verbatim}
% \renewcommand{\cftXpresnum}{SOMETHING }
% \end{verbatim}
%
% \item To add a colon after the section number:
% \begin{verbatim}
% \renewcommand{\cftXaftersnum}{:}
% \end{verbatim}
%
% \item To put something before the title number, add a colon after the
%    the title number, set everything in bold font,
% and start the title text on the following line:
% \begin{verbatim}
% \renewcommand{\cftXfont}{\bfseries}
% \renewcommand{\cftXleader}{\bfseries\cftdotfill{\cftXdotsep}}
% \renewcommand{\cftXpagefont}{\bfseries}
% \renewcommand{\cftXpresnum}{SOMETHING }
% \renewcommand{\cftXaftersnum}{:}
% \renewcommand{\cftXaftersnumb}{\\}
% \end{verbatim}
%
%    If you are adding text in the number box in addition to the number,
% then you will probably have to increase the width of the box so that
% multiline titles have a neat vertical alignment; changing box widths
% usually implies that the indents will require modification as
% well.\footnote{Lyndon Dudding (\texttt{lyndon.dudding@totalise.co.uk})
% discovered this.}
% One possible method of adjusting the box width for the above example
% is:
% \begin{verbatim}
% \newlength{\mylen}   % a "scratch" length
% \settowidth{\mylen}{\bfseries\cftXpresnum\cftXaftersnum} % extra space
% \addtolength{\cftXnumwidth}{\mylen} % add the extra space
% \end{verbatim}
%
% \item To set the section numbers flushright:\footnote{With thanks to
% David Holz (\texttt{lbda@earthlink.net}) for requesting this.}
% \begin{verbatim}
% \setlength{\mylen}{0.5em}   % need some extra space at end of number
% \renewcommand{\cftXpresnum}{\hfill}  % note the double `l'
% \renewcommand{\cftXaftersnum}{\hspace*{\mylen}}
% \addtolength{\cftXnumwidth}{\mylen}
% \end{verbatim}
% In the above, the added initial |\hfill| in the box overrides the
% final |\hfil| in the box, thus shifting everything to the right hand
% end of the box. The extra space is so that the number is not typeset
% immediately at the left of the title text.
%
% \item To set the entry ragged left (but this only looks good for single
%       line titles):
% \begin{verbatim}
% \renewcommand{\cftXfont}{\hfill\bfseries}
% \renewcommand{\cftXleader}{}
% \end{verbatim}
%
% \item To set the page number immediately after the entry text instead of at
%       the righthand margin:
% \begin{verbatim}
% \renewcommand{\cftXleader}{}
% \renewcommand{\cftXafterpnum}{\cftparfillskip}
% \renewcommand{\cftpnumalign}{l}
% \end{verbatim}
% By default the |\parfillskip| value is locally set to fill up the last
% line of a paragraph. Just changing |\cftXleader| puts horrible interword
% spaces into the last line of the title. The |\cftparfillskip|
% command
% is part of the \Lpack{tocloft} package and is provided just so that
% the above effect can be achieved.
% In addition, this is a good example of when it would be suitable to change the alignment of the page number box.
%
% \item To remove the space inserted between table and figure caption entries between chapters:
% \begin{verbatim}
% \begingroup
%   \renewcommand*{\addvspace}[1]{}
%   \listoftables
%   \listoffigures
% \endgroup
% \end{verbatim}
% \end{itemize}
%
% \DescribeMacro{\cftpagenumbersoff}
% \DescribeMacro{\cftpagenumberson}
% The command |\cftpagenumbersoff{|\meta{entry}|}| will
% eliminate the page numbers for \meta{entry} in the listing, where
% \meta{entry} is the name of one of the standard
% kinds of entries (e.g., |subsection|, or |figure| --- including |subfigure|
% if the \Lpack{subfigure} package is used --- etc.), or the name of a
% new entry defined with the \Lpack{tocloft} package.
%
%    The command |\cftpagenumberson{|\meta{entry}|}| reverses
% the effect of a corresponding |\cftpagenumbersoff|.
%
% One question that appeared on the \file{comp.text.tex} newsgroup asked
% how to get the titles of Appendices list in the ToC \emph{without}
% page numbers. Here is a simple way of doing it, assuming the document
% has chapters
% \begin{verbatim}
% ...
% \appendix
% \addtocontents{toc}{\cftpagenumbersoff{chapter}}
% \chapter{First appendix}
% \end{verbatim}
% If there are other chaptered headings to go into the ToC after the
% appendices, then it will be necessary to do a similar \\
% |\addtocontents{toc}{\cftpagenumberson{chapter}}| \\
% to restore the page numbering in the ToC.
%
%    Similarly, if you are using the \Lpack{subfigure} package you may
% want to eliminate the page numbers for the subfigure captions. This
% can be accomplished by: \\
% |\cftpagenumbersoff{subfigure}|
%
% At this point, I leave it up to your ingenuity as to other effects that
% you can achieve. However, if you come up with further examples, let me
% know for possible inclusion in a later version of this document.
%
% \subsection{New list of\ldots}
%
% \DescribeMacro{\newlistof}
% The command |\newlistof[|\meta{within}|]{|\meta{entry}|}{|\meta{ext}|}{|\meta{listofname}|}|
% creates a new List of \ldots, and assorted commands to go along with it.
%
% The first required argument, \meta{entry} is used to define a new
% counter called |entry|. The optional \meta{within} argument can
% be used so that |entry| gets reset to one every time the counter called
% |within| is changed. That is, the first two arguments are equivalent to
% calling |\newcounter{|\meta{entry}|}[|\meta{within}|]|.
%
% The next argument, \meta{ext}, is the file extension for the new List of.
% The last argument, \meta{listofname}, is the text for the heading of the
% new List of. As an example:
% \begin{verbatim}
% \newcommand{\listanswername}{List of Answers}
% \newlistof[chapter]{answer}{ans}{\listanswername}
% \end{verbatim}
% will create a new |answer| counter that will be reset at the start of each
% |\chapter{...}|. Any answer titles will be written to the file
% \file{jobname.ans} and |\listanswername| will be used as the list heading.
% A command |\listofanswer| is created which can be used just like the
% |\listoftables| or |tableofcontents| commands to generate a listing.
% It is up to you to specify how the entries are put into the
% new List of Answers. Here is a very simple example, remembering that an
% |answer| counter has been created.
% \begin{verbatim}
% \newcommand{\answer}[1]{%
%   \refstepcounter{answer}
%   \par\noindent\textbf{Answer \theanswer. #1}
%   \addcontentsline{ans}{answer}{\protect\numberline{\theanswer}#1}\par}
% \end{verbatim}
% which, when used like: \\
% |\answer{Hard} The \ldots|  will print as:
% \par\noindent\textbf{Answer 1. Hard}\par The \ldots
%
%    As mentioned above, the |\newlistof| command creates several new
% commands, most of which you should now be familiar with. For convenience,
% assume that |\newlistof{X}{Z}{...}| has been issued; so |X| is the name
% of the new counter and corresponds to the |X| in section~\ref{sec:entries},
% and |Z| is the new file extension and corresponds to the |Z| in
% section~\ref{sec:titles}. Then, among others, the following new commands
% will be made available.
%
% The five commands, |\cftmarkZ|,
% |\cftbeforeZtitleskip|,
% |\cftafterZtitleskip|,
% |\cftZtitlefont|, and
% |\cftafterZtitle|,
% are analogous to the commands of the same names
% described in section~\ref{sec:titles}.
%
% \DescribeMacro{\listofX}
% The command |\listofX| is similar to |\listoftables|, etc.,
% in that it typesets
% the new listing at the point where it is called.
%
% \DescribeMacro{\Zdepth}
% The command |\Zdepth{|\meta{number}|}| is analogous to the standard
% |\tocdepth{|\meta{number}|}| command, in that it specifies that entries
% in the new listing should not be typeset if their numbering level
% is greater
% than \meta{number}. The default definition is
% |\setcounter{Zdepth}{1}|.
%
% \DescribeMacro{\newlistentry}
% The command
% |\newlistentry[|\meta{within}|]{|\meta{entry}|}{|\meta{ext}|}{|\meta{level-1}|}| creates
% new commands for typesetting a new kind of entry in a listing. It is used
% internally by the |\newlistof| command but may be used independently.
%
% The first required argument, \meta{entry} is used to define a new
% counter called |entry|. The optional \meta{within} argument can
% be used so that |entry| gets reset to one every time the counter called
% |within| is changed. That is, the first two arguments are equivalent to
% calling |\newcounter{|\meta{entry}|}[|\meta{within}|]|.
% The second required argument, \meta{ext}, is the file extension for the
% entry listing.
% The last argument, \meta{level-1}, is a number specifying the numbering
% level minus one,
% of the entry in a listing.
% For example, the command \\
% |\newlistof[chapter]{answer}{ans}{\listanswername}| \\
% will call the command: \\
% |\newlistentry[chapter]{answer}{ans}{0}| \\
%
%
%    Calling |\newlistentry| creates several new commands. Assuming that
% it is called as |\newlistentry[within]{X}{Z}{N}|, where |X| and |Z| are
% similar to the
% previous uses of them, and |N| is an integer number, then the following
% commands are made available.
%
%  The set of commands |\cftbeforeXskip|,
% |\cftXfont|,
% |\cftXpresnum|,
% |\cftXaftersnum|,
% |\cftXaftersnumb|,
% |\cftXleader|,
% |\cftXdotsep|,
% |\cftXpagefont|, and
% |\cftXafterpnum|,
%  are analogous to the commands of the same names
% described in section~\ref{sec:entries}. Their default values are also
% as described earlier.
%
% The default values of |\cftXindent| and |\cftXnumwidth| are set according
% to the value of the \meta{level-1} argument (i.e., |N| in this example).
% For |N=0| the settings correspond to those for
% sections in non-chaptered documents, as listed in Table~\ref{tab:indents}.
% For |N=4| the settings correspond
% to subparagraphs in non-chaptered documents, and for intermediate values
% correspond to the matching sectional division in chaptered documents.
% For values of |N| less than zero or greater than four,
% or for non-default values, use the
% |\cftsetindents| command to set the values.
%
%
% \DescribeMacro{\l@X}
%  |\l@X| is an internal command that typesets an entry in the list, and
% is defined in terms of the above |\cft*X*| commands. It will not typeset
% an entry if |\Zdepth| is |N| or less, where |Z| is the listing's file
% extension.
%
% \DescribeMacro{\theX}
% The command |\theX| prints the value of the |X| counter. It is initially
% defined so that it prints arabic numerals. If the optional \meta{within}
% argument is used, |\theX| is defined as \\
% |\renewcommand{\theX}{\thewithin.\arabic{X}}| otherwise as \\
% |\renewcommand{\theX}{\arabic{X}}|.
%
%
% As an example of the independent use of |\newlistentry|, the following
% will set up for sub-answers.
% \begin{verbatim}
% \newlistentry[answer]{subanswer}{1}
% \cftsetindents{subanswer}{1.5em}{3.0em}
% \renewcommand{\thesubanswer}{\theanswer.\alph{subanswer}}
% \newcommand{\subanswer}[1]{%
%    \refstepcounter{subanswer}
%    \par\textbf{\thesubanswer) #1}
%    \addcontentsline{ans}{subanswer{\protect\numberline{\thesubanswer}#1}}
% \setcounter{ansdepth}{2}
% \end{verbatim}
% And then:
% \begin{verbatim}
% \answer{Harder} The \ldots
%   \subanswer{Reformulate the problem} It assists \ldots
% \end{verbatim}
% will be typeset as:
% \par\noindent\textbf{Answer 2. Harder}\par The \ldots
% \par\textbf{2.a) Reformulate the problem} It assists \ldots
%
% By default the answer entries will appear in the List of Answers listing
% (typeset by the |\listofanswer| command).
% In order to get the subanswers to appear,
% the |\setcounter{ansdepth}{2}| command was used above.
%
% To turn off page numbering for the subanswers, do \\
% |\cftpagenumbersoff{subanswer}|
%
%    As another example of |\newlistentry|, suppose that an extra sectioning
% division below |subparagraph| is required, called |subsubpara|.
% The |\subsubpara| command itself can be defined via the LaTeX kernel
% |\@startsection| command.
% Also it is necessary to define a |\subsubparamark| macro,
% a new |subsubpara| counter, a |\thesubsubpara| macro and a |\l@subsubpara|
% macro. Using the \Lpack{tocloft} package's |\newlistentry|
% takes care of most of these as shown below (remember
% the caveats about commands with |@| signs in them).
% \begin{verbatim}
% \newcommand{\subsubpara}{\@startsection{subpara}%
%    {6}%                                                level
%    {\parindent}%                     indent from left margin
%    {3.25ex \@plus1ex \@minus .2ex}%       skip above heading
%    {-1em}%       runin heading with 1em between title & text
%    {\normalfont\normalsize\itshape}% italic number and title
% }
% \newlistentry[subparagraph]{subsubpara}{toc}{5}
% \cftsetindents{subsubpara}{14.0em}{7.0em}
% \newcommand*{\subsubparamark}[1]{}     % gobble heading mark
% \end{verbatim}
%
%
%     Each List of\ldots uses a file to store the list entries, and these
% files must remain open for writing throughout the document processing.
% TeX has only a limited number of files that it can keep open, and this
% puts a limit on the number of listings that can be used. For a document
% that includes a ToC but no other extra ancillary files (e.g., no
% index or bibliography output files) the maximum number of LoX's, including
% a LoF and LoT, is no more than about eleven. If you try and create too many
% new listings LaTeX will respond with the error message:
% \begin{center}
% |No room for a new write|
% \end{center}
% If you get such a message the only recourse is to redesign your document.
%
%    The \Lpack{tocloft} package does not provide a simple means of specifying
% new Lists of Floats or float environments.
% For those, I recommend the \Lpack{ccaption} package~\cite{CCAPTION}.
%
% \subsection{Experimental utilities}
%
% The macros described in this section are even more experimental than
% those described previously.
%
% \DescribeMacro{\cftchapterprecis}
%   Some old style novels, and even some modern text
% books,\footnote{For example, Robert Sedgewick, \textit{Algorithms},
% Addison-Wesley, 1983.} include a short synopsis of the contents of
% the chapter either immediately
% after the chapter heading or in the Toc, or in both places.
%
%     The command |\cftchapterprecis{|\meta{text}|}| prints its argument
% both at the
% point in the document where it is called, and also adds it to the \file{.toc}
% file. For example:
% \begin{verbatim}
% ...
% \chapter{} % first chapter
% \cftchapterprecis{Our hero is introduced; family tree; early days.}
% ...
% \end{verbatim}
%
% \DescribeMacro{\cftchapterprecishere}
% \DescribeMacro{\cftchapterprecistoc}
% The |\cftchapterprecis| command calls these two commands to print the
% text in the document (the |\...here{|\meta{text}|}| command)
% and to put it into the ToC (the |\...toc{|\meta{text}|}| command).
% These can be used individually if required.
%
% Sometimes it may be desirable to make a change to the global parameters
% for an individual entry. For example, a figure might be placed on
% the end paper of a book (the inside of the front or back cover), and
% this needs to be placed in a LoF with the page number set as, say
% `inside front cover'. If `inside front cover' is typeset as an ordinary
% page number it will stick out into the margin. Therefore, the parameters
% for this particular entry need to be changed.
%
% \DescribeMacro{\cftlocalchange}
% The command |\cftlocalchange{|\meta{file}|}{|\meta{pnumwidth}|}{|\meta{tocrmarg}|}|
% will write an entry into \meta{file} to reset the global parameters.
% The command should be called again after any special entry to reset
% the parameters back to their usual values. Any fragile commands used
% in the arguments must be protected.
%
% \DescribeMacro{\cftaddtitleline}
% The command |\cftaddtitleline{|\meta{file}|}{|\meta{kind}|}{|\meta{title}|}{|\meta{page}|}|
% will write a |\contentsline| entry into \meta{file} for a \meta{kind}
% entry with title \meta{title} and page number \meta{page}. That is,
% an entry is made of the form: \\
% |\contentsline{kind}{title}{page}| \\
% Any fragile commands used in the arguments must be protected.
%
% \DescribeMacro{\cftaddnumtitleline}
% The command |\cftaddnumtitleline{|\meta{file}|}{|\meta{kind}|}{|\meta{num}|}{|\meta{title}|}{|\meta{page}|}|
% is similar except that it also includes \meta{num} as the argument to
% the |\numberline|. That is, an entry is made of the form: \\
% |\contentsline{kind}{\numberline{num} title}{page}| \\
% Any fragile commands used in the arguments must be protected.
%
% As an example of the use of these commands,
% noting that the default \LaTeX{} values for
% |\@pnumwidth| and |\@tocrmarg| are 1.55em and 2.55em respectively,
% one might do the
% following for a figure on the frontispiece page.
% \begin{verbatim}
% ...
% % this is the frontispiece page with no number
% % draw or import the picture (with no \caption)
% \cftlocalchange{lof}{4em}{5em} % make pnumwidth big enough for
%                                % frontispiece and change margin to suit
% \cftaddtitleline{lof}{figure}{The title}{frontispiece}
% \cftlocalchange{lof}{1.55em}{2.55em} % return to normal settings
% ...
% \end{verbatim}
%    Recall that a |\caption| command will put an entry in the \file{.lof}
% file, which is not wanted here. If a caption is required, then you can
% either craft one yourself or, assuming that your general captions are not
% too exotic, use the |\legend| command from the
% \Lpack{ccaption} package. If the illustration is numbered, use the
% |\cftaddnumtitleline| command instead of |\cftaddtitleline|.
%
% \DescribeMacro{\cftZprehook}
% \DescribeMacro{\cftZposthook}
% It's surprisingly difficult to achieve multicolumn ToCs; can you guess what the problem is to write the following?
% \begin{verbatim}
% \begin{multicols}{2}
% \tableofcontents
% \end{multicols}
% \end{verbatim}
% Probably the easiest way to do it in regular \LaTeX{} is something like
% \begin{verbatim}
% \RequirePackage{multicol}
% \AtBeginDocument{\addtocontents{toc}{\protect\begin{multicols}{2}}}
% \AtEndDocument  {\addtocontents{toc}{\protect\end  {multicols}}}
% \end{verbatim}
% This method of writing to the |.toc| file is most flexible for trying to control the typesetting output within the table of contents.
%
% To make this \emph{slightly} easier with \Lpack{tocloft}, the following macros are available: \cs{cftZprehook} and \cs{cftZprehook}, where |Z| is |toc|, |lof|, |lot|, etc.
% If these are defined, they insert material just before the actual typesetting of the entries of the table of contents and so on.
% A multicolumn ToC can therefore be achieved with this:
% \begin{verbatim}
% \RequirePackage{multicol}
% \renewcommand\cfttocprehook{\begin{multicols}{2}}
% \renewcommand\cfttocposthook{\end{multicols}}
% \end{verbatim}
%
% \subsection{Usage with other packages}
%
%    The \Lpack{tocloft} and \Lpack{tocbibind} packages can be used together
% in the same document. The \Lpack{tocbibind} package provides easy means
% of adding document elements like the bibliography or the index to the
% Table of Contents. However there is one known potential problem:
% \begin{itemize}
% \item If the argument to the |\tocotherhead| command is other than one
% of the normal sectioning divisions (i.e., part through to sub-paragraph)
% such as |\tocotherhead{clause}|,
% then this will almost certainly cause a problem (as the \Lpack{tocloft}
% package will not know how to define the corresponding |\l@clause| command).
% In such a case you will have to supply the appropriate macros yourself.
% \end{itemize}
%
% \DescribeMacro{\@cftbsnum}
% \DescribeMacro{\@cftasnum}
% \DescribeMacro{\@cftasnumb}
%    Some packages, like the \Lpack{float} package by Anselm Lingnau,
% enable the creation of other kinds of \textit{List of \ldots}.
% The \Lpack{tocloft} package is only minimally able to change the
% formatting of these,
% principally because the packages are independent of each other and, in
% the case of the \Lpack{float} package, new kinds of float environments
% and their associated lists can be created on the fly at any point in
% a document. Some aspects of the typesetting
% are controlled by |\@cftbsnum|, |\@cftasnum| and |\@cftasnumb| commands.
% These are equivalent to the |\cftXpresnum|, |\cftXaftersnum| and |\cftXaftersnumb|
% commands described earlier. By default they are defined to do nothing, but
% may be renewed to do something.
%
%   The \Lpack{tocloft} and \Lpack{minitoc} packages have an unfortunate
% interaction,\footnote{Discovered by Lyndon Dudding
% (\texttt{lyndon.dudding@totalise.co.uk}).} which fortunately can be fixed.
% In the normal course of events, when \Lpack{minitoc} is used in a chaptered
% document it will typeset section
% entries in the minitocs in bold font. If \Lpack{tocloft} is used in
% conjunction with \Lpack{minitoc}, then the minitoc section entries are
% typeset in the normal font, except for the page numbers which are in
% bold font, while the ToC section entries are all in normal font.
%
%    One cure, if you want the minitoc section entries to be all in normal
% font is to put:
% \begin{verbatim}
% \renewcommand{\mtcSfont}{\small\normalfont}
% \end{verbatim}
% in the preamble.
%
%    Otherwise, the cure is the following incantation:
% \begin{verbatim}
% \renewcommand{\cftsecfont}{\bfseries}
% \renewcommand{\cftsecleader}{\bfseries\cftdotfill{\cftdotsep}}
% \renewcommand{\cftsecpagefont}{\bfseries}
% \end{verbatim}
% To have the section entries in both the ToC and the minitocs in bold then
% put the incantation in the preamble. To have only the minitoc section
% entries in bold while the ToC entries are in the normal font,
% put the incantation between the |\tableofcontents|
% command and the first |\chapter| command.
%
%
% In general, use with other packages that redefine any of the macros that
% \Lpack{tocloft} also modifies is likely to be problematic.
%
% \section{The package code} \label{sec:code}
%
%    \begin{macrocode}
%<*usc>
%    \end{macrocode}
%
% In order to try and avoid name clashes with other packages, each internal
% name will include the character string \texttt{@cft}.
%
% \begin{macro}{\@cftifundefined}
% \changes{v2.3h}{2017/08/29}{Use internal ifundefined macro to fix conflict with fancyhdr}
% Due to a conflict with how this package and fancyhdr checked for undefinedness.
%    \begin{macrocode}
\newcommand\@cftifundefined[1]{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname #1\endcsname\relax
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@cftquit}
% \begin{macro}{\if@cfthaschapter}
% We will be using either chapter or section type headings for the ToC, etc.,
% so we need to know which of these the document class supports.
% \changes{v2.0}{2001/03/03}{Revamped chapter checking so the stdclsdv package no longer required}
%    \begin{macrocode}
\newcommand{\@cftquit}{}
\newif\if@cfthaschapter
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\if@cftkoma}
% The \Lpack{koma} classes have different defaults than the standard classes,
% so we need to know if a \Lpack{koma} class has been loaded.
% \changes{v2.3}{2002/06/15}{Added check for a koma class}
%    \begin{macrocode}
\newif\if@cftkoma
\@cftkomafalse
\@ifclassloaded{scrartcl}{\@cftkomatrue}{}
\@ifclassloaded{scrreprt}{\@cftkomatrue}{}
\@ifclassloaded{scrbook}{\@cftkomatrue}{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@cfttitlesec}
% \changes{v2.3f}{2013/04/30}{Added check for titlesec package}
%    \begin{macrocode}
\newif\if@cfttitlesec
\AtBeginDocument{\@ifpackageloaded{titlesec}{\@cfttitlesectrue}{}}
%    \end{macrocode}
% \end{macro}
%
% Issue a warning if there are no recognised sectional divisions
% and then skip the rest of the package code.
%    \begin{macrocode}
\@cftifundefined{chapter}{%
  \@cfthaschapterfalse
  \@cftifundefined{section}{%
    \PackageWarning{tocloft}%
      {I don't recognize any sectional divisions so I'll do nothing}
    \renewcommand{\@cftquit}{\endinput}
    }{\PackageInfo{tocloft}{The document has section divisions}}
  }{\@cfthaschaptertrue
    \PackageInfo{tocloft}{The document has chapter divisions}}
%    \end{macrocode}
% Perhaps quit now.
%    \begin{macrocode}
\@cftquit
%    \end{macrocode}
%
% Use chapter style if |\if@cfthaschapter| is TRUE, otherwise section style.
%
% \begin{macro}{\if@cfttocbibind}
% A flag that is set TRUE iff the \Lpack{tocbibind} package has been loaded.
% The 1998/11/15 version of \Lpack{tocbibind} does not necessarily work well
% with \Lpack{tocloft}.
%    \begin{macrocode}
\newif\if@cfttocbibind
\AtBeginDocument{%
  \@ifpackageloaded{tocbibind}{\@cfttocbibindtrue}{\@cfttocbibindfalse}
  \if@cfttocbibind
    \@ifpackagelater{tocbibind}{1998/11/16}{}{%
      \PackageWarning{tocloft}{%
You are using a version of the tocbibind package\MessageBreak
that is not compatible with tocloft.\MessageBreak
The results may be surprising.\MessageBreak
Consider installing the current version of tocbibind.}}
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@cftnctoc}
% A boolean used to implement the \Lopt{titles} option. It is TRUE
% if the ToC, LoT, LoF titles should use the default styles.
%    \begin{macrocode}
\newif\if@cftnctoc\@cftnctocfalse
\DeclareOption{titles}{\@cftnctoctrue}
  %% \ProcessOptions\relax
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@cftsubfigopt}
% A boolean used to implement the \Lopt{subfigure} option.
%    \begin{macrocode}
\newif\if@cftsubfigopt\@cftsubfigoptfalse
\DeclareOption{subfigure}{\@cftsubfigopttrue}
%    \end{macrocode}
% \end{macro}
%
% Process the options.
%
%    \begin{macrocode}

\ProcessOptions\relax

%    \end{macrocode}
%
% \begin{macro}{\tocloftpagestyle}
% \begin{macro}{\@cftpagestyle}
% A user-level macro to set the pagestyle for the first page of the ToC, etc.
% The default is the |plain| pagestyle.
% \changes{v2.3}{2002/06/15}{Added \cs{tocloftpagestyle}}
%    \begin{macrocode}
\newcommand{\tocloftpagestyle}[1]{%
  \def\@cftpagestyle{\thispagestyle{#1}}}
\tocloftpagestyle{plain}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cftmarktoc}
% \begin{macro}{\cftmarklof}
% \begin{macro}{\cftmarklot}
%  These three macros set the style for running heads. They are initialised
% to give the default appearance.
% \changes{v2.3}{2002/06/15}{Marking commands are different for koma}
%    \begin{macrocode}
\newcommand{\cftmarktoc}{%
  \@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}
\newcommand{\cftmarklof}{%
  \@mkboth{\MakeUppercase\listfigurename}{\MakeUppercase\listfigurename}}
\newcommand{\cftmarklot}{%
  \@mkboth{\MakeUppercase\listtablename}{\MakeUppercase\listtablename}}
\if@cftkoma
  \renewcommand{\cftmarktoc}{%
    \@mkboth{\contentsname}{\contentsname}}
  \renewcommand{\cftmarklof}{%
    \@mkboth{\listfigurename}{\listfigurename}}
  \renewcommand{\cftmarklot}{%
    \@mkboth{\listtablename}{\listtablename}}
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@cfttocstart}
% \begin{macro}{\@cfttocfinish}
% Two macros to perform the actions at the beginning and end of the
% |\tableofcontents| command (and friends). |\@cfttocstart| deals with
% chaptered documents, ensuring that the ToC is typeset in a single
% column (see \file{classes.dtx} for the original code).
% These macros are also provided by the \Lpack{ccaption} package.
%    \begin{macrocode}
\providecommand{\@cfttocstart}{%
  \if@cfthaschapter
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
  \fi}
%    \end{macrocode}
% |\@cfttocfinish| resets, if required, twocolumn typesetting.
%    \begin{macrocode}
\providecommand{\@cfttocfinish}{%
  \if@cfthaschapter
    \if@restonecol\twocolumn\fi
  \fi}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\phantomsection}
% This is provided because the \Lopt{hyperref} package screws with
% |\addcontentsline|.
% \changes{v2.2}{2001/04/17}{Provided \cs{phantomsection}}
% \changes{v2.2}{2001/04/17}{Added \cs{phantomsection} before \cs{addcontentsline} commands}
%    \begin{macrocode}
\providecommand{\phantomsection}{}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@cftdobibtoc}
% If the \Lpack{tocbibind} package has been used and it has
% redefined |\tableofcontents| we need to cater for that. The contents
% of the definition are defined in \Lpack{tocbibind}.
%    \begin{macrocode}
\newcommand{\@cftdobibtoc}{%
  \if@dotoctoc
    \if@bibchapter
      \phantomsection
      \addcontentsline{toc}{chapter}{\contentsname}
    \else
      \phantomsection
      \addcontentsline{toc}{\@tocextra}{\contentsname}
    \fi
  \fi}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftparskip}
% The |\parskip| local to the ToC, etc., is set to the length |\cftparskip|.
% \changes{v2.1}{2001/04/08}{Added \cs{cftparskip} for local parskip in ToC, etc.}
%    \begin{macrocode}
\newlength{\cftparskip}
\setlength{\cftparskip}{0pt}

%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\tableofcontents}
% This is a parameterised version of the default |\tableofcontents| command.
% Each class has its own definition, but we have to cater for all classes
% in one definition, hence some of the checks. The definition is
% modified after all packages have been loaded.
%
% If the \Lopt{titles} option has been used, then the command is not modified.
%
%    \begin{macrocode}
\AtBeginDocument{%
\if@cftnctoc
  % ensure \cftparskip is still set properly
  \let\OLD@starttoc\@starttoc
  \renewcommand{\@starttoc}[1]{%
    \begingroup
      \parskip=\cftparskip
      \OLD@starttoc{#1}%
    \endgroup
  }
\else
  \renewcommand{\tableofcontents}{%
    \@cfttocstart
%    \end{macrocode}
% Ensure that any previous paragraph has been finished. Within a group set
% the local paragraphing style and typeset the title.
%    \begin{macrocode}
    \par
    \begingroup
      \parindent\z@ \parskip\cftparskip
      \@cftmaketoctitle
%    \end{macrocode}
% If \Lpack{tocbibind} has been used, then add the ToC
% name to the ToC.
%    \begin{macrocode}
      \if@cfttocbibind
        \@cftdobibtoc
      \fi
%    \end{macrocode}
% Finally, read the \file{.toc} file and finish up.
%    \begin{macrocode}
      \@starttoc{toc}%
    \endgroup
    \@cfttocfinish}
\fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@cftmaketoctitle}
% This command typesets the title for the ToC.
% \changes{v2.3}{2002/06/15}{Added \cs{@secpenalty} to \cs{@cftmaketoctitle}}
% \changes{v2.3}{2002/06/15}{Added \cs{@cftpagestyle} to \cs{@cftmaketoctitle}}
%    \begin{macrocode}
\newcommand{\@cftmaketoctitle}{%
  \addpenalty\@secpenalty
  \if@cfthaschapter
    \vspace*{\cftbeforetoctitleskip}%
  \else
    \vspace{\cftbeforetoctitleskip}%
  \fi
  \@cftpagestyle
  {\interlinepenalty\@M
  {\cfttoctitlefont\contentsname}{\cftaftertoctitle}%
  \cftmarktoc
  \par\nobreak
  \vskip \cftaftertoctitleskip
  \@afterheading}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftbeforetoctitleskip}
% \begin{macro}{\cftaftertoctitleskip}
%  These two lengths control the vertical spacing before and after the
%  ToC title.
%    \begin{macrocode}
\newlength{\cftbeforetoctitleskip}
\newlength{\cftaftertoctitleskip}
%    \end{macrocode}
% Their values depend on whether the document has chapters or not. In
% chaptered documents the default ToC title is typeset as a |\chapter*|,
% otherwise as a |\section*|.
%    \begin{macrocode}
\if@cfthaschapter
  \setlength{\cftbeforetoctitleskip}{50pt}
  \setlength{\cftaftertoctitleskip}{40pt}
\else
  \setlength{\cftbeforetoctitleskip}{3.5ex \@plus 1ex \@minus .2ex}
  \setlength{\cftaftertoctitleskip}{2.3ex \@plus.2ex}
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cfttoctitlefont}
% \begin{macro}{\cftaftertoctitle}
% The ToC title is typeset in the style given by |\cfttoctitlefont|.
% The macro |\cftaftertoctitle| is called after typesetting the title.
% This is initialised to do nothing.
% Both these macros can be redefined to do other things (e.g., adding
% an |\hfill| to |\cfttoctitlefont| will make the title flushright).
% \changes{v2.3}{2002/06/15}{koma changes the title fonts}
%    \begin{macrocode}
\if@cfthaschapter
  \newcommand{\cfttoctitlefont}{\normalfont\Huge\bfseries}
  \if@cftkoma\renewcommand{\cfttoctitlefont}{\size@chapter\sectfont}\fi
\else
  \newcommand{\cfttoctitlefont}{\normalfont\Large\bfseries}
  \if@cftkoma\renewcommand{\cfttoctitlefont}{\size@section\sectfont}\fi
\fi
\newcommand{\cftaftertoctitle}{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cftsetpnumwidth}
% \begin{macro}{\cftsetrmarg}
%  Users commands for setting |\@pnumwidth| and |\@tocrmarg|.
%    \begin{macrocode}
\newcommand{\cftsetpnumwidth}[1]{\renewcommand{\@pnumwidth}{#1}}
\newcommand{\cftsetrmarg}[1]{\renewcommand{\@tocrmarg}{#1}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cftpnumalign}
% \changes{v2.3f}{2013/05/02}{Add \cs{cftpnumalign} for page number alignment}
% Alignment string (as input to \cs{makebox} for the page number box.
%    \begin{macrocode}
\newcommand{\cftpnumalign}{r}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftdot}
% \begin{macro}{\cftdotfill}
% In the default ToC, a dotted line can be used to provide a leader between
% a title and the page number. The definition of this leader is buried
% in the |\@dottedtocline| command. The |\cftdotfill{|\meta{sep}|}|
% command provides a parameterised version of the leader code, where
% \meta{sep} is the separation between the dots in mu units.
% The symbol used for the `dots' in the leader is given by the value
% of |\cftdot|. These macros are also provided by the \Lpack{ccaption} package.
%    \begin{macrocode}
\providecommand{\cftdot}{.}
\providecommand{\cftdotfill}[1]{%
  \def\@tempa{#1}%
  \def\@tempb{\cftnodots}%
  \ifx\@tempa\@tempb
    \hfill
  \else
    \leaders\hbox{$\m@th\mkern #1 mu\hbox{\cftdot}\mkern #1 mu$}\hfill
  \fi
}
%    \end{macrocode}
% \changes{v2.3f}{2013/04/30}{Specifically avoid placing dots when \cs{cftnodots} is used}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cftdotsep}
% \begin{macro}{\cftnodots}
% |\cftdotsep| holds the default dot separation, and is also provided
% by the \Lpack{ccaption} package.
% If the kerns in |\cftdotfill| are large enough, then no dots will
% be printed. |\cftnodots| should be `large enough'.
% (Actually, |\cftnodots| is now used as a flag for a conditional branch, so its numerical value isn't as important now.)
%    \begin{macrocode}
\providecommand{\cftdotsep}{4.5}
\newcommand{\cftnodots}{5000}
%    \end{macrocode}
% \changes{v2.3f}{2013/04/30}{Reduce \cs{cftnodots} to avoid very large dotsep sizes.}
% \end{macro}
% \end{macro}
%
%     Now for the trickier bits regarding the typesetting of the ToC
% entries.
%
%     A \file{.toc} (also \file{.lof} and \file{.lot}) file consists
% of a list of
% |\contentsline{|\meta{kind}|}{|\meta{title}|}{|\meta{page}|}|
% commands, where \meta{kind} is the kind of heading (e.g., |part| or
% |section| or |figure|), \meta{title} is the title text (including the number),
% and \meta{page} is the page number. The entries are inserted into the
% file by calling the
% |\addcontentsline{|\meta{file}|}{|\meta{kind}|}{|\meta{title}|}|
% command, where \meta{file} is the file extension (e.g., |toc|, |lot|)
% and the other arguments are the same as for the |\contentsline|
% command. (Arbitrary stuff may also be put into the file via the
% |\addtocontents{|\meta{file}|}{|\meta{text}|}| command).
% The typesetting of the |\contentsline| entries is performed by
% commands of the form |\l@kind|. The sectioning and captioning commands
% call |\addcontentsline| to insert their titles into the \file{.toc}
% etc., files.
%
%     For the purposes at hand it is generally impossible to treat
% the typesetting
% of a title and its number separately, as both are bundled into the
% \meta{title} argument within |\contentsline|. They could be handled
% separately if the |\contentsline| command was suitably modified. If
% this was done, then the |\addtocontentsline| command would also need
% to be changed which would then require the sectioning and captioning
% commands to be modified as well. This is certainly possible, but would
% cause problems if any other package also modified the sectioning or
% captioning commands, and there are several packages which do this.
%
%     Having said this, for all but Part entries, the sectional number
% is typeset via the |\numberline| command. We can take advantage of
% this fact.
%
%     I have taken the decision to not touch the |\contentsline| macro
% and instead to do what can be done with it as it exists. That is, I will
% modify the |\l@kind| commands. Essentially, my new definitions
% consist of inlined versions of the code for |\@dottedtocline|.
%
% \begin{macro}{\cftparfillskip}
% The |\l@kind| commands modify (locally) the value of |\parfillskip|.
% |\cftparfillskip| is a copy of the default \textit{\TeX book}
% |\parfillskip| definition.
%    \begin{macrocode}
\newcommand{\cftparfillskip}{\parfillskip=0pt plus1fil}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\numberline}
% \changes{v1.1}{2000/02/11}{Added \cs{@cftbsnum} to \cs{numberline}}
% The purpose of the |\numberline{|\meta{secnum}|}| command is to typeset
% \meta{secnum} left justified in a box of width |\@tempdima|. I redefine
% it to add three additional parameters, namely |\@cftbsnum|,
% |\@cftasnum| and |\@cftasnumb|
% (see \file{ltsect.dtx} for the original
% definition).
%    \begin{macrocode}
\renewcommand{\numberline}[1]{%
  \hb@xt@\@tempdima{\@cftbsnum #1\@cftasnum\hfil}\@cftasnumb}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@cftbsnum}
% \begin{macro}{\@cftasnum}
% \begin{macro}{\@cftasnumb}
% \changes{v0.2b}{1999/03/07}{Added empty definitions for @cftasnum and @cftasnumb commands}
% \changes{v1.1}{2000/02/11}{Added empty definition of \cs{@cftbsnum}}
% Originally these were not defined but were |\let| to appropriate commands
% in the |\l@...| commands, but they
% have to be defined in case something unexpected calls |\numberline|,
% for example through use of the \Lpack{float} package.\footnote{This bug
% was discovered by Andrew Thurber when using the \Lpack{tocloft} and
% \Lpack{algorithm} packages together.}
%    \begin{macrocode}
\newcommand{\@cftbsnum}{}
\newcommand{\@cftasnum}{}
\newcommand{\@cftasnumb}{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \begin{macro}{\l@part}
% \begin{macro}{\if@cftdopart}
% \changes{v1.1}{2000/02/11}{Added \cs{@cftbsnum} and \cs{cftXpresnum} to
%                            all \cs{\l@X} commands}
% \changes{v1.1}{2000/02/11}{Added \cs{cftXpresnum} commands}
%  |\l@part{|\meta{title}|}{|\meta{page}|}| typesets the ToC entry for
% a |part| heading. It is a parameterised copy of the default |\l@part|
% (see \file{classes.dtx} for the original definition and the code
%  below for |\l@subsection| for an explanation of most of this
%  code). By default, Parts
% (and Chapters) do not have dotted leaders. This package provides
% for all entries to have dotted leaders.
% \changes{v0.2a}{1999/01/24}{In article class, Part level is 0 not -1}
% \changes{v2.0}{2001/03/03}{Checked directly for \cs{part} definition}
% \changes{v2.3a}{2002/10/03}{Added \cs{cftpartpresnum} to \cs{l@part}}
%
%    \begin{macrocode}
\newif\if@cftdopart
\newif\if@cfthaspart
\@cftifundefined{part}{\@cfthaspartfalse}{\@cfthasparttrue}
\if@cfthaspart
\renewcommand*{\l@part}[2]{%
  \@cftdopartfalse
  \ifnum \c@tocdepth >-2\relax
    \if@cfthaschapter
      \@cftdoparttrue
    \fi
    \ifnum \c@tocdepth >\m@ne
      \if@cfthaschapter\else
        \@cftdoparttrue
      \fi
    \fi
  \fi
  \if@cftdopart
    \if@cfthaschapter
      \addpenalty{-\@highpenalty}%
    \else
      \addpenalty\@secpenalty
    \fi
    \addvspace{\cftbeforepartskip}%
    \begingroup
      {\leftskip \cftpartindent\relax
       \rightskip \@tocrmarg
       \parfillskip -\rightskip
       \parindent \cftpartindent\relax\@afterindenttrue
       \interlinepenalty\@M
       \leavevmode
       \@tempdima \cftpartnumwidth\relax
       \let\@cftbsnum \cftpartpresnum
       \let\@cftasnum \cftpartaftersnum
       \let\@cftasnumb \cftpartaftersnumb
       \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
%    \end{macrocode}
% In default \LaTeX, the part ToC entry is written without \verb|\numberline|
% and hence the `presnum' needs to be inserted manually.
% In Koma-Script and titlesec (and probably others---let me know!), however, this is not the case.
%    \begin{macrocode}
       {\cftpartfont \if@cftkoma\else\if@cfttitlesec\else\cftpartpresnum\fi\fi #1}%
       \cftpartfillnum{#2}}
      \nobreak
      \if@cfthaschapter
        \global\@nobreaktrue
        \everypar{\global\@nobreakfalse\everypar{}}%
      \else
        \if@compatibility
          \global\@nobreaktrue
          \everypar{\global\@nobreakfalse\everypar{}}%
        \fi
      \fi
    \endgroup
  \fi}
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cftbeforepartskip}
% \begin{macro}{\cftpartnumwidth}
% \begin{macro}{\cftpartfont}
% \begin{macro}{\cftpartpresnum}
% \begin{macro}{\cftpartaftersnum}
% \begin{macro}{\cftpartaftersnumb}
% \begin{macro}{\cftpartleader}
% \begin{macro}{\cftpartdotsep}
% \begin{macro}{\cftpartpagefont}
% \begin{macro}{\cftpartafterpnum}
% \begin{macro}{\cftpartindent}
% \begin{macro}{\cftpartfillnum}
%  These are the user commands to control the typesetting of Part entries.
%  They are initialised to give the standard appearance.
% \changes{v2.3a}{2002/10/03}{Deleted \cs{cftpartaftersnum} and \cs{cftpartaftersnumb}}
% \changes{v2.3b}{2003/01/20}{Reinstated \cs{cftpartaftersnum} and \cs{cftpartaftersnumb}}
%    \begin{macrocode}
\if@cfthaspart
  \newlength{\cftbeforepartskip}
    \setlength{\cftbeforepartskip}{2.25em \@plus\p@}
  \newlength{\cftpartnumwidth}
    \setlength{\cftpartnumwidth}{0em}
  \newcommand{\cftpartfont}{\large\bfseries}
  \newcommand{\cftpartpresnum}{}
  \newcommand{\cftpartaftersnum}{}
  \newcommand{\cftpartaftersnumb}{}
  \newcommand{\cftpartleader}{\large\bfseries\cftdotfill{\cftpartdotsep}}
  \newcommand{\cftpartdotsep}{\cftnodots}
  \newcommand{\cftpartpagefont}{\large\bfseries}
  \newcommand{\cftpartafterpnum}{}
  \newlength{\cftpartindent}
    \setlength{\cftpartindent}{0em}
  \newcommand{\cftpartfillnum}[1]{%
    {\cftpartleader}%
    {\makebox[\@pnumwidth][\cftpnumalign]{\cftpartpagefont #1}\cftpartafterpnum\par}%
  }
%    \end{macrocode}
% \Lpack{koma} classes use some different settings.
% \changes{v2.3}{2002/06/15}{koma has different part settings}
%    \begin{macrocode}
  \if@cftkoma
    \setlength{\cftpartnumwidth}{2em}
    \renewcommand{\cftpartfont}{\sectfont\large}
    \renewcommand{\cftpartpagefont}{\sectfont\large}
  \fi
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\l@chapter}
%  |\l@chapter{|\meta{title}|}{|\meta{page}|}| typesets the ToC entry for
% a |chapter| heading. It is a parameterised copy of the default |\l@chapter|
% (see \file{classes.dtx} for the original definition). This only applies
% to chaptered documents.
%    \begin{macrocode}
\if@cfthaschapter
\renewcommand*{\l@chapter}[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip \cftbeforechapskip
    {\leftskip \cftchapindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \cftchapindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftchapnumwidth\relax
     \let\@cftbsnum \cftchappresnum
     \let\@cftasnum \cftchapaftersnum
     \let\@cftasnumb \cftchapaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\cftchapfont #1}\nobreak
     \cftchapfillnum{#2}}%
  \fi}%
\fi
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftbeforechapskip}
% \begin{macro}{\cftchapindent}
% \begin{macro}{\cftchapnumwidth}
% \begin{macro}{\cftchapfont}
% \begin{macro}{\cftchappresnum}
% \begin{macro}{\cftchapaftersnum}
% \begin{macro}{\cftchapaftersnumb}
% \begin{macro}{\cftchapleader}
% \begin{macro}{\cftchapdotsep}
% \begin{macro}{\cftchappagefont}
% \begin{macro}{\cftchapafterpnum}
% \begin{macro}{\cftchapfillnum}
%  These are the user commands to control the typesetting of Chapter entries.
%  They are initialised to give the standard appearance.
%    \begin{macrocode}
\if@cfthaschapter
  \newlength{\cftbeforechapskip}
    \setlength{\cftbeforechapskip}{1.0em \@plus\p@}
  \newlength{\cftchapindent}
    \setlength{\cftchapindent}{0em}
  \newlength{\cftchapnumwidth}
    \setlength{\cftchapnumwidth}{1.5em}
  \newcommand{\cftchapfont}{\bfseries}
  \newcommand{\cftchappresnum}{}
  \newcommand{\cftchapaftersnum}{}
  \newcommand{\cftchapaftersnumb}{}
  \newcommand{\cftchapleader}{\bfseries\cftdotfill{\cftchapdotsep}}
  \newcommand{\cftchapdotsep}{\cftnodots}
  \newcommand{\cftchappagefont}{\bfseries}
  \newcommand{\cftchapafterpnum}{}
  \newcommand{\cftchapfillnum}[1]{%
    {\cftchapleader}\nobreak
    \makebox[\@pnumwidth][\cftpnumalign]{\cftchappagefont #1}\cftchapafterpnum\par
  }
%    \end{macrocode}
% \Lpack{koma} classes have different chapter settings.
% \changes{v2.3}{2002/06/15}{koma has different chapter settings}
%    \begin{macrocode}
  \if@cftkoma
    \renewcommand{\cftchapfont}{\sectfont}
  \fi
\fi

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\l@section}
%  |\l@section{|\meta{title}|}{|\meta{page}|}| typesets the ToC entry for
% a |section| heading. It is a parameterised copy of the default |\l@section|
% (see \file{classes.dtx} for the original definition).
%    \begin{macrocode}
\renewcommand*{\l@section}[2]{%
  \ifnum \c@tocdepth >\z@
    \if@cfthaschapter
      \vskip \cftbeforesecskip
    \else
      \addpenalty\@secpenalty
      \addvspace{\cftbeforesecskip}
    \fi
    {\leftskip \cftsecindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \cftsecindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftsecnumwidth\relax
     \let\@cftbsnum \cftsecpresnum
     \let\@cftasnum \cftsecaftersnum
     \let\@cftasnumb \cftsecaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\cftsecfont #1}\nobreak
     \cftsecfillnum{#2}}%
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftbeforesecskip}
% \begin{macro}{\cftsecindent}
% \begin{macro}{\cftsecnumwidth}
% \begin{macro}{\cftsecfont}
% \begin{macro}{\cftsecpresnum}
% \begin{macro}{\cftsecaftersnum}
% \begin{macro}{\cftsecaftersnumb}
% \begin{macro}{\cftsecleader}
% \begin{macro}{\cftsecdotsep}
% \begin{macro}{\cftsecpagefont}
% \begin{macro}{\cftsecafterpnum}
% \begin{macro}{\cftsecfillnum}
%  These are the user commands to control the typesetting of Section entries.
%  They are initialised to give the standard appearance.
%    \begin{macrocode}
\newlength{\cftbeforesecskip}
\newlength{\cftsecindent}
\newlength{\cftsecnumwidth}
\newcommand{\cftsecpresnum}{}
\newcommand{\cftsecaftersnum}{}
\newcommand{\cftsecaftersnumb}{}
\if@cfthaschapter
  \setlength{\cftbeforesecskip}{\z@ \@plus.2\p@}
  \setlength{\cftsecindent}{1.5em}
  \setlength{\cftsecnumwidth}{2.3em}
  \newcommand{\cftsecfont}{\normalfont}
  \newcommand{\cftsecleader}{\normalfont\cftdotfill{\cftsecdotsep}}
  \newcommand{\cftsecdotsep}{\cftdotsep}
  \newcommand{\cftsecpagefont}{\normalfont}
\else
  \setlength{\cftbeforesecskip}{1.0em \@plus\p@}
  \setlength{\cftsecindent}{0em}
  \setlength{\cftsecnumwidth}{1.5em}
  \newcommand{\cftsecfont}{\bfseries}
  \newcommand{\cftsecleader}{\bfseries\cftdotfill{\cftsecdotsep}}
  \newcommand{\cftsecdotsep}{\cftnodots}
  \newcommand{\cftsecpagefont}{\bfseries}
\fi
\newcommand{\cftsecafterpnum}{}
\newcommand{\cftsecfillnum}[1]{%
  {\cftsecleader}\nobreak
  \makebox[\@pnumwidth][\cftpnumalign]{\cftsecpagefont #1}\cftsecafterpnum\par
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\l@subsection}
%  |\l@subsection{|\meta{title}|}{|\meta{page}|}| typesets the ToC entry for
% a |subsection| heading. It is a parameterised copy of the default
% |\l@subsection|
% (see \file{classes.dtx} for the original definition).
%    \begin{macrocode}
\renewcommand*{\l@subsection}[2]{%
%    \end{macrocode}
% Only typeset the entry if it falls within the |tocdepth|.
%    \begin{macrocode}
  \ifnum \c@tocdepth >\@ne
%    \end{macrocode}
% Add some vertical space.
%    \begin{macrocode}
    \vskip \cftbeforesubsecskip
%    \end{macrocode}
% Start a group to keep paragraphing changes local. Set the |\leftskip|
% to the entry's indentation.
%    \begin{macrocode}
    {\leftskip \cftsubsecindent\relax
%    \end{macrocode}
% Set the |\rightskip| to |\@tocrmarg| to leave room for the page number.
%    \begin{macrocode}
     \rightskip \@tocrmarg
%    \end{macrocode}
% Ensure that the last line of the entry will be filled. Setting
% |\parfillskip| to a negative number prevents any overfull box messages.
%    \begin{macrocode}
     \parfillskip -\rightskip
%    \end{macrocode}
% Set the paragraph indent to the entry's indentation.
%    \begin{macrocode}
     \parindent \cftsubsecindent\relax\@afterindenttrue
%    \end{macrocode}
% Try and prevent breaks between lines in a multiple line entry.
%    \begin{macrocode}
     \interlinepenalty\@M
%    \end{macrocode}
% Make sure that we have left vertical mode.
%    \begin{macrocode}
     \leavevmode
%    \end{macrocode}
% Our version of |\numberline| expects that the width of the number box
% is in |\@tempdima|, and that the three macros |\@cftbsnum|,
% |\@cftasnum| and |\@cftasnumb|
% are defined. We set all these to the values for this entry.
%    \begin{macrocode}
     \@tempdima \cftsubsecnumwidth\relax
     \let\@cftbsnum \cftsubsecpresnum
     \let\@cftasnum \cftsubsecaftersnum
     \let\@cftasnumb \cftsubsecaftersnumb
%    \end{macrocode}
% Arrange that the (section number and) first line of the title is set
% at the current indent, and any further lines are further indented.
%    \begin{macrocode}
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
%    \end{macrocode}
% Print the (number and) title, prohibiting any breaking.
%    \begin{macrocode}
     {\cftsubsecfont #1}\nobreak
%    \end{macrocode}
% Print the leader and the page number, and close the group.
%    \begin{macrocode}
     \cftsubsecfillnum{#2}}%
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftbeforesubsecskip}
% \begin{macro}{\cftsubsecindent}
% \begin{macro}{\cftsubsecnumwidth}
% \begin{macro}{\cftsubsecfont}
% \begin{macro}{\cftsubsecpresnum}
% \begin{macro}{\cftsubsecaftersnum}
% \begin{macro}{\cftsubsecaftersnumb}
% \begin{macro}{\cftsubsecleader}
% \begin{macro}{\cftsubsecdotsep}
% \begin{macro}{\cftsubsecpagefont}
% \begin{macro}{\cftsubsecafterpnum}
%  These are the user commands to control the typesetting of Sub-section entries.
%  They are initialised to give the standard appearance.
%    \begin{macrocode}
\newlength{\cftbeforesubsecskip}
  \setlength{\cftbeforesubsecskip}{\z@ \@plus.2\p@}
\newlength{\cftsubsecindent}
\newlength{\cftsubsecnumwidth}
\if@cfthaschapter
  \setlength{\cftsubsecindent}{3.8em}
  \setlength{\cftsubsecnumwidth}{3.2em}
\else
  \setlength{\cftsubsecindent}{1.5em}
  \setlength{\cftsubsecnumwidth}{2.3em}
\fi
\newcommand{\cftsubsecfont}{\normalfont}
\newcommand{\cftsubsecpresnum}{}
\newcommand{\cftsubsecaftersnum}{}
\newcommand{\cftsubsecaftersnumb}{}
\newcommand{\cftsubsecleader}{\normalfont\cftdotfill{\cftsubsecdotsep}}
\newcommand{\cftsubsecdotsep}{\cftdotsep}
\newcommand{\cftsubsecpagefont}{\normalfont}
\newcommand{\cftsubsecafterpnum}{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cftsubsecfillnum}
% |\cftsubsecfillnum{|\meta{page}|}| typesets the leader and the \meta{page}
% number of a |subsection| entry.
% First print the leader and then, with no break, set the page number
% flushright in  a box of width |\@pnumwidth|,
% not forgetting to finish the paragraph.
%    \begin{macrocode}
\newcommand{\cftsubsecfillnum}[1]{%
  {\cftsubsecleader}\nobreak
  \makebox[\@pnumwidth][\cftpnumalign]{\cftsubsecpagefont #1}\cftsubsecafterpnum\par
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l@subsubsection}
%  |\l@subsubsection{|\meta{title}|}{|\meta{page}|}| typesets the ToC entry for
% a |subsubsection| heading. It is a parameterised copy of the default
% |\l@subsubsection|
% (see \file{classes.dtx} for the original definition).
%    \begin{macrocode}
\renewcommand*{\l@subsubsection}[2]{%
  \ifnum \c@tocdepth >\tw@
    \vskip \cftbeforesubsubsecskip
    {\leftskip \cftsubsubsecindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \cftsubsubsecindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftsubsubsecnumwidth\relax
     \let\@cftbsnum \cftsubsubsecpresnum
     \let\@cftasnum \cftsubsubsecaftersnum
     \let\@cftasnumb \cftsubsubsecaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\cftsubsubsecfont #1}\nobreak
     \cftsubsubsecfillnum{#2}}%
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftbeforesubsubsecskip}
% \begin{macro}{\cftsubsubsecindent}
% \begin{macro}{\cftsubsubsecnumwidth}
% \begin{macro}{\cftsubsubsecfont}
% \begin{macro}{\cftsubsubsecpresnum}
% \begin{macro}{\cftsubsubsecaftersnum}
% \begin{macro}{\cftsubsubsecaftersnumb}
% \begin{macro}{\cftsubsubsecleader}
% \begin{macro}{\cftsubsubsecdotsep}
% \begin{macro}{\cftsubsubsecpagefont}
% \begin{macro}{\cftsubsubsecafterpnum}
% \begin{macro}{\cftsubsubsecfillnum}
%  These are the user commands to control the typesetting of Sub-sub-section entries.
%  They are initialised to give the standard appearance.
%    \begin{macrocode}
\newlength{\cftbeforesubsubsecskip}
  \setlength{\cftbeforesubsubsecskip}{\z@ \@plus.2\p@}
\newlength{\cftsubsubsecindent}
\newlength{\cftsubsubsecnumwidth}
\if@cfthaschapter
  \setlength{\cftsubsubsecindent}{7.0em}
  \setlength{\cftsubsubsecnumwidth}{4.1em}
\else
  \setlength{\cftsubsubsecindent}{3.8em}
  \setlength{\cftsubsubsecnumwidth}{3.2em}
\fi
\newcommand{\cftsubsubsecfont}{\normalfont}
\newcommand{\cftsubsubsecpresnum}{}
\newcommand{\cftsubsubsecaftersnum}{}
\newcommand{\cftsubsubsecaftersnumb}{}
\newcommand{\cftsubsubsecleader}{\normalfont\cftdotfill{\cftsubsubsecdotsep}}
\newcommand{\cftsubsubsecdotsep}{\cftdotsep}
\newcommand{\cftsubsubsecpagefont}{\normalfont}
\newcommand{\cftsubsubsecafterpnum}{}
\newcommand{\cftsubsubsecfillnum}[1]{%
  {\cftsubsubsecleader}\nobreak
  \makebox[\@pnumwidth][\cftpnumalign]{\cftsubsubsecpagefont #1}\cftsubsubsecafterpnum\par
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\l@paragraph}
%  |\l@paragraph{|\meta{title}|}{|\meta{page}|}| typesets the ToC entry for
% a |paragraph| heading. It is a parameterised copy of the default
% |\l@paragraph|
% (see \file{classes.dtx} for the original definition).
%    \begin{macrocode}
\renewcommand*{\l@paragraph}[2]{%
  \ifnum \c@tocdepth >3\relax
    \vskip \cftbeforeparaskip
    {\leftskip \cftparaindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \cftparaindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftparanumwidth\relax
     \let\@cftbsnum \cftparapresnum
     \let\@cftasnum \cftparaaftersnum
     \let\@cftasnumb \cftparaaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\cftparafont #1}\nobreak
     \cftparafillnum{#2}}%
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftbeforeparaskip}
% \begin{macro}{\cftparaindent}
% \begin{macro}{\cftparanumwidth}
% \begin{macro}{\cftparafont}
% \begin{macro}{\cftparapresnum}
% \begin{macro}{\cftparaaftersnum}
% \begin{macro}{\cftparaaftersnumb}
% \begin{macro}{\cftparaleader}
% \begin{macro}{\cftparadotsep}
% \begin{macro}{\cftparapagefont}
% \begin{macro}{\cftparaafterpnum}
% \begin{macro}{\cftparafillnum}
%  These are the user commands to control the typesetting of Paragraph entries.
%  They are initialised to give the standard appearance.
%    \begin{macrocode}
\newlength{\cftbeforeparaskip}
  \setlength{\cftbeforeparaskip}{\z@ \@plus.2\p@}
\newlength{\cftparaindent}
\newlength{\cftparanumwidth}
\if@cfthaschapter
  \setlength{\cftparaindent}{10em}
  \setlength{\cftparanumwidth}{5em}
\else
  \setlength{\cftparaindent}{7.0em}
  \setlength{\cftparanumwidth}{4.1em}
\fi
\newcommand{\cftparafont}{\normalfont}
\newcommand{\cftparapresnum}{}
\newcommand{\cftparaaftersnum}{}
\newcommand{\cftparaaftersnumb}{}
\newcommand{\cftparaleader}{\normalfont\cftdotfill{\cftparadotsep}}
\newcommand{\cftparadotsep}{\cftdotsep}
\newcommand{\cftparapagefont}{\normalfont}
\newcommand{\cftparaafterpnum}{}
\newcommand{\cftparafillnum}[1]{%
  {\cftparaleader}\nobreak
  \makebox[\@pnumwidth][\cftpnumalign]{\cftparapagefont #1}\cftparaafterpnum\par
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\l@subparagraph}
%  |\l@subparagraph{|\meta{title}|}{|\meta{page}|}| typesets the ToC entry for
% a |subparagraph| heading. It is a parameterised copy of the default
% |\l@subparagraph|
% (see \file{classes.dtx} for the original definition).
%    \begin{macrocode}
\renewcommand*{\l@subparagraph}[2]{%
  \ifnum \c@tocdepth >4\relax
    \vskip \cftbeforesubparaskip
    {\leftskip \cftsubparaindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \cftsubparaindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftsubparanumwidth\relax
     \let\@cftbsnum \cftsubparapresnum
     \let\@cftasnum \cftsubparaaftersnum
     \let\@cftasnumb \cftsubparaaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\cftsubparafont #1}\nobreak
     \cftsubparafillnum{#2}}%
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftbeforesubparaskip}
% \begin{macro}{\cftsubparaindent}
% \begin{macro}{\cftsubparanumwidth}
% \begin{macro}{\cftsubparafont}
% \begin{macro}{\cftsubparapresnum}
% \begin{macro}{\cftsubparaaftersnum}
% \begin{macro}{\cftsubparaaftersnumb}
% \begin{macro}{\cftsubparaleader}
% \begin{macro}{\cftsubparadotsep}
% \begin{macro}{\cftsubparapagefont}
% \begin{macro}{\cftsubparaafterpnum}
% \begin{macro}{\cftsubparafillnum}
%  These are the user commands to control the typesetting of Sub-paragraph entries.
%  They are initialised to give the standard appearance.
%    \begin{macrocode}
\newlength{\cftbeforesubparaskip}
  \setlength{\cftbeforesubparaskip}{\z@ \@plus.2\p@}
\newlength{\cftsubparaindent}
\newlength{\cftsubparanumwidth}
\if@cfthaschapter
  \setlength{\cftsubparaindent}{12em}
  \setlength{\cftsubparanumwidth}{6em}
\else
  \setlength{\cftsubparaindent}{10em}
  \setlength{\cftsubparanumwidth}{5em}
\fi
\newcommand{\cftsubparafont}{\normalfont}
\newcommand{\cftsubparapresnum}{}
\newcommand{\cftsubparaaftersnum}{}
\newcommand{\cftsubparaaftersnumb}{}
\newcommand{\cftsubparaleader}{\normalfont\cftdotfill{\cftsubparadotsep}}
\newcommand{\cftsubparadotsep}{\cftdotsep}
\newcommand{\cftsubparapagefont}{\normalfont}
\newcommand{\cftsubparaafterpnum}{}
\newcommand{\cftsubparafillnum}[1]{%
  {\cftsubparaleader}\nobreak
  \makebox[\@pnumwidth][\cftpnumalign]{\cftsubparapagefont #1}\cftsubparaafterpnum\par
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\@cftdobiblof}
% If the \Lpack{tocbibind} package has been used and it has
% redefined |\listoffigures| we need to cater for that. The contents
% of the definition are defined in \Lpack{tocbibind}.
%    \begin{macrocode}
\newcommand{\@cftdobiblof}{%
  \if@dotoclof
    \if@bibchapter
      \phantomsection
      \addcontentsline{toc}{chapter}{\listfigurename}
    \else
      \phantomsection
      \addcontentsline{toc}{\@tocextra}{\listfigurename}
    \fi
  \fi}

%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\listoffigures}
% This is a parameterised version of the default |\listoffigures| command.
% The changes are postponed until after all packages have been loaded.
% Each class has its own definition, but we have to cater for all classes
% in one definition, hence some of the checks. First, perform the default
% checks for multicolumns. (Do nothing if \Lopt{titles} option is used).
%    \begin{macrocode}
\AtBeginDocument{%
\if@cftnctoc\else
\renewcommand{\listoffigures}{%
  \@cfttocstart
%    \end{macrocode}
% Ensure that any previous paragraph has been finished. Within a group set
% the local paragraphing style. Typeset the title and then do the contents
% of the \file{.lof} file.
%    \begin{macrocode}
  \par
  \begingroup
    \parindent\z@ \parskip\cftparskip
    \@cftmakeloftitle
    \if@cfttocbibind
      \@cftdobiblof
    \fi
    \@starttoc{lof}%
  \endgroup
%    \end{macrocode}
% Finally, restore any multicolumn typesetting.
%    \begin{macrocode}
  \@cfttocfinish}%
\fi
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@cftmakeloftitle}
% This command typesets the title for the LoF.
% \changes{v2.3}{2002/06/15}{Added \cs{@secpenalty} to \cs{cftmakeloftitle}}
% \changes{v2.3}{2002/06/15}{Added \cs{@cftpagestyle} to \cs{cftmakeloftitle}}
%    \begin{macrocode}
\newcommand{\@cftmakeloftitle}{%
  \addpenalty\@secpenalty
  \if@cfthaschapter
    \vspace*{\cftbeforeloftitleskip}
  \else
    \vspace{\cftbeforeloftitleskip}
  \fi
  \@cftpagestyle
  {\interlinepenalty\@M
  {\cftloftitlefont\listfigurename}{\cftafterloftitle}
  \cftmarklof
  \par\nobreak
  \vskip \cftafterloftitleskip
  \@afterheading}}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftbeforeloftitleskip}
% \begin{macro}{\cftafterloftitleskip}
%  These two lengths control the vertical spacing before and after the
%  LoF title.
%    \begin{macrocode}
\newlength{\cftbeforeloftitleskip}
\newlength{\cftafterloftitleskip}
%    \end{macrocode}
% Their values depend on whether the document has chapters or not. In
% chaptered documents the default LoF title is typeset as a |\chapter*|,
% otherwise as a |\section*|.
%    \begin{macrocode}
\if@cfthaschapter
  \setlength{\cftbeforeloftitleskip}{50pt}
  \setlength{\cftafterloftitleskip}{40pt}
\else
  \setlength{\cftbeforeloftitleskip}{3.5ex \@plus 1ex \@minus .2ex}
  \setlength{\cftafterloftitleskip}{2.3ex \@plus.2ex}
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cftloftitlefont}
% \begin{macro}{\cftafterloftitle}
% The LoF title is typeset in the style given by |\cftloftitlefont|.
% The macro |\cftafterloftitle| is called after typesetting the title.
% This is initialised to do nothing.
% Both these macros can be redefined to do other things (e.g., adding
% an |\hfill| to |\cftloftitlefont| will make the title flushright).
% \changes{v2.3}{2002/06/15}{koma has different settings for LoF titles}
%    \begin{macrocode}
\if@cfthaschapter
  \newcommand{\cftloftitlefont}{\normalfont\Huge\bfseries}
  \if@cftkoma\renewcommand{\cftloftitlefont}{\size@chapter\sectfont}\fi
\else
  \newcommand{\cftloftitlefont}{\normalfont\Large\bfseries}
  \if@cftkoma\renewcommand{\cftloftitlefont}{\size@section\sectfont}\fi
\fi
\newcommand{\cftafterloftitle}{}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\l@figure}
%  |\l@figure{|\meta{title}|}{|\meta{page}|}| typesets the LoF entry for
% a |figure| caption heading. It is a parameterised copy of the default
% |\l@figure|
% (see \file{classes.dtx} for the original definition).
%    \begin{macrocode}
\renewcommand*{\l@figure}[2]{%
  \ifnum \c@lofdepth >\z@
    \vskip \cftbeforefigskip
    {\leftskip \cftfigindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \cftfigindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftfignumwidth\relax
     \let\@cftbsnum \cftfigpresnum
     \let\@cftasnum \cftfigaftersnum
     \let\@cftasnumb \cftfigaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\cftfigfont #1}\nobreak
     \cftfigfillnum{#2}}%
   \fi
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftbeforefigskip}
% \begin{macro}{\cftfigindent}
% \begin{macro}{\cftfignumwidth}
% \begin{macro}{\cftfigfont}
% \begin{macro}{\cftfigpresnum}
% \begin{macro}{\cftfigaftersnum}
% \begin{macro}{\cftfigaftersnumb}
% \begin{macro}{\cftfigleader}
% \begin{macro}{\cftfigdotsep}
% \begin{macro}{\cftfigpagefont}
% \begin{macro}{\cftfigafterpnum}
% \begin{macro}{\cftfigfillnum}
%  These are the user commands to control the typesetting of Figure caption entries.
%  They are initialised to give the standard appearance.
%    \begin{macrocode}
\newlength{\cftbeforefigskip}
  \setlength{\cftbeforefigskip}{\z@ \@plus.2\p@}
\newlength{\cftfigindent}
  \setlength{\cftfigindent}{1.5em}
\newlength{\cftfignumwidth}
  \setlength{\cftfignumwidth}{2.3em}
\newcommand{\cftfigfont}{\normalfont}
\newcommand{\cftfigpresnum}{}
\newcommand{\cftfigaftersnum}{}
\newcommand{\cftfigaftersnumb}{}
\newcommand{\cftfigleader}{\normalfont\cftdotfill{\cftfigdotsep}}
\newcommand{\cftfigdotsep}{\cftdotsep}
\newcommand{\cftfigpagefont}{\normalfont}
\newcommand{\cftfigafterpnum}{}
\newcommand{\cftfigfillnum}[1]{%
  {\cftfigleader}\nobreak
  \makebox[\@pnumwidth][\cftpnumalign]{\cftfigpagefont #1}\cftfigafterpnum\par
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{lofdepth}
% \begin{macro}{lotdepth}
% The counters |lofdepth| and |lotdepth| are defined by the
% \Lpack{subfigure} package.
% Define them here if that package is not used.
%    \begin{macrocode}
\if@cftsubfigopt\else
  \newcounter{lofdepth}\setcounter{lofdepth}{1}
  \newcounter{lotdepth}\setcounter{lotdepth}{1}
\fi

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@cftdobiblot}
% If the \Lpack{tocbibind} package has been used and it has
% redefined |\listoftables| we need to cater for that. The contents
% of the definition are defined in \Lpack{tocbibind}.
%    \begin{macrocode}
\newcommand{\@cftdobiblot}{%
  \if@dotoclot
    \if@bibchapter
      \phantomsection
      \addcontentsline{toc}{chapter}{\listtablename}
    \else
      \phantomsection
      \addcontentsline{toc}{\@tocextra}{\listtablename}
    \fi
  \fi}

%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\listoftables}
% This is a parameterised version of the default |\listoftables| command.
% The changes are postponed until after all packages have been loaded.
% Each class has its own definition, but we have to cater for all classes
% in one definition, hence some of the checks. First, perform the default
% checks for multicolumns. (Do nothing if the \Lopt{titles} option has
%  been used).
%    \begin{macrocode}
\AtBeginDocument{%
\if@cftnctoc\else
\renewcommand{\listoftables}{%
  \@cfttocstart
%    \end{macrocode}
% Ensure that any previous paragraph has been finished. Within a group set
% the local paragraphing style. Typeset the title and then do the contents
% of the \file{.lot} file.
%    \begin{macrocode}
  \par
  \begingroup
    \parindent\z@ \parskip\cftparskip
    \@cftmakelottitle
    \if@cfttocbibind
      \@cftdobiblot
    \fi
    \@starttoc{lot}%
  \endgroup
%    \end{macrocode}
% Finally, restore any multicolumn typesetting.
%    \begin{macrocode}
  \@cfttocfinish}%
\fi
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@cftmakelottitle}
% This command typesets the title for the LoT.
% \changes{v2.3}{2002/06/15}{Added \cs{@secpenalty} to \cs{@cftmakelottitle}}
% \changes{v2.3}{2002/06/15}{Added \cs{@cftpagestyle} to \cs{@cftmakelottitle}}
%    \begin{macrocode}
\newcommand{\@cftmakelottitle}{%
  \addpenalty\@secpenalty
  \if@cfthaschapter
    \vspace*{\cftbeforelottitleskip}
  \else
    \vspace{\cftbeforelottitleskip}
  \fi
  \@cftpagestyle
  {\interlinepenalty\@M
  {\cftlottitlefont\listtablename}{\cftafterlottitle}
  \cftmarklot
  \par\nobreak
  \vskip \cftafterlottitleskip
  \@afterheading}}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftbeforelottitleskip}
% \begin{macro}{\cftafterlottitleskip}
%  These two lengths control the vertical spacing before and after the
%  LoT title.
%    \begin{macrocode}
\newlength{\cftbeforelottitleskip}
\newlength{\cftafterlottitleskip}
%    \end{macrocode}
% Their values depend on whether the document has chapters or not. In
% chaptered documents the default LoT title is typeset as a |\chapter*|,
% otherwise as a |\section*|.
%    \begin{macrocode}
\if@cfthaschapter
  \setlength{\cftbeforelottitleskip}{50pt}
  \setlength{\cftafterlottitleskip}{40pt}
\else
  \setlength{\cftbeforelottitleskip}{3.5ex \@plus 1ex \@minus .2ex}
  \setlength{\cftafterlottitleskip}{2.3ex \@plus.2ex}
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cftlottitlefont}
% \begin{macro}{\cftafterlottitle}
% The LoT title is typeset in the style given by |\cftlottitlefont|.
% The macro |\cftafterlottitle| is called after typesetting the title.
% This is initialised to do nothing.
% Both these macros can be redefined to do other things (e.g., adding
% an |\hfill| to |\cftlottitlefont| will make the title flushright).
% \changes{v2.3}{2002/06/15}{koma has different settings for LoT titles}
%    \begin{macrocode}
\if@cfthaschapter
  \newcommand{\cftlottitlefont}{\normalfont\Huge\bfseries}
  \if@cftkoma\renewcommand{\cftlottitlefont}{\size@chapter\sectfont}\fi
\else
  \newcommand{\cftlottitlefont}{\normalfont\Large\bfseries}
  \if@cftkoma\renewcommand{\cftlottitlefont}{\size@section\sectfont}\fi
\fi
\newcommand{\cftafterlottitle}{}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\l@table}
%  |\l@table{|\meta{title}|}{|\meta{page}|}| typesets the LoT entry for
% a |table| caption heading. It is a parameterised copy of the default
% |\l@table|
% (see \file{classes.dtx} for the original definition).
%    \begin{macrocode}
\renewcommand*{\l@table}[2]{%
  \ifnum\c@lotdepth >\z@
    \vskip \cftbeforetabskip
    {\leftskip \cfttabindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \cfttabindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cfttabnumwidth\relax
     \let\@cftbsnum \cfttabpresnum
     \let\@cftasnum \cfttabaftersnum
     \let\@cftasnumb \cfttabaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\cfttabfont #1}\nobreak
     \cfttabfillnum{#2}}%
   \fi
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftbeforetabskip}
% \begin{macro}{\cfttabindent}
% \begin{macro}{\cfttabnumwidth}
% \begin{macro}{\cfttabfont}
% \begin{macro}{\cfttabpresnum}
% \begin{macro}{\cfttabaftersnum}
% \begin{macro}{\cfttabaftersnumb}
% \begin{macro}{\cfttableader}
% \begin{macro}{\cfttabdotsep}
% \begin{macro}{\cfttabpagefont}
% \begin{macro}{\cfttabafterpnum}
% \begin{macro}{\cfttabfillnum}
%  These are the user commands to control the typesetting of Table caption entries.
%  They are initialised to give the standard appearance.
%    \begin{macrocode}
\newlength{\cftbeforetabskip}
  \setlength{\cftbeforetabskip}{\z@ \@plus.2\p@}
\newlength{\cfttabindent}
  \setlength{\cfttabindent}{1.5em}
\newlength{\cfttabnumwidth}
  \setlength{\cfttabnumwidth}{2.3em}
\newcommand{\cfttabfont}{\normalfont}
\newcommand{\cfttabpresnum}{}
\newcommand{\cfttabaftersnum}{}
\newcommand{\cfttabaftersnumb}{}
\newcommand{\cfttableader}{\normalfont\cftdotfill{\cfttabdotsep}}
\newcommand{\cfttabdotsep}{\cftdotsep}
\newcommand{\cfttabpagefont}{\normalfont}
\newcommand{\cfttabafterpnum}{}
\newcommand{\cfttabfillnum}[1]{%
  {\cfttableader}\nobreak
  \makebox[\@pnumwidth][\cftpnumalign]{\cfttabpagefont #1}\cfttabafterpnum\par
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Support for the \Lpack{subfigure} package}
% \changes{v1.1}{2000/02/12}{Added subfigure support}
%
%  The code for supporting the \Lpack{subfigure} package is, in all
% essentials, the same as that for the figure and table captions; only the
% names are changed. However, the code need only be executed if the
% \Lpack{subfigure} package is actually loaded.
%
% \begin{macro}{\@cftl@subfig}
%    This command redefines the |\l@subfigure| command.
%    \begin{macrocode}
\newcommand{\@cftl@subfig}{%
%    \end{macrocode}
% \begin{macro}{\l@subfigure}
%  |\l@subfigure{|\meta{title}|}{|\meta{page}|}| typesets the LoF entry for
% a |subfigure| caption heading. It is essentially the same as the
% parameterised code for |\l@figure| except that account has to be taken
% of |lofdepth|.
%    \begin{macrocode}
\renewcommand*{\l@subfigure}[2]{%
  \ifnum \c@lofdepth > \toclevel@subfigure
    \vskip \cftbeforesubfigskip
    {\leftskip \cftsubfigindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \cftsubfigindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftsubfignumwidth\relax
     \let\@cftbsnum \cftsubfigpresnum
     \let\@cftasnum \cftsubfigaftersnum
     \let\@cftasnumb \cftsubfigaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\cftsubfigfont ##1}\nobreak
     \cftsubfigfillnum{##2}}%
  \fi
  }%
}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@cftsetsubfig}
% This command initialises the setup for subfigure captions in the LoF.
%    \begin{macrocode}
\newcommand{\@cftsetsubfig}{%
%    \end{macrocode}
% \begin{macro}{\cftbeforesubfigskip}
% \begin{macro}{\cftsubfigindent}
% \begin{macro}{\cftsubfignumwidth}
% \begin{macro}{\cftsubfigfont}
% \begin{macro}{\cftsubfigpresnum}
% \begin{macro}{\cftsubfigaftersnum}
% \begin{macro}{\cftsubfigaftersnumb}
% \begin{macro}{\cftsubfigleader}
% \begin{macro}{\cftsubfigdotsep}
% \begin{macro}{\cftsubfigpagefont}
% \begin{macro}{\cftsubfigafterpnum}
% \begin{macro}{\toclevel@subfig}
% \begin{macro}{\cftsubfigfillnum}
%    \begin{macrocode}
\newlength{\cftbeforesubfigskip}
  \setlength{\cftbeforesubfigskip}{\z@ \@plus.2\p@}
\newlength{\cftsubfigindent}
  \setlength{\cftsubfigindent}{3.8em}
\newlength{\cftsubfignumwidth}
  \setlength{\cftsubfignumwidth}{2.5em}
\newcommand{\cftsubfigfont}{\normalfont}
\newcommand{\cftsubfigpresnum}{}
\newcommand{\cftsubfigaftersnum}{}
\newcommand{\cftsubfigaftersnumb}{}
\newcommand{\cftsubfigleader}{\normalfont\cftdotfill{\cftsubtabdotsep}}
\newcommand{\cftsubfigdotsep}{\cftdotsep}
\newcommand{\cftsubfigpagefont}{\normalfont}
\newcommand{\cftsubfigafterpnum}{}
\providecommand{\toclevel@subfigure}{1}
\newcommand{\cftsubfigfillnum}[1]{%
  {\cftsubfigleader}\nobreak
  \makebox[\@pnumwidth][\cftpnumalign]{\cftsubfigpagefont ##1}\cftsubfigafterpnum\par
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% This is the end of |\@cftsetsubfig|.
%    \begin{macrocode}
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@cftl@subtab}
%    This code redefines the code for |\l@subtable|.
%    \begin{macrocode}
\newcommand{\@cftl@subtab}{%
%    \end{macrocode}
% \begin{macro}{\l@subtable}
%  |\l@subtable{|\meta{title}|}{|\meta{page}|}| typesets the LoT entry for
% a |subtable| caption heading. It is essentially the same as the
% parameterised code for |\l@table| except account has to be taken of
% |lotdepth|.
%    \begin{macrocode}
\renewcommand*{\l@subtable}[2]{%
  \ifnum \c@lotdepth > \toclevel@subtable
    \vskip \cftbeforesubtabskip
    {\leftskip \cftsubtabindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \cftsubtabindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftsubtabnumwidth\relax
     \let\@cftbsnum \cftsubtabpresnum
     \let\@cftasnum \cftsubtabaftersnum
     \let\@cftasnumb \cftsubtabaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\cftsubtabfont ##1}\nobreak
     \cftsubtabfillnum{##2}}%
  \fi
  }%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@cftsetsubtab}
% This command sets up the defaults for subtable entries in the LoT.
%    \begin{macrocode}
\newcommand{\@cftsetsubtab}{%
%    \end{macrocode}
% \begin{macro}{\cftbeforesubtabskip}
% \begin{macro}{\cftsubtabindent}
% \begin{macro}{\cftsubtabnumwidth}
% \begin{macro}{\cftsubtabfont}
% \begin{macro}{\cftsubtabpresnum}
% \begin{macro}{\cftsubtabaftersnum}
% \begin{macro}{\cftsubtabaftersnumb}
% \begin{macro}{\cftsubtableader}
% \begin{macro}{\cftsubtabdotsep}
% \begin{macro}{\cftsubtabpagefont}
% \begin{macro}{\cftsubtabafterpnum}
% \begin{macro}{\toclevel@subtable}
% \begin{macro}{\cftsubtabfillnum}
%  These are the user commands to control the typesetting of Subtable
% caption entries.
%  They are initialised to give the standard appearance.
%    \begin{macrocode}
\newlength{\cftbeforesubtabskip}
  \setlength{\cftbeforesubtabskip}{\z@ \@plus.2\p@}
\newlength{\cftsubtabindent}
  \setlength{\cftsubtabindent}{3.8em}
\newlength{\cftsubtabnumwidth}
  \setlength{\cftsubtabnumwidth}{2.5em}
\newcommand{\cftsubtabfont}{\normalfont}
\newcommand{\cftsubtabpresnum}{}
\newcommand{\cftsubtabaftersnum}{}
\newcommand{\cftsubtabaftersnumb}{}
\newcommand{\cftsubtableader}{\normalfont\cftdotfill{\cftsubtabdotsep}}
\newcommand{\cftsubtabdotsep}{\cftdotsep}
\newcommand{\cftsubtabpagefont}{\normalfont}
\newcommand{\cftsubtabafterpnum}{}
\providecommand{\toclevel@subtable}{1}
\newcommand{\cftsubtabfillnum}[1]{%
  {\cftsubtableader}\nobreak
  \makebox[\@pnumwidth][\cftpnumalign]{\cftsubtabpagefont ##1}\cftsubtabafterpnum\par
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% This is the end of |\@cftsetsubtab|.
%    \begin{macrocode}
}

%    \end{macrocode}
% \end{macro}
%
%    Call the \Lpack{subfigure} package setup code only if the
% \Lopt{subfigure} option is specified. The |\l@...| redefinitions have to
% come after the \Lpack{subfigure} package is loaded.
%    \begin{macrocode}

\if@cftsubfigopt
  \@cftsetsubfig\@cftsetsubtab
  \AtBeginDocument{\@cftl@subfig\@cftl@subtab}
\fi
%%  \AtBeginDocument{\if@cftsubfigopt
%%    \@cftsetsubfig\@cftsetsubtab
%%    \@cftl@subfig\@cftl@subtab
%%  \fi}

%    \end{macrocode}
%
%
% \subsection{New list of\ldots}
% \changes{v2.0}{2001/03/03}{Added \cs{newlistof} and \cs{newlistentry}}
%
% \begin{macro}{\newlistentry}
% |\newlistentry[|\meta{within}|]{|\meta{counter}|}{|\meta{ext}|}{|\meta{level-1}|}| creates a set of commands for a new kind of entry into a List of.
%    \begin{macrocode}
\newcommand{\newlistentry}[4][\@empty]{%
%    \end{macrocode}
% \begin{macro}{\c@X}
% \begin{macro}{\theX}
% Check if \meta{within} and \meta{counter} have been defined. It is
% an error if \meta{within} has not been defined, and an error if
% \meta{counter} has been defined. Set the default counter values.
%    \begin{macrocode}
  \@ifundefined{c@#2}{%    check & set the counter
    \ifx \@empty#1\relax
      \newcounter{#2}
    \else
      \@ifundefined{c@#1}{\PackageWarning{tocloft}%
                          {#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{tocloft}{#2 has been previously defined}{\@eha}}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% That finishes off the error checking. No matter what the result, the
% rest of the new commands are defined.
%
% \begin{macro}{\l@X}
% |\l@X{|\meta{title}|}{|\meta{page}|}| typesets the entry.
%    \begin{macrocode}
  \@namedef{l@#2}##1##2{%
%    \end{macrocode}
% Only typeset if the |\Zdepth| is greater than \meta{level-1}.
%    \begin{macrocode}
    \ifnum \@nameuse{c@#3depth} > #4\relax
      \vskip \@nameuse{cftbefore#2skip}
      {\leftskip \@nameuse{cft#2indent}\relax
       \rightskip \@tocrmarg
       \parfillskip -\rightskip
       \parindent \@nameuse{cft#2indent}\relax\@afterindenttrue
       \interlinepenalty\@M
       \leavevmode
       \@tempdima \@nameuse{cft#2numwidth}\relax
       \expandafter\let\expandafter\@cftbsnum\csname cft#2presnum\endcsname
       \expandafter\let\expandafter\@cftasnum\csname cft#2aftersnum\endcsname
       \expandafter\let\expandafter\@cftasnumb\csname cft#2aftersnumb\endcsname
       \advance\leftskip\@tempdima \null\nobreak\hskip -\leftskip
       {\@nameuse{cft#2font}##1}\nobreak
       \@nameuse{cft#2fillnum}{##2}}%
    \fi
  }  % end of \l@#2

%    \end{macrocode}
% \end{macro}
%
% Now define all the layout commands used by |\l@X|. The default
% values of these correspond to those for section entries in
% non-chaptered documents.
% \begin{macro}{\cftbeforeXskip}
%    \begin{macrocode}
  \expandafter\newlength\csname cftbefore#2skip\endcsname
    \setlength{\@nameuse{cftbefore#2skip}}{\z@ \@plus .2\p@}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\cftXindent}
% \begin{macro}{\cftXnumwidth}
%    \begin{macrocode}
  \expandafter\newlength\csname cft#2indent\endcsname
  \expandafter\newlength\csname cft#2numwidth\endcsname
%    \end{macrocode}
% Set the default values for the indent and numwidth depending on
% the entry's level. A level of 1 corresponds to a figure entry.
%    \begin{macrocode}
  \ifcase #4\relax  % 0
    \setlength{\@nameuse{cft#2indent}}{0em}
    \setlength{\@nameuse{cft#2numwidth}}{1.5em}
  \or               % 1
    \setlength{\@nameuse{cft#2indent}}{1.5em}
    \setlength{\@nameuse{cft#2numwidth}}{2.3em}
  \or               % 2
    \setlength{\@nameuse{cft#2indent}}{3.8em}
    \setlength{\@nameuse{cft#2numwidth}}{3.2em}
  \or               % 3
    \setlength{\@nameuse{cft#2indent}}{7.0em}
    \setlength{\@nameuse{cft#2numwidth}}{4.1em}
  \else             % anything else
    \setlength{\@nameuse{cft#2indent}}{10.0em}
    \setlength{\@nameuse{cft#2numwidth}}{5.0em}
  \fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\cftXfont}
% \begin{macro}{\cftXpresnum}
% \begin{macro}{\cftXaftersnum}
% \begin{macro}{\cftXaftersnumb}
% \begin{macro}{\cftXdotsep}
% \begin{macro}{\cftXleader}
% \begin{macro}{\cftXpagefont}
% \begin{macro}{\cftXafterpnum}
% And the remaining commands.
%    \begin{macrocode}
  \@namedef{cft#2font}{\normalfont}
  \@namedef{cft#2presnum}{}
  \@namedef{cft#2aftersnum}{}
  \@namedef{cft#2aftersnumb}{}
  \@namedef{cft#2dotsep}{\cftdotsep}
  \@namedef{cft#2leader}{\normalfont\cftdotfill{\@nameuse{cft#2dotsep}}}
  \@namedef{cft#2pagefont}{\normalfont}
  \@namedef{cft#2afterpnum}{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\toclevel@X}
% The hyperref package needs a command |\toclevel@X|, holding
% the \meta{level-1} value.
%    \begin{macrocode}
  \@namedef{toclevel@#2}{#4}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftXfillnum}
% Typeset the leader and page number.
%    \begin{macrocode}
  \@namedef{cft#2fillnum}##1{%
    {\@nameuse{cft#2leader}}\nobreak
    \makebox[\@pnumwidth][\cftpnumalign]{\@nameuse{cft#2pagefont}##1}\@nameuse{cft#2afterpnum}\par
  }
%    \end{macrocode}
% \end{macro}
% This ends the definition of |\newlistentry|.
%    \begin{macrocode}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newlistof}
% |\newlistof[|\meta{within}|]{|\meta{entry}|}{|\meta{ext}|}{|\meta{listofname}|}|
% creates the commands for a new List of.
%    \begin{macrocode}
\newcommand{\newlistof}[4][\@empty]{%
%    \end{macrocode}
% Call |\newlistentry| to set up the first level entry.
%    \begin{macrocode}
  \ifx \@empty#1\relax
    \newlistentry{#2}{#3}{0}
  \else
    \newlistentry[#1]{#2}{#3}{0}
  \fi
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ext@Z}
% \begin{macro}{\Zdepth}
% The file extension and listing depth.
%    \begin{macrocode}
  \@namedef{ext@#2}{#3}
  \newcounter{#3depth}
  \setcounter{#3depth}{1}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cftmarkZ}
% The heading marks for the listing.
% \changes{v2.3}{2002/06/15}{different koma settings in \cs{newlistof}}
%    \begin{macrocode}
  \if@cftkoma
    \@namedef{cftmark#3}{%
      \@mkboth{#4}{#4}}
  \else
    \@namedef{cftmark#3}{%
      \@mkboth{\MakeUppercase{#4}}{\MakeUppercase{#4}}}
  \fi
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\listofX}
% Typeset the listing title and entries.
%    \begin{macrocode}
 \if@cftnctoc
%    \end{macrocode}
% For the \Lopt{titles} option, basically copy the code from
% the standard |\tableofcontents| command.
%    \begin{macrocode}
  \@namedef{listof#2}{%
    \@cfttocstart
    \if@cfthaschapter
      \chapter*{#4}
    \else
      \section*{#4}
    \fi
    \@nameuse{cftmark#3}
    \@starttoc{#3}%
    \@cfttocfinish}
 \else
%    \end{macrocode}
% Otherwise use the fully parameterised definition.
%    \begin{macrocode}
  \@namedef{listof#2}{%
    \@cfttocstart
    \par
    \begingroup
      \parindent\z@ \parskip\cftparskip
      \@nameuse{@cftmake#3title}
      \@starttoc{#3}%
    \endgroup
    \@cfttocfinish}
 \fi

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@cftmakeZtitle}
% Typeset the title.
% \changes{v2.3}{2002/06/15}{Added \cs{@secpenalty} to \cs{@cftmakeZtitle}}
% \changes{v2.3}{2002/06/15}{Added \cs{@cftpagestyle} to \cs{@cftmakeZtitle}}
%    \begin{macrocode}
  \@namedef{@cftmake#3title}{%
    \addpenalty\@secpenalty
    \if@cfthaschapter
      \vspace*{\@nameuse{cftbefore#3titleskip}}%
    \else
      \vspace{\@nameuse{cftbefore#3titleskip}}%
    \fi
    \@cftpagestyle
    {\interlinepenalty\@M
    {\@nameuse{cft#3titlefont}#4}{\@nameuse{cftafter#3title}}%
    \@nameuse{cftmark#3}%
    \par\nobreak
    \vskip \@nameuse{cftafter#3titleskip}%
    \@afterheading}}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftbeforeZtitleskip}
% \begin{macro}{\cftafterZtitleskip}
% \begin{macro}{\cftZtitlefont}
% The skips before and after the title heading, and the title font.
% The default values depend on whether or not the document class
% has chapters.
%    \begin{macrocode}
   \expandafter\newlength\csname cftbefore#3titleskip\endcsname
   \expandafter\newlength\csname cftafter#3titleskip\endcsname
   \if@cfthaschapter
      \setlength{\@nameuse{cftbefore#3titleskip}}{50pt}
      \setlength{\@nameuse{cftafter#3titleskip}}{40pt}
      \if@cftkoma
        \@namedef{cft#3titlefont}{\size@chapter\sectfont}
      \else
        \@namedef{cft#3titlefont}{\normalfont\Huge\bfseries}
      \fi
    \else
      \setlength{\@nameuse{cftbefore#3titleskip}}{3.5ex \@plus 1ex \@minus .2ex}
      \setlength{\@nameuse{cftafter#3titleskip}}{2.3ex \@plus .2ex}
      \if@cftkoma
        \@namedef{cft#3titlefont}{\size@section\sectfont}
      \else
        \@namedef{cft#3titlefont}{\normalfont\Huge\bfseries}
      \fi
    \fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cftafterZtitle}
% Something to go after the title.
%    \begin{macrocode}
    \@namedef{cftafter#3title}{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftZprehook}
% \begin{macro}{\cftZposthook}
% Hooks before and after the list of entries.
%    \begin{macrocode}
    \@namedef{cft#3prehook}{}
    \@namedef{cft#3posthook}{}
%    \end{macrocode}
% \end{macro}
%
% This is the end of the definition of |\newlistof|.
%    \begin{macrocode}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftsetindents}
% \changes{v2.0}{2001/03/15}{Added \cs{cftsetindents}}
% |\cftsetindents{|\meta{entry}|}{|\meta{indent}|}{|\meta{numwidth}|}| sets
% the \textit{indent} and \textit{numwidth} for entry \meta{entry}. The macro
% has to map between the external entry name and the internal shorthand.
%    \begin{macrocode}
\newcommand{\cftsetindents}[3]{%
  \def\@cftemp{#1}
  \ifx\@cftemp\cftchapname
    \@cftsetindents{chap}{#2}{#3}
  \else
    \ifx\@cftemp\cftsecname \@cftsetindents{sec}{#2}{#3}
    \else
      \ifx\@cftemp\cftsubsecname \@cftsetindents{subsec}{#2}{#3}
      \else
        \ifx\@cftemp\cftsubsubsecname \@cftsetindents{subsubsec}{#2}{#3}
        \else
          \ifx\@cftemp\cftparaname \@cftsetindents{para}{#2}{#3}
          \else
            \ifx\@cftemp\cftsubparaname \@cftsetindents{subpara}{#2}{#3}
            \else
              \ifx\@cftemp\cftfigname \@cftsetindents{fig}{#2}{#3}
              \else
                \ifx\@cftemp\cftsubfigname \@cftsetindents{subfig}{#2}{#3}
                \else
                  \ifx\@cftemp\cfttabname \@cftsetindents{tab}{#2}{#3}
                  \else
                    \ifx\@cftemp\cftsubtabname \@cftsetindents{subtab}{#2}{#3}
                    \else
                      \@cftsetindents{#1}{#2}{#3}
                    \fi
                  \fi
                \fi
              \fi
            \fi
          \fi
        \fi
      \fi
    \fi
  \fi
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@cftsetindents}
% |\@cftsetindents{|\meta{X}|}{|\meta{indent}|}{|\meta{numwidth}|}| is
% the internal version of |\cftsetindents|, where in this case \meta{X}
% is the internal (shorthand) name of the entry.
%    \begin{macrocode}
\newcommand{\@cftsetindents}[3]{%
  \setlength{\@nameuse{cft#1indent}}{#2}
  \setlength{\@nameuse{cft#1numwidth}}{#3}
}

%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Switching page numbering}
% \changes{v2.0}{2001/03/03}{Added page number switching off/on}
%
% \begin{macro}{\@cftpnumoff}
% |\@cftpnumoff{|\meta{shorthand}|}| is the workhorse
% for switching page numbering off. The \meta{shorthand} argument is the
% shorthand name of the entry (e.g. |subsec| for |subsection|).
% The macro redefines the |\cftXnumfill| command so that there is no leader
% and the page number is ignored.
%    \begin{macrocode}
\newcommand{\@cftpnumoff}[1]{%
  \@namedef{cft#1fillnum}##1{%
    \cftparfillskip\@nameuse{cft#1afterpnum}\par}}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftchapname}
% \begin{macro}{\cftsecname}
% \begin{macro}{\cftsubsecname}
% \begin{macro}{\cftsubsubsecname}
% \begin{macro}{\cftparaname}
% \begin{macro}{\cftsubparaname}
% \begin{macro}{\cftfigname}
% \begin{macro}{\cftsubfigname}
% \begin{macro}{\cfttabname}
% \begin{macro}{\cftsubtabname}
%  Unfortunately an early design decision was the use shorthands like |sec|
% for |section|. For the page switching I need to be able to correlate the
% shorthands and longhands.
%    \begin{macrocode}
\newcommand*{\cftchapname}{chapter}
\newcommand*{\cftsecname}{section}
\newcommand*{\cftsubsecname}{subsection}
\newcommand*{\cftsubsubsecname}{subsubsection}
\newcommand*{\cftparaname}{paragraph}
\newcommand*{\cftsubparaname}{subparagraph}
\newcommand*{\cftfigname}{figure}
\newcommand*{\cftsubfigname}{subfigure}
\newcommand*{\cfttabname}{table}
\newcommand*{\cftsubtabname}{subtable}

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cftpagenumbersoff}
% The user level command for switching off page numbers is
% |\cftpagenumbersoff{|\meta{entry}|}| where \meta{entry} is the longhand
% name of the entry. The principal task opf this macro is to determine
% the corresponding shorthand name of the \meta{entry} and then call
% |\@cftpnumoff| to do the work. For |part| and user-defined entries
% the long- and short-hand entry names are identical.
%    \begin{macrocode}
\DeclareRobustCommand{\cftpagenumbersoff}[1]{%
  \def\@cftemp{#1}
  \ifx\@cftemp\cftchapname
    \@cftpnumoff{chap}
  \else
    \ifx\@cftemp\cftsecname \@cftpnumoff{sec}
    \else
      \ifx\@cftemp\cftsubsecname \@cftpnumoff{subsec}
      \else
        \ifx\@cftemp\cftsubsubsecname \@cftpnumoff{subsubsec}
        \else
          \ifx\@cftemp\cftparaname \@cftpnumoff{para}
          \else
            \ifx\@cftemp\cftsubparaname \@cftpnumoff{subpara}
            \else
              \ifx\@cftemp\cftfigname \@cftpnumoff{fig}
              \else
                \ifx\@cftemp\cftsubfigname \@cftpnumoff{subfig}
                \else
                  \ifx\@cftemp\cfttabname \@cftpnumoff{tab}
                  \else
                    \ifx\@cftemp\cftsubtabname \@cftpnumoff{subtab}
                    \else
                      \@cftpnumoff{#1}
                    \fi
                  \fi
                \fi
              \fi
            \fi
          \fi
        \fi
      \fi
    \fi
  \fi
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftpagenumberson}
% |\cftpagenumberson{|\meta{entry}|}| is the user level command for
% reversing the corresponding |\cftpagenumbersoff|.
%    \begin{macrocode}
\DeclareRobustCommand{\cftpagenumberson}[1]{%
  \def\@cftemp{#1}
  \ifx\@cftemp\cftchapname
    \@cftpnumon{chap}
  \else
    \ifx\@cftemp\cftsecname \@cftpnumon{sec}
    \else
      \ifx\@cftemp\cftsubsecname \@cftpnumon{subsec}
      \else
        \ifx\@cftemp\cftsubsubsecname \@cftpnumon{subsubsec}
        \else
          \ifx\@cftemp\cftparaname \@cftpnumon{para}
          \else
            \ifx\@cftemp\cftsubparaname \@cftpnumon{subpara}
            \else
              \ifx\@cftemp\cftfigname \@cftpnumon{fig}
              \else
                \ifx\@cftemp\cftsubfigname \@cftpnumon{subfig}
                \else
                  \ifx\@cftemp\cfttabname \@cftpnumon{tab}
                  \else
                    \ifx\@cftemp\cftsubtabname \@cftpnumon{subtab}
                    \else
                      \@cftpnumon{#1}
                    \fi
                  \fi
                \fi
              \fi
            \fi
          \fi
        \fi
      \fi
    \fi
  \fi
}

%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@cftpnumon}
% |\@cftpnumon{|\meta{shorthand}|}| is the workhorse
% for switching page numbering off. The \meta{shorthand} argument is the
% shorthand name of the entry (e.g. |subsec| for |subsection|).
% The macro defines the |\cftXnumfill| command to correspond to
% the default definition.
%    \begin{macrocode}
\newcommand{\@cftpnumon}[1]{%
  \@namedef{cft#1fillnum}##1{%
    {\@nameuse{cft#1leader}}\nobreak
    \makebox[\@pnumwidth][\cftpnumalign]{\@nameuse{cft#1pagefont}##1}\@nameuse{cft#1afterpnum}\par
  }%
}
%    \end{macrocode}
% \end{macro}
%
%
%
%
%
%
% \subsection{Experimental utilities}
%
%    The code in this section is experimental but in the sense that the
% capabilities might be modified in the future rather than that the code
% does not work.
%
% \begin{macro}{\cftchapterprecis}
% This is experimental. |\cftchapterprecis{|\meta{text}|}| typesets
% \meta{text} at the point where it is called, and also adds \meta{text}
% to the \file{.toc} file. It is expects to be called immediately after
% a |\chapter| command.
%    \begin{macrocode}
\newcommand{\cftchapterprecis}[1]{%
  \cftchapterprecishere{#1}
  \cftchapterprecistoc{#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftchapterprecishere}
% |\cftchapterprecishere{|\meta{text}|}| typesets \meta{text}. It expects
% to be called immediately after a |\chapter| command. First add some
% negative vertical space to move it closer to the chapter heading.
%    \begin{macrocode}
\newcommand{\cftchapterprecishere}[1]{%
  \vspace*{-2\baselineskip}
%    \end{macrocode}
% Typeset its argument using italic font in a |quote| environment.
%    \begin{macrocode}
  \begin{quote}\textit{#1}\end{quote}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftchapterprecistoc}
% |\cftchapterprecistoc{|\meta{text}|}| adds \meta{text} to the \file{.toc}
% file. The \meta{text} will be typeset within the same margins as the
% the title text of a |\chapter| heading, using an italic font.
%    \begin{macrocode}
\newcommand{\cftchapterprecistoc}[1]{\addtocontents{toc}{%
%    \end{macrocode}
% Start a group to localize changes to the paragraphing. Set the
% left margin to the chapter indent plus the chapter number width.
%    \begin{macrocode}
  {\leftskip \cftchapindent\relax
   \advance\leftskip \cftchapnumwidth\relax
%    \end{macrocode}
% Set the right hand margin to |\@tocrmarg|.
%    \begin{macrocode}
   \rightskip \@tocrmarg\relax
%    \end{macrocode}
% Typeset \meta{text} using an italic font, then ensure that the paragraph
% is finished (to use the local skips). Finally close the group and we
% are done.
%    \begin{macrocode}
   \textit{#1}\protect\par}}}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftlocalchange}
% |\cftmakelocalchange{|\meta{file}|}{|\meta{pnumwidth}|}{|\meta{tocrmarg}|}|
% makes an entry into \meta{file} to change the |\@pnumwidth| and
% the |\@tocrmarg| values.
%    \begin{macrocode}
\newcommand{\cftlocalchange}[3]{%
  \addtocontents{#1}{\protect\cftsetpnumwidth{#2} \protect\cftsetrmarg{#3}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftaddtitleline}
% |\cftaddtitleline{|\meta{file}|}{|\meta{kind}|}{|\meta{title}|}{|\meta{page}|}|
% adds a |\contentsline| entry to \meta{file} with the given information.
%    \begin{macrocode}
\newcommand{\cftaddtitleline}[4]{\addtocontents{#1}{%
  \protect\contentsline{#2}{#3}{#4}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cftaddnumtitleline}
% |\cftaddtitleline{|\meta{file}|}{|\meta{kind}|}{|\meta{num}|}{|\meta{title}|}{|\meta{page}|}|
% adds a |\contentsline| entry to \meta{file} with the given information.
% \changes{v2.3c}{2003/09/26}{Removed \cs{ignorespaces} from \cs{cftaddnumtitleline}}
%    \begin{macrocode}
\newcommand{\cftaddnumtitleline}[5]{\addtocontents{#1}{%
    \protect\contentsline{#2}{\protect\numberline{#3}#4}{#5}}}
%    \end{macrocode}
% \end{macro}
%
% And, if dear old \Lpack{hyperref} has been used, we have to fix up these
% two macros.
% \changes{2003/09/26}{v2.3c}{Hyperref fix for \cs{cftaddtitleline} and
%                             \cs{cftaddnumtitleline}}
%    \begin{macrocode}
\AtBeginDocument{%
  \@ifpackageloaded{hyperref}{%
    \renewcommand{\cftaddtitleline}[4]{\addtocontents{#1}{%
      \protect\contentsline{#2}{#3}{#4}{\@currentHref}}}
    \renewcommand{\cftaddnumtitleline}[5]{\addtocontents{#1}{%
      \protect\contentsline{#2}{\protect\numberline{#3}#4}{#5}{\@currentHref}}}
  }{}
}

%    \end{macrocode}
%
%
% \begin{macro}{\@starttoc}
%
% Okay, here's a roughly-comprehensive list where \cs{@starttoc} is redefined in \TeX{} Live 2014.
% \begin{itemize}
% \item amsart, amsbook, amsdtx, amsproc
% \item asect
% \item latx.ltx (of course)
% \item newfloat
% \item flowfram
% \item gmampulex (?), gmtypos
% \item hyperref, memhfixc
% \item ijmart
% \item scrartcl, scrbook, scrreprt
% \item scrwtfile
% \item tocbasic
% \item tocstyle
% \item memoir
% \item multitoc
% \item nccsect
% \item notoccite
% \item artikel3, boek3, rapport3,
% \item rerunfilecheck
% \item parskip
% \item pdfwin
% \item revtex4
% \item devanagari
% \end{itemize}
% This makes things difficult if we want to redefine \cs{@starttoc} here.
% Many of the packages/classes above will not be used in conjunction with tocloft; on the other hand, we don't want to trample too much on others' code.
%
% So for our own work here, let's be extra conservative, at least for now, and only hook into \cs{starttoc} if it's the standard \LaTeX{} version.
%    \begin{macrocode}
\def\@starttoc@latex@orig#1{%
 \begingroup
   \makeatletter
   \@input{\jobname.#1}%
   \if@filesw
     \expandafter\newwrite\csname tf@#1\endcsname
     \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
   \fi
  \@nobreakfalse
\endgroup}
\ifx\@starttoc\@starttoc@latex@orig
  \def\@starttoc#1{%
    \csname cft#1prehook\endcsname
    \begingroup
      \makeatletter
      \@input{\jobname.#1}%
      \if@filesw
        \expandafter\newwrite\csname tf@#1\endcsname
        \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
      \fi
      \@nobreakfalse
    \endgroup
    \csname cft#1posthook\endcsname}
  \newcommand\cfttocprehook{}
  \newcommand\cftlofprehook{}
  \newcommand\cftlotprehook{}
  \newcommand\cfttocposthook{}
  \newcommand\cftlofposthook{}
  \newcommand\cftlotposthook{}
\else
  \PackageWarning{tocloft}{\string\@starttoc\space has already been redefined; tocloft bailing out.}
\fi
%    \end{macrocode}
% \end{macro}
%
%
%
%
%    The end of this package.
%    \begin{macrocode}
%</usc>
%    \end{macrocode}
%
%
% \bibliographystyle{alpha}
%
% \begin{thebibliography}{GMS94}
%
% \bibitem[Coc95]{SUBFIGURE}
% Steven Douglas Cochran.
% \newblock \emph{{The subfigure package}}.
% \newblock March 1995.
% \newblock (Available from CTAN as file \texttt{subfigure.dtx})
%
% \bibitem[Dru99]{MINITOC}
% Jean-Pierre Drucbert.
% \newblock \emph{{The minitoc package}}.
% \newblock August 1999.
% \newblock (Available from CTAN in subdirectory \texttt{/minitoc})
%
% \bibitem[GMS94]{GOOSSENS94}
% Michel Goossens, Frank Mittelbach, and Alexander Samarin.
% \newblock {\em The LaTeX Companion}.
% \newblock Addison-Wesley Publishing Company, 1994.
%
% \bibitem[Lin97]{FNCYCHAP}
% Ulf~A. Lindgren.
% \newblock \emph{{FncyChap V1.11}}.
% \newblock April 1997.
% \newblock (Available from CTAN in subdirectory \texttt{/fncychap})
%
% \bibitem[Lin95]{FLOAT}
% Anselm Lingnau.
% \newblock \emph{{An Improved Environment for Floats}}.
% \newblock March 1995.
% \newblock (Available from CTAN in subdirectory \texttt{/float})
%
% \bibitem[Wil96a]{ALGORITHM}
% Peter Williams.
% \newblock \emph{{Algorithms}}.
% \newblock April 1996.
% \newblock (Available from CTAN in subdirectory \texttt{/algorithm})
%
% \bibitem[Wil96b]{PRW96i}
% Peter~R. Wilson.
% \newblock \emph{{LaTeX for standards: The LaTeX package files user manual}}.
% \newblock NIST Report NISTIR, June 1996.
%
% \bibitem[Wil00]{TOCBIBIND}
% Peter~R. Wilson.
% \newblock \emph{{The tocbibind package}}.
% \newblock March 2000.
% \newblock (Available from CTAN as file \texttt{tocbibind.dtx})
%
% \bibitem[Wil01]{CCAPTION}
% Peter~R. Wilson.
% \newblock \emph{{The ccaption package}}.
% \newblock March 2001.
% \newblock (Available from CTAN as file \texttt{ccaption.dtx})
%
% \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         \~}


