Debian Codegraph @

texmf-dist/tex/plain/pdftoolbox/pdfDstruct/ptb-tableofcontents.tex

raw
1 \input ptb-utils
2
3 \_checkloaded{tableofcontents}
4
5 \input ptb-pdfData
6 \input pdfDstruct/ptb-fonts
7 \input pdfDstruct/ptb-hooks
8 \input pdfDstruct/ptb-hyperlinks
9
10 \newwrite\_tocwrite
11 \newread\_tocread
12
13 \def\setuptoc{%
14 \immediate\openout\_tocwrite{\jobname .toc}%
15 \immediate\openin\_tocread{\jobname .data}%
16 \unless\ifeof\_tocread%
17 \input{\jobname .data}%
18 \fi%
19 }
20
21 \createbordertype{toc}{}{0}
22
23 % #1: Content marker
24 % #2: Content title
25 % #3: Content value
26 % #4: Content depth
27 % #5: Anchor name
28 \def\addtoccontent#1#2#3#4#5{%
29 \anchor[toc]{#5}%
30 \immediate\write\_tocwrite{\noexpand\tocline{#1}{#2}{#3}{#4}{#5}}%
31 }
32
33 \def\tocline#1#2#3#4#5{%
34 \csname tocline@depth@#4\endcsname{#1}{#2}{#3}{#5}%
35 }
36
37 \def\settoclinemanager#1{%
38 \_xp\currdef\csname tocline@depth@#1\endcsname##1##2##3##4%
39 }
40
41 \def\settoctitleformat#1#2{%
42 \_xp\currdef\csname toctitle@depth@#1\endcsname{#2}%
43 }
44
45 \def\settocvalueformat#1#2{%
46 \_xp\currdef\csname tocvalue@depth@#1\endcsname{#2}%
47 }
48
49 \def\settocleader#1#2{%
50 \_xp\currdef\csname tocleader@depth@#1\endcsname{#2}%
51 }
52
53 \def\settocindent#1#2{%
54 \_xp\curredef\csname tocindent@depth@#1\endcsname{#2}%
55 }
56
57 \def\settocbuf#1#2{
58 \_xp\curredef\csname tocbuf@depth@#1\endcsname{#2}%
59 }
60
61 \def\printtoc{%
62 \immediate\openin\_tocread{\jobname .toc}%
63 \unless\ifeof\_tocread%
64 \input{\jobname .toc}%
65 \fi%
66 \immediate\closein\_tocread%
67 }
68
69 \def\tableofcontents{\printtoc\setuptoc}
70
71 \def\dotfill{\xleaders\hbox{$\m@th\mkern1.5mu\hbox{.}\mkern1.5mu$}\hfill}
72
73 \def\settomax#1#2{{%
74 \setbox0=\hbox{#2}%
75 \ifdim\wd0>#1 %
76 \xdef#1{\the\wd0}%
77 \fi%
78 }}
79
80 \def\settomaxanddisplay#1#2#3#4{{%
81 \setbox0=\hbox{#2}%
82 \ifdim\wd0>#1 %
83 \xdef#1{\the\wd0}%
84 \fi%
85 \hbox to#1{#3\unhbox0\relax#4}%
86 }}
87
88 \def\_definetocmanager#1{%
89 \_xp\xdef\csname tocvaluewd@depth@#1\endcsname{0pt}%
90 \_xp\xdef\csname tocmarkerwd@depth@#1\endcsname{0pt}%
91 \_xp\docdata\_xp{\csname tocvaluewd@depth@#1\endcsname}%
92 \_xp\docdata\_xp{\csname tocmarkerwd@depth@#1\endcsname}%
93 \settoclinemanager{#1}{%
94 \kern\csname tocbuf@depth@#1\endcsname\relax%
95 \hbox to\hsize{%
96 \hskip\csname tocindent@depth@#1\endcsname\relax%
97 \gotoanchor[toc]{##4}{%
98 \_xp\settomaxanddisplay\csname tocmarkerwd@depth@#1\endcsname{%
99 \csname tocmarker@depth@#1\endcsname{##1}%
100 }{}\hss%
101 \kern\csname tocmbuf@depth@#1\endcsname\csname toctitle@depth@#1\endcsname{##2}%
102 }%
103 \hfil\ {\csname tocleader@depth@#1\endcsname}\ %
104 \gotoanchor[toc]{##4}{%
105 \_xp\settomaxanddisplay\csname tocvaluewd@depth@#1\endcsname{%
106 \csname tocvalue@depth@#1\endcsname{##3}%
107 }\hss{}%
108 }
109 }%
110 \kern\csname tocbuf@depth@#1\endcsname\relax%
111 }%
112 }
113
114
115 \def\settocdepthformat#1#2{%
116 \mapkeys{%
117 marker={%
118 name=tocmarker@depth@#1,
119 default=\setfont{rm}%
120 },
121 marker buffer={%
122 name=tocmbuf@depth@#1,
123 default=.25cm%
124 },
125 title={%
126 name=toctitle@depth@#1,
127 default=\setfont{rm}%
128 },
129 value={%
130 name=tocvalue@depth@#1,
131 default=\setfont{rm}%
132 },
133 leader={%
134 name=tocleader@depth@#1,
135 default%
136 },
137 indent={%
138 name=tocindent@depth@#1,
139 default=0pt%
140 },
141 buffer={%
142 name=tocbuf@depth@#1,
143 default=0pt%
144 }%
145 }{#2}%
146 \_definetocmanager{#1}%
147 }
148
149 \def\upperroman#1{\uppercase\expanded{{\_xp\romannumeral\expanded{#1}}}}
150 \def\_partmarker#1{\rlap{\upperroman{#1}}}
151 \settocdepthformat0{marker=\setfontandscale{bf}{12pt}\_partmarker, marker buffer=.75cm, title=\setfontandscale{bf}{12pt}, value=\setfontandscale{bf}{12pt}, leader=, indent=0pt, buffer=5pt}
152 \settocdepthformat1{marker=\setfont{bf}\rlap, marker buffer=.75cm, title=\setfont{bf}, value=\setfont{bf}, leader=, indent=0pt, buffer=3pt}
153 \settocdepthformat2{leader=\dotfill, indent=.75cm, buffer=0pt}
154 \settocdepthformat3{leader=\dotfill, indent=\dimexpr 1cm+\csname tocmarkerwd@depth@2\endcsname\relax, buffer=0pt}
155
156 \createcounter{part}
157 \createcounter{section}[part]
158 \createcounter{subsection}[section]
159 \createcounter{subsubsection}[subsection]
160
161 \def\part#1{%
162 \par\vfill%
163 \advancecounter{part}{1}%
164 \def\currpart{#1}%
165 \gdef\currsection{#1}%
166 \gdef\currsubsection{#1}%
167 \gdef\currsubsubsection{#1}%
168 \addtoccontent{\the\counter{part}}{#1}{\the\pageno}{0}{part@\the\counter{part}}%
169 \vbox to\vsize{\vfil\centerline{\setfontandscale{sc}{40pt}\upperroman{\the\counter{part}}. #1}\vfil}%
170 }
171
172 \def\_section#1{%
173 \advancecounter{section}{1}%
174 \par\bigskip%
175 \noindent{\setfontandscale{bf}{15pt}\the\counter{section} #1}%
176 \addtoccontent{\the\counter{section}}{#1}{\the\pageno}{1}{section@\the\counter{part}.\the\counter{section}}%
177 \gdef\currsection{#1}%
178 \gdef\currsubsection{#1}%
179 \gdef\currsubsubsection{#1}%
180 \par\penalty\@M\bigskip%
181 }
182
183 \def\_pseudosection#1{%
184 \par\bigskip%
185 \noindent{\setfontandscale{bf}{15pt}#1}%
186 \par\penalty\@M\bigskip%
187 }
188
189 \def\section{\@ifstar \_pseudosection\_section}
190
191 \def\currsubsubsection{}
192 \def\currsubsection{}
193 \def\currsection{}
194 \def\currpart{}
195
196 \def\_subsection#1{%
197 \advancecounter{subsection}{1}%
198 \par\medskip%
199 \noindent{\setfontandscale{bf}{12pt}\the\counter{section}.\the\counter{subsection} #1}%
200 \addtoccontent{\the\counter{section}.\the\counter{subsection}}{#1}{\the\pageno}{2}{subsection@\the\counter{part}.\the\counter{section}.\the\counter{subsection}}%
201 \gdef\currsubsection{#1}%
202 \gdef\currsubsubsection{#1}%
203 \par\penalty\@M\medskip%
204 }
205
206 \def\_pseudosubsection#1{%
207 \par\medskip%
208 \noindent{\setfontandscale{bf}{12pt}#1}%
209 \par\penalty\@M\medskip%
210 }
211
212 \def\subsection{\@ifstar \_pseudosubsection\_subsection}
213
214 \def\_subsubsection#1{%
215 \advancecounter{subsubsection}{1}%
216 \par\medskip%
217 \noindent{\setfontandscale{bf}{12pt}\the\counter{section}.\the\counter{subsection}.\the\counter{subsubsection} #1}%
218 \addtoccontent{\the\counter{section}.\the\counter{subsection}.\the\counter{subsubsection}}{#1}{\the\pageno}{3}{subsubsection@\the\counter{part}.\the\counter{section}.\the\counter{subsection}.\the\counter{subsubsection}}%
219 \gdef\currsubsubsection{#1}%
220 \par\penalty\@M\medskip%
221 }
222
223 \def\_pseudosubsubsection#1{%
224 \par\medskip%
225 \noindent{\setfontandscale{bf}{12pt}#1}%
226 \par\penalty\@M\medskip%
227 }
228
229 \def\subsubsection{\@ifstar \_pseudosubsubsection\_subsubsection}
230