Debian Codegraph @

texmf-dist/source/latex/base/ltsect.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 1993-2025
4 % The LaTeX Project and any individual authors listed elsewhere
5 % in this file.
6 %
7 % This file is part of the LaTeX base system.
8 % -------------------------------------------
9 %
10 % It may be distributed and/or modified under the
11 % conditions of the LaTeX Project Public License, either version 1.3c
12 % of this license or (at your option) any later version.
13 % The latest version of this license is in
14 % https://www.latex-project.org/lppl.txt
15 % and version 1.3c or later is part of all distributions of LaTeX
16 % version 2008 or later.
17 %
18 % This file has the LPPL maintenance status "maintained".
19 %
20 % The list of all files belonging to the LaTeX base distribution is
21 % given in the file `manifest.txt'. See also `legal.txt' for additional
22 % information.
23 %
24 % The list of derived (unpacked) files belonging to the distribution
25 % and covered by LPPL is defined by the unpacking scripts (with
26 % extension .ins) which are part of the distribution.
27 %
28 % \fi
29 %
30 % \iffalse
31 %%% From File: ltsect.dtx
32 %<*driver>
33 % \fi
34 \ProvidesFile{ltsect.dtx}[2025/05/22 v1.1h LaTeX Kernel (Sectioning)]
35 % \iffalse
36 \documentclass{ltxdoc}
37 \GetFileInfo{ltsect.dtx}
38 \title{\filename}
39 \date{\filedate}
40 \author{%
41 Johannes Braams\and
42 David Carlisle\and
43 Alan Jeffrey\and
44 Leslie Lamport\and
45 Frank Mittelbach\and
46 Chris Rowley\and
47 Tobias Oetiker\thanks{Tobi updated
48 the comments to `doc' conventions}\and
49 Rainer Sch\"opf}
50
51 \begin{document}
52 \MaintainedByLaTeXTeam{latex}
53 \maketitle
54 \DocInput{\filename}
55 \end{document}
56 %</driver>
57 % \fi
58 %
59 %
60 % \changes{v1.0o}{1995/05/07}{Use \cs{hb@xt@}}
61 % \changes{v1.0y}{1996/10/31}{Corrected and tidied documentation;
62 % removed long lines}
63 %
64 %
65 % \section{Sectioning Commands}
66 %
67 % This file defines the declarations such as |\author| which are used
68 % by |\maketitle|. |\maketitle| itself is defined by each class, not
69 % in the \LaTeX{} kernel.
70 %
71 % The second part of the file defines the generic commands used for
72 % defining sectioning commands such as |\chapter|. Again the actual
73 % document level commands are defined in the class files, in terms of
74 % these commands.
75 %
76 % \MaybeStop{}
77 %
78 %
79 % \changes{v1.0a}{1994/03/04}{Initial version, split from latex.dtx}
80 % \changes{v1.0b}{1994/03/28}{Split further from ltherest.dtx}
81 % \changes{v1.0d}{1994/05/21}{Use new error commands}
82 % \changes{v1.0f}{1994/10/12}{Doc. typos}
83 % \changes{v1.0g}{1994/10/18}{Added \cs{normalcolor}}
84 % \changes{v1.0i}{1994/11/17}
85 % {\cs{@tempa} to \cs{reserved@a}}
86 % \changes{v1.0m}{1995/05/03}{TO: Promoted documentation to doc.sty
87 % standard}
88 % \changes{v1.1d}{2019/08/27}{Make various commands robust}
89 %
90 % \begin{macrocode}
91 %<*2ekernel>
92 \message{title,}
93 % \end{macrocode}
94 %
95 % \subsection{The Title}
96 %
97 % \DescribeMacro{\title}
98 % The user defines the title and author by the declarations
99 % |\title|\marg{name},
100 % \DescribeMacro{\author}
101 % |\author|\marg{name}
102 %
103 % \DescribeMacro{\date}
104 % Similarly the date is declared with
105 % |\date|\marg{date}.
106 %
107 % \DescribeMacro{\thanks}
108 % Inside these, the |\thanks|\marg{footnote text} command may be used
109 % to make acknowledgements, notice of address, etc.\ in a footnote.
110 % \DescribeMacro{\and}
111 % If there are multiple authors, they have to be separated with the
112 % |\and| command.
113 %
114 % \DescribeMacro{\maketitle}
115 % And finally, the |\maketitle| command produces the actual title,
116 % using the information previously saved with the other commands.
117 %
118 %
119 %
120 % \begin{macrocode}
121 %</2ekernel>
122 %<*2ekernel|latexrelease>
123 %<latexrelease>\IncludeInRelease{2019/10/01}%
124 %<latexrelease> {\title}{Make commands robust}%
125 % \end{macrocode}
126 %
127 %
128 % \begin{macro}{\title}
129 % \changes{LaTeX2e}{1993/12/11}{Added default}
130 % |\title| for use in |\maketitle|. If not given |\maketitle| will
131 % produce an error message.
132 % \begin{macrocode}
133 \DeclareRobustCommand\title[1]{\gdef\@title{#1}}
134 % \end{macrocode}
135 % \end{macro}
136 %
137 %
138 % \begin{macro}{\author}
139 % \changes{LaTeX2e}{1993/12/11}{Added default}
140 % \changes{v1.1e}{2020/07/27}{Don't make the command \cs{long} (gh/354)}
141 %
142 % |\author| for use in |\maketitle|. If not given |\maketitle| will
143 % produce a warning message.
144 %
145 % \begin{macrocode}
146 \DeclareRobustCommand*\author[1]{\gdef\@author{#1}}
147 % \end{macrocode}
148 % \end{macro}
149 %
150 % \begin{macro}{\date}
151 % |\date| for use in |\maketitle|. If not given |\maketitle| will
152 % produce |\today| as the default.
153 % \changes{v1.1e}{2020/07/27}{Don't make the command \cs{long} (gh/354)}
154 % \begin{macrocode}
155 \DeclareRobustCommand*\date[1]{\gdef\@date{#1}}
156 % \end{macrocode}
157 % \end{macro}
158 %
159 % \changes{1.0h}{1994/11/04}{(ASAJ) Added \cs{protected@xdef} to
160 % \cs{thanks}.}
161 % \begin{macro}{\thanks}
162 % \begin{macrocode}
163 \DeclareRobustCommand\thanks[1]{\footnotemark
164 \protected@xdef\@thanks{\@thanks
165 \protect\footnotetext[\the\c@footnote]{#1}}%
166 }
167 % \end{macrocode}
168 % \end{macro}
169 %
170 % \begin{macro}{\and}
171 % \begin{macrocode}
172 \DeclareRobustCommand\and{% % \begin{tabular}
173 \end{tabular}%
174 \hskip 1em \@plus.17fil%
175 \begin{tabular}[t]{c}}% % \end{tabular}
176 % \end{macrocode}
177 % \end{macro}
178 %
179 % \begin{macrocode}
180 %</2ekernel|latexrelease>
181 %<latexrelease>\EndIncludeInRelease
182 %<latexrelease>\IncludeInRelease{0000/00/00}%
183 %<latexrelease> {\title}{Make commands robust}%
184 %<latexrelease>
185 %<latexrelease>\kernel@make@fragile\title
186 %<latexrelease>\kernel@make@fragile\author
187 %<latexrelease>\kernel@make@fragile\date
188 %<latexrelease>\kernel@make@fragile\thanks
189 %<latexrelease>\kernel@make@fragile\and
190 %<latexrelease>
191 %<latexrelease>\EndIncludeInRelease
192 %<*2ekernel>
193 % \end{macrocode}
194 %
195 %
196 %
197 % \begin{macro}{\@title}
198 % \begin{macrocode}
199 \def\@title{\@latex@error{No \noexpand\title given}\@ehc}
200 % \end{macrocode}
201 % \end{macro}
202 %
203 % \begin{macro}{\@author}
204 % \begin{macrocode}
205 \def\@author{\@latex@warning@no@line{No \noexpand\author given}}
206 % \end{macrocode}
207 % \end{macro}
208 %
209 % \begin{macro}{\@date}
210 % \begin{macrocode}
211 \gdef\@date{\today}
212 % \end{macrocode}
213 % \end{macro}
214 %
215 % \begin{macro}{\@thanks}
216 % \begin{macrocode}
217 \let\@thanks\@empty
218 % \end{macrocode}
219 % \end{macro}
220 %
221 % \begin{macrocode}
222 \message{sectioning,}
223 % \end{macrocode}
224 % \subsection{Sectioning}
225 %
226 %
227 % \begin{macro}{\@secpenalty}
228 % \begin{macrocode}
229 \newcount\@secpenalty
230 \@secpenalty = -300
231 % \end{macrocode}
232 % \end{macro}
233 %
234 % \begin{macro}{\if@noskipsec}
235 % \begin{macro}{\@noskipsectrue}
236 % \changes{1.0w}{1996/09/29}{Added documentation}
237 % Way back in 1991 (08/26) FMi \& RmS set the |@noskipsec| switch
238 % to true for the preamble and to false in |\document|.
239 % This was done to trap lists and related text in the preamble but it
240 % does not catch everything.
241 % \begin{macrocode}
242 \newif\if@noskipsec \@noskipsectrue
243 % \end{macrocode}
244 % \end{macro}
245 % \end{macro}
246 %
247 % \begin{macro}{\@startsection}
248 %
249 % The |\@startsection{|\meta{name}|}{|\meta{level}|}{|%
250 % \meta{indent}|}{|\meta{beforeskip}|}|\\
251 % |{|\meta{afterskip}|}{|\meta{style}|}*[|\meta{altheading}%
252 % |]{|\meta{heading}|}|
253 % command is the mother of all the user level sectioning commands.
254 % The part after the |*|, including the |*| is optional.
255 %
256 % \begin{description}
257 % \item[name:] e.g., 'subsection'
258 % \item[level:] a number, denoting depth of section -- e.g.,
259 % chapter = 0, section = 1, etc.
260 % \item[indent:] Indentation of heading from left margin
261 % \item[beforeskip:] Absolute value = skip to leave above the heading.
262 % If negative, then paragraph indent of text following
263 % heading is suppressed.
264 % \item[afterskip:] if positive, then skip to leave below heading, else
265 % negative of skip to leave to right of run-in heading.
266 % \item[style:] Commands to set style. Since June 1996 release the
267 % \emph{last} command in this argument may be a command
268 % such as |\MakeUppercase| or |\fbox| that takes an
269 % argument. The section heading will be supplied as the
270 % argument to this command. So setting |#6| to, say,
271 % |\bfseries\MakeUppercase| would produce bold,
272 % uppercase headings.
273 % \end{description}
274 %
275 % If `|*|' is missing, then increment the counter. If it is
276 % present, then there should be no |[|\meta{altheading}|]| argument.
277 % The command uses the counter 'secnumdepth'. It contains a pointer
278 % to the highest section level that is to be numbered.
279 %
280 % \textbf{Warning:}
281 % The |\@startsection| command should be at the same or higher
282 % grouping level as the text that follows it. For example, you should
283 % \emph{not} do something like
284 % \begin{verbatim}
285 % \def\foo{ \begingroup ...
286 % \paragraph{...}
287 % \endgroup}
288 % \end{verbatim}
289 %
290 % Pseudocode for the |\@startsection| command
291 % \begin{oldcomments}
292 % \@startsection {NAME}{LEVEL}{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE} ==
293 % BEGIN
294 % IF @noskipsec = T THEN \leavevmode FI
295 % % true if previous section had no body.
296 %
297 % \par
298 % \@tempskipa := BEFORESKIP
299 % @afterindent := T
300 % IF \@tempskipa < 0 THEN \@tempskipa := -\@tempskipa
301 % @afterindent := F
302 % FI
303 % IF @nobreak = true
304 % THEN \everypar == null
305 % ELSE \addpenalty{\@secpenalty}
306 % \addvspace{\@tempskipa}
307 % FI
308 % IF * next
309 % THEN \@ssect{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE}
310 % ELSE \@dblarg{\@sect
311 % {NAME}{LEVEL}{INDENT}
312 % {BEFORESKIP}{AFTERSKIP}{STYLE}}
313 % FI
314 % END
315 % \end{oldcomments}
316 %
317 % \begin{macrocode}
318 \def\@startsection#1#2#3#4#5#6{%
319 \if@noskipsec \leavevmode \fi
320 \par
321 \@tempskipa #4\relax
322 \@afterindenttrue
323 \ifdim \@tempskipa <\z@
324 \@tempskipa -\@tempskipa \@afterindentfalse
325 \fi
326 \if@nobreak
327 \everypar{}%
328 \else
329 \addpenalty\@secpenalty\addvspace\@tempskipa
330 \fi
331 \@ifstar
332 {\@ssect{#3}{#4}{#5}{#6}}%
333 {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}
334 % \end{macrocode}
335 % \end{macro}
336 %
337 % \begin{macro}{\@sect}
338 % Pseudocode for the |\@sect| command
339 % \begin{oldcomments}
340 % \@sect{NAME}{LEVEL}
341 % {INDENT}{BEFORESKIP}{AFTERSKIP}
342 % {STYLE}[ARG1]{ARG2}
343 % ==
344 % BEGIN
345 % IF LEVEL > \c@secnumdepth
346 % THEN \@svsec :=L null
347 % ELSE \refstepcounter{NAME}
348 % \@svsec :=L BEGIN \@seccntformat{#1}\relax END
349 % FI
350 % IF AFTERSKIP > 0
351 % THEN \begingroup
352 % STYLE
353 % \@hangfrom{\hskip INDENT\@svsec}
354 % {\interlinepenalty 10000 ARG2\par}
355 % \endgroup
356 % \NAMEmark{ARG1}
357 % \addcontentsline{toc}{NAME}
358 % { IF LEVEL > \c@secnumdepth
359 % ELSE \protect\numberline{\theNAME} FI
360 % ARG1 }
361 % ELSE \@svsechd == BEGIN STYLE
362 % \hskip INDENT\@svsec
363 % ARG2
364 % \NAMEmark{ARG1}
365 % \addcontentsline{toc}{NAME}
366 % { IF LEVEL > \c@secnumdepth
367 % ELSE
368 % \protect\numberline{\theNAME}
369 % FI
370 % ARG1 }
371 % END
372 % FI
373 % \@xsect{AFTERSKIP}
374 % END
375 % \end{oldcomments}
376 %
377 % \changes{LaTeX2.09}{1992/08/25}
378 % {(FMi) replaced explicit setting of \cs{@svsec}
379 % by call to \cs{@seccntformat}}
380 % \changes{LaTeX2.09}{1993/08/05}
381 % {(RmS) Made sure that \cs{protect} works correctly in
382 % expansion of \cs{the} counter}
383 % \changes{1.0h}{1994/11/04}
384 % {(ASAJ) Added \cs{protected@edef}.}
385 % \begin{macrocode}
386 \def\@sect#1#2#3#4#5#6[#7]#8{%
387 \ifnum #2>\c@secnumdepth
388 \let\@svsec\@empty
389 \else
390 \refstepcounter{#1}%
391 % \end{macrocode}
392 % Since |\@seccntformat| might end with an improper |\hskip| which
393 % is scanning forward for |plus| or |minus| we end the definition
394 % of |\@svsec| with |\relax| as a precaution.
395 % \changes{1.0n}{1995/05/06}{Added \cs{relax} after
396 % \cs{@seccntformat} just in case}
397 % \begin{macrocode}
398 \protected@edef\@svsec{\@seccntformat{#1}\relax}%
399 \fi
400 \@tempskipa #5\relax
401 \ifdim \@tempskipa>\z@
402 \begingroup
403 % \end{macrocode}
404 % \changes{v1.0s}{1996/05/21}
405 % {(DPC) Moved brace to allow commands like
406 % \cs{MakeUppercase} in 6th argument.
407 % Changed \cs{par} to \cs{endgraf} to allow non-long
408 % commands. internal/2148}
409 % \changes{v1.0t}{1996/06/10}
410 % {(DPC) Changed \cs{endgraf} to \cs{@@par}}
411 % This |{| used to be after the argument to |\@hangfrom| but was moved
412 % here to allow commands such as |\MakeUppercase| to be used at the end
413 % of |#6|.
414 % \begin{macrocode}
415 #6{%
416 \@hangfrom{\hskip #3\relax\@svsec}%
417 \interlinepenalty \@M #8\@@par}%
418 \endgroup
419 \csname #1mark\endcsname{#7}%
420 \addcontentsline{toc}{#1}{%
421 \ifnum #2>\c@secnumdepth \else
422 \protect\numberline{\csname the#1\endcsname}%
423 \fi
424 #7}%
425 \else
426 % \end{macrocode}
427 % |\relax| added 2 May 90
428 % \changes{v1.0s}{1996/05/21}
429 % {(DPC) Added extra braces for internal/2148}
430 % \begin{macrocode}
431 \def\@svsechd{%
432 #6{\hskip #3\relax
433 \@svsec #8}%
434 \csname #1mark\endcsname{#7}%
435 \addcontentsline{toc}{#1}{%
436 \ifnum #2>\c@secnumdepth \else
437 \protect\numberline{\csname the#1\endcsname}%
438 \fi
439 #7}}%
440 \fi
441 \@xsect{#5}}
442 % \end{macrocode}
443 % \end{macro}
444 %
445 % \begin{macro}{\@xsect}%
446 % Pseudocode for the |\@xsect| command
447 % \begin{oldcomments}
448 % \@xsect{AFTERSKIP} ==
449 % BEGIN
450 % IF AFTERSKIP > 0
451 % THEN \par \nobreak
452 % \vskip AFTERSKIP
453 % \@afterheading
454 % ELSE @nobreak :=G F
455 % @noskipsec :=G T
456 % \everypar{ IF @noskipsec = T
457 % THEN @noskipsec :=G F
458 % \clubpenalty := 10000 % local
459 % \hskip -\parindent
460 % \begingroup
461 % \@svsechd
462 % \endgroup
463 % \unskip
464 % \hskip -AFTERSKIP \relax
465 % %% relax added 14 Jan 91
466 % ELSE \clubpenalty := \@clubpenalty % local
467 % \everypar := NULL
468 % FI
469 % }
470 % FI
471 %
472 % END
473 % \end{oldcomments}
474 %
475 % \changes{0.0}{1992/08/19}
476 % {(RmS) corrected bug: stretch and shrink in argument to
477 % \cs{hskip} previously not negated}
478 % \begin{macrocode}
479 \def\@xsect#1{%
480 \@tempskipa #1\relax
481 \ifdim \@tempskipa>\z@
482 % \end{macrocode}
483 % Why not combine |\@sect| and |\@xsect| and save doing the
484 % same test twice? It is not possible to change this now as these
485 % have become hooks!
486 %
487 % This |\par| seems unnecessary.
488 % \begin{macrocode}
489 \par \nobreak
490 \vskip \@tempskipa
491 \@afterheading
492 \else
493 % \end{macrocode}
494 % \changes{v1.0u}{1996/07/26}{Removed \cs{global} before
495 % \cs{@nobreak...}}
496 % \changes{v1.0x}{1996/10/23}{Replaced \cs{hskip...} with \cs{setbox...}
497 % as used in \cs{@afterheading}}
498 % \begin{macrocode}
499 \@nobreakfalse
500 \global\@noskipsectrue
501 \everypar{%
502 \if@noskipsec
503 \global\@noskipsecfalse
504 {\setbox\z@\lastbox}%
505 \clubpenalty\@M
506 \begingroup \@svsechd \endgroup
507 \unskip
508 \@tempskipa #1\relax
509 \hskip -\@tempskipa
510 \else
511 \clubpenalty \@clubpenalty
512 \everypar{}%
513 \fi}%
514 \fi
515 \ignorespaces}
516 % \end{macrocode}
517 % \end{macro}
518 %
519 % \begin{macro}{\@seccntformat}
520 % This command formats the section number including the space
521 % following it.
522 % \changes{1.0n}{1995/05/06}{Use \cs{quad} instead of \cs{hskip}}
523 % \begin{macrocode}
524 \def\@seccntformat#1{\csname the#1\endcsname\quad}
525 % \end{macrocode}
526 % \end{macro}
527 %
528 % Pseudocode for the |\@ssect| command
529 % \begin{oldcomments}
530 % \@ssect{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE}{ARG} ==
531 % BEGIN
532 % IF AFTERSKIP > 0
533 % THEN \begingroup
534 % STYLE
535 % \@hangfrom{\hskip INDENT}
536 % {\interlinepenalty 10000 ARG\par}
537 % \endgroup
538 % ELSE \@svsechd == BEGIN STYLE
539 % \hskip INDENT
540 % ARG
541 % END
542 % FI
543 % \@xsect{AFTERSKIP}
544 % END
545 % \end{oldcomments}
546 %
547 % Pseudocode for the |\@afterheading| command
548 % \begin{oldcomments}
549 % \@afterheading ==
550 % BEGIN
551 % @nobreak :=G true
552 % \everypar := BEGIN IF @nobreak = T
553 % THEN @nobreak :=G false
554 % \clubpenalty := 10000 % local
555 % IF @afterindent = F
556 % THEN remove \lastbox
557 % FI
558 % ELSE \clubpenalty := \@clubpenalty % local
559 % \everypar := NULL
560 % FI
561 % END
562 % END
563 % \end{oldcomments}
564 %
565 %
566 % \begin{macro}{\@ssect}
567 % \begin{macrocode}
568 \def\@ssect#1#2#3#4#5{%
569 \@tempskipa #3\relax
570 \ifdim \@tempskipa>\z@
571 \begingroup
572 % \end{macrocode}
573 % \changes{v1.0s}{1996/05/21}
574 % {(DPC) Moved brace to allow commands like
575 % \cs{MakeUppercase} in 4th argument.
576 % Changed \cs{par} to \cs{endgraf} to allow non-long
577 % commands. internal/2148}
578 % \changes{v1.0t}{1996/06/10}
579 % {(DPC) Changed \cs{endgraf} to \cs{@@par}}
580 % This |{| used to be after the argument to |\@hangfrom| but was moved
581 % here to allow commands such as |\MakeUppercase| to be used at the end
582 % of |#4|.
583 % \begin{macrocode}
584 #4{%
585 \@hangfrom{\hskip #1}%
586 \interlinepenalty \@M #5\@@par}%
587 \endgroup
588 \else
589 % \end{macrocode}
590 % \changes{v1.0s}{1996/05/21}
591 % {(DPC) Added extra braces for internal/2148}
592 % \begin{macrocode}
593 \def\@svsechd{#4{\hskip #1\relax #5}}%
594 \fi
595 \@xsect{#3}}
596 % \end{macrocode}
597 % \end{macro}
598 %
599 % \begin{macro}{\if@afterindent}
600 % \begin{macro}{\@afterindenttrue}
601 % \begin{macrocode}
602 \newif\if@afterindent \@afterindenttrue
603 % \end{macrocode}
604 % \end{macro}\end{macro}
605 %
606 % \begin{macro}{\@afterheading}
607 % \changes{v1.0v}{1996/08/02}{Removed \cs{global}
608 % before \cs{@nobreak...}}
609 %
610 % This hook is used in setting up custom-built headings in classes.dtx.
611 %
612 % \begin{macrocode}
613 \def\@afterheading{%
614 \@nobreaktrue
615 \everypar{%
616 \if@nobreak
617 \@nobreakfalse
618 \clubpenalty \@M
619 \if@afterindent \else
620 {\setbox\z@\lastbox}%
621 \fi
622 \else
623 \clubpenalty \@clubpenalty
624 \everypar{}%
625 \fi}}
626 % \end{macrocode}
627 % \end{macro}
628 %
629 %
630 % \begin{macro}{\@hangfrom}
631 %
632 % |\@hangfrom{|\meta{text}|}| : Puts \meta{text} in a box, and makes a
633 % hanging indentation of the following material up to the first
634 % |\par|. Should be used in vertical mode.
635 %
636 % \changes{v1.0a}{1994/03/07}{(DPC)Extra groups for colour}
637 % \begin{macrocode}
638 \def\@hangfrom#1{\setbox\@tempboxa\hbox{{#1}}%
639 \hangindent \wd\@tempboxa\noindent\box\@tempboxa}
640 % \end{macrocode}
641 % \end{macro}
642 %
643 % \begin{macro}{\c@secnumdepth}
644 % \begin{macro}{\c@tocdepth}
645 % \begin{macrocode}
646 \newcount\c@secnumdepth
647 \newcount\c@tocdepth
648 % \end{macrocode}
649 % \end{macro}\end{macro}
650 %
651 % \begin{macro}{\secdef}
652 %
653 % |\secdef{|\meta{unstarcmds}|}{|\meta{unstarcmds}|}{|%
654 % \meta{starcmds}|}|\\
655 % When defining a |\chapter| or |\section| command without using
656 % |\@startsection|, you can use |\secdef| as follows:
657 % \begin{enumerate}
658 % \item |\def\chapter{| \ldots |\secdef|
659 % |\|\meta{starcmd} |\|\meta{unstarcmd} |}|
660 % \item |\def\|\meta{starcmd}|[#1]#2{| \ldots |}|
661 % |%| Command to define |\chapter[|\ldots|]{|\ldots|}|
662 % \item |\def\|\meta{unstarcmd}|#1{| \ldots |}|
663 % |%| Command to define |\chapter*{|\ldots|}|
664 % \end{enumerate}
665 %
666 % \begin{macrocode}
667 \def\secdef#1#2{\@ifstar{#2}{\@dblarg{#1}}}
668 % \end{macrocode}
669 % \end{macro}
670 %
671 % \subsubsection{Initializations}
672 % \begin{macro}{\sectionmark}
673 % \begin{macro}{\subsectionmark}
674 % \begin{macro}{\subsubsectionmark}
675 % \begin{macro}{\paragraphmark}
676 % \begin{macro}{\subparagraphmark}
677 % \changes{v1.0q}{1995/10/25}{Use \cs{let} not \cs{def} to save space.}
678 % \begin{macrocode}
679 \let\sectionmark\@gobble
680 \let\subsectionmark\@gobble
681 \let\subsubsectionmark\@gobble
682 \let\paragraphmark\@gobble
683 \let\subparagraphmark\@gobble
684 % \end{macrocode}
685 % \end{macro}
686 % \end{macro}
687 % \end{macro}
688 % \end{macro}
689 % \end{macro}
690 %
691 % \begin{macrocode}
692 \message{contents,}
693 % \end{macrocode}
694 %
695 % \subsection{Table of Contents etc.}
696 %
697 % \subsubsection{Convention}
698 % |\tf@|\meta{foo} = file number for output for table foo.
699 % The file is opened only if |@filesw| = |true|.
700 %
701 % \subsubsection{Commands}
702 %
703 %
704 % A |\l@|\meta{type}|{|\meta{entry}|}{|\meta{page}|}| Macro needs to
705 % defined by document style for making an entry of type \meta{type}
706 % in a table of contents, etc. E.g., the document style
707 % should define |\l@chapter|, |\l@section|, etc.
708 %
709 % \textbf{Note:} When the |\protect| command is
710 % used in the \meta{entry} or \meta{text} of one of the commands
711 % below, it causes the following control sequence to be written on
712 % the file without being expanded. The sequence will be expanded
713 % when the table of contents entry is processed.
714 %
715 % \textbf{Surprise:} Inside an |\addcontentsline| or |\addtocontents|
716 % command argument, the commands: |\index|, |\glossary|, and |\label|
717 % are no-ops . This could cause a problem if the user puts an
718 % |\index| or |\label| into one of the commands he writes, or into the
719 % optional `short version' argument of a |\section| or |\caption|
720 % command.
721 %
722 % \begin{macro}{\@starttoc}
723 % The |\@starttoc|\marg{ext} command is used to define the commands:\\
724 % |\tableofcontents|, |\listoffigures|, etc.
725 %
726 % For example:
727 % |\@starttoc{lof}| is used in |\listoffigures|. This command
728 % reads the |.|\meta{ext} file and sets up to write the new
729 % |.|\meta{ext} file.
730 %
731 % \begin{oldcomments}
732 % \@starttoc{EXT} ==
733 % BEGIN
734 % \begingroup
735 % \makeatletter
736 % read file \jobname.EXT
737 % IF @filesw = true
738 % THEN open \jobname.EXT as file \tf@EXT
739 % FI
740 % @nobreak :=G FALSE %% added 24 May 89
741 % \endgroup
742 % END
743 % \end{oldcomments}
744 %
745 % \changes{0.0}{1992/01/14}{(RmS) added \cs{immediate} to \cs{openout}
746 % as all \cs{write} commands
747 % are also executed \cs{immediate}}
748 % \changes{v1.0u}{1996/07/26}{removed \cs{global}
749 % before \cs{@nobreak...}}
750 % \begin{macrocode}
751 \def\@starttoc#1{%
752 \begingroup
753 \makeatletter
754 \@input{\jobname.#1}%
755 \if@filesw
756 \expandafter\newwrite\csname tf@#1\endcsname
757 \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
758 \fi
759 \@nobreakfalse
760 \endgroup}
761 % \end{macrocode}
762 % \end{macro}
763 %
764 % \begin{macro}{\addcontentsline}
765 % The |\addcontentsline{|\meta{table}|}{|\meta{type}|}{|\meta{entry}|}|
766 % command allows the user to add
767 % his/her own entry to a table of contents, etc. The command adds the
768 % entry |\contentsline{|\meta{type}|}{|\meta{entry}|}{|\meta{page}|}{}|
769 % to the |.|\meta{table} file.
770 %
771 % This macro is implemented as an application of |\addtocontents|.
772 % Note that |\thepage| is not expandable during |\protected@write|
773 % therefore one gets the page number at the time of the |\shipout|.
774 %
775 % \changes{v1.0c}{1994/05/20}{Correct setting of \cs{protect}.}
776 % \changes{v1.0j}{1995/04/23}{Use \cs{contentsline} internally.}
777 % \changes{v1.0h}{1994/11/04}{Added \cs{protected@write} to
778 % \cs{addcontentsline}. ASAJ.}
779 % \changes{v1.1c}{2018/09/26}{Sometimes mask the endline char when
780 % writing to files (github/73)}
781 % \changes{v1.1e}{2020/10/01}{add a fourth argument for better
782 % hyperref compatibility}
783 % \begin{macrocode}
784 %</2ekernel>
785 %<*2ekernel|latexrelease>
786 %<latexrelease>\IncludeInRelease{2020/10/01}%
787 %<latexrelease> {\addcontentsline}{fourth argument}%
788 \def\addcontentsline#1#2#3{%
789 % \end{macrocode}
790 % We add an empty brace pair at the end of \cs{contentsline}
791 % so that the number of argument is identical in documents
792 % with and without hyperref.
793 % \begin{macrocode}
794 \addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}{}%
795 \protected@file@percent}}
796 %</2ekernel|latexrelease>
797 %<latexrelease>\EndIncludeInRelease
798 %<latexrelease>\IncludeInRelease{2018/12/01}%
799 %<latexrelease> {\addcontentsline}{Mask line endings}%
800 %<latexrelease> \def\addcontentsline#1#2#3{%
801 %<latexrelease> \addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}%
802 % \end{macrocode}
803 % We add \cs{protected@file@percent} at the end which is turned inside
804 % \cs{@writefile} into a percent character to mask the newline after
805 % the closing argument brace.
806 % \begin{macrocode}
807 %<latexrelease> \protected@file@percent}}
808 %<latexrelease>\EndIncludeInRelease
809 %<latexrelease>\IncludeInRelease{0000/00/00}%
810 %<latexrelease> {\addcontentsline}{Mask line endings}%
811 %<latexrelease>\def\addcontentsline#1#2#3{%
812 %<latexrelease> \addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}}}
813 %<latexrelease>\EndIncludeInRelease
814 %<*2ekernel>
815 % \end{macrocode}
816 % \end{macro}
817 %
818 %
819 %
820 %
821 %
822 % \begin{macro}{\@gobble@om,\@gobble@som,\@gobble@with@sphack@om,\@gobble@with@sphack@som}
823 %
824 % Each of these four commands accepts an optional and a mandatory
825 % argument, possibly preceeded by a star. In all cases the
826 % expansion is empty or just manipulates the spaces around the command.
827 % Used to disable commands such as \cs{index}
828 % or \cs{label} in certain situations.
829 % \begin{macrocode}
830 %</2ekernel>
831 %<*2ekernel|latexrelease>
832 %<latexrelease>\IncludeInRelease{2025/06/01}%
833 %<latexrelease> {\@gobble@som}{Extended index/label}%
834 % \end{macrocode}
835 %
836 % Just getting rid of the input in an expandable way is done by these two.
837 % \changes{v1.1g}{2025/01/21}
838 % {Support extended syntax for \cs{label}, \cs{index} and \cs{glossary} (gh/311)}
839 % \begin{macrocode}
840 \DeclareExpandableDocumentCommand\@gobble@om{+o+m}{}
841 \DeclareExpandableDocumentCommand\@gobble@som{s+o+m}{}
842 % \end{macrocode}
843 %
844 % When something needs to be suppressed during typesetting, one often
845 % also wants to ensure that this doesn't end up with two spaces (in
846 % case there is one before and one after). This can't be done expandably.
847 % \changes{v1.1h}{2025/01/23}
848 % {Make \cs{label}, \cs{index} and \cs{glossary} truely invisible
849 % when typesetting (gh/1638)}
850 % \begin{macrocode}
851 \DeclareDocumentCommand\@gobble@with@sphack@om{+o+m}{\@bsphack\@esphack}
852 \DeclareDocumentCommand\@gobble@with@sphack@som{s+o+m}{\@bsphack\@esphack}
853 % \end{macrocode}
854 % \end{macro}
855 %
856 %
857 %
858 %
859 %
860 % \begin{macro}{\addtocontents}
861 %
862 % The |\addtocontents{|\meta{table}|}{|\meta{text}|}| command
863 % adds \meta{text} to the |.|\meta{table} file, with no
864 % page number.
865 %
866 % \changes{v1.0c}{1994/05/20}{Correct setting of \cs{protect}.}
867 % \changes{v1.0h}{1994/11/04}{Added \cs{protected@write} to
868 % \cs{addtocontents}. ASAJ.}
869 % \changes{v1.1g}{2025/01/21}{Support extended syntax
870 % for \cs{label}, \cs{index}, and \cs{glossary} (gh/311)}
871 % \begin{macrocode}
872 \long\def\addtocontents#1#2{%
873 \protected@write\@auxout
874 {\let\label\@gobble@om
875 \let\index\@gobble@som
876 \let\glossary\@gobble@om}%
877 {\string\@writefile{#1}{#2}}}
878 %</2ekernel|latexrelease>
879 %<latexrelease>\EndIncludeInRelease
880 % \end{macrocode}
881 %
882 % \begin{macrocode}
883 %<latexrelease>\IncludeInRelease{0000/00/00}%
884 %<latexrelease> {\@gobble@som}{Extended index/label}%
885 %<latexrelease>\long\def\addtocontents#1#2{%
886 %<latexrelease> \protected@write\@auxout
887 %<latexrelease> {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
888 %<latexrelease> {\string\@writefile{#1}{#2}}}
889 %<latexrelease>
890 %<latexrelease>\let\@gobble@om\@undefined
891 %<latexrelease>\let\@gobble@som\@undefined
892 %<latexrelease>\let\@gobble@with@sphack@om\@undefined
893 %<latexrelease>\let\@gobble@with@sphack@som\@undefined
894 %<latexrelease>\EndIncludeInRelease
895 %<*2ekernel>
896 % \end{macrocode}
897 % \end{macro}
898 %
899 % \begin{macro}{\contentsline}
900 % The |\contentsline{|\meta{type}|}{|\meta{entry}|}{|\meta{page}|}{}|
901 % macro produces a \meta{type} entry in a table of contents, etc.
902 % It will appear in the |.toc| or other file.
903 % For example, the entry for subsection 1.4.3 in the table of contents,
904 % might be produced by:
905 %
906 % \begin{verbatim}
907 % \contentsline{subsection}
908 % {\numberline{1.4.3}Gnats and Gnus}{22}{}
909 % \end{verbatim}
910 %
911 % The |\protect| command causes command sequences to be written
912 % without expanding them.
913 %
914 % \begin{macrocode}
915 %</2ekernel>
916 %<*2ekernel|latexrelease>
917 %<latexrelease>\IncludeInRelease{2021/11/15}%
918 %<latexrelease> {\contentsline}{Four arguments}%
919 % \end{macrocode}
920 %
921 % In the toc file \cs{contentsline} is followed by 4 arguments
922 % these days, but only the first 3 are used in the old
923 % interface. The fourth was by default empty and only used when
924 % \pkg{hyperref} was loaded. We now pick up all 4 arguments, save
925 % the last one away in \cs{@contentsline@destination} and then call
926 % the old interface. This is done to simplify the interface to
927 % \pkg{hyperref} and to prepare for future changes.
928 % \changes{v1.1f}{2021/07/28}{Pick up four arguments (gh/633)}
929 % \begin{macrocode}
930 \def\contentsline#1#2#3#4{\gdef\@contentsline@destination{#4}%
931 \csname l@#1\endcsname{#2}{#3}}
932 % \end{macrocode}
933 % Default definition.
934 % \begin{macrocode}
935 \let\@contentsline@destination\@empty
936 % \end{macrocode}
937 %
938 % \begin{macrocode}
939 %</2ekernel|latexrelease>
940 %<latexrelease>\EndIncludeInRelease
941 %<latexrelease>\IncludeInRelease{0000/00/00}%
942 %<latexrelease> {\contentsline}{Four arguments}%
943 %<latexrelease>
944 %<latexrelease>\def\contentsline#1{\csname l@#1\endcsname}
945 %<latexrelease>\let\@contentsline@destination\@undefined
946 %<latexrelease>\EndIncludeInRelease
947 %<*2ekernel>
948 % \end{macrocode}
949 % \end{macro}
950 %
951 %
952 %
953 % |\@dottedtocline{|\meta{level}|}{|\meta{indent}|}{|\meta{numwidth}%
954 % |}{|\meta{title}|}{|\meta{page}|}|:
955 % Macro to produce a table of contents line with the following
956 % parameters:
957 % \begin{description}
958 % \item[level] If \meta{level} $>$ |\c@tocdepth|, then no line
959 % produced.
960 % \item[indent] Total indentation from the left margin.
961 % \item[numwidth] Width of box for number if the \meta{title} has a
962 % |\numberline| command.
963 % As of 25 Jan 1988, this is also the amount of extra
964 % indentation added to second and later lines of a
965 % multiple line entry.
966 % \item[title] Contents of entry.
967 % \item[page] Page number.
968 % \end{description}
969 %
970 % Uses the following parameters, which must be set by the document
971 % style. They should be defined with |\def|'s.
972 % \begin{description}
973 % \item[|\@pnumwidth|] Width of box in which page number is set.
974 % \item[|\@tocrmarg|] Right margin indentation for all but last line
975 % of multiple-line entries.
976 % \item[|\@dotsep|] Separation between dots, in mu units.
977 % Should be |\def|'d to a number like 2 or 1.7
978 % \end{description}
979 %
980 % \begin{macro}{\@dottedtocline}
981 % \changes{LaTeX2.09}{1991/09/29}
982 % {(RmS) added \cs{reset@font} for page number}
983 % \changes{v1.0e}{1994/05/25}{Put braces around argument 4
984 % (the actual toc entry) to avoid font (and possibly other)
985 % changes leaking out to the leaders.}
986 % \changes{v1.0g}{1994/10/18}{Added \cs{normalcolor} for page number}
987 % \changes{v1.0z}{1996/12/20}{Added \cs{nobreak} for latex/2343}
988 % \begin{macrocode}
989 %</2ekernel>
990 %<*2ekernel|latexrelease>
991 %<latexrelease>\IncludeInRelease{2018/12/01}%
992 %<latexrelease> {\@dottedtocline}{Prevent protrusion}%
993 \def\@dottedtocline#1#2#3#4#5{%
994 \ifnum #1>\c@tocdepth \else
995 \vskip \z@ \@plus.2\p@
996 {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
997 \parindent #2\relax\@afterindenttrue
998 \interlinepenalty\@M
999 \leavevmode
1000 \@tempdima #3\relax
1001 % \end{macrocode}
1002 % \changes{v1.0z}{1996/12/20}{Added \cs{nobreak} for latex/2343}
1003 % \begin{macrocode}
1004 \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
1005 {#4}\nobreak
1006 \leaders\hbox{$\m@th
1007 % \end{macrocode}
1008 % If a document uses fonts other than computer modern, the use of a
1009 % dot from math can be very disturbing despite the fact that this
1010 % might be the only place in a document that then uses computer
1011 % modern.
1012 % Therefore we surround the dot with an |\hbox| to escape to the
1013 % surrounding text font.
1014 % \changes{v1.0k}{1995/04/25}{Added \cs{hbox} around dots.}
1015 % \changes{v1.0l}{1995/05/02}{Don't reset to \cs{rmfamily}}
1016 % \begin{macrocode}
1017 \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
1018 mu$}\hfill
1019 \nobreak
1020 \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5%
1021 % \end{macrocode}
1022 % We finish off by preventing
1023 % any protrusion if that is enabled. If protrusion happens the
1024 % number may shift to the right and as a result you may end up with
1025 % an additional dot in the toc line in some situations.
1026 % \changes{v1.1b}{2018/09/02}{Prevent protrusion
1027 % (\url{https://tex.stackexchange.com/q/172785/10109})}
1028 % \begin{macrocode}
1029 \kern-\p@\kern\p@}%
1030 \par}%
1031 \fi}
1032 % \end{macrocode}
1033 % \end{macro}
1034 %
1035 %
1036
1037 % \begin{macro}{\noprotrusion}
1038 % This command, if placed directly to the right (or left) of a
1039 % word, will prevent protrusion of that word into the
1040 % margin. It is used in the toc entry lines as they shouldn't
1041 % protrude. It is implemented as to kerns that cancel each other
1042 % but being there hide the word so that protrusion is not
1043 % added. Note that a zero kern or an empty box would not work as
1044 % the protrusion mechanism will skip over those.
1045 % \begin{macrocode}
1046 \DeclareRobustCommand\noprotrusion{\leavevmode\kern-\p@\kern\p@}
1047 % \end{macrocode}
1048 % \end{macro}
1049 %
1050 %
1051 % \begin{macrocode}
1052 %</2ekernel|latexrelease>
1053 %<latexrelease>\EndIncludeInRelease
1054 %<latexrelease>\IncludeInRelease{0000/00/00}%
1055 %<latexrelease> {\@dottedtocline}{Prevent protrusion}%
1056 %<latexrelease>\def\@dottedtocline#1#2#3#4#5{%
1057 %<latexrelease> \ifnum #1>\c@tocdepth \else
1058 %<latexrelease> \vskip \z@ \@plus.2\p@
1059 %<latexrelease> {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
1060 %<latexrelease> \parindent #2\relax\@afterindenttrue
1061 %<latexrelease> \interlinepenalty\@M
1062 %<latexrelease> \leavevmode
1063 %<latexrelease> \@tempdima #3\relax
1064 %<latexrelease> \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
1065 %<latexrelease> {#4}\nobreak
1066 %<latexrelease> \leaders\hbox{$\m@th
1067 %<latexrelease> \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
1068 %<latexrelease> mu$}\hfill
1069 %<latexrelease> \nobreak
1070 %<latexrelease> \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%
1071 %<latexrelease> \par}%
1072 %<latexrelease> \fi}
1073 %<latexrelease>
1074 %<latexrelease>\let\noprotrusion\@undefined
1075 %<latexrelease>\EndIncludeInRelease
1076 %<*2ekernel>
1077 % \end{macrocode}
1078 %
1079 %
1080 %
1081 % \textbf{Note:} |\nobreak|'s added 7 Jan 86 to prevent bad line break
1082 % that left the page number dangling by itself at left edge of a new
1083 % line.
1084 %
1085 % Changed 25 Jan 88 to use |\leftskip| instead of |\hangindent| so
1086 % leaders of multiple-line contents entries would line up properly.
1087 % \begin{macro}{\numberline}
1088 % |\numberline{|\meta{number}|}|: For use in a |\contentsline| command.
1089 % It puts \meta{number} flushleft in a box of width |\@tempdima|
1090 % (Before 25
1091 % Jan 88 change, it also added |\@tempdima| to the hanging
1092 % indentation.)
1093 %
1094 % \begin{macrocode}
1095 \def\numberline#1{\hb@xt@\@tempdima{#1\hfil}}
1096 %</2ekernel>
1097 % \end{macrocode}
1098 % \end{macro}
1099 %
1100 % \Finale
1101 %