Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 1993-2026
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}[2026/02/25 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| that takes an
269 % argument but doesn't start a paragraph (so |\fbox| or |\textit|,
270 % for example, wouldn't work without breaking the formatting).
271 % The section heading will be supplied as the
272 % argument to this command. So setting |#6| to, say,
273 % |\bfseries\MakeUppercase| would produce bold,
274 % uppercase headings.
275 % \end{description}
276 %
277 % If `|*|' is missing, then increment the counter. If it is
278 % present, then there should be no |[|\meta{altheading}|]| argument.
279 % The command uses the counter 'secnumdepth'. It contains a pointer
280 % to the highest section level that is to be numbered.
281 %
282 % \textbf{Warning:}
283 % The |\@startsection| command should be at the same or higher
284 % grouping level as the text that follows it. For example, you should
285 % \emph{not} do something like
286 % \begin{verbatim}
287 % \def\foo{ \begingroup ...
288 % \paragraph{...}
289 % \endgroup}
290 % \end{verbatim}
291 %
292 % Pseudocode for the |\@startsection| command
293 % \begin{oldcomments}
294 % \@startsection {NAME}{LEVEL}{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE} ==
295 % BEGIN
296 % IF @noskipsec = T THEN \leavevmode FI
297 % % true if previous section had no body.
298 %
299 % \par
300 % \@tempskipa := BEFORESKIP
301 % @afterindent := T
302 % IF \@tempskipa < 0 THEN \@tempskipa := -\@tempskipa
303 % @afterindent := F
304 % FI
305 % IF @nobreak = true
306 % THEN \everypar == null
307 % ELSE \addpenalty{\@secpenalty}
308 % \addvspace{\@tempskipa}
309 % FI
310 % IF * next
311 % THEN \@ssect{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE}
312 % ELSE \@dblarg{\@sect
313 % {NAME}{LEVEL}{INDENT}
314 % {BEFORESKIP}{AFTERSKIP}{STYLE}}
315 % FI
316 % END
317 % \end{oldcomments}
318 %
319 % \begin{macrocode}
320 \def\@startsection#1#2#3#4#5#6{%
321 \if@noskipsec \leavevmode \fi
322 \par
323 \@tempskipa #4\relax
324 \@afterindenttrue
325 \ifdim \@tempskipa <\z@
326 \@tempskipa -\@tempskipa \@afterindentfalse
327 \fi
328 \if@nobreak
329 \everypar{}%
330 \else
331 \addpenalty\@secpenalty\addvspace\@tempskipa
332 \fi
333 \@ifstar
334 {\@ssect{#3}{#4}{#5}{#6}}%
335 {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}
336 % \end{macrocode}
337 % \end{macro}
338 %
339 % \begin{macro}{\@sect}
340 % Pseudocode for the |\@sect| command
341 % \begin{oldcomments}
342 % \@sect{NAME}{LEVEL}
343 % {INDENT}{BEFORESKIP}{AFTERSKIP}
344 % {STYLE}[ARG1]{ARG2}
345 % ==
346 % BEGIN
347 % IF LEVEL > \c@secnumdepth
348 % THEN \@svsec :=L null
349 % ELSE \refstepcounter{NAME}
350 % \@svsec :=L BEGIN \@seccntformat{#1}\relax END
351 % FI
352 % IF AFTERSKIP > 0
353 % THEN \begingroup
354 % STYLE
355 % \@hangfrom{\hskip INDENT\@svsec}
356 % {\interlinepenalty 10000 ARG2\par}
357 % \endgroup
358 % \NAMEmark{ARG1}
359 % \addcontentsline{toc}{NAME}
360 % { IF LEVEL > \c@secnumdepth
361 % ELSE \protect\numberline{\theNAME} FI
362 % ARG1 }
363 % ELSE \@svsechd == BEGIN STYLE
364 % \hskip INDENT\@svsec
365 % ARG2
366 % \NAMEmark{ARG1}
367 % \addcontentsline{toc}{NAME}
368 % { IF LEVEL > \c@secnumdepth
369 % ELSE
370 % \protect\numberline{\theNAME}
371 % FI
372 % ARG1 }
373 % END
374 % FI
375 % \@xsect{AFTERSKIP}
376 % END
377 % \end{oldcomments}
378 %
379 % \changes{LaTeX2.09}{1992/08/25}
380 % {(FMi) replaced explicit setting of \cs{@svsec}
381 % by call to \cs{@seccntformat}}
382 % \changes{LaTeX2.09}{1993/08/05}
383 % {(RmS) Made sure that \cs{protect} works correctly in
384 % expansion of \cs{the} counter}
385 % \changes{1.0h}{1994/11/04}
386 % {(ASAJ) Added \cs{protected@edef}.}
387 % \begin{macrocode}
388 \def\@sect#1#2#3#4#5#6[#7]#8{%
389 \ifnum #2>\c@secnumdepth
390 \let\@svsec\@empty
391 \else
392 \refstepcounter{#1}%
393 % \end{macrocode}
394 % Since |\@seccntformat| might end with an improper |\hskip| which
395 % is scanning forward for |plus| or |minus| we end the definition
396 % of |\@svsec| with |\relax| as a precaution.
397 % \changes{1.0n}{1995/05/06}{Added \cs{relax} after
398 % \cs{@seccntformat} just in case}
399 % \begin{macrocode}
400 \protected@edef\@svsec{\@seccntformat{#1}\relax}%
401 \fi
402 \@tempskipa #5\relax
403 \ifdim \@tempskipa>\z@
404 \begingroup
405 % \end{macrocode}
406 % \changes{v1.0s}{1996/05/21}
407 % {(DPC) Moved brace to allow commands like
408 % \cs{MakeUppercase} in 6th argument.
409 % Changed \cs{par} to \cs{endgraf} to allow non-long
410 % commands. internal/2148}
411 % \changes{v1.0t}{1996/06/10}
412 % {(DPC) Changed \cs{endgraf} to \cs{@@par}}
413 % This |{| used to be after the argument to |\@hangfrom| but was moved
414 % here to allow commands such as |\MakeUppercase| to be used at the end
415 % of |#6|.
416 % \begin{macrocode}
417 #6{%
418 \@hangfrom{\hskip #3\relax\@svsec}%
419 \interlinepenalty \@M #8\@@par}%
420 \endgroup
421 \csname #1mark\endcsname{#7}%
422 \addcontentsline{toc}{#1}{%
423 \ifnum #2>\c@secnumdepth \else
424 \protect\numberline{\csname the#1\endcsname}%
425 \fi
426 #7}%
427 \else
428 % \end{macrocode}
429 % |\relax| added 2 May 90
430 % \changes{v1.0s}{1996/05/21}
431 % {(DPC) Added extra braces for internal/2148}
432 % \begin{macrocode}
433 \def\@svsechd{%
434 #6{\hskip #3\relax
435 \@svsec #8}%
436 \csname #1mark\endcsname{#7}%
437 \addcontentsline{toc}{#1}{%
438 \ifnum #2>\c@secnumdepth \else
439 \protect\numberline{\csname the#1\endcsname}%
440 \fi
441 #7}}%
442 \fi
443 \@xsect{#5}}
444 % \end{macrocode}
445 % \end{macro}
446 %
447 % \begin{macro}{\@xsect}%
448 % Pseudocode for the |\@xsect| command
449 % \begin{oldcomments}
450 % \@xsect{AFTERSKIP} ==
451 % BEGIN
452 % IF AFTERSKIP > 0
453 % THEN \par \nobreak
454 % \vskip AFTERSKIP
455 % \@afterheading
456 % ELSE @nobreak :=G F
457 % @noskipsec :=G T
458 % \everypar{ IF @noskipsec = T
459 % THEN @noskipsec :=G F
460 % \clubpenalty := 10000 % local
461 % \hskip -\parindent
462 % \begingroup
463 % \@svsechd
464 % \endgroup
465 % \unskip
466 % \hskip -AFTERSKIP \relax
467 % %% relax added 14 Jan 91
468 % ELSE \clubpenalty := \@clubpenalty % local
469 % \everypar := NULL
470 % FI
471 % }
472 % FI
473 %
474 % END
475 % \end{oldcomments}
476 %
477 % \changes{0.0}{1992/08/19}
478 % {(RmS) corrected bug: stretch and shrink in argument to
479 % \cs{hskip} previously not negated}
480 % \begin{macrocode}
481 \def\@xsect#1{%
482 \@tempskipa #1\relax
483 \ifdim \@tempskipa>\z@
484 % \end{macrocode}
485 % Why not combine |\@sect| and |\@xsect| and save doing the
486 % same test twice? It is not possible to change this now as these
487 % have become hooks!
488 %
489 % This |\par| seems unnecessary.
490 % \begin{macrocode}
491 \par \nobreak
492 \vskip \@tempskipa
493 \@afterheading
494 \else
495 % \end{macrocode}
496 % \changes{v1.0u}{1996/07/26}{Removed \cs{global} before
497 % \cs{@nobreak...}}
498 % \changes{v1.0x}{1996/10/23}{Replaced \cs{hskip...} with \cs{setbox...}
499 % as used in \cs{@afterheading}}
500 % \begin{macrocode}
501 \@nobreakfalse
502 \global\@noskipsectrue
503 \everypar{%
504 \if@noskipsec
505 \global\@noskipsecfalse
506 {\setbox\z@\lastbox}%
507 \clubpenalty\@M
508 \begingroup \@svsechd \endgroup
509 \unskip
510 \@tempskipa #1\relax
511 \hskip -\@tempskipa
512 \else
513 \clubpenalty \@clubpenalty
514 \everypar{}%
515 \fi}%
516 \fi
517 \ignorespaces}
518 % \end{macrocode}
519 % \end{macro}
520 %
521 % \begin{macro}{\@seccntformat}
522 % This command formats the section number including the space
523 % following it.
524 % \changes{1.0n}{1995/05/06}{Use \cs{quad} instead of \cs{hskip}}
525 % \begin{macrocode}
526 \def\@seccntformat#1{\csname the#1\endcsname\quad}
527 % \end{macrocode}
528 % \end{macro}
529 %
530 % Pseudocode for the |\@ssect| command
531 % \begin{oldcomments}
532 % \@ssect{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE}{ARG} ==
533 % BEGIN
534 % IF AFTERSKIP > 0
535 % THEN \begingroup
536 % STYLE
537 % \@hangfrom{\hskip INDENT}
538 % {\interlinepenalty 10000 ARG\par}
539 % \endgroup
540 % ELSE \@svsechd == BEGIN STYLE
541 % \hskip INDENT
542 % ARG
543 % END
544 % FI
545 % \@xsect{AFTERSKIP}
546 % END
547 % \end{oldcomments}
548 %
549 % Pseudocode for the |\@afterheading| command
550 % \begin{oldcomments}
551 % \@afterheading ==
552 % BEGIN
553 % @nobreak :=G true
554 % \everypar := BEGIN IF @nobreak = T
555 % THEN @nobreak :=G false
556 % \clubpenalty := 10000 % local
557 % IF @afterindent = F
558 % THEN remove \lastbox
559 % FI
560 % ELSE \clubpenalty := \@clubpenalty % local
561 % \everypar := NULL
562 % FI
563 % END
564 % END
565 % \end{oldcomments}
566 %
567 %
568 % \begin{macro}{\@ssect}
569 % \begin{macrocode}
570 \def\@ssect#1#2#3#4#5{%
571 \@tempskipa #3\relax
572 \ifdim \@tempskipa>\z@
573 \begingroup
574 % \end{macrocode}
575 % \changes{v1.0s}{1996/05/21}
576 % {(DPC) Moved brace to allow commands like
577 % \cs{MakeUppercase} in 4th argument.
578 % Changed \cs{par} to \cs{endgraf} to allow non-long
579 % commands. internal/2148}
580 % \changes{v1.0t}{1996/06/10}
581 % {(DPC) Changed \cs{endgraf} to \cs{@@par}}
582 % This |{| used to be after the argument to |\@hangfrom| but was moved
583 % here to allow commands such as |\MakeUppercase| to be used at the end
584 % of |#4|.
585 % \begin{macrocode}
586 #4{%
587 \@hangfrom{\hskip #1}%
588 \interlinepenalty \@M #5\@@par}%
589 \endgroup
590 \else
591 % \end{macrocode}
592 % \changes{v1.0s}{1996/05/21}
593 % {(DPC) Added extra braces for internal/2148}
594 % \begin{macrocode}
595 \def\@svsechd{#4{\hskip #1\relax #5}}%
596 \fi
597 \@xsect{#3}}
598 % \end{macrocode}
599 % \end{macro}
600 %
601 % \begin{macro}{\if@afterindent}
602 % \begin{macro}{\@afterindenttrue}
603 % \begin{macrocode}
604 \newif\if@afterindent \@afterindenttrue
605 % \end{macrocode}
606 % \end{macro}\end{macro}
607 %
608 % \begin{macro}{\@afterheading}
609 % \changes{v1.0v}{1996/08/02}{Removed \cs{global}
610 % before \cs{@nobreak...}}
611 %
612 % This hook is used in setting up custom-built headings in classes.dtx.
613 %
614 % \begin{macrocode}
615 \def\@afterheading{%
616 \@nobreaktrue
617 \everypar{%
618 \if@nobreak
619 \@nobreakfalse
620 \clubpenalty \@M
621 \if@afterindent \else
622 {\setbox\z@\lastbox}%
623 \fi
624 \else
625 \clubpenalty \@clubpenalty
626 \everypar{}%
627 \fi}}
628 % \end{macrocode}
629 % \end{macro}
630 %
631 %
632 % \begin{macro}{\@hangfrom}
633 %
634 % |\@hangfrom{|\meta{text}|}| : Puts \meta{text} in a box, and makes a
635 % hanging indentation of the following material up to the first
636 % |\par|. Should be used in vertical mode.
637 %
638 % \changes{v1.0a}{1994/03/07}{(DPC)Extra groups for colour}
639 % \begin{macrocode}
640 \def\@hangfrom#1{\setbox\@tempboxa\hbox{{#1}}%
641 \hangindent \wd\@tempboxa\noindent\box\@tempboxa}
642 % \end{macrocode}
643 % \end{macro}
644 %
645 % \begin{macro}{\c@secnumdepth}
646 % \begin{macro}{\c@tocdepth}
647 % \begin{macrocode}
648 \newcount\c@secnumdepth
649 \newcount\c@tocdepth
650 % \end{macrocode}
651 % \end{macro}\end{macro}
652 %
653 % \begin{macro}{\secdef}
654 %
655 % |\secdef{|\meta{unstarcmds}|}{|\meta{unstarcmds}|}{|%
656 % \meta{starcmds}|}|\\
657 % When defining a |\chapter| or |\section| command without using
658 % |\@startsection|, you can use |\secdef| as follows:
659 % \begin{enumerate}
660 % \item |\def\chapter{| \ldots |\secdef|
661 % |\|\meta{starcmd} |\|\meta{unstarcmd} |}|
662 % \item |\def\|\meta{starcmd}|[#1]#2{| \ldots |}|
663 % |%| Command to define |\chapter[|\ldots|]{|\ldots|}|
664 % \item |\def\|\meta{unstarcmd}|#1{| \ldots |}|
665 % |%| Command to define |\chapter*{|\ldots|}|
666 % \end{enumerate}
667 %
668 % \begin{macrocode}
669 \def\secdef#1#2{\@ifstar{#2}{\@dblarg{#1}}}
670 % \end{macrocode}
671 % \end{macro}
672 %
673 % \subsubsection{Initializations}
674 % \begin{macro}{\sectionmark}
675 % \begin{macro}{\subsectionmark}
676 % \begin{macro}{\subsubsectionmark}
677 % \begin{macro}{\paragraphmark}
678 % \begin{macro}{\subparagraphmark}
679 % \changes{v1.0q}{1995/10/25}{Use \cs{let} not \cs{def} to save space.}
680 % \begin{macrocode}
681 \let\sectionmark\@gobble
682 \let\subsectionmark\@gobble
683 \let\subsubsectionmark\@gobble
684 \let\paragraphmark\@gobble
685 \let\subparagraphmark\@gobble
686 % \end{macrocode}
687 % \end{macro}
688 % \end{macro}
689 % \end{macro}
690 % \end{macro}
691 % \end{macro}
692 %
693 % \begin{macrocode}
694 \message{contents,}
695 % \end{macrocode}
696 %
697 % \subsection{Table of Contents etc.}
698 %
699 % \subsubsection{Convention}
700 % |\tf@|\meta{foo} = file number for output for table foo.
701 % The file is opened only if |@filesw| = |true|.
702 %
703 % \subsubsection{Commands}
704 %
705 %
706 % A |\l@|\meta{type}|{|\meta{entry}|}{|\meta{page}|}| Macro needs to
707 % defined by document style for making an entry of type \meta{type}
708 % in a table of contents, etc. E.g., the document style
709 % should define |\l@chapter|, |\l@section|, etc.
710 %
711 % \textbf{Note:} When the |\protect| command is
712 % used in the \meta{entry} or \meta{text} of one of the commands
713 % below, it causes the following control sequence to be written on
714 % the file without being expanded. The sequence will be expanded
715 % when the table of contents entry is processed.
716 %
717 % \textbf{Surprise:} Inside an |\addcontentsline| or |\addtocontents|
718 % command argument, the commands: |\index|, |\glossary|, and |\label|
719 % are no-ops . This could cause a problem if the user puts an
720 % |\index| or |\label| into one of the commands he writes, or into the
721 % optional `short version' argument of a |\section| or |\caption|
722 % command.
723 %
724 % \begin{macro}{\@starttoc}
725 % The |\@starttoc|\marg{ext} command is used to define the commands:\\
726 % |\tableofcontents|, |\listoffigures|, etc.
727 %
728 % For example:
729 % |\@starttoc{lof}| is used in |\listoffigures|. This command
730 % reads the |.|\meta{ext} file and sets up to write the new
731 % |.|\meta{ext} file.
732 %
733 % \begin{oldcomments}
734 % \@starttoc{EXT} ==
735 % BEGIN
736 % \begingroup
737 % \makeatletter
738 % read file \jobname.EXT
739 % IF @filesw = true
740 % THEN open \jobname.EXT as file \tf@EXT
741 % FI
742 % @nobreak :=G FALSE %% added 24 May 89
743 % \endgroup
744 % END
745 % \end{oldcomments}
746 %
747 % \changes{0.0}{1992/01/14}{(RmS) added \cs{immediate} to \cs{openout}
748 % as all \cs{write} commands
749 % are also executed \cs{immediate}}
750 % \changes{v1.0u}{1996/07/26}{removed \cs{global}
751 % before \cs{@nobreak...}}
752 % \begin{macrocode}
753 \def\@starttoc#1{%
754 \begingroup
755 \makeatletter
756 \@input{\jobname.#1}%
757 \if@filesw
758 \expandafter\newwrite\csname tf@#1\endcsname
759 \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
760 \fi
761 \@nobreakfalse
762 \endgroup}
763 % \end{macrocode}
764 % \end{macro}
765 %
766 % \begin{macro}{\addcontentsline}
767 % The |\addcontentsline{|\meta{table}|}{|\meta{type}|}{|\meta{entry}|}|
768 % command allows the user to add
769 % his/her own entry to a table of contents, etc. The command adds the
770 % entry |\contentsline{|\meta{type}|}{|\meta{entry}|}{|\meta{page}|}{}|
771 % to the |.|\meta{table} file.
772 %
773 % This macro is implemented as an application of |\addtocontents|.
774 % Note that |\thepage| is not expandable during |\protected@write|
775 % therefore one gets the page number at the time of the |\shipout|.
776 %
777 % \changes{v1.0c}{1994/05/20}{Correct setting of \cs{protect}.}
778 % \changes{v1.0j}{1995/04/23}{Use \cs{contentsline} internally.}
779 % \changes{v1.0h}{1994/11/04}{Added \cs{protected@write} to
780 % \cs{addcontentsline}. ASAJ.}
781 % \changes{v1.1c}{2018/09/26}{Sometimes mask the endline char when
782 % writing to files (github/73)}
783 % \changes{v1.1e}{2020/10/01}{add a fourth argument for better
784 % hyperref compatibility}
785 % \begin{macrocode}
786 %</2ekernel>
787 %<*2ekernel|latexrelease>
788 %<latexrelease>\IncludeInRelease{2020/10/01}%
789 %<latexrelease> {\addcontentsline}{fourth argument}%
790 \def\addcontentsline#1#2#3{%
791 % \end{macrocode}
792 % We add an empty brace pair at the end of \cs{contentsline}
793 % so that the number of argument is identical in documents
794 % with and without hyperref.
795 % \begin{macrocode}
796 \addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}{}%
797 \protected@file@percent}}
798 %</2ekernel|latexrelease>
799 %<latexrelease>\EndIncludeInRelease
800 %<latexrelease>\IncludeInRelease{2018/12/01}%
801 %<latexrelease> {\addcontentsline}{Mask line endings}%
802 %<latexrelease> \def\addcontentsline#1#2#3{%
803 %<latexrelease> \addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}%
804 % \end{macrocode}
805 % We add \cs{protected@file@percent} at the end which is turned inside
806 % \cs{@writefile} into a percent character to mask the newline after
807 % the closing argument brace.
808 % \begin{macrocode}
809 %<latexrelease> \protected@file@percent}}
810 %<latexrelease>\EndIncludeInRelease
811 %<latexrelease>\IncludeInRelease{0000/00/00}%
812 %<latexrelease> {\addcontentsline}{Mask line endings}%
813 %<latexrelease>\def\addcontentsline#1#2#3{%
814 %<latexrelease> \addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}}}
815 %<latexrelease>\EndIncludeInRelease
816 %<*2ekernel>
817 % \end{macrocode}
818 % \end{macro}
819 %
820 %
821 %
822 %
823 %
824 % \begin{macro}{\@gobble@om,\@gobble@som,\@gobble@with@sphack@om,\@gobble@with@sphack@som}
825 %
826 % Each of these four commands accepts an optional and a mandatory
827 % argument, possibly preceeded by a star. In all cases the
828 % expansion is empty or just manipulates the spaces around the command.
829 % Used to disable commands such as \cs{index}
830 % or \cs{label} in certain situations.
831 % \begin{macrocode}
832 %</2ekernel>
833 %<*2ekernel|latexrelease>
834 %<latexrelease>\IncludeInRelease{2025/06/01}%
835 %<latexrelease> {\@gobble@som}{Extended index/label}%
836 % \end{macrocode}
837 %
838 % Just getting rid of the input in an expandable way is done by these two.
839 % \changes{v1.1g}{2025/01/21}
840 % {Support extended syntax for \cs{label}, \cs{index} and \cs{glossary} (gh/311)}
841 % \begin{macrocode}
842 \DeclareExpandableDocumentCommand\@gobble@om{+o+m}{}
843 \DeclareExpandableDocumentCommand\@gobble@som{s+o+m}{}
844 % \end{macrocode}
845 %
846 % When something needs to be suppressed during typesetting, one often
847 % also wants to ensure that this doesn't end up with two spaces (in
848 % case there is one before and one after). This can't be done expandably.
849 % \changes{v1.1h}{2025/01/23}
850 % {Make \cs{label}, \cs{index} and \cs{glossary} truely invisible
851 % when typesetting (gh/1638)}
852 % \begin{macrocode}
853 \DeclareDocumentCommand\@gobble@with@sphack@om{+o+m}{\@bsphack\@esphack}
854 \DeclareDocumentCommand\@gobble@with@sphack@som{s+o+m}{\@bsphack\@esphack}
855 % \end{macrocode}
856 % \end{macro}
857 %
858 %
859 %
860 %
861 %
862 % \begin{macro}{\addtocontents}
863 %
864 % The |\addtocontents{|\meta{table}|}{|\meta{text}|}| command
865 % adds \meta{text} to the |.|\meta{table} file, with no
866 % page number.
867 %
868 % \changes{v1.0c}{1994/05/20}{Correct setting of \cs{protect}.}
869 % \changes{v1.0h}{1994/11/04}{Added \cs{protected@write} to
870 % \cs{addtocontents}. ASAJ.}
871 % \changes{v1.1g}{2025/01/21}{Support extended syntax
872 % for \cs{label}, \cs{index}, and \cs{glossary} (gh/311)}
873 % \begin{macrocode}
874 \long\def\addtocontents#1#2{%
875 \protected@write\@auxout
876 {\let\label\@gobble@om
877 \let\index\@gobble@som
878 \let\glossary\@gobble@om}%
879 {\string\@writefile{#1}{#2}}}
880 %</2ekernel|latexrelease>
881 %<latexrelease>\EndIncludeInRelease
882 % \end{macrocode}
883 %
884 % \begin{macrocode}
885 %<latexrelease>\IncludeInRelease{0000/00/00}%
886 %<latexrelease> {\@gobble@som}{Extended index/label}%
887 %<latexrelease>\long\def\addtocontents#1#2{%
888 %<latexrelease> \protected@write\@auxout
889 %<latexrelease> {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
890 %<latexrelease> {\string\@writefile{#1}{#2}}}
891 %<latexrelease>
892 %<latexrelease>\let\@gobble@om\@undefined
893 %<latexrelease>\let\@gobble@som\@undefined
894 %<latexrelease>\let\@gobble@with@sphack@om\@undefined
895 %<latexrelease>\let\@gobble@with@sphack@som\@undefined
896 %<latexrelease>\EndIncludeInRelease
897 %<*2ekernel>
898 % \end{macrocode}
899 % \end{macro}
900 %
901 % \begin{macro}{\contentsline}
902 % The |\contentsline{|\meta{type}|}{|\meta{entry}|}{|\meta{page}|}{}|
903 % macro produces a \meta{type} entry in a table of contents, etc.
904 % It will appear in the |.toc| or other file.
905 % For example, the entry for subsection 1.4.3 in the table of contents,
906 % might be produced by:
907 %
908 % \begin{verbatim}
909 % \contentsline{subsection}
910 % {\numberline{1.4.3}Gnats and Gnus}{22}{}
911 % \end{verbatim}
912 %
913 % The |\protect| command causes command sequences to be written
914 % without expanding them.
915 %
916 % \begin{macrocode}
917 %</2ekernel>
918 %<*2ekernel|latexrelease>
919 %<latexrelease>\IncludeInRelease{2021/11/15}%
920 %<latexrelease> {\contentsline}{Four arguments}%
921 % \end{macrocode}
922 %
923 % In the toc file \cs{contentsline} is followed by 4 arguments
924 % these days, but only the first 3 are used in the old
925 % interface. The fourth was by default empty and only used when
926 % \pkg{hyperref} was loaded. We now pick up all 4 arguments, save
927 % the last one away in \cs{@contentsline@destination} and then call
928 % the old interface. This is done to simplify the interface to
929 % \pkg{hyperref} and to prepare for future changes.
930 % \changes{v1.1f}{2021/07/28}{Pick up four arguments (gh/633)}
931 % \begin{macrocode}
932 \def\contentsline#1#2#3#4{\gdef\@contentsline@destination{#4}%
933 \csname l@#1\endcsname{#2}{#3}}
934 % \end{macrocode}
935 % Default definition.
936 % \begin{macrocode}
937 \let\@contentsline@destination\@empty
938 % \end{macrocode}
939 %
940 % \begin{macrocode}
941 %</2ekernel|latexrelease>
942 %<latexrelease>\EndIncludeInRelease
943 %<latexrelease>\IncludeInRelease{0000/00/00}%
944 %<latexrelease> {\contentsline}{Four arguments}%
945 %<latexrelease>
946 %<latexrelease>\def\contentsline#1{\csname l@#1\endcsname}
947 %<latexrelease>\let\@contentsline@destination\@undefined
948 %<latexrelease>\EndIncludeInRelease
949 %<*2ekernel>
950 % \end{macrocode}
951 % \end{macro}
952 %
953 %
954 %
955 % |\@dottedtocline{|\meta{level}|}{|\meta{indent}|}{|\meta{numwidth}%
956 % |}{|\meta{title}|}{|\meta{page}|}|:
957 % Macro to produce a table of contents line with the following
958 % parameters:
959 % \begin{description}
960 % \item[level] If \meta{level} $>$ |\c@tocdepth|, then no line
961 % produced.
962 % \item[indent] Total indentation from the left margin.
963 % \item[numwidth] Width of box for number if the \meta{title} has a
964 % |\numberline| command.
965 % As of 25 Jan 1988, this is also the amount of extra
966 % indentation added to second and later lines of a
967 % multiple line entry.
968 % \item[title] Contents of entry.
969 % \item[page] Page number.
970 % \end{description}
971 %
972 % Uses the following parameters, which must be set by the document
973 % style. They should be defined with |\def|'s.
974 % \begin{description}
975 % \item[|\@pnumwidth|] Width of box in which page number is set.
976 % \item[|\@tocrmarg|] Right margin indentation for all but last line
977 % of multiple-line entries.
978 % \item[|\@dotsep|] Separation between dots, in mu units.
979 % Should be |\def|'d to a number like 2 or 1.7
980 % \end{description}
981 %
982 % \begin{macro}{\@dottedtocline}
983 % \changes{LaTeX2.09}{1991/09/29}
984 % {(RmS) added \cs{reset@font} for page number}
985 % \changes{v1.0e}{1994/05/25}{Put braces around argument 4
986 % (the actual toc entry) to avoid font (and possibly other)
987 % changes leaking out to the leaders.}
988 % \changes{v1.0g}{1994/10/18}{Added \cs{normalcolor} for page number}
989 % \changes{v1.0z}{1996/12/20}{Added \cs{nobreak} for latex/2343}
990 % \begin{macrocode}
991 %</2ekernel>
992 %<*2ekernel|latexrelease>
993 %<latexrelease>\IncludeInRelease{2018/12/01}%
994 %<latexrelease> {\@dottedtocline}{Prevent protrusion}%
995 \def\@dottedtocline#1#2#3#4#5{%
996 \ifnum #1>\c@tocdepth \else
997 \vskip \z@ \@plus.2\p@
998 {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
999 \parindent #2\relax\@afterindenttrue
1000 \interlinepenalty\@M
1001 \leavevmode
1002 \@tempdima #3\relax
1003 % \end{macrocode}
1004 % \changes{v1.0z}{1996/12/20}{Added \cs{nobreak} for latex/2343}
1005 % \begin{macrocode}
1006 \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
1007 {#4}\nobreak
1008 \leaders\hbox{$\m@th
1009 % \end{macrocode}
1010 % If a document uses fonts other than computer modern, the use of a
1011 % dot from math can be very disturbing despite the fact that this
1012 % might be the only place in a document that then uses computer
1013 % modern.
1014 % Therefore we surround the dot with an |\hbox| to escape to the
1015 % surrounding text font.
1016 % \changes{v1.0k}{1995/04/25}{Added \cs{hbox} around dots.}
1017 % \changes{v1.0l}{1995/05/02}{Don't reset to \cs{rmfamily}}
1018 % \begin{macrocode}
1019 \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
1020 mu$}\hfill
1021 \nobreak
1022 \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5%
1023 % \end{macrocode}
1024 % We finish off by preventing
1025 % any protrusion if that is enabled. If protrusion happens the
1026 % number may shift to the right and as a result you may end up with
1027 % an additional dot in the toc line in some situations.
1028 % \changes{v1.1b}{2018/09/02}{Prevent protrusion
1029 % (\url{https://tex.stackexchange.com/q/172785/10109})}
1030 % \begin{macrocode}
1031 \kern-\p@\kern\p@}%
1032 \par}%
1033 \fi}
1034 % \end{macrocode}
1035 % \end{macro}
1036 %
1037 %
1038
1039 % \begin{macro}{\noprotrusion}
1040 % This command, if placed directly to the right (or left) of a
1041 % word, will prevent protrusion of that word into the
1042 % margin. It is used in the toc entry lines as they shouldn't
1043 % protrude. It is implemented as to kerns that cancel each other
1044 % but being there hide the word so that protrusion is not
1045 % added. Note that a zero kern or an empty box would not work as
1046 % the protrusion mechanism will skip over those.
1047 % \begin{macrocode}
1048 \DeclareRobustCommand\noprotrusion{\leavevmode\kern-\p@\kern\p@}
1049 % \end{macrocode}
1050 % \end{macro}
1051 %
1052 %
1053 % \begin{macrocode}
1054 %</2ekernel|latexrelease>
1055 %<latexrelease>\EndIncludeInRelease
1056 %<latexrelease>\IncludeInRelease{0000/00/00}%
1057 %<latexrelease> {\@dottedtocline}{Prevent protrusion}%
1058 %<latexrelease>\def\@dottedtocline#1#2#3#4#5{%
1059 %<latexrelease> \ifnum #1>\c@tocdepth \else
1060 %<latexrelease> \vskip \z@ \@plus.2\p@
1061 %<latexrelease> {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
1062 %<latexrelease> \parindent #2\relax\@afterindenttrue
1063 %<latexrelease> \interlinepenalty\@M
1064 %<latexrelease> \leavevmode
1065 %<latexrelease> \@tempdima #3\relax
1066 %<latexrelease> \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
1067 %<latexrelease> {#4}\nobreak
1068 %<latexrelease> \leaders\hbox{$\m@th
1069 %<latexrelease> \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
1070 %<latexrelease> mu$}\hfill
1071 %<latexrelease> \nobreak
1072 %<latexrelease> \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%
1073 %<latexrelease> \par}%
1074 %<latexrelease> \fi}
1075 %<latexrelease>
1076 %<latexrelease>\let\noprotrusion\@undefined
1077 %<latexrelease>\EndIncludeInRelease
1078 %<*2ekernel>
1079 % \end{macrocode}
1080 %
1081 %
1082 %
1083 % \textbf{Note:} |\nobreak|'s added 7 Jan 86 to prevent bad line break
1084 % that left the page number dangling by itself at left edge of a new
1085 % line.
1086 %
1087 % Changed 25 Jan 88 to use |\leftskip| instead of |\hangindent| so
1088 % leaders of multiple-line contents entries would line up properly.
1089 % \begin{macro}{\numberline}
1090 % |\numberline{|\meta{number}|}|: For use in a |\contentsline| command.
1091 % It puts \meta{number} flushleft in a box of width |\@tempdima|
1092 % (Before 25
1093 % Jan 88 change, it also added |\@tempdima| to the hanging
1094 % indentation.)
1095 %
1096 % \begin{macrocode}
1097 \def\numberline#1{\hb@xt@\@tempdima{#1\hfil}}
1098 %</2ekernel>
1099 % \end{macrocode}
1100 % \end{macro}
1101 %
1102 % \Finale
1103 %