% General commands
% A level register. Explicit numbers because they are
% used in csnames.
\let\ttl@prefix\@empty
\def\ttl@setlevels#1#2{%
\count@=#1
\@for\ttl@a:=#2\do{%
\expandafter\edef\csname ttll@\ttl@prefix\ttl@a\endcsname
{\the\count@}%
\advance\count@\@ne}}
\def\ttl@levels{{-1}{part,chapter,section,subsection,subsubsection,%
paragraph,subparagraph}}
\@ifundefined{chapter}
{\def\ttl@levels{{\z@}{part,section,subsection,%
subsubsection,paragraph,subparagraph}}}
{\def\ttl@levels{{\m@ne}{part,chapter,section,subsection,
subsubsection,paragraph,subparagraph}}}
\expandafter\ttl@setlevels\ttl@levels
% We make sure that a series of * entries are finished and
% that a \titlecontents in the middle of a document is
% written to the right file.
\newcommand\contentsuse[2]{%
\expandafter\def\csname ttlx@#1\endcsname{#2}%
\expandafter\def\csname ttll@#1\endcsname{-1000}%
\AtEndDocument{\addtocontents{#2}{\protect\ttl@finish}}}
\contentsuse{figure}{lof}
\contentsuse{table}{lot}
\AtEndDocument{\addtocontents{toc}{\protect\ttl@finish}}
\def\ttl@finish{%
\ifttl@fromblock
\csname ttle@\ttl@lasttoc\endcsname
\@@par
\endgroup
\global\ttl@fromblockfalse
\fi}
% There is a further tag
% ttle@: ending punctuacion
%
% The two basic commands:
\newcommand\contentsmargin[1][\z@]{%
\def\ttl@corr{#1}\def\@pnumwidth}
\newcommand\ttl@margin[2][\z@]{%
\def\ttl@corr{#1}%
\advance\rightskip-\@pnumwidth\relax
\advance\rightskip#1\relax
\def\@pnumwidth{#2}}
%% titlecontents deals with concepts, not commands; hence no escape
\newcommand\titlecontents{%
\@ifstar{\ttl@contents{\z@}}
{\ttl@contents{\@ne}}}
\def\ttl@contents#1#2{%
\@ifnextchar[{\ttl@contents@x{#1}{#2}}
{\PackageError{titletoc}{Unimplemented}%
{The optional argument is currently mandatory}}}%
\def\ttl@contents@x#1#2[#3]#4#5#6#7{%
\@ifnextchar[{\ttl@contents@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}}%
{\ttl@contents@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}[]}}
\def\ttl@contents@i#1#2#3#4#5#6#7[#8]{%
\ifcase#1
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\@ifnextchar[{\ttl@contents@ii{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}}
{\ttl@contents@ii{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}[]}}
{\ttl@contents@ii{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}[]}}
\def\ttl@contents@ii#1#2#3#4#5#6#7#8[#9]{%
\expandafter\def\csname l@#2\endcsname
{\ttl@tocentry{#1}{#2}{#3}{#4}{{#5}{#6}}{#7}{#8}}
\expandafter\def\csname ttle@#2\endcsname{#9}}
\begingroup
\catcode`\-=12\catcode`\>=12
\gdef\ttl@strip#1->#2\@@#3{\def#3{#2}}
\endgroup
\AtBeginDocument{%
\let\ttl@change\ttl@contents@ii
\def\ttl@contents@ii#1#2#3#4#5#6#7#8[#9]{%
\def\ttl@a{\ttl@change{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}[#9]}
\expandafter\ttl@strip\meaning\ttl@a\@@\ttl@a
\addtocontents
{\expandafter\ifx\csname ttlx@#2\endcsname\relax
toc%
\else
\csname ttlx@#2\endcsname
\fi}%
{\ttl@a}}}
% Printing the toc entry
% ~~~~~~~~~~~~~~~~~~~~~~
\def\ttl@lasttoc{figure} % An inital dummy assignment
% When \contentsafter is called \ttl@b is the current level and
% \ttl@a the previous level.
\newcommand\contentsafter[4]{%
\count@\ttl@a
\advance\count@-\ttl@b
\advance\count@\@ne
\ifcase\count@#1\or#2\or#3\or#4\else
\PackageError{titletoc}{Unknown separation punctuation}
{Punctuation for separating levels in blocked\MessageBreak
toc entries are defined for the most important\MessageBreak
cases only. See manual for further information}%
\fi}
% 1 ifblock, 2 sect name, 3 left, 4 before,
% 5 {with}{without}, 6 filler/page, 7 after 8 title 9 pageno
\def\ttl@tocentry#1#2#3#4#5#6#7#8#9{%
\edef\ttl@b{\csname ttll@#2\endcsname}%
\ifnum\ttl@b>\c@tocdepth\else
\ifnum\ttl@b<\ttl@toctop\else
\edef\ttl@a{\csname ttll@\ttl@lasttoc\endcsname}%
% \gdef\thecontentspage{#9}% Moved to templates
% \global\let\thecontentslabel\@empty
% \ttl@numsecfalse
% \sbox\z@{% Unused box. It just catch the numberline
%
\def\numberline##1{\global\ttl@numsectrue\gdef\thecontentslabel{##1}}%
% #8}%
\ifttl@fromblock
\ifcase#1\relax
{\ttl@lastafter}%
\else
{\csname ttle@\ttl@lasttoc\endcsname}%
\@@par
\endgroup
\@firstoftwo
\fi
\else
\begingroup
\ifnum\ttl@b>\ttl@a
\nobreak
\else\ifnum\ttl@b<\ttl@a
\addpenalty{\@secpenalty}%
\else
\addpenalty{\z@}%
\fi\fi
\ifcase#1\relax\else\interlinepenalty\@M\fi
\parindent\z@
\setlength\leftskip{#3}%
\let\contentsmargin\ttl@margin
\def\ttl@makeline##1{##1}%
#4%
\setlength\rightskip{\@pnumwidth}%
\addtolength{\parfillskip}{-\ttl@corr}%
\addtolength{\rightskip}{\ttl@corr}%
\vskip \z@ \@plus .1\p@
\nobreak
\let\ttl@leaders\leaders
\fi
\def\numberline##1{\ignorespaces}%
\ifttl@numsec
{\leavevmode\strut\@firstoftwo#5{#8}\strut\kern\z@}%
\else
{\leavevmode\strut\@secondoftwo#5{#8}\strut\kern\z@}%
\fi
{#6}%
\ifcase#1\relax
\global\ttl@fromblocktrue
\protected@xdef\ttl@lastafter{#7}%
\else
\@@par
\nobreak
#7%
\endgroup
\global\ttl@fromblockfalse
\fi
\xdef\ttl@lasttoc{#2}%
\fi
\fi
\ignorespaces}
|