% \CheckSum{1211}
% \iffalse meta-comment
% ======================================================================
% tocbasic.dtx
% Copyright (c) Markus Kohm, 2008-2011
%
% This file is part of the LaTeX2e KOMA-Script bundle.
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, version 1.3c of the license.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later and of this work.
%
% This work has the LPPL maintenance status "author-maintained".
%
% The Current Maintainer and author of this work is Markus Kohm.
%
% This work consists of files `tocbasic.dtx' and `scrlogo.dtx' at least.
%
% To create `tocbasic.sty' run `tex tocbasic.dtx'.  Using LaTeX instead
% of TeX would generate the implementation documentation.
% ----------------------------------------------------------------------
% tocbasic.dtx
% Copyright (c) Markus Kohm, 2008-2011
%
% Dieses Werk darf nach den Bedingungen der LaTeX Project Public Lizenz,
% Version 1.3c, verteilt und/oder veraendert werden.
% Die neuste Version dieser Lizenz ist
%   http://www.latex-project.org/lppl.txt
% und Version 1.3c ist Teil aller Verteilungen von LaTeX
% Version 2005/12/01 oder spaeter und dieses Werks.
%
% Dieses Werk hat den LPPL-Verwaltungs-Status "author-maintained"
% (allein durch den Autor verwaltet).
%
% Der Aktuelle Verwalter und Autor dieses Werkes ist Markus Kohm.
%
% Dieses Werk besteht mindestens aus den Dateien `tocbasic.dtx' und
% `scrlogo.dtx'.
%
% `tocbasic.sty' kann durch den Aufruf `tex tocbasic.dtx' erzeugt 
% werden. Bei Verwendung von LaTeX statt TeX wird hingegen die
% Implementierungsdokumentation erzeugt.
% ======================================================================
% \fi
%
% \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         \~}
%
% \iffalse
%%% From File: tocbasic.dtx
%<*dtx|package|driver|doc|load>
% \fi
\def\tocbasicversion{2011/03/23 v3.09}
% \iffalse
%</dtx|package|driver|doc|load>
%<*dtx>
\def\LaTeXformat{LaTeX2e}
\ifx\fmtname\LaTeXformat\def\MainBodyWork{%
\ProvidesFile{tocbasic.dtx}
%</dtx>
%<package>\NeedsTeXFormat{LaTeX2e}[1995/06/01]
%<driver>\ProvidesFile{tocbasic.drv}
%<doc>\ProvidesFile{tocbasic.tex}
%<package>\ProvidesPackage{tocbasic}
%<*dtx|package|driver|doc>
                [\tocbasicversion\space KOMA-Script package
%</dtx|package|driver|doc>
%<driver>                 (driver)%
%<package>                (handling toc-files)%
%<doc>                    (manual)%
%<*dtx>
                 (dtx)%
%</dtx>
%<*dtx|package|driver|doc>
                ]
%</dtx|package|driver|doc>
%<*dtx|driver>
\IfFileExists{scrdoc.cls}{%
  \documentclass[halfparskip-]{scrdoc}
}{%
  \documentclass{ltxdoc}
  \DeclareRobustCommand{\KOMAScript}{\textsf{K\kern.05em O\kern.05em%
      M\kern.05em A\kern.1em-\kern.1em Script}}
}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{listings}
\lstset{breaklines,prebreak=\mbox{$\hookleftarrow$},language=[LaTeX]TeX,
  basicstyle=\small}
\CodelineIndex
\RecordChanges
\GetFileInfo{tocbasic.dtx}
\sloppy
\DocInput{\filename}
\end{document}
%</dtx|driver>
%<*dtx>
}%
\else
  \let\MainBodyWork\relax
\fi

\MainBodyWork

\def\batchfile{tocbasic.dtx}
%</dtx>
%<ins>\def\batchfile{tocbasic.ins}
%<*dtx|ins>
\input docstrip.tex

\let\ifbeta=\iffalse

\ifToplevel{\ifx\generate\undefined
    \errhelp{Install a new version of docstrip.}
    \errmessage{Old docstrip in input path}
    \batchmode
    \csname @@end\endcsname
  \fi
  \Msg{************************************************************}
  \Msg{*}
  \Msg{* KOMA-Script}
  \Msg{* a versatile LaTeX2e bundle}
  \Msg{*}
  \Msg{* This is `\batchfile', a batchfile to unpack some or all}
  \Msg{* parts of KOMA-Script. See `liesmich.txt' (german) or}
  \Msg{* `readme.txt' (english) for additional information.}
  \Msg{*}
  \Msg{* Files of an old KOMA-Script installation may be}
  \Msg{* overwritten without asking!}
  \Msg{*}
  \Msg{************************************************************}
}

% ---------- some docstrip switchs -------------------------------------

\ifToplevel{%
  \keepsilent
  \askforoverwritefalse
}

% ---------- defining preambles ----------------------------------------

\preamble

Copyright (c) 2007-2011
Markus Kohm and any individual authors listed elsewhere in this file.

This file was generated from file(s) of the KOMA-Script bundle.
---------------------------------------------------------------

This work may be distributed and/or modified under the conditions of
the LaTeX Project Public License, version 1.3c of the license.
The latest version of this license is in
  http://www.latex-project.org/lppl.txt
and version 1.3c or later is part of all distributions of LaTeX
version 2005/12/01 or later and of this work.

This work has the LPPL maintenance status "author-maintained".

The Current Maintainer and author of this work is Markus Kohm.

This file may only be distributed together with the files
`scrlogo.dtx' and `tocbasic.dtx'. You may however distribute the files
`scrlogo.dtx' and `tocbasic.dtx' without this file. 
See also `tocbasic.dtx' for additional information.

If this file is a beta version, you are not allowed to distribute it.

Currently there is only a short english manual at `tocbasic.dtx', that
should also be found as `tocbasic.pdf'.

The KOMA-Script bundle (but maybe not this file) was based upon the
LaTeX2.09 Script family created by Frank Neukam 1993 and the LaTeX2e
standard classes created by The LaTeX3 Project 1994-1996.

\endpreamble

% ---------- File generation -------------------------------------------

\generate{\usepreamble\defaultpreamble
  \file{tocbasic.ins}{%
    \from{tocbasic.dtx}{ins}%
  }%
%  \file{tocbasic.drv}{%
%    \from{tocbasic.dtx}{driver}%
%  }%
  \file{tocbasic.tex}{%
    \from{tocbasic.dtx}{doc}%
  }%
}

\generate{\usepreamble\defaultpreamble
  \file{tocbasic.sty}{%
    \ifbeta\from{scrbeta.dtx}{package,tocbasic}\fi
    \from{tocbasic.dtx}{package}%
    \from{scrlogo.dtx}{logo}%
  }%
}%

% ---------- end of docstrip process -----------------------------------

\ifToplevel{%
  \Msg{************************************************************}
  \Msg{*}
  \Msg{* KOMA-Script}
  \Msg{* a versatile LaTeX2e bundle}
  \Msg{*}
  \Msg{* To finish the installation you have to move some}
  \Msg{* files into a directory searched by TeX.}
  \Msg{* See INSTALL.TXT (english) or INSTALLD.TXT (german)}
  \Msg{* from KOMA-Script bundle for additional information.}
  \Msg{*}
  \Msg{* You may also produce the implementation documentation}
  \Msg{* including also a short version of the english manual.}
  \Msg{* To produce it, do}
  \Msg{* \space\space pdflatex tocbasic.dtx}
  \Msg{* \space\space mkindex tocbasic}
  \Msg{* \space\space pdflatex tocbasic.dtx}
  \Msg{* after finishing the installation.}
  \Msg{*}
  \Msg{* Happy TeXing}
  \Msg{*}
  \Msg{************************************************************}
}

\bye
%</dtx|ins>
%<*dtx>
% \fi
%
% \providecommand*{\DescribeCounter}{\DescribeMacro}
% \let\Macro\cs
% \let\Class\textsf
% \let\Package\textsf
% \let\File\texttt
% \let\Parameter\marg
% \let\OParameter\oarg
% \let\PName\meta
% \let\PValue\texttt
% \newenvironment{Example}{\quote
%   \hspace*{-\leftmargin}\textbf{Example:}\enskip\ignorespaces
% }{\endquote}
% \newlength\descwidth
% \newenvironment{desctabular}{
%   \setlength{\descwidth}{\linewidth}
%   \addtolength{\descwidth}{-1em}
%   \addtolength{\descwidth}{-2\tabcolsep}
%   \tabular{@{}lp{\descwidth}@{}}
%   \hline
% }{%
%   \hline
%   \endtabular
% }
% \newcommand{\pventry}[2]{\multicolumn{2}{@{}l@{}}{\PValue{#1}}\\
%   ~ & #2 \\ }
% \providecommand*{\autoref}[1]{\expandafter\AUTOREF#1:}
% \newcommand*{\AUTOREF}{}
% \makeatletter
% \def\AUTOREF#1:#2:{\edef\@tempa{#1}\edef\@tempb{tab}\ifx\@tempa\@tempb 
%   table~\fi
%   \edef\@tempb{sec}\ifx\@tempa\@tempb section~\fi
%   \ref{#1:#2}}
% \makeatother
%
% \begin{document}
% \title{\KOMAScript{} \partname\ \texttt{\filename}%
%   \thanks{Diese Datei ist Version \fileversion\ von \texttt{\filename}.}}
% \date{\filedate}
% \author{Markus Kohm\thanks{mailto:komascript(at)gmx.info}}
% \maketitle
% \begin{abstract}
% \iffalse
%</dtx>
%<*doc>

\chapter{Package \Package{tocbasic} for Class and Package Authors}
\labelbase{tocbasic}

\textsc{Note: This is only a short version of the documentation.  The german
  \KOMAScript{} guide does contain a long version with usefull examples, that
  should also be translated!}

%</doc>
%<*doc|dtx>
% \fi
If a package creates it's list ``list of something''---something like ``list
of figures'', ``list of tables'', ``list of listings'', ``list of
algorithms'', etc. also known as \emph{toc-files}---have to do some
operations, that are equal for all those packages. Also it may be usefull
for classes and other packages to know about these additional
toc-files. This packages implements some basic functionality for all those
packages. Using this package will also improve compatibility with
\KOMAScript{} and---let us hope---other classes and packages.
% \iffalse
%<*dtx>
% \fi
% \end{abstract}
%
% \tableofcontents
% 
% \iffalse
%</dtx>
% \fi
%

\section{Legal Note}
\label{sec:tocbasic.legalnote}

You are allowed to destribute this part of \KOMAScript{} without the main
part of \KOMAScript{}. The files ``\File{scrlogo.dtx}'' and
``\File{tocbasic.dtx}'' may be distributed together under the conditions
of the \LaTeX{} Project Public License, either version~1.3c of this license
or (at your option) any later version.

The latest version of this license is in
\mbox{http://www.latex-project.org/lppl.txt} and version~1.3c or later is
part of all distributions of \LaTeX{} version~2005/12/01 or later.

% \iffalse
%<*dtx>
% \fi
% \KOMAScript{} comes with a detailed manual in English and German. But for
%  this package theres currently only this short English manual, because this
%  package should be used by package authors, not users.
%
% The \KOMAScript{} bundle may be found at
% CTAN:/\mbox{macros}/\linebreak[3]\mbox{latex}/\linebreak[3]\mbox{contrib}/%
% \linebreak[3]\mbox{koma-script}/. 
% ``CTAN:'' is a shortcut for every ``tex-archive'' directory at every
% CTAN-server or CTAN-mirror. See \mbox{http://www.ctan.org} for a list of all
% those servers and mirrors.
% \iffalse
%</dtx>
% \fi

\section{Using Package \Package{tocbasic}}
\label{sec:tocbasic.usage}

This package was made to be used by class and package authors.  Because of
this the package has no options.  If different packages would load it with
different options a option clash would be the result.  So using options
wouldn't be a good idea.

This package may be used by by other class and package authors.  It is also
allowed to distribute it without the main part of \KOMAScript{} (see
section~\ref{sec:tocbasic.legalnote}.  Because of this, it does not use any
\KOMAScript{} package, that isn't allowed to be distributed without the main
part of \KOMAScript{}, too.  Currently \Package{tocbasic} does only need
package \Package{keyval} from the graphics bundle.

There are two kind of commands.  The first kind are basic command.  Those
are used to inform other packages about the extensions used for files that
represent a list of something.  Classes or packages may use this information
e.g, for putting something to every of those files.  Packages may also ask,
if an extension is already in use.  This does even work, if \Macro{nofiles}
was used. The second kind are commands to create the list of something.


\subsection{Basic Commands}
\label{sec:tocbasic.basics}

Basic commands are used to handle a list of all extensions known for files
representing a list of something.  Entries to such files are written using
\Macro{addtocontents} or \Macro{addcontentsline} typically.  There are also
commands to do something for all known extensions.  And there are commands to
set or unset features of an extension or the file represented by the
extension.  Typically an extension also has an owner.  This owner may be a
class or package or a term decided by the author of the class or package
using \Package{tocbasic}, e.g., \KOMAScript{} uses the owner \texttt{float}
for list of figures ans list of tables and the default owner for the table of
contents.

% \iffalse
\begin{Declaration}
  \Macro{ifattoclist}\Parameter{extension}\Parameter{true
    part}\Parameter{false part}
\end{Declaration}
\BeginIndex{Cmd}{ifattoclist}%
This command
%<*dtx>
%\fi
\DescribeMacro{\ifattoclist}
Command \Macro{ifattoclist}\Parameter{extension}\Parameter{true
  part}\Parameter{false part}
% \iffalse
%</dtx>
% \fi
may be used to ask, wether a \PName{extension} is already a known extension or
not.  If the \PName{extension} is already known the \PName{true part} will be
used, otherwise the \PName{false part} will be used.
\begin{Example}
  Maybe you want to know if the extension ``\File{foo}'' is already in use to
  report an error, if you can not use it:
  \begin{lstlisting}
  \ifattoclist{foo}{%
    \PackageError{bar}{%
      extension `foo' already in use%
    }{%
      Each extension may be used only 
      once.\MessageBreak
      The class or another package already 
      uses extension `foo'.\MessageBreak
      This error is fatal!\MessageBreak  
      You should not continue!}%
  }{%
    \PackageInfo{bar}{using extension `foo'}%
  }
  \end{lstlisting}
\end{Example}
% \iffalse
\EndIndex{Cmd}{ifattoclist}%

\begin{Declaration}
  \Macro{addtotoclist}\OParameter{owner}\Parameter{extension}
\end{Declaration}
\BeginIndex{Cmd}{addtotoclist}%
This command
%<*dtx>
%\fi
\DescribeMacro{\addtotoclist}
Command \Macro{addtotoclist}\OParameter{owner}\Parameter{extension}
% \iffalse
%</dtx>
% \fi
adds the \PName{extension} to the list of known extensions.  If the optional
argument, \OParameter{owner}, was given this \PName{owner} will be stored to
be the owner of the \PName{extension}.  If you omit the optional argument,
\Package{tocbasic} tries to find out the filename of the current processed
class or package and stores this as owner.  This will fail if
\Macro{addtotoclist} was not used, loading a class or package but using a
command of a class or package after loading this class or package.  In this
case the owner will be set to ``\PValue{.}''.  Note that an empty
\PName{owner} is not the same like omitting the optional argument, but an
empty owner.

\begin{Example}
  You want to add the extension ``\File{foo}'' to the list of known extension,
  while loading your package with file name ``\File{bar.sty}'':
  \begin{lstlisting}
  \addtotoclist{foo}
  \end{lstlisting}%
  This will add the extension ``\PValue{foo}'' with owner ``\PValue{bar.sty}''
  to the list of known extensions, if it was not already at the list of known
  extensions. If the class or another package already added the extension you
  will get the error:
  \begin{lstlisting}
  Package tocbasic Error: file extension `#2' cannot be used twice

  See the tocbasic package documentation for explanation.
  Type  H <return>  for immediate help.
  \end{lstlisting}
  and after typing \texttt{H <return>} you will get the help:
  \begin{lstlisting}
  File extension `foo' is already used by a toc-file, while bar.sty
  tried to use it again for a toc-file.
  This may be either an incompatibility of packages, an error at a package,
  or a mistake by the user.
  \end{lstlisting}
  
  Maybe you package has a command, that creates list of files dynamically.  In
  this case you should use the optional argument of \Macro{addtotoclist} to
  set the owner.
  \begin{lstlisting}
  \newcommand*{\createnewlistofsomething}[1]{%
    \addtotoclist[bar.sty]{#1}%
    % Do something more to make this list of something available
  }
  \end{lstlisting}
  If the user calls know, e.g.
  \begin{lstlisting}
  \createnewlistofsomething{foo}
  \end{lstlisting}
  this would add the extension ``\PValue{foo}'' with the owner
  ``\PValue{bar.sty}'' to the list of known extension or report an error, if the
  extension is already in use.  You may use any owner you want.  But it should
  be unique!  So, if you are the author of package \Package{float} you may
  use for example owner ``\PValue{float}'' instead of owner
  ``\PValue{float.sty}'', so the \KOMAScript{} options for list of figure and
  list of table will also handle the lists of this package, that are already
  added to the known extensions, when the option is used.
\end{Example}
% \iffalse
\EndIndex{Cmd}{addtotoclist}%

\begin{Declaration}
  \Macro{AtAddToTocList}\OParameter{owner}\Parameter{commands}
\end{Declaration}
\BeginIndex{Cmd}{AtAddToTocList}%
This command
%<*dtx>
%\fi
\DescribeMacro{\AtAddtoTocList}
Command \Macro{AtAddToTocList}\OParameter{owner}\Parameter{commands}
% \iffalse
%</dtx>
% \fi
adds the \PName{commands} to a internal list of commands, that should be
processed, if a toc-file with the given \PName{owner} will be added to the
list of known extensions using \Macro{addtotoclist}.  If you omit the optional
argument, \Package{tocbasic} tries to find out the filename of the current
processed class or package and stores this as owner.  This will fail if
\Macro{AtAddToTocList} was not used, loading a class or package but using a
command of a class or package after loading this class or package.  In this
case the owner will be set to ``\PValue{.}''.  Note that an empty
\PName{owner} is not the same like omitting the optional argument. With an
empty \PName{owner} you may add \Parameter{commands}, that will be processed
at every succefull \Macro{addtotoclist}, after processing the commands for the
indivdual owner.  While processing the \PValue{commands}, \Macro{@currext} wil
be set to the extension of the currently added extension.
\begin{Example}
\Package{tocbasic} itself uses
\begin{lstlisting}
  \AtAddToTocList[]{%
    \expandafter\tocbasic@extend@babel
    \expandafter{\@currext}%
  }
\end{lstlisting}
to add every extension to the \Package{tocbasic}-internal babel handling of
toc-files.  The \Macro{expandafter} are needed, because the argument of
\Macro{tocbasic@extend@babel} has to expanded!  See the description of
\Macro{tocbasic@extend@babel} at \autoref{sec:tocbasic.internals}%
% \iffalse
, \autopageref{desc:tocbasic.cmd.tocbasic@extend@babel}
% \fi
for more information.
\end{Example}
% \iffalse
\EndIndex{Cmd}{AtAddToTocList}%

\begin{Declaration}
  \Macro{removefromtoclist}\OParameter{owner}\Parameter{extension}
\end{Declaration}
\BeginIndex{Cmd}{removefromtoclist}%
This command
%<*dtx>
%\fi
\DescribeMacro{\removefromtoclist}
Command \Macro{removefromtotoclist}\OParameter{owner}\Parameter{extension}
% \iffalse
%</dtx>
% \fi
removes the \PName{extension} from the list of known extensions.  If the
optional argument, \OParameter{owner}, was given the \PName{extension} will
only be removed, if it was added by this \PName{owner}.  If you omit the
optional argument, \Package{tocbasic} tries to find out the filename of the
current processed class or package and use this as owner.  This will fail if
\Macro{removefromtoclist} was not used, loading a class or package but using a
command of a class or package after loading this class or package.  In this
case the owner will be set to ``\PValue{.}''.  Note that an empty
\PName{owner} is not the same like omitting the optional argument, but removes
the \PName{extension} without any owner test.
% \iffalse
\EndIndex{Cmd}{removefromtoclist}%

\begin{Declaration}
  \Macro{doforeachtocfile}\OParameter{owner}\Parameter{commands}
\end{Declaration}
\BeginIndex{Cmd}{doforeachtocfile}%
This command
%<*dtx>
% \fi
\DescribeMacro{\doforeachtocfile}
Command \Macro{doforeachtocfile}\OParameter{owner}\Parameter{commands}
% \iffalse
%</dtx>
% \fi
processes \PName{commands} for every known toc-file of the given
\PName{owner}.  While processing the \PName{commands} \Macro{@currext} ist the
extension of the current toc-file for every known toc-file.  If you omit the
optional argument, \OParameter{owner}, every known toc-file will be used. If
the optional argument is empty, only toc-files with an empty owner will be
used.
\begin{Example}
  If you want to type out all known extensions, you may simply write:
  \begin{lstlisting}
  \doforeachtocfile{\typeout{\@currext}}
  \end{lstlisting}
  and if only the extensions of owner ``\PValue{foo}'' should be typed out:
  \begin{lstlisting}
  \doforeachtocfile[foo]{\typeout{\@currext}}
  \end{lstlisting}
\end{Example}
% \iffalse
\EndIndex{Cmd}{doforeachtocfile}%

%<*dtx>
% \fi
\DescribeMacro{\tocbasicautomode}
Command
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{tocbasicautomode}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{tocbasicautomode}%
This command
% \fi
redefines \LaTeX{} kernel macro \Macro{@starttoc} to add all not yet added
extensions to the list of known extensions and use \Macro{tocbasic@starttoc}
instead of \Macro{@starttoc}.
% \iffalse
\EndIndex{Cmd}{tocbasicautomode}%
% \fi

\subsection{Creating a List of Something}
\label{sec:tocbasic.more}

At the previous section you've seen commands to handle a list of known
extensions and to trigger commands while adding a new extension to this
list. You've also seen a command to do something for all known extensions or
all known extensions of one owner. In this section you will see commands to
handle the file corresponding with an extension or the list of known
extensions.

% \iffalse
\begin{Declaration}
  \Macro{addtoeachtocfile}\OParameter{owner}\Parameter{contents}
\end{Declaration}
\BeginIndex{Cmd}{addtoeachtocfile}%
This command
%<*dtx>
% \fi
\DescribeMacro{\addtoeachtocfile}
Command \Macro{addtoeachtocfile}\OParameter{owner}\Parameter{contents}
% \iffalse
%</dtx>
% \fi
writes \PName{contents} to every known toc-file of \PName{owner}. If you omit
the optional argument, \PName{contents} it written to every known
toc-file. While writing the contents, \Macro{@currext} is the extension of
the currently handled toc-file.
\begin{Example}
  You may add a vertical space of one text line to all toc-files.
  \begin{lstlisting}
    \addtoeachtocfile{%
      \protect\addvspace{\protect\baselineskip}%
    }
  \end{lstlisting}
  And if you want to do this, only for the toc-files of owner
  ``\PValue{foo}'':
  \begin{lstlisting}
    \addtoeachtocfile[foo]{%
      \protect\addvspace{\protect\baselineskip}%
    }
  \end{lstlisting}
\end{Example}
% \iffalse
\EndIndex{Cmd}{addtoeachtocfile}%

\begin{Declaration}
  \Macro{addcontentslinetoeachtocfile}\OParameter{owner}\Parameter{level}%
  \Parameter{contentsline}
\end{Declaration}
\BeginIndex{Cmd}{addcontentslinetoeachtocfile}%
This command
%<*dtx>
% \fi
\DescribeMacro{\addcontentslinetoeachfile}
Command \Macro{addcontentslinetoeachtocfile}\OParameter{owner}%^^A
\Parameter{level}\Parameter{contentsline} 
% \iffalse
%</dtx>
% \fi
is something like \Macro{addcontentsline} not only for one file, but all known
toc-files or all known toc-files of a given owner.
\begin{Example}
  You are a class author and want to write the chapter entry not only to the
  table of contents toc-file but to all toc-files, while \texttt{\#1} is the
  title, that should be written to the files.
  \begin{lstlisting}
    \addcontentslinetoeachtocfile{chapter}{%
      \protect\numberline{\thechapter}#1}
  \end{lstlisting}
\end{Example}
% \iffalse
\EndIndex{Cmd}{addcontentslinetoeachtocfile}%

%<*dtx>
% \fi
\DescribeMacro{\listoftoc}
\DescribeMacro{\listoftoc*}
Commands
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{listoftoc*}\Parameter{extension}
% \iffalse
\\
%<*dtx>
% \fi
and
% \iffalse
%</dtx>
% \fi
  \Macro{listoftoc}\OParameter{list of title}\Parameter{extension}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{listoftoc*}%
\BeginIndex{Cmd}{listoftoc}%
This commands
% \fi
may be used to set the ``list of'' of a toc-file. The star version
\Macro{listoftoc*} needs only one argument, the extension of the toc-file. It
does setup the vertical and horizontal spacing of paragraphs, calls before and
after hooks and reads the toc-file.  You may use it as direct replacement of
the \LaTeX{} kernel macro \Macro{@starttoc}.

The version without star, sets the whole toc-file with title, optional table
of contents entry, and running heads. If the optional argument
\OParameter{list of title} was given, it will be used as title term, optional
table of contents entry and running head. Note: If the optional argument is
empty, this term will be empty, too! If you omit the optional argument, but
\Macro{listof\PName{extension}name} was defined, that will be used.

\begin{Example}
  You have a new ``list of algorithms'' with extension \PValue{loa} and want to
  show it.
  \begin{lstlisting}
  \listof[list of algorithm]{loa}
  \end{lstlisting}
  Maybe you want, that the ``list of algorithms'' will create an entry at the
  table of contents. You may set
  \begin{lstlisting}
  \setuptoc{loa}{totoc}
  \end{lstlisting}
  But maybe the ``list of algorithms'' should not be set with a title. So you
  may use
  \begin{lstlisting}
  \listof*{loa}
  \end{lstlisting}
  Note that in this case no entry at the table of contents will be created,
  even if you'd used the setup command above.
\end{Example}

The default heading new following features using \Macro{setuptoc}:
\begin{description}
\item[\texttt{totoc}] writes the title of the list of to the table of contents
\item[\texttt{numbered}] uses a numbered headings for the list of
\item[\texttt{leveldown}] uses not the top level heading (e.g., \Macro{chapter}
  with book) but the first sub level (e.g., \Macro{section} with book).
\end{description}
% \iffalse
\EndIndex{Cmd}{listoftoc*}%
\EndIndex{Cmd}{listoftoc}%

%<*dtx>
% \fi
\DescribeMacro{\BeforeStartingTOC}
\DescribeMacro{\AfterStartingTOC}
The Commands
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{BeforeStartingTOC}\OParameter{extension}\Parameter{commands}
% \iffalse
\\
%<*dtx>
% \fi
and
% \iffalse
%</dtx>
% \fi
  \Macro{AfterStartingTOC}\OParameter{extension}\Parameter{commands}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{BeforeStartingTOC}%
\BeginIndex{Cmd}{AfterStartingTOC}%
This commands
% \fi
may be used to process \PName{commands} before or after loading the toc-file
with given \PName{extension} using \Macro{listoftoc*} or \Macro{listoftoc}. If
you omit the optional argument (or set an empty one) the general hooks will be
set. The general before hook will be called before the individuel one and the
general after hook will be called after the individuel one. While calling the
hooks \Macro{@currext} is the extension of the toc-file and should not be
changed.
% \iffalse
\EndIndex{Cmd}{AfterStartingTOC}%
\EndIndex{Cmd}{BeforeStartingTOC}%

%<*dtx>
% \fi
\DescribeMacro{\BeforeTOCHead}
\DescribeMacro{\AfterTOCHead}
The Commands
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{BeforeTOCHead}\OParameter{extension}\Parameter{commands}
% \iffalse
\\
%<*dtx>
% \fi
and
% \iffalse
%</dtx>
% \fi
  \Macro{AfterTOCHead}\OParameter{extension}\Parameter{commands}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{BeforeTOCHead}%
\BeginIndex{Cmd}{AfterTOCHead}%
This commands
% \fi
may be used to process \PName{commands} before or after setting the title of a
toc-file with given \PName{extension} using \Macro{listoftoc*} or
\Macro{listoftoc}. If you omit the optional argument (or set an empty one) the
general hooks will be set. The general before hook will be called before the
individuel one and the general after hook will be called after the individuel
one. While calling the hooks \Macro{@currext} is the extension of the toc-file
and should not be changed.
% \iffalse
\EndIndex{Cmd}{AfterTOCHead}%
\EndIndex{Cmd}{BeforeTOCHead}%

%<*dtx>
% \fi
\DescribeMacro{\listofeachtoc}
Command
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{listofeachtoc}\OParameter{owner}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{listofeachtoc}%
This command
% \fi
sets all toc-files or all toc-files of the given \PName{owner} using
\Macro{listoftoc}. You should have defined
\Macro{listof\PName{extension}name} for each toc-file, otherwise you'll get a
warning.
% \iffalse
\EndIndex{Cmd}{listofeachtoc}%

%<*dtx>
% \fi
\DescribeMacro{\MakeMarkcase}
Command
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{MakeMarkcase}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{MakeMarkcase}%
This command
% \fi
will be used to change the case of the letters at the running
head. The default is, to use \Macro{@firstofone} for \KOMAScript{} classes and
\Macro{MakeUppercase} for all other classes. If you are the class author you
may define \Macro{MakeMarkcase} on your own. If \Package{scrpage2} or another
package, that defines \Macro{MakeMarkcase} will be used, \Package{tocbasci}
will not overwrite that Definition.
% \iffalse
\EndIndex{Cmd}{MakeMarkcase}%

%<*dtx>
% \fi
\DescribeMacro{\deftocheading}
Command
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{deftocheading}\Parameter{extension}\Parameter{definition}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{deftocheading}%
This command
% \fi
defines a heading command, that will be used instead of the
default heading using \Macro{listoftoc}. The heading command has exactly one
argument. You may reference to that argument using \texttt{\#1} at your
\PName{defintion}.
% \iffalse
\EndIndex{Cmd}{deftocheading}%

%<*dtx>
% \fi
\DescribeMacro{\setuptoc}
\DescribeMacro{\unsettoc}
The Commands
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{setuptoc}\Parameter{extension}\Parameter{featurelist}
% \iffalse
\\
%<*dtx>
% \fi
and
% \iffalse
%</dtx>
% \fi
  \Macro{unsettoc}\Parameter{extension}\Parameter{featurelist}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{setuptoc}%
\BeginIndex{Cmd}{unsettoc}%
This commands
% \fi
set up and unset features binded to an \PName{extension}. The
\PName{featurelist} is a comma seperated list of single
features. \Package{tocbasic} does know following features:
\begin{description}
\item[\texttt{totoc}] writes the title of the list of to the table of contents
\item[\texttt{numbered}] uses a numbered headings for the list of
\item[\texttt{leveldown}] uses not the top level heading (e.g., \Macro{chapter}
  with book) but the first sub level (e.g., \Macro{section} with book).
\item[\texttt{onecolumn}] switchs to internal one column mode, if the toc
  is set in internal two column mode and no \texttt{leveldown} was used.
\item[\texttt{nobabel}] prevents the extension to be added to the babel
  handling of toc-files.  To make this work, you have to set the feature
  before adding the extension to the list of known extension.
\item[\texttt{noprotrusion}] prevents disabling character protrusion at the
  lists of something. Character protrusion at the lists will be disabled by
  default if package \Package{microtype} or another package, that supports
  \Macro{microtypesetup}, was loaded. So if you want protrusion at the lists,
  you have to set this feature. But note, that with character protrusion
  entries at the list may be set wrong. This is a known issue of character
  protrusion.
\end{description}
Classes and packages may know features, too, e.g, the \KOMAScript{} classes
know following additional features:
\begin{description}
\item[\texttt{chapteratlist}] activates special code to be put into the list
  at start of a new chapter. This code may either be vertical space or the
  heading of the chapter.
\end{description}
% \iffalse
\EndIndex{Cmd}{unsettoc}%
\EndIndex{Cmd}{setuptoc}%

%<*dtx>
% \fi
\DescribeMacro{\iftocfeature}
Command
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{iftocfeature}\Parameter{extension}\Parameter{feature}%^^A
  \Parameter{true-part}\Parameter{false-part}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{iftocfeature}%
This command
% \fi
may be used, to test, if a \PName{feature} was set for \PName{extension}. If
so the \PName{true-part} will be processed, otherwise the \PName{false-part}
will be.
% \iffalse
\EndIndex{Cmd}{iftocfeature}%
% \fi


\subsection{Generating new Lists of and new Floats}
\label{sec:tocbasic.highlevel}

There is one simple command to generate either a new list of foo or a new list
of a new float.

% \iffalse
%<*dtx>
% \fi
\DescribeMacro{\DeclareNewTOC}
Command
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{DeclareNewTOC}\OParameter{options}\Parameter{extension}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{DeclareNewTOC}%
This command
% \fi
declares at least a new list of \PName{extension}. Depending on the
\PName{options} it may also define a new float. The mandatory argument
\PName{extension} is the extension of the help file for that list. See the
prior sections for more informations about this. The optional parameter
\PName{options} is a comma separated list of \emph{key}=\emph{value}
pairs.
\begin{description}
\item[\normalfont\PValue{atbegin}=\PName{code}]\hfill\\*
  The \PName{code} will be executed at the begin of the float or nonfloat
  environment.
\item[\normalfont\PValue{atend}=\PName{code}]\hfill\\*
  The \PName{code} will be executed at the end of the float or nonfloat
  environment.
%^^A not yet implemented
%^^A \item[\normalfont\PValue{captionpos}=\PName{position}]\hfill\\*
%^^A   If \PName{position} is \PValue{top} or \PValue{above} the spacing above
%^^A   and below the caption will be done for captions above objects. If
%^^A   \PName{position} is \PValue{bot}, \PValue{bottom}, or \PValue{below} the
%^^A   spacing above and below the caption will be done for captions below
%^^A   objects.
\item[\normalfont\PValue{counterwithin}=\PName{parent counter}]\hfill\\*
  If you define a float or nonfloat, the captions will be numbered. You may
  declare another counter to be the parent counter. In this case, the parent
  counter will be set before the float counter and the float counter will be
  reset whenever the parent counter is increased using \Macro{stepcounter}
  oder \Macro{refstepcounter}.
\item[\normalfont\PValue{float}]\hfill\\*
  If set, float environments for that type will be defined. The names of the
  environments are the value of \PName{type} and for double column floats the
  value of \PName{type} with postfix ``\PValue{*}''.
\item[\normalfont\PValue{floatpos}=\PName{float positions}]\hfill\\*
  The default floating-position of the float. If no float position was given,
  ``tbp'' will be used like the standard classes do for figures and tables.
\item[\normalfont\PValue{floattype}=\PName{number}]\hfill\\*
  The numericle float type of the defined floats. Float types with common bits
  cannot be reordered. At the standard classes figures has float type 1 and
  tables has float type 2. If no float type was given, 16 will be used.
\item[\normalfont\PValue{forcenames}]\hfill\\*
  If set, the names will be even defined, if they where already defined
  before.
\item[\normalfont\PValue{hang}=\PName{length}]\hfill\\*
  The amount of the hanging indent of the entries for that list. If not given,
  1.5\,em will be used like standard classes use for entries to list of
  figures or list of tables.
\item[\normalfont\PValue{indent}=\PName{length}]\hfill\\*
  The indent value for the entries of that list. If not given, 1\,em will be
  used like standard classes use for entries to list of figures or list of
  tables.
\item[\normalfont\PValue{level}=\PName{number}]\hfill\\*
  The level of the entries of that list. If not given level 1 will be used
  like standard classes use for entries to list of figures or list of tables.
\item[\normalfont\PValue{listname}=\PName{string}]\hfill\\*
  The name of the list of foo. If not given the value of \PValue{types} with
  upper case first char prefixed by ``List of '' will be used.
\item[\normalfont\PValue{name}=\PName{string}]\hfill\\*
  The name of an element. If no name is given, the value of \PValue{type} with
  upper case first char will be used.
\item[\normalfont\PValue{nonfloat}]\hfill\\*
  If set, a non floating environment will be defined. The name of the
  environment is the value of \PName{type} with postfix ``\PValue{-}''.
\item[\normalfont\PValue{owner}=\PName{string}]\hfill\\*
  The owner as described in the sections before. If no owner was given owner
  \PValue{float} will be used.
\item[\normalfont\PValue{type}=\PName{string}]\hfill\\*
  sets the type of the new declared list. The type will be used e.g. to
  defined a \Macro{listof}\PName{string}. If no type is set up the extension
  from the mandatory argument will be used.
\item[\normalfont\PValue{types}=\PName{string}]\hfill\\*
  the plural of the type. If no plural was given the value of \PValue{type}
  with postfix ``s'' will be used.
\end{description}


\subsection{Internal Commands for Class and Package Authors}
\label{sec:tocbasic.internals}

Commands with prefix \Macro{tocbasic@} are internal but class and package
authors may use them. But even if you are a class or package author you
should not change them!

% \iffalse
%<*dtx>
% \fi
\DescribeMacro{\tocbasic@extend@babel}
Command
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{tocbasic@extend@babel}\Parameter{extension}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{tocbasic@extend@babel}%
This command
% \fi
extends the babel handling of toc-files. By default babel writes language
selections only to \PValue{toc}, \PValue{lot} and
\PValue{lof}. \Package{tocbasic} adds every \PName{extension} added to the
list of known extensions (see \Macro{addtotoclist}, \autoref{sec:tocbasic.basics}%
% \iffalse
, \autopageref{desc:tocbasic.cmd.addtotoclist}%
% \fi
) using \Macro{tocbasic@extend@babel}. Note: This should be called only once
per \PName{extension}. \Macro{tocbasic@extend@babel} does nothing, if the
feature \PValue{nobabel} was set for \PName{extension} before using
\Macro{addtotoclist}.
% \iffalse
\EndIndex{Cmd}{tocbasic@extend@babel}%

%<*dtx>
% \fi
\DescribeMacro{\tocbasic@starttoc}
Command
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{tocbasic@starttoc}\Parameter{extension}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{tocbasic@starttoc}
This command is something like the \LaTeX{} kernel macro \Macro{@starttoc},
but does some additional settings before using \Macro{@starttoc}. It does set
\Macro{parskip} zu zero, \Macro{parindent} to zero, \Macro{parfillskip} to
zero plus one fil, \Macro{@currext} to the \PName{extension}, and processes
hooks before and after reading the toc-file.
\EndIndex{Cmd}{tocbasic@starttoc}
% \fi
%


% \iffalse
%<*dtx>
% \fi
\DescribeMacro{\tocbasic@@before@hook}
\DescribeMacro{\tocbasic@@after@hook}
\def\\{ and }%^^A
Macros
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{tocbasic@@before@hook}\\
  \Macro{tocbasic@@after@hook}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{tocbasic@@before@hook}%
\BeginIndex{Cmd}{tocbasic@@after@hook}%
This macros
% \fi
are processed before and after loading a toc-file. If you don't use
\Macro{listoftoc} or \Macro{listoftoc*} or \Macro{tocbasic@starttoc} to load
the toc-file, you should call these, too. But you should not redefine them!
% \iffalse
\EndIndex{Cmd}{tocbasic@@before@hook}%
\EndIndex{Cmd}{tocbasic@@after@hook}%

%<*dtx>
% \fi
\DescribeMacro{\tocbasic@\PName{extension}@before@hook}
\DescribeMacro{\tocbasic@\PName{extension}@after@hook}
\def\\{ and }%^^A
Macros
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{tocbasic@\PName{extension}@before@hook}\\
  \Macro{tocbasic@\PName{extension}@after@hook}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{tocbasic@\PName{extension}@before@hook}%
\BeginIndex{Cmd}{tocbasic@\PName{extension}@after@hook}%
This macros
% \fi
are processed before and after loading a toc-file. If you don't use
\Macro{listoftoc} or \Macro{listoftoc*} or \Macro{tocbasic@starttoc} to load
the toc-file, you should call these, too. But you should not redefine them!
The first macro is processed just before \Macro{tocbasic@@before@hook}, the
second one just after \Macro{tocbasic@@after@hook}
% \iffalse
\EndIndex{Cmd}{tocbasic@\PName{extension}@after@hook}%
\EndIndex{Cmd}{tocbasic@\PName{extension}@before@hook}%

%<*dtx>
% \fi
\DescribeMacro{\tocbasic@listhead}
Command
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{tocbasic@listhead}\Parameter{title}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{tocbasic@listhead}%
This command
% \fi
is used by \Macro{listoftoc} to set the heading of the list, either the
default heading or the indiviually defined heading. If you define your own
list command not using \Macro{listoftoc} you may use
\Macro{tocbasic@listhead}. In this case you should define \Macro{@currext} to
be the extension of the toc-file before using \Macro{tocbasic@listhead}.
% \iffalse
\EndIndex{Cmd}{tocbasic@listhead}%

%<*dtx>
% \fi
\DescribeMacro{\tocbasic@listhead@\PName{extension}}
Command
% \iffalse
%</dtx>
\begin{Declaration}
% \fi
  \Macro{tocbasic@listhead@\PName{extension}}\Parameter{title}
% \iffalse
\end{Declaration}
\BeginIndex{Cmd}{tocbasic@listhead@\PName{extension}}%
This command
% \fi
is used in \Macro{tocbasic@listhead} to set the individual headings, optional
toc-entry, and running head, if it was defined. If it was not defined it will
be defined and used in \Macro{tocbasic@listhead}.
% \iffalse
\EndIndex{Cmd}{tocbasic@listhead@\PName{extension}}%
%</doc|dtx>
% \fi
%
% \StopEventually{\PrintIndex\PrintChanges}
%
%
% \section{Implementation}
% \label{sec:implementation}
%
% All macros with prefix \texttt{tb@} or \texttt{@} are internal macros and
% should not be used by package and class authors. Macros with prefix
% \texttt{tocbasic@} are internal macros, that may be used by class and
% packages authors. Macros without \texttt{@} are interface macros and may be
% used by class and package authors and users.
%
% \iffalse
%<*package>
% \fi
%
% \subsection{Options}
% \label{sec:options}
%
% There are no options because the package should be used by class and package
% authors not by users. So the package will be loaded using
% \Macro{RequiresPackage}. Using different options by different packages would
% result in an option clash.
%    \begin{macrocode}
\ProcessOptions\relax
%    \end{macrocode}
%
%
% \subsection{Required Packages}
% \label{sec:packages}
%
% Currently only graphics bundle's package \Package{keyval} is needed.
%    \begin{macrocode}
\RequirePackage{keyval}
%    \end{macrocode}
% We load it after processing the options, because we don't need it for
% processing options.
%
%
% \subsection{Having a List of All Tocs}
% \label{sec:listoftocs}
%
% If we have a list of all toc-files we may do commands for all
% toc-files. Somethimes it may be usefull to known the package, that created
% the toc-file, so this information will be stored additionally.
%
% \begin{macro}{\tb@listoftocs}
%   This is the list of toc-files. The list will be:
%   \begin{quote}
%   \cs{do}\marg{extension}\marg{class or
%   package}\cs{do}\marg{extension}\marg{class or package}\dots
%   \end{quote}
%   With this, adding and processing the list will be very fast but removing
%   an element will be very slow.
%
%   The initial state of the list will be \emph{empty}.
%    \begin{macrocode}
\newcommand*{\tb@listoftocs}{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifattoclist}
%   This command tests, if an extension is already at the list of
%   toc-files. The extension has to be the first argument. The second argument
%   will be done, if the extension is already at the list of toc-files. The
%   third argument will be done, if the extension is at the list of toc-files
%   not yet.
%    \begin{macrocode}
\newcommand{\ifattoclist}[1]{%
  \begingroup
    \def\do##1##2{%
      \edef\reserved@a{##1}%
      \ifx\reserved@a\reserved@b\@tempswatrue\fi
    }%
    \edef\reserved@b{#1}\@tempswafalse\tb@listoftocs
    \if@tempswa\aftergroup\@firstoftwo\else\aftergroup\@secondoftwo\fi
  \endgroup
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\addtotoclist}
%   \changes{v1.0a}{2008/11/11}{internal \cs{@addtotoclist} renamed to
%     \cs{scr@addtotoclist} because of package \textsf{floatfram}}.%
%   \changes{v1.0a}{2008/11/11}{internal \cs{@@addtotoclist} renamed to
%     \cs{scr@@addtotoclist} because of package \textsf{floatfram}}.%
%   \changes{v3.06a}{2010/09/14}{expand the arguments while adding them to the
%     internal list}
%   This command adds an extension to the list of toc-files. The first,
%   optional argument is the class or package name with the corresponding
%   extension of class or package files. If this argument was omitted
%   \textsf{tocbasic} tries to get it automatically. This should be
%   successfull while loading a class or package but not while processing any
%   command of a class or package after loading the class or package. The
%   second, mandatory argument is the extension of the toc-file. NOTE: An
%   empty first argument is not the same like omitting the first argument!
%    \begin{macrocode}
\newcommand*{\addtotoclist}{%
  \@ifnextchar [%]
    \scr@@addtotoclist\scr@addtotoclist
}
\newcommand*{\scr@addtotoclist}{%
  \ifx\@currname\@empty
    \def\reserved@a{\scr@@addtotoclist[]}%
  \else
    \edef\reserved@a{\noexpand\scr@@addtotoclist[\@currname.\@currext]}%
  \fi
  \reserved@a
}
\newcommand*{\scr@@addtotoclist}[2][]{%
  \ifattoclist{#2}{%
    \PackageError{tocbasic}{%
      file extension `#2' cannot be used twice
    }{%
      File extension `#2' is already used by a toc-file, while
      \ifx\relax#1\relax someone\else #2\fi\MessageBreak
      tried to use it again for a toc-file.\MessageBreak
      This may be either an incompatibility of packages, an error at a
      package,\MessageBreak
      or a mistake by the user.\MessageBreak
    }%
  }{%
    \begingroup
      \protected@edef\reserved@a{%
        \noexpand\g@addto@macro\noexpand\tb@listoftocs{%
          \noexpand\do{#2}{#1}}}\reserved@a
    \endgroup
    \ifx\relax #1\relax\else
      \@ifundefined{tb@#1@add@hook}{}{%
        \edef\reserved@a{%
          \noexpand\def\noexpand\@currext{#2}%
          \noexpand\@nameuse{tb@#1@add@hook}%
          \noexpand\def\noexpand\@currext{\@currext}%
        }\reserved@a
      }%
    \fi
    \edef\reserved@a{%
      \noexpand\def\noexpand\@currext{#2}%
      \noexpand\@nameuse{tb@@add@hook}%
      \noexpand\def\noexpand\@currext{\@currext}%
    }\reserved@a
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\AtAddToTocList}
%   Action to be done, when adding a toc-file of a known owner. The first
%   optional argument is the owner. The second, mandatory argument is the
%   action. While doing the action \cs{@currext} will be the extension of the
%   added toc-file. If the first argument was omitted \textsf{tocbasic} tries
%   to get it automatically. This should be successfull while loading a class
%   or package but not while processing any command of a class or package
%   after loading the class or package. The second, mandatory argument is the
%   extension of the toc-file. NOTE: An empty first argument is not the same
%   like omitting the first argument, but set's up the general hook. The
%   general hook will be done for every adding after the individual hook (this
%   means, you may dactivate features at the individual hook before processing
%   the general hook). But the individual hook will not be processed for
%   toc-files without any owner!
%    \begin{macrocode}
\newcommand*{\AtAddToTocList}{%
  \@ifnextchar [%]
    \@@AtAddToTocList\@AtAddToTocList
}
\newcommand*{\@AtAddToTocList}{%
  \ifx\@currname\@empty
    \def\reserved@a{\@@AtAddToTocList[]}%
  \else
    \edef\reserved@a{\noexpand\@@AtAddToTocList[\@currname.\@currext]}%
  \fi
  \reserved@a
}
\newcommand*{\@@AtAddToTocList}[1][]{%
  \@ifundefined{tb@#1@add@hook}{\@namedef{tb@#1@add@hook}{}}{}%
  \expandafter\g@addto@macro\csname tb@#1@add@hook\endcsname
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\tocbasic@extend@babel}
%   NOTE: To extend the original \cs{bbl@set@language} the argument of
%   \cs{tocbasic@extend@babel} must not be a local macro (like \cs{@currext})
%    \begin{macrocode}
\newcommand*{\tocbasic@extend@babel}[1]{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \ifx\csname bbl@set@language\endcsname\relax
    \PackageInfo{tocbasic}{babel extension for `#1' omitted\MessageBreak
      because of missing \string\bbl@set@language}%
  \else
    \iftocfeature{#1}{nobabel}{%
      \PackageInfo{tocbasic}{omitting babel extension for `#1'\MessageBreak
        because of feature `nobabel' available\MessageBreak
        for `#1'}%
    }{%
      \PackageInfo{tocbasic}{setting babel extension for `#1'}%
      \expandafter\gdef\expandafter\bbl@set@language\expandafter##\expandafter1%
      \expandafter{%
        \bbl@set@language{##1}%
        \addtocontents{#1}{\xstring\select@language{\languagename}}%
      }%
    }%
  \fi
}
%    \end{macrocode}
%   This feature should be used for all toc-files (unless feature
%   \texttt{nobabel} was set for the toc-file.
%    \begin{macrocode}
\AtAddToTocList[]{\expandafter\tocbasic@extend@babel\expandafter{\@currext}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\removefromtoclist}
%   This command will remove an extension from the list of toc-files. If the
%   first, optional argument is given, the extension will only be removed, if
%   it was added by the given owner. NOTE: An empty first argument is not the
%   same like omitting the first argument!
%    \begin{macrocode}
\newcommand*{\removefromtoclist}{%
  \@ifnextchar [%]
    \@removefromtoclist\@@removefromtoclist
}
\newcommand*{\@removefromtoclist}[2][]{%
  \begingroup
    \let\tb@oldlist\tb@listoftocs
    \def\do##1##2{%
      \edef\reserved@a{##1}%
      \ifx\reserved@a\reserved@b
        \begingroup
          \edef\reserved@a{##2}%
          \edef\reserved@b{#1}%
          \ifx\reserved@a\reserved@b\else
            \g@addto@macro\tb@listoftocs{\do{##1}{##2}}%
          \fi
        \endgroup
      \else
        \g@addto@macro\tb@listoftocs{\do{##1}{##2}}%
      \fi
    }%
    \edef\reserved@b{#2}\let\tb@listoftocs\@empty
    \tb@oldlist
  \endgroup
}
\newcommand*{\@@removefromtoclist}[1]{%
  \begingroup
    \let\tb@oldlist\tb@listoftocs
    \def\do##1##2{%
      \edef\reserved@a{##1}%
      \ifx\reserved@a\reserved@b\else
        \g@addto@macro\tb@listoftocs{\do{##1}{##2}}%
      \fi
    }%
    \edef\reserved@b{#1}\let\tb@listoftocs\@empty
    \tb@oldlist
  \endgroup
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\doforeachtocfile}
%   \changes{v3.09}{2011/03/01}{\cs{@currext} defined using \cs{edef} instead
%     of \cs{def}}
%   This command does the second, mandatory argument for each toc-file at the
%   list of toc-files. If the first, optional argument was given this will be
%   done only for the toc-files of that owner. NOTE: An empty first argument
%   is not the same like omitting the first argument!
%
%   While processing the second argument \cs{@currext} is the extension of
%   the toc-file. The second argument will be processed with increased group
%   level!
%
%   See \cs{addtoeachtocfile} for an example of usage of
%   \cs{doforeachtocfile}.
%    \begin{macrocode}
\newcommand{\doforeachtocfile}{%
  \@ifnextchar [%]
    \@doforeachtocfile\@@doforeachtocfile
}
\newcommand{\@doforeachtocfile}[2][]{%
  \def\do##1##2{%
    \edef\reserved@a{#1}\edef\reserved@b{##2}\ifx\reserved@a\reserved@b
      \edef\@currext{##1}#2%
    \fi
  }%
  \edef\reserved@a{%
    \noexpand\tb@listoftocs
    \noexpand\def\noexpand\@currext{\@currext}%
  }\reserved@a
  \let\do\relax
}
\newcommand{\@@doforeachtocfile}[1]{%
  \def\do##1##2{%
    \edef\@currext{##1}#1%
  }%
  \edef\reserved@a{%
    \noexpand\tb@listoftocs
    \noexpand\def\noexpand\@currext{\@currext}%
  }\reserved@a
  \let\do\relax
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\addtoeachtocfile}
% \begin{macro}{\@addtoeachtocfile}
% \begin{macro}{\@@addtoeachtocfile}
%   \changes{v3.03b}{2009/06/08}{typo fix at usage of \cs{doforeachtocfile}}
%   This command calls \cs{addtocontents} with the section, mandatory
%   argument for each toc-file at the list of toc-files. If the first,
%   optional argument was given this will be done only for the toc-files of
%   that owener. NOTE: An empty first argument is not the same like omitting
%   the first argument! And don't forget to protect the commands, that should
%   not be expanded, at the mandatory argument.
%    \begin{macrocode}
\newcommand{\addtoeachtocfile}{%
  \@ifnextchar [%]
    \@addtoeachtocfile\@@addtoeachtocfile
}
\newcommand{\@addtoeachtocfile}[2][]{%
  \doforeachtocfile[{#1}]{\addtocontents{\@currext}{#2}}%
}
\newcommand{\@@addtoeachtocfile}[1]{%
  \doforeachtocfile{\addtocontents{\@currext}{#1}}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\addcontentslinetoeachtocfile}
%   Something like a combination of \cs{addtoeachtocfile} and
%   \cs{addcontentsline}.
%    \begin{macrocode}
\newcommand{\addcontentslinetoeachtocfile}{%
  \@ifnextchar [%]
    \@addcontentslinetoeachtocfile\@@addcontentslinetoeachtocfile
}
\newcommand{\@addcontentslinetoeachtocfile}[3][]{%
  \doforeachtocfile[{#1}]{\addcontentsline{\@currext}{#2}{#3}}%
}
\newcommand{\@@addcontentslinetoeachtocfile}[2]{%
  \doforeachtocfile{\addcontentsline{\@currext}{#1}{#2}}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Show List of Toc-File}
% \label{sec:showlistoftocfile}
%
% If you have a toc-file you want a list-of-command for this toc-file,
% too. Here are basics and high level commands for this.
%
% \begin{macro}{\tocbasic@starttoc}
%   Some basics are done like setting up \cs{parskip}, \cs{parindent} and
%   \cs{parfillskip}, a general hook will be called, an individual hook will
%   be called, the toc will be started, an individual hook will be called, an
%   general hook wil be called, that's it.
%    \begin{macrocode}
\newcommand*{\tocbasic@starttoc}[1]{%
  \begingroup
    \setlength{\parskip}{\z@}%
    \setlength{\parindent}{\z@}%
    \setlength{\parfillskip}{\z@\@plus 1fil}%
    \edef\@currext{#1}%
    \csname tocbasic@@before@hook\endcsname
    \csname tb@#1@before@hook\endcsname
    \@starttoc{#1}%
    \csname tb@#1@after@hook\endcsname
    \csname tocbasic@@after@hook\endcsname
  \endgroup
}
%    \end{macrocode}
% \begin{macro}{\tocbasic@@before@hook}
% \begin{macro}{\tocbasic@@after@hook}
%   These are the general hooks. They may be used by classes and packages for
%   commands, that should be used for all lists of not only the own lists of,
%   e.g., \KOMAScript{} may use it to handle option \texttt{tocleft}.
%    \begin{macrocode}
\newcommand*{\tocbasic@@before@hook}{}
\newcommand*{\tocbasic@@after@hook}{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\BeforeStartingTOC}
%   \changes{v3.04b}{2010/01/05}{fix: define the hook if not already defined}
%   \changes{v3.06}{2010/06/09}{fix: using \cs{@ifundefined} instead of
%     undefined \cs{scr@ifundefinedorrelax}}
% \begin{macro}{\AfterStartingTOC}
%   \changes{v3.04b}{2010/01/05}{fix:define the hook if not already defined}
%   \changes{v3.06}{2010/06/09}{fix: using \cs{@ifundefined} instead of
%     undefined \cs{scr@ifundefinedorrelax}}
%   These are the commands to add code to the general or individual hooks. If
%   the first, optional argument was given, the second, mandatory argument
%   will be added to the individual hook, otherwise the general hook will be
%   extended.
%    \begin{macrocode}
\newcommand{\BeforeStartingTOC}[2][]{%
  \ifx\relax#1\relax
    \g@addto@macro\tocbasic@@before@hook{#2}%
  \else
    \@ifundefined{tb@#1@before@hook}{%
      \PackageInfo{tocbasic}{defining new hook before starting `#1'}%
      \expandafter\global\expandafter\let\csname tb@#1@before@hook\endcsname
      \@empty
    }{}%
    \expandafter\g@addto@macro\csname tb@#1@before@hook\endcsname{#2}%
  \fi
}
\newcommand{\AfterStartingTOC}[2][]{%
  \ifx\relax#1\relax
    \g@addto@macro\tocbasic@@after@hook{#2}%
  \else
    \@ifundefined{tb@#1@after@hook}{%
      \PackageInfo{tocbasic}{defining new hook after starting `#1'}%
      \expandafter\global\expandafter\let\csname tb@#1@after@hook\endcsname
      \@empty
    }{}%
    \expandafter\g@addto@macro\csname tb@#1@after@hook\endcsname{#2}%
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\listoftoc}
% \begin{macro}{\listoftoc*}
%   \changes{v1.0a}{2008/11/12}{\cs{twocolumn} fixed}%
%   \changes{v1.01}{2008/11/13}{new feature \texttt{onecolumn}}
%   \changes{v3.09}{2011/03/01}{\cs{@currext} defined using \cs{edef} instead
%     of \cs{def}}
%   Command to handle the hole list of something. There are additional hooks
%   for this. The first optional argument is the title for this list. If the
%   optional argument was omitted \cs{listof\#2name} will be used. The star
%   version does not set up a heading or switch the column number!
%    \begin{macrocode}
\newcommand*{\listoftoc}{%
  \@ifstar \tocbasic@starttoc\@listoftoc
}
\newcommand*{\@listoftoc}[2][\list@fname]{%
  \begingroup
    \@ifundefined{listof#2name}{%
      \let\list@fname\relax
      \ifx\relax#1\relax
        \PackageWarning{tocbasic}{%
          You should either define \expandafter\string\csname
          listof#2name\endcsname\MessageBreak
          or use the optional argument of \string\listoftoc\space\MessageBreak
          to set the term to be used for the\MessageBreak
          heading of list of #2}%
        \def\list@fname{\listofname~#2}%
      \fi
    }{%
      \expandafter\let\expandafter\list@fname\csname listof#2name\endcsname
    }%
    \edef\@currext{#2}%
    \iftocfeature{\@currext}{onecolumn}{%
      \iftocfeature{\@currext}{leveldown}{}{%
        \if@twocolumn
          \aftergroup\twocolumn\onecolumn
        \fi
      }%
    }{}%
    \tocbasic@listhead{#1}%
    \begingroup\expandafter\expandafter\expandafter\endgroup
    \expandafter\ifx\csname microtypesetup\endcsname\relax
    \else
      \iftocfeature{\@currext}{noprotrusion}{}{%
        \microtypesetup{protrusion=false}%
        \PackageInfo{tocbasic}{character protrusion at \@currext\space deactivated}%
      }%
    \fi
    \tocbasic@starttoc{#2}%
  \endgroup
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\listofname}
%   While this is only an emergancy command, we don't support languages.
%    \begin{macrocode}
\newcommand*{\listofname}{List of}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\listofeachtoc}
% \begin{macro}{\@listofeachtoc}
% \begin{macro}{\@@listofeachtoc}
%   \changes{v3.03b}{2009/06/08}{typo fix at usage of \cs{doforeachtocfile}}
%   Another example of using \cs{doforeachtocfile}.
%    \begin{macrocode}
\newcommand*{\listofeachtoc}{%
  \@ifnextchar [%]
    \@listofeachtoc\@@listofeachtoc
}
\newcommand{\@listofeachtoc}[1][]{%
  \doforeachtocfile[{#1}]{\listoftoc{\@currext}}%
}
\newcommand{\@@listofeachtoc}[1]{%
  \doforeachtocfile{\listoftoc{\@currext}}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\tocbasic@listhead}
%   \changes{v3.02a}{2009/01/20}{no explicite marks if ``numbered''}
%   Setting the headings of a list of something. The heading is the only
%   argument.
%    \begin{macrocode}
\newcommand*{\tocbasic@listhead}[1]{%
  \@ifundefined{tocbasic@listhead@\@currext}{%
    \begingroup\expandafter\expandafter\expandafter\endgroup
    \expandafter\ifx\csname chapter\endcsname\relax
      \expandafter\def\csname tocbasic@listhead@\@currext\endcsname##1{%
        \iftocfeature{\@currext}{leveldown}{%
          \iftocfeature{\@currext}{numbered}{%
            \subsection[##1]{##1}%
          }{%
            \subsection*{##1}%
            \ifx\@mkboth\@gobbletwo\else\markright{\MakeMarkcase{##1}}\fi
            \iftocfeature{\@currext}{totoc}{%
              \addcontentsline{toc}{subsection}{##1}%
            }{}%
          }%
        }{%
          \iftocfeature{\@currext}{numbered}{%
            \section[##1]{##1\@mkboth{##1}{##1}}%
          }{%
            \section*{##1}%
            \@mkboth{\MakeMarkcase{##1}}{\MakeMarkcase{##1}}%
            \iftocfeature{\@currext}{totoc}{%
              \addcontentsline{toc}{section}{##1}%
            }{}%
          }%
        }%
      }%
    \else
      \expandafter\def\csname tocbasic@listhead@\@currext\endcsname##1{%
        \iftocfeature{\@currext}{leveldown}{%
          \iftocfeature{\@currext}{numbered}{%
            \section{##1}%
          }{%
            \section*{##1}%
            \iftocfeature{\@currext}{totoc}{%
              \addcontentsline{toc}{section}{##1}%
            }{}%
            \ifx\@mkboth\@gobbletwo\else\markright{\MakeMarkcase{##1}}\fi
          }%
        }{%
          \iftocfeature{\@currext}{numbered}{%
            \chapter[##1]{##1\@mkboth{##1}{##1}}%
          }{%
            \chapter*{##1}%
            \@mkboth{\MakeMarkcase{##1}}{\MakeMarkcase{##1}}%
            \iftocfeature{\@currext}{totoc}{%
              \addcontentsline{toc}{chapter}{##1}%
            }{}%
          }%
        }%
      }%
    \fi
  }{}%
  \csname tb@@beforehead@hook\endcsname
  \csname tb@\@currext @beforehead@hook\endcsname
  \csname tocbasic@listhead@\@currext\endcsname{#1}%
  \csname tb@\@currext @afterhead@hook\endcsname
  \csname tb@@afterhead@hook\endcsname
}
%    \end{macrocode}
% \begin{macro}{\BeforeTOCHead}
%   \changes{v3.04b}{2010/01/05}{fix: define the hook if not already defined}
%   \changes{v3.06}{2010/06/09}{fix: using \cs{@ifundefined} instead of
%     undefined \cs{scr@ifundefinedorrelax}}
% \begin{macro}{\AfterTOCHead}
%   \changes{v3.04b}{2010/01/05}{fix: define the hook if not already defined}
%   \changes{v3.06}{2010/06/09}{fix: using \cs{@ifundefined} instead of
%     undefined \cs{scr@ifundefinedorrelax}}
%   These are the commands to add code to the general or individual hooks. If
%   the first, optional argument was given, the second, mandatory argument
%   will be added to the individual hook, otherwise the general hook will be
%   extended.
%    \begin{macrocode}
\newcommand{\BeforeTOCHead}[2][]{%
  \@ifundefined{tb@#1@beforehead@hook}{%
    \PackageInfo{tocbasic}{defining new hook before heading of `#1'}%
    \expandafter\global\expandafter\let\csname tb@#1@beforehead@hook\endcsname
    \@empty
  }{}%
  \expandafter\g@addto@macro\csname tb@#1@beforehead@hook\endcsname{#2}%
}
\newcommand{\AfterTOCHead}[2][]{%
  \@ifundefined{tb@#1@afterhead@hook}{%
    \PackageInfo{tocbasic}{defining new hook after heading of `#1'}%
    \expandafter\global\expandafter\let\csname tb@#1@afterhead@hook\endcsname
    \@empty
  }{}%
  \expandafter\g@addto@macro\csname tb@#1@afterhead@hook\endcsname{#2}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\MakeMarkcase}
%   Use upper-case or not?
%    \begin{macrocode}
\AtBeginDocument{%
  \@ifundefined{MakeMarkcase}{%
    \begingroup\expandafter\expandafter\expandafter\endgroup
    \expandafter\ifx\csname KOMAClassName\endcsname\relax
      \let\MakeMarkcase\MakeUppercase
    \else
      \let\MakeMarkcase\@firstofone
    \fi
  }{}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\deftocheading}
%   Define a toc headings command with one argument (the title).
%    \begin{macrocode}
\newcommand*{\deftocheading}[1]{%
  \@namedef{tocbasic@listhead@#1}##1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\setuptoc}
% \begin{macro}{\unsettoc}
%   Known features are:
%   \begin{description}
%   \item[\texttt{totoc}] writes the title of the list of to the table of
%     contents
%   \item[\texttt{numbered}] uses a numbered headings for the list of
%   \item[\texttt{leveldown}] uses not the top level heading (e.g.,
%     \cs{chapter} with book) but the first sub level (e.g., \cs{section} with
%     book).
%   \item[\texttt{nobabel}] prevents the extension to be added to the babel
%     handling of toc-files.  To make this work, you have to set the feature
%     before adding the extension to the list of known extension.
%   \item[[\texttt{noprotrusion}]] prevents disabling character protrusion at
%     the toc.
%   \end{description}
%   Other features may be package dependent. You may test the feature using:
%   \begin{quote}
%   \cs{@ifundefined}\texttt{\{tocbasic@\meta{toc}@feature@\meta{feature}\}}\\
%   \phantom{\cs{@ifundefined}}\marg{do if feature not set}\\
%   \phantom{\cs{@ifundefined}}\marg{do if feature set}
%   \end{quote}
%   See \cs{tocbasic@listhead} for an example of this.
%    \begin{macrocode}
\newcommand*{\setuptoc}[2]{%
  \@for\@tempa:=#2\do{%
    \expandafter\tb@@sp@def\expandafter\@tempa\expandafter{\@tempa}%
    \@namedef{tocbasic@#1@feature@\@tempa}{}%
  }%
}
\newcommand*{\unsettoc}[2]{%
  \@for\@tempa:=#2\do{%
    \expandafter\tb@@sp@def\expandafter\@tempa\expandafter{\@tempa}%
    \expandafter\let\csname tocbasic@#1@feature@\@tempa\endcsname\relax
  }%
}
\def\@tempa#1{%
  \def\tb@@sp@def##1##2{%
    \futurelet\tb@sp@tempa\tb@@sp@d##2\@nil\@nil#1\@nil\relax##1}%
  \def\tb@@sp@d{%
    \ifx\tb@sp@tempa\@sptoken
      \expandafter\tb@@sp@b
    \else
      \expandafter\tb@@sp@b\expandafter#1%
    \fi}%
  \def\tb@@sp@b#1##1 \@nil{\tb@@sp@c##1}%
}
\@tempa{ }
\def\tb@@sp@c#1\@nil#2\relax#3{\@temptokena{#1}\edef#3{\the\@temptokena}}
%    \end{macrocode}
%   Do not add the files, that babel handles by default.
%    \begin{macrocode}
\setuptoc{toc}{nobabel}
\setuptoc{lof}{nobabel}
\setuptoc{lot}{nobabel}
%    \end{macrocode}
% \begin{macro}{\iftocfeature}
%   We need a test for the features
%    \begin{macrocode}
\newcommand*{\iftocfeature}[2]{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname tocbasic@#1@feature@#2\endcsname\relax
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\tocbasicautomode}
%   \changes{v1.0a}{2008/11/11}{use of \cs{addtotoclist} instead of internal}%
%   \changes{v3.07a}{2010/11/25}{fix: added missing
%     \cs{let}\cs{@starttoc}\cs{tocbasic@starttoc}}%
%   \Package{tocbasic} can overtake \Macro{@starttoc} to automaticly add all
%   used extensions to the list of known extensions and use
%   \Macro{tocbasic@starttoc} instead of \Macro{@starttoc} from \LaTeX{}
%   kernel.
%    \begin{macrocode}
\newcommand*{\tocbasicautomode}{%
  \let\tb@saved@starttoc\@starttoc
  \let\@starttoc\tocbasic@starttoc
  \BeforeStartingTOC{%
    \let\@starttoc\tb@saved@starttoc
    \expandafter\ifattoclist\expandafter{\@currext}{}{%
      \addtotoclist[tocbasicautomode]{\@currext}%
    }%
  }%
}
%    \end{macrocode}
% \end{macro}
%
%
% \section{High Level Interface for Generating New TOCs and Floats}
% \label{sec:newfloats}
%
% \begin{macro}{\DeclareNewTOC}
%   \changes{v3.06}{2010/06/01}{new high level command}%
%   This command defines only a new TOC and a new caption command for this
%   TOC.  It does not define a new foat unless option float was set!  It does
%   not define a new nonfloat unless option nonfloat was set!  The optional
%   argument is used to set up several settings using \Package{keyval}.  The
%   mandatory argument is the shortcut.  The default type is the shortcut.
%   The extension is the shortcut.  The default owner is ``\texttt{float}''.
%
%   But first of all, we define the options used by the optional argument:
%   The type of list is used for environment and counter names and as part of
%   several internal and user macros.
%    \begin{macrocode}
\define@key{tocbasic}{type}{%
  \tb@ifvalueisnotempty{type}{#1}{\edef\tb@nt@type{#1}}%
}
%    \end{macrocode}
% \begin{macro}{\tb@nt@counterwithin}
%   If a counter will be defined, this counter may depend on another counter
%   (like figure counter depends on chapter counter at book classes). If the
%   value is empty, the counter does not depend on any other counter.
%    \begin{macrocode}
\define@key{tocbasic}{counterwithin}{%
  \edef\tb@nt@counterwithin{#1}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@nt@types}
%   Sometimes the plural of the type is needed and may be defined by a
%   seperate option.
%    \begin{macrocode}
\define@key{tocbasic}{types}{%
  \tb@ifvalueisnotempty{types}{#1}{\edef\tb@nt@types{#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@nt@ext}
%   Don't tell the user, that the mandatory argument of the command may be
%   overloaded by this option. This was only done to simplify the definition.
%    \begin{macrocode}
\define@key{tocbasic}{extension}{%
  \tb@ifvalueisnotempty{extension}{#1}{\edef\tb@nt@ext{#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@nt@owner}
%   The owner of the new list extension.
%    \begin{macrocode}
\define@key{tocbasic}{owner}{%
  \tb@ifvalueisnotempty{owner}{#1}{\edef\tb@nt@owner{#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@nt@name}
%   We need a name/term for the entries of the new list. This may e.g. be used
%   for |caption| output. A |\<type>name| will also be defined.
%    \begin{macrocode}
\define@key{tocbasic}{name}{%
  \tb@ifvalueisnotempty{name}{#1}{\edef\tb@nt@name{#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@nt@listname}
%   The list itself has a heading. A |\list<type>name| will also be defined.
%    \begin{macrocode}
\define@key{tocbasic}{listname}{%
  \tb@ifvalueisnotempty{listname}{#1}{\edef\tb@nt@listname{#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\iftb@forcenames}
%   \changes{v3.06}{2010/06/01}{new internal}
%   The |\...name| commands will only be defined, if they are not already
%   defined. But some users may want to define their own names even if there
%   are already definitions. So this boolean option may switch to force the
%   definition.
%    \begin{macrocode}
\newif\iftb@forcenames
\define@key{tocbasic}{forcenames}[true]{%
  \lowercase{\tb@boolkey{#1}}{forcenames}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@nt@level}
%   Each entry to a TOC/list of has a numeric level. You may set up your own
%   level.
%    \begin{macrocode}
\define@key{tocbasic}{level}{%
  \tb@ifvalueisnotempty{level}{#1}{\tb@numkey\tb@nt@level{#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@nt@indent}
%   Earch entry of a TOC/list of is idented on the left side. This is the
%   amount of the indention of the number part.
%    \begin{macrocode}
\define@key{tocbasic}{indent}{%
  \tb@ifvalueisnotempty{indent}{#1}{\tb@dimkey\tb@nt@indent{#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@nt@hang}
%   Earch entry of a TOC/list of is idented on the left side. This is the
%   amount of the indention of the text of the entry.
%    \begin{macrocode}
\define@key{tocbasic}{hang}{%
  \tb@ifvalueisnotempty{hang}{#1}{\tb@dimkey\tb@nt@hang{#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\iftb@float}
%   \changes{v3.06}{2010/06/01}{new internal}
%   This boolean indicates, that float environments should also be defined.
%    \begin{macrocode}
\newif\iftb@float
\define@key{tocbasic}{float}[true]{%
  \lowercase{\tb@boolkey{#1}}{float}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\iftb@nonfloat}
%   \changes{v3.06}{2010/06/01}{new internal}
%   This boolean indicates, that non-float environment should also be
%   defined. The environment has the postfix ``-''.
%    \begin{macrocode}
\newif\iftb@nonfloat
\define@key{tocbasic}{nonfloat}[true]{%
  \lowercase{\tb@boolkey{#1}}{nonfloat}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@nt@floattype}
%   Simply the value for the |\ftype@...| macro. It has to be
%   $1<=\textrm{value}<=31$.
%    \begin{macrocode}
\define@key{tocbasic}{floattype}{%
  \tb@ifvalueisnotempty{floattype}{#1}{\tb@numkey\tb@nt@floattype{#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@nt@floatpos}
%   Simply the value for the |\fps@...| macro.
%    \begin{macrocode}
\define@key{tocbasic}{floatpos}{%
  \tb@ifvalueisnotempty{floatpos}{#1}{\edef\tb@nt@floatpos{#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@nt@atbegin}
%   \changes{v3.09}{new optional identifier \texttt{atbegin}}
%   Additional code executed at the begin of a new defined environment.
%    \begin{macrocode}
\define@key{tocbasic}{atbegin}{%
  \tb@ifvalueisnotempty{atbegin}{#1}{\def\tb@nt@atbegin{#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@nt@atend}
%   \changes{v3.09}{new optional identifier \texttt{atbend}}
%   Additional code executed at the end of a new defined environment.
%    \begin{macrocode}
\define@key{tocbasic}{atend}{%
  \tb@ifvalueisnotempty{atend}{#1}{\def\tb@nt@atend{#1}}%
}
%    \end{macrocode}
% \end{macro}
%  Now the command to define a new list and maybe float or nonfloat.
%    \begin{macrocode}
\newcommand*{\DeclareNewTOC}[2][]{%
  \tb@floatfalse
  \tb@nonfloatfalse
  \tb@forcenamesfalse
  \def\tb@nt@floattype{\tb@nt@autofloattype}%
  \def\tb@nt@floatpos{tbp}%
  \def\tb@nt@ext{#2}%
  \def\tb@nt@type{#2}%
  \def\tb@nt@types{\tb@nt@type s}%
  \def\tb@nt@owner{float}%
  \def\tb@nt@name{\expandafter\MakeUppercase\tb@nt@type}%
  \def\tb@nt@listname{List of \expandafter\MakeUppercase\tb@nt@types}%
  \def\tb@nt@level{1}%
  \def\tb@nt@indent{1em}%
  \def\tb@nt@hang{1.5em}%
  \let\tb@nt@counterwithin\@empty
  \let\tb@nt@atbegin\@empty
  \let\tb@nt@atend\@empty
  \setkeys{tocbasic}{#1}%
%    \end{macrocode}
%   First of all, every TOC needs a extension, that should be added to the
%   list of known extensions.
%    \begin{macrocode}
  \expandafter\newcommand\csname ext@\tb@nt@type\endcsname{}%
  \expandafter\let\csname ext@\tb@nt@type\endcsname\tb@nt@ext
  \addtotoclist[\tb@nt@owner]{\csname ext@\tb@nt@type\endcsname}%
%    \end{macrocode}
% Then we need the TOC itself with a name:
%    \begin{macrocode}
  \@ifundefined{\tb@nt@type name}{%
    \expandafter\let\csname \tb@nt@type name\endcsname\tb@nt@name
  }{%
    \iftb@forcenames
      \expandafter\let\csname \tb@nt@type name\endcsname\tb@nt@name
    \fi
  }%
  \@ifundefined{list\tb@nt@type name}{%
    \expandafter\let\csname list\tb@nt@type name\endcsname\tb@nt@listname
  }{%
    \iftb@forcenames
      \expandafter\let\csname list\tb@nt@type name\endcsname\tb@nt@listname
    \fi
  }%
  \expandafter\newcommand\csname listof\tb@nt@ext name\expandafter\endcsname
    \expandafter{\csname list\tb@nt@type name\endcsname}%
  \begingroup\edef\@tempa{\endgroup
    \noexpand\newcommand*\csname listof\tb@nt@types\endcsname{%
      \noexpand\listoftoc{\tb@nt@ext}%
    }%
  }\@tempa
%    \end{macrocode}
% The list entry:
%    \begin{macrocode}
  \begingroup\edef\@tempa{\endgroup
    \noexpand\newcommand*\csname l@\tb@nt@type\endcsname{%
      \noexpand\@dottedtocline{\tb@nt@level}{\tb@nt@indent}{\tb@nt@hang}%
    }%
  }\@tempa
%    \end{macrocode}
% The setup command:
%    \begin{macrocode}
  \begingroup\edef\@tempa{\endgroup
    \noexpand\newcommand*\csname setup\tb@nt@types\endcsname{%
      \noexpand\setuptoc{\tb@nt@ext}%
    }%
  }\@tempa
  \@tempswafalse
%    \end{macrocode}
% The float environments:
%    \begin{macrocode}
  \iftb@float
    \expandafter\newcommand\expandafter*\csname fps@\tb@nt@type\expandafter
    \endcsname{\tb@nt@floatpos}%
    \expandafter\newcommand\expandafter*\csname ftype@\tb@nt@type\expandafter
    \endcsname{\tb@nt@floattype}%
    \begingroup
      \edef\@tempa{%
        \noexpand\endgroup
        \noexpand\newenvironment{\tb@nt@type}{%
          \noexpand\@float{\tb@nt@type}%
          \noexpand\csname \tb@nt@type @atbegin\noexpand\endcsname
        }{%
          \noexpand\csname \tb@nt@type @atend\noexpand\endcsname
          \noexpand\end@float
        }%
        \noexpand\newenvironment{\tb@nt@type*}{%
          \noexpand\@dblfloat{\tb@nt@type}%
          \noexpand\csname \tb@nt@type @atbegin\noexpand\endcsname
        }{%
          \noexpand\csname \tb@nt@type @atend\noexpand\endcsname
          \noexpand\end@dblfloat
        }%
      }%
    \@tempa
    \@tempswatrue
  \fi
%    \end{macrocode}
% The nonfloat environment:
%    \begin{macrocode}
  \iftb@nonfloat
    \begingroup
      \edef\@tempa{%
        \noexpand\endgroup
        \noexpand\newenvironment{\tb@nt@type-}{%
          \noexpand\trivlist\noexpand\item\noexpand\relax
          \noexpand\minipage{\noexpand\linewidth}%
          \noexpand\def\noexpand\@captype{\tb@nt@type}%
          \noexpand\csname \tb@nt@type @atbegin\noexpand\endcsname
        }{%
          \noexpand\csname \tb@nt@type @atend\noexpand\endcsname
          \noexpand\endminipage\noexpand\endtrivlist
        }%
      }%
    \@tempa
    \@tempswatrue
  \fi
%    \end{macrocode}
% The counter and hooks of float and nonfloat environments:
%    \begin{macrocode}
  \if@tempswa
    \@ifundefined{c@\tb@nt@type}{%
      \newcounter{\tb@nt@type}%
    }{%
      \PackageWarning{tocbasic}{using already defined counter `\tb@nt@type'}%
    }%
    \ifx\tb@nt@counterwithin\@empty\else
      \@addtoreset{\tb@nt@type}{\tb@nt@counterwithin}%
      \begingroup\edef\@tempa{%
        \noexpand\endgroup
        \noexpand\renewcommand*\expandafter\noexpand
        \csname the\tb@nt@type\endcsname{%
          \expandafter\noexpand\csname the\tb@nt@counterwithin\endcsname
          .\noexpand\arabic{\tb@nt@type}%
        }%
      }\@tempa
    \fi
    \begingroup
      \edef\@tempa{%
        \noexpand\endgroup
        \noexpand\newcommand*\expandafter\noexpand
        \csname \tb@nt@type format\endcsname{%
          \expandafter\noexpand\csname \tb@nt@type name\endcsname
          \noexpand\nobreakspace
          \expandafter\noexpand\csname the\tb@nt@type\endcsname
          \csname autodot\endcsname
        }%
        \noexpand\newcommand*\expandafter\noexpand
        \csname fnum@\tb@nt@type\endcsname{%
          \expandafter\noexpand\csname \tb@nt@type format\endcsname
        }%
      }%
    \@tempa
    \expandafter\newcommand\expandafter*\csname \tb@nt@type @atbegin\expandafter
    \endcsname\expandafter{\tb@nt@atbegin}%
    \expandafter\newcommand\expandafter*\csname \tb@nt@type @atend\expandafter
    \endcsname\expandafter{\tb@nt@atend}%
  \fi
}
%    \end{macrocode}
% \begin{macro}{\tb@ifvalueisnotempty}
%   \changes{v3.06}{2010/05/21}{new internal}%
%   This is only a helper for defining some of the keys.
%    \begin{macrocode}
\newcommand*{\tb@ifvalueisnotempty}[2]{%
  \begingroup
    \edef\@tempa{#2}\ifx\@tempa\@empty
      \PackageError{tocbasic}{empty value for key `#1'}{%
        The argument of key `#1' may not by empty!}%
      \aftergroup\@gobble
    \else
      \aftergroup\@firstofone
    \fi
  \endgroup
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@boolkey}
%   \changes{v3.06}{2010/05/21}{new internal}%
%   This is only a helper for boolean keys.
%    \begin{macrocode}
\newcommand*{\tb@boolkey}[2]{%
  \csname tb@#2\ifx\relax#1\relax true\else#1\fi\endcsname
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@dimkey}
%   \changes{v3.06}{2010/05/21}{new internal}%
%   This is only a helper for dimension keys.
%    \begin{macrocode}
\newcommand*{\tb@dimkey}[2]{%
  \begingroup
    \@defaultunits\@tempdima#2pt\relax\@nnil
    \edef\@tempa{\noexpand\endgroup\noexpand\def\noexpand#1{\the\@tempdima}}
  \@tempa
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@dimkey}
%   \changes{v3.06}{2010/05/21}{new internal}%
%   This is only a helper for numerical keys.
%    \begin{macrocode}
\newcommand*{\tb@numkey}[2]{%
  \begingroup
    \afterassignment\remove@to@nnil\@tempcnta#2\relax\@nnil
    \edef\@tempa{\noexpand\endgroup\noexpand\def\noexpand#1{\the\@tempcnta}}
  \@tempa
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tb@nt@autofloattype}
%   \changes{v3.06}{2010/06/01}{new internal}
%   This macro saves the float type for auto generated float types.
%    \begin{macrocode}
\newcommand*{\tb@nt@autofloattype}{16}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%
% \iffalse
%</package>
%<*load>
% Used at \KOMAScript{} packages and classes to load the package.
%    \begin{macrocode}
\edef\@tempa{\noexpand\RequirePackage{tocbasic}[\tocbasicversion]}
\@tempa
%    \end{macrocode}
%
%<*class>
% \KOMAScript{} classes need some additional initialization.
%
% \changes{v1.00}{auto-activation of feature \texttt{onecolumn}}
% Set feature \texttt{onecolumn} for every toc file if feature
% \texttt{leveldown} was not used.
%    \begin{macrocode}
%<*chapter>
\AtAddToTocList[\@currname.\@currext]{\setuptoc{\@currext}{onecolumn}}%
\AtAddToTocList[float]{\setuptoc{\@currext}{onecolumn}}%
%</chapter>
%    \end{macrocode}
% Tell the package, what files are used:
%    \begin{macrocode}
\addtotoclist{toc}
\addtotoclist[float]{lof}
\addtotoclist[float]{lot}
%    \end{macrocode}
%</class>
%</load>
% \fi
%
% \Finale
%
\endinput
%
% end of file `tocbasic.dtx'
%%% Local Variables:
%%% mode: doctex
%%% coding: iso-latin-1
%%% TeX-master: t
%%% End:
