Invoked Tables of Contents

A table is communicated from one compilation to another through an auxiliary file.

<..TeX4ht tocs..>
 \def\TableOfContents{\futurelet\:temp\:TOC}
 \def\:TOC{\ifx [\:temp \expandafter\:TableOfContents
           \else \:TableOfContents[Part,Chapter,LikeChapter,Appendix,%
                                   Section,LikeSection]\fi}
 -_-_-

<..config plain utilities..>+
 \NewConfigure{TableOfContents}{5}
 -_-_-

<..html TeX4ht tocs..>
 \def\tocPart#1#2#3{\IgnorePar\HCode{<div
     align="center">}#2\HCode{</div>}\IgnoreIndent}%
 \def\tocChapter#1#2#3{%
    <.indentations from Chapter.>%
    \par\ignorespaces #1 #2\par }
 \def\tocLikeChapter{\tocChapter}
 \def\tocAppendix{\tocChapter}
 \def\tocSection#1#2#3{%
    <.indentations from Section.>%
    \par\tocSection:idnt \ignorespaces #1 #2\par}%
 \def\tocLikeSection{\tocSection}
 \def\tocSubSection#1#2#3{\par\csname tocSubSection:idnt\endcsname
    \ignorespaces #1 #2\par}
 -_-_-

A self-modifying definition like ‘\def\tocChapter{... \def\tocChapter##1##2##3{\par\ignorespaces ##1 ##2\par}% \tocChapter }’ can be harmful when \TocAt commands are used.

<..indentations from Chapter..>
 \ifx \tocSubSection:idnt\:UnDef
    \def\tocSection:idnt{\ }%
    \def\tocSubSection:idnt{\ \ }%
 \fi
 -_-_-

<..indentations from Section..>
 \ifx \tocSubSection:idnt\:UnDef
    \let\tocSection:idnt=\empty
    \def\tocSubSection:idnt{\ }%
 \else
    \ifx \SubSection:idnt\:UnDef    warning?
        \let\tocSection:idnt=\empty
        \def\tocSubSection:idnt{\ }%
    \fi
 \fi
 -_-_-

<..non-html TeX4ht tocs..>
 \def\tocPart#1#2#3{\sl \medskip \hfil #2\par\nobreak}%
 \def\tocChapter#1#2#3{\medskip  \:ChapNum{#1}#2\hfill
                                 \:pagenum{#3}\penalty1000}
 \let\tocLikeChapter=\tocChapter
 \let\tocAppendix=\tocChapter
 \def\tocSection#1#2#3{%
    \:ChapNum{\relax}%
    \:SectNum{#1}#2\TocDotfill\:pagenum{#3}}
 \let\tocLikeSection=\tocSection
 \def\tocSubSection#1#2#3{%
    \phantom{xxxx}%
    \:ChapNum{\relax}\:SectNum{\relax}$\bullet$
    #2\TocDotfill\:pagenum{#3}}
 \def\:BeforeTOC{{\let\TocLikeChapter=\empty \LikeChapter{Contents}}}
 -_-_-

A ‘\nobreak=\penalty10000’ can be a problem for chapters, because it may cause too much stretching of spaces when there are no sections in between. A ‘\penalty1000’ seems to be good enough to avoid HPage breaks when sections are close enough.

<..non-html TeX4ht tocs..>+
 \def\TocDotfill{\leaders\hbox to 1em{\hfil.\hfil}\hfill}
 -_-_-

The prefix \leaders\hbox to 1em{\hfil.\hfil} of \hfill asks the command \hfill to fill the void with multiple copies of the content of the horizontal box (instead of just with white space).

<..non-html TeX4ht tocs..>+
 \def\:ChapNum#1{\bf\leavevmode
    \def\:test{#1}%
    \ifx \:test\empty \def\uppercase{}\else
       \hbox to 1.7em{#1\hfil}%
    \fi}%
 \def\:SectNum#1{\rm
    \def\:test{#1}%
    \ifx \:test\empty \else
       \hbox to 2.5em{#1\hfil}%
    \fi}%
 \def\:pagenum#1{\hbox to 1.7em{\hfil #1}\par}
 -_-_-

<..html tocsNO..>
 \def\:ChapNum#1{\leavevmode
    \def\:test{#1}%
    \ifx \:test\empty \def\uppercase{}\else
       {#1\space}%
    \fi}%
 \def\:SectNum#1{\rm
    \def\:test{#1}%
    \ifx \:test\empty \else
       {#1\space}%
    \fi}%
 \def\:pagenum#1{}%
 -_-_-