Debian Codegraph @

texmf-dist/doc/latex/etoc/etocsnippet-08.tex

raw
1 %% LaTeX2e file `etocsnippet-08.tex'
2 %% generated by the `filecontentshere' environment
3 %% from source `etoc' on 2026/05/05.
4 %%
5 % it will be easy to globally shift the TOC horizontally if needed
6 \def\TOCleftmargin {0pt}
7 \def\TOCrightmargin {2.55em}% like LaTeX's \@tocrmarg
8
9 % this is for dotted leaders
10 \newbox\TOCleaderbox
11 \def\TOCleaderboxwidth {0.7777em}% about like what standard classes do
12
13 % vertical spacing
14 \def\TOCverysmallvskip {0pt plus .2pt}
15 \def\TOCmedvskip {1em plus 1pt}
16 \def\TOCbigvskip {2.25em plus 1pt}
17
18 % the ``numwidths'' for typesetting the numbering of division units.
19 % I don't recall exactly how (and for which fonts) these figures were chosen.
20 % They quickly prove too small if using Roman numerals (as do too the book
21 % class defaults even though they are a bit larger).
22 % NOTA BENE IT WOULD PROBABLY BE BETTER TO NOT USE THE FONT-DEPENDENT
23 % em DIMENSION UNIT HERE BUT EITHER pt OR bp
24 \def\TOCnumwidthB {1.5em} % chapter
25 \def\TOCnumwidthC {2.278em}% section, I think default is 2.3em
26 \def\TOCnumwidthD {3.056em}% analog in standard class is 3.2em
27 \def\TOCnumwidthE {3.833em}% analog in standard class is 4.1em
28 \def\TOCnumwidthF {4.611em}% analog in standard class is 5em
29 \def\TOCnumwidthG {5.389em}% analog in standard class is 6em
30
31 % The code for the ``global toc style''.
32 \makeatletter % (was missing from this code snippet demo up to doc v1.2e)
33 \newcommand*\TOCglobalstyle {%
34 \etocsettocstyle
35 {\if@twocolumn \@restonecoltrue \onecolumn \else \@restonecolfalse \fi
36 \parindent\z@ \leftskip\z@skip \rightskip \z@skip
37 \setbox\TOCleaderbox\hbox to \TOCleaderboxwidth{\hss.\hss}%
38 \chapter *{\noindent\kern\TOCleftmargin\relax % uses "pt"...
39 \contentsname
40 \@mkboth {\MakeUppercase \contentsname}{\MakeUppercase \contentsname}}%
41 \rightskip \TOCrightmargin\relax
42 \parfillskip -\rightskip % or a smaller value if desired
43 \leftskip \TOCleftmargin \relax }
44 {\if@restonecol \twocolumn \fi\cleardoublepage}%
45 %
46 \etocsetlinestyle{part}
47 {}
48 {\addpenalty {-\@highpenalty}%
49 \addvspace \TOCbigvskip
50 \leavevmode
51 {\large \bfseries % use a group to limit font change
52 \interlinepenalty\@M
53 \etocifnumbered{\etocnumber\hspace{1em}}{}%
54 \etocname
55 \nobreak\hfil\makebox[-\parfillskip][r]{\etocpage}}\par
56 \nobreak
57 }
58 {}
59 {}%
60 %
61 \etocsetlinestyle{chapter}
62 {\advance\leftskip\TOCnumwidthB\relax}
63 {\addpenalty {-\@highpenalty }%
64 \vskip \TOCmedvskip\relax
65 \leavevmode
66 {\interlinepenalty\@M
67 \etocifnumbered
68 {\llap{\makebox[\TOCnumwidthB][l]{\bfseries\etocnumber}}}
69 {\advance\leftskip-\TOCnumwidthB\relax}%
70 \bfseries\etocname
71 \nobreak\hfil\makebox[-\parfillskip][r]{\etocpage}\par }%
72 \penalty \@highpenalty
73 }
74 {}
75 {\advance\leftskip-\TOCnumwidthB\relax}%
76 %
77 \TOCsetlinestyle {section} {\TOCnumwidthC}%
78 \TOCsetlinestyle {subsection} {\TOCnumwidthD}%
79 \TOCsetlinestyle {subsubsection}{\TOCnumwidthE}%
80 \TOCsetlinestyle {paragraph} {\TOCnumwidthF}%
81 \TOCsetlinestyle {subparagraph} {\TOCnumwidthG}%
82 }% end of \TOCglobalstyle
83
84 %The common code for line styles is abstracted into a macro:
85
86 \newcommand\TOCsetlinestyle [2]{% #1= unit, #2= numwidth as macro
87 \etocsetlinestyle{#1}
88 {\advance\leftskip#2\relax}
89 {\vskip \TOCverysmallvskip\relax
90 \leavevmode
91 {\interlinepenalty\@M
92 \etocifnumbered
93 {\llap{\makebox[#2][l]{\etocnumber}}}{\advance\leftskip-#2\relax}%
94 \etocname
95 \nobreak\leaders \copy\TOCleaderbox
96 \hfil\makebox[-\parfillskip][r]{\etocpage}%
97 \par }%
98 }
99 {}
100 {\advance\leftskip-#2\relax}%
101 }
102 \makeatother