summaryrefslogtreecommitdiff
path: root/macros/latex/base/ltsect.dtx
blob: 29ea142ba6c3edcc133d20534d58bd43c3ce4b1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
% \iffalse meta-comment
%
% Copyright (C) 1993-2021
% The LaTeX Project and any individual authors listed elsewhere
% in this file.
%
% This file is part of the LaTeX base system.
% -------------------------------------------
%
% It may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
%    https://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2008 or later.
%
% This file has the LPPL maintenance status "maintained".
%
% The list of all files belonging to the LaTeX base distribution is
% given in the file `manifest.txt'. See also `legal.txt' for additional
% information.
%
% The list of derived (unpacked) files belonging to the distribution
% and covered by LPPL is defined by the unpacking scripts (with
% extension .ins) which are part of the distribution.
%
% \fi
%
% \iffalse
%%% From File: ltsect.dtx
%<*driver>
% \fi
\ProvidesFile{ltsect.dtx}[2020/12/05 v1.1e LaTeX Kernel (Sectioning)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltsect.dtx}
\title{\filename}
\date{\filedate}
 \author{%
  Johannes Braams\and
  David Carlisle\and
  Alan Jeffrey\and
  Leslie Lamport\and
  Frank Mittelbach\and
  Chris Rowley\and
  Tobias Oetiker\thanks{Tobi updated
              the comments to `doc' conventions}\and
  Rainer Sch\"opf}

\begin{document}
 \MaintainedByLaTeXTeam{latex}
 \maketitle
 \DocInput{\filename}
\end{document}
%</driver>
% \fi
%
%
% \changes{v1.0o}{1995/05/07}{Use \cs{hb@xt@}}
% \changes{v1.0y}{1996/10/31}{Corrected and tidied documentation;
%                             removed long lines}
%
%
% \section{Sectioning Commands}
%
% This file defines the declarations such as |\author| which are used
% by |\maketitle|. |\maketitle| itself is defined by each class, not
% in the \LaTeX{} kernel.
%
% The second part of the file defines the generic commands used for
% defining sectioning commands such as |\chapter|. Again the actual
% document level commands are defined in the class files, in terms of
% these commands.
%
% \StopEventually{}
%
%
% \changes{v1.0a}{1994/03/04}{Initial version, split from latex.dtx}
% \changes{v1.0b}{1994/03/28}{Split further from ltherest.dtx}
% \changes{v1.0d}{1994/05/21}{Use new error commands}
% \changes{v1.0f}{1994/10/12}{Doc. typos}
% \changes{v1.0g}{1994/10/18}{Added \cs{normalcolor}}
% \changes{v1.0i}{1994/11/17}
%         {\cs{@tempa} to \cs{reserved@a}}
% \changes{v1.0m}{1995/05/03}{TO: Promoted documentation to doc.sty
%         standard}
% \changes{v1.1d}{2019/08/27}{Make various commands robust}
%
%    \begin{macrocode}
%<*2ekernel>
\message{title,}
%    \end{macrocode}
%
% \subsection{The Title}
%
% \DescribeMacro{\title}
% The user defines the title and  author by the declarations
% |\title|\marg{name},
% \DescribeMacro{\author}
% |\author|\marg{name}
%
% \DescribeMacro{\date}
% Similarly the date is declared with
% |\date|\marg{date}.
%
% \DescribeMacro{\thanks}
% Inside these, the |\thanks|\marg{footnote text} command may be used
% to make acknowledgements, notice of address, etc.\ in a footnote.
% \DescribeMacro{\and}
% If there are multiple authors, they have to be separated with the
% |\and| command.
%
% \DescribeMacro{\maketitle}
% And finally, the |\maketitle| command produces the actual title,
% using the information previously saved with the other commands.
%
%
%
%    \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2019/10/01}%
%<latexrelease>                 {\title}{Make commands robust}%
%    \end{macrocode}
%
%
%  \begin{macro}{\title}
% \changes{LaTeX2e}{1993/12/11}{Added default}
% |\title| for use in |\maketitle|. If not given |\maketitle| will
% produce an error message.
%    \begin{macrocode}
\DeclareRobustCommand\title[1]{\gdef\@title{#1}}
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\author}
% \changes{LaTeX2e}{1993/12/11}{Added default}
% \changes{v1.1e}{2020/07/27}{Don't make the command \cs{long} (gh/354)}
%
%  |\author| for use in |\maketitle|. If not given |\maketitle| will
%  produce a warning message.
%
%    \begin{macrocode}
\DeclareRobustCommand*\author[1]{\gdef\@author{#1}}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\date}
%    |\date| for use in |\maketitle|. If not given |\maketitle| will
%    produce |\today| as the default.
% \changes{v1.1e}{2020/07/27}{Don't make the command \cs{long} (gh/354)}
%    \begin{macrocode}
\DeclareRobustCommand*\date[1]{\gdef\@date{#1}}
%    \end{macrocode}
%  \end{macro}
%
% \changes{1.0h}{1994/11/04}{(ASAJ) Added \cs{protected@xdef} to
%    \cs{thanks}.}
% \begin{macro}{\thanks}
%    \begin{macrocode}
\DeclareRobustCommand\thanks[1]{\footnotemark
    \protected@xdef\@thanks{\@thanks
        \protect\footnotetext[\the\c@footnote]{#1}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\and}
%    \begin{macrocode}
\DeclareRobustCommand\and{%   % \begin{tabular}
  \end{tabular}%
  \hskip 1em \@plus.17fil%
  \begin{tabular}[t]{c}}%     % \end{tabular}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease>                 {\title}{Make commands robust}%
%<latexrelease>
%<latexrelease>\kernel@make@fragile\title
%<latexrelease>\kernel@make@fragile\author
%<latexrelease>\kernel@make@fragile\date
%<latexrelease>\kernel@make@fragile\thanks
%<latexrelease>\kernel@make@fragile\and
%<latexrelease>
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
%    \end{macrocode}
%
%
%
%  \begin{macro}{\@title}
%    \begin{macrocode}
\def\@title{\@latex@error{No \noexpand\title given}\@ehc}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\@author}
%    \begin{macrocode}
\def\@author{\@latex@warning@no@line{No \noexpand\author given}}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\@date}
%    \begin{macrocode}
\gdef\@date{\today}
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{\@thanks}
%    \begin{macrocode}
\let\@thanks\@empty
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\message{sectioning,}
%    \end{macrocode}
% \subsection{Sectioning}
%
%
% \begin{macro}{\@secpenalty}
%    \begin{macrocode}
\newcount\@secpenalty
\@secpenalty = -300
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@noskipsec}
% \begin{macro}{\@noskipsectrue}
% \changes{1.0w}{1996/09/29}{Added documentation}
% Way back in 1991 (08/26) FMi \& RmS set the |\@noskipsec| switch
% to true for the preamble and to false in |\document|.
% This was done to trap lists and related text in the preamble but it
% does not catch everything.
%    \begin{macrocode}
\newif\if@noskipsec \@noskipsectrue
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@startsection}
%
% The |\@startsection{|\meta{name}|}{|\meta{level}|}{|%
%       \meta{indent}|}{|\meta{beforeskip}|}|\\
%     |{|\meta{afterskip}|}{|\meta{style}|}*[|\meta{altheading}%
%     |]{|\meta{heading}|}|
% command is the mother of all the user level sectioning commands.
% The part after the |*|, including the |*| is optional.
%
% \begin{description}
% \item[name:] e.g., 'subsection'
% \item[level:] a number, denoting depth of section -- e.g.,
%                  chapter = 0, section = 1, etc.
% \item[indent:] Indentation of heading from left margin
% \item[beforeskip:] Absolute value = skip to leave above the heading.
%                If negative, then paragraph indent of text following
%                heading is suppressed.
% \item[afterskip:] if positive, then skip to leave below heading, else
%                negative of skip to leave to right of run-in heading.
% \item[style:] Commands to set style. Since June 1996 release the
%               \emph{last} command in this argument may be a command
%                such as |\MakeUppercase| or |\fbox| that takes an
%                argument. The section heading will be supplied as the
%                argument to this command. So setting |#6| to, say,
%                |\bfseries\MakeUppercase| would produce bold,
%                uppercase headings.
% \end{description}
%
%  If `|*|' is  missing, then increment the counter.  If it is
%  present, then there should be no |[|\meta{altheading}|]| argument.
%  The command uses the counter 'secnumdepth'. It contains a pointer
%  to the highest section level that is to be numbered.
%
%  \textbf{Warning:}
%  The |\@startsection| command should be at the same or higher
%  grouping level as the text that follows it.  For example, you should
%  \emph{not} do something like
%  \begin{verbatim}
%      \def\foo{ \begingroup ...
%                   \paragraph{...}
%                 \endgroup}
%  \end{verbatim}
%
% Pseudocode for the |\@startsection| command
% \begin{oldcomments}
% \@startsection {NAME}{LEVEL}{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE} ==
%    BEGIN
%     IF  @noskipsec = T  THEN  \leavevmode  FI
%                              % true if previous section had no body.
%
%     \par
%     \@tempskipa  := BEFORESKIP
%     @afterindent := T
%     IF \@tempskipa < 0  THEN  \@tempskipa  := -\@tempskipa
%                               @afterindent := F
%     FI
%     IF @nobreak = true
%       THEN \everypar == null
%       ELSE \addpenalty{\@secpenalty}
%            \addvspace{\@tempskipa}
%     FI
%     IF * next
%       THEN \@ssect{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE}
%       ELSE \@dblarg{\@sect
%                {NAME}{LEVEL}{INDENT}
%                {BEFORESKIP}{AFTERSKIP}{STYLE}}
%     FI
% END
% \end{oldcomments}
%
%    \begin{macrocode}
\def\@startsection#1#2#3#4#5#6{%
  \if@noskipsec \leavevmode \fi
  \par
  \@tempskipa #4\relax
  \@afterindenttrue
  \ifdim \@tempskipa <\z@
    \@tempskipa -\@tempskipa \@afterindentfalse
  \fi
  \if@nobreak
    \everypar{}%
  \else
    \addpenalty\@secpenalty\addvspace\@tempskipa
  \fi
  \@ifstar
    {\@ssect{#3}{#4}{#5}{#6}}%
    {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@sect}
% Pseudocode for the |\@sect| command
% \begin{oldcomments}
% \@sect{NAME}{LEVEL}
%       {INDENT}{BEFORESKIP}{AFTERSKIP}
%       {STYLE}[ARG1]{ARG2}
%           ==
%   BEGIN
%    IF LEVEL > \c@secnumdepth
%      THEN \@svsec :=L null
%      ELSE \refstepcounter{NAME}
%           \@svsec :=L BEGIN \@seccntformat{#1}\relax END
%    FI
%    IF AFTERSKIP > 0
%      THEN \begingroup
%              STYLE
%              \@hangfrom{\hskip INDENT\@svsec}
%              {\interlinepenalty 10000 ARG2\par}
%           \endgroup
%           \NAMEmark{ARG1}
%           \addcontentsline{toc}{NAME}
%              { IF  LEVEL > \c@secnumdepth
%                  ELSE \protect\numberline{\theNAME}  FI
%                ARG1 }
%      ELSE \@svsechd == BEGIN  STYLE
%                               \hskip INDENT\@svsec
%                               ARG2
%                               \NAMEmark{ARG1}
%                               \addcontentsline{toc}{NAME}
%                                  { IF  LEVEL > \c@secnumdepth
%                                      ELSE
%                                        \protect\numberline{\theNAME}
%                                      FI
%                                    ARG1 }
%                        END
%    FI
%    \@xsect{AFTERSKIP}
% END
% \end{oldcomments}
%
% \changes{LaTeX2.09}{1992/08/25}
%         {(FMi) replaced explicit setting of \cs{@svsec}
%               by call to \cs{@seccntformat}}
% \changes{LaTeX2.09}{1993/08/05}
%         {(RmS) Made sure that \cs{protect} works correctly in
%               expansion of \cs{the} counter}
% \changes{1.0h}{1994/11/04}
%         {(ASAJ) Added \cs{protected@edef}.}
%    \begin{macrocode}
\def\@sect#1#2#3#4#5#6[#7]#8{%
  \ifnum #2>\c@secnumdepth
    \let\@svsec\@empty
  \else
    \refstepcounter{#1}%
%    \end{macrocode}
%    Since |\@seccntformat| might end with an improper |\hskip| which
%    is scanning forward for |plus| or |minus| we end the definition
%    of |\@svsec| with |\relax| as a precaution.
% \changes{1.0n}{1995/05/06}{Added \cs{relax} after
%                            \cs{@seccntformat} just in case}
%    \begin{macrocode}
    \protected@edef\@svsec{\@seccntformat{#1}\relax}%
  \fi
  \@tempskipa #5\relax
  \ifdim \@tempskipa>\z@
    \begingroup
%    \end{macrocode}
% \changes{v1.0s}{1996/05/21}
%         {(DPC) Moved brace to allow commands like
%           \cs{MakeUppercase} in 6th argument.
%            Changed \cs{par} to \cs{endgraf} to allow non-long
%            commands. internal/2148}
% \changes{v1.0t}{1996/06/10}
%         {(DPC) Changed \cs{endgraf} to \cs{@@par}}
% This |{| used to be after the argument to |\@hangfrom| but was moved
% here to allow commands such as |\MakeUppercase| to be used at the end
% of |#6|.
%    \begin{macrocode}
      #6{%
        \@hangfrom{\hskip #3\relax\@svsec}%
          \interlinepenalty \@M #8\@@par}%
    \endgroup
    \csname #1mark\endcsname{#7}%
    \addcontentsline{toc}{#1}{%
      \ifnum #2>\c@secnumdepth \else
        \protect\numberline{\csname the#1\endcsname}%
      \fi
      #7}%
  \else
%    \end{macrocode}
% |\relax| added 2 May 90
% \changes{v1.0s}{1996/05/21}
%         {(DPC) Added extra braces for internal/2148}
%    \begin{macrocode}
    \def\@svsechd{%
      #6{\hskip #3\relax
      \@svsec #8}%
      \csname #1mark\endcsname{#7}%
      \addcontentsline{toc}{#1}{%
        \ifnum #2>\c@secnumdepth \else
          \protect\numberline{\csname the#1\endcsname}%
        \fi
        #7}}%
  \fi
  \@xsect{#5}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@xsect}%
% Pseudocode for the |\@xsect| command
% \begin{oldcomments}
% \@xsect{AFTERSKIP} ==
%  BEGIN
%    IF AFTERSKIP > 0
%      THEN \par \nobreak
%           \vskip AFTERSKIP
%           \@afterheading
%      ELSE @nobreak :=G F
%           @noskipsec :=G T
%           \everypar{ IF @noskipsec = T
%                        THEN @noskipsec :=G F
%                             \clubpenalty := 10000 % local
%                             \hskip -\parindent
%                             \begingroup
%                               \@svsechd
%                             \endgroup
%                             \unskip
%                             \hskip -AFTERSKIP \relax
%                                           %% relax added 14 Jan 91
%                        ELSE \clubpenalty := \@clubpenalty % local
%                             \everypar := NULL
%                      FI
%                    }
%    FI
%
%   END
% \end{oldcomments}
%
% \changes{0.0}{1992/08/19}
%     {(RmS) corrected bug: stretch and shrink in argument to
%               \cs{hskip} previously not negated}
%    \begin{macrocode}
\def\@xsect#1{%
  \@tempskipa #1\relax
  \ifdim \@tempskipa>\z@
%    \end{macrocode}
%    Why not combine |\@sect| and |\@xsect| and save doing the
%    same test twice? It is not possible to change this now as these
%    have become hooks!
%
%    This |\par| seems unnecessary.
%    \begin{macrocode}
    \par \nobreak
    \vskip \@tempskipa
    \@afterheading
  \else
%    \end{macrocode}
% \changes{v1.0u}{1996/07/26}{Removed \cs{global} before
%                             \cs{@nobreak...}}
% \changes{v1.0x}{1996/10/23}{Replaced \cs{hskip...} with \cs{setbox...}
%                             as used in \cs{@afterheading}}
%    \begin{macrocode}
    \@nobreakfalse
    \global\@noskipsectrue
    \everypar{%
      \if@noskipsec
        \global\@noskipsecfalse
       {\setbox\z@\lastbox}%
        \clubpenalty\@M
        \begingroup \@svsechd \endgroup
        \unskip
        \@tempskipa #1\relax
        \hskip -\@tempskipa
      \else
        \clubpenalty \@clubpenalty
        \everypar{}%
      \fi}%
  \fi
  \ignorespaces}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@seccntformat}
%    This command formats the section number including the space
%    following it.
% \changes{1.0n}{1995/05/06}{Use \cs{quad} instead of \cs{hskip}}
%    \begin{macrocode}
\def\@seccntformat#1{\csname the#1\endcsname\quad}
%    \end{macrocode}
% \end{macro}
%
% Pseudocode for the |\@ssect| command
% \begin{oldcomments}
% \@ssect{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE}{ARG} ==
%   BEGIN
%    IF AFTERSKIP > 0
%      THEN \begingroup
%             STYLE
%             \@hangfrom{\hskip INDENT}
%                       {\interlinepenalty 10000 ARG\par}
%           \endgroup
%      ELSE \@svsechd == BEGIN STYLE
%                              \hskip INDENT
%                              ARG
%                        END
%    FI
%    \@xsect{AFTERSKIP}
%   END
% \end{oldcomments}
%
% Pseudocode for the |\@afterheading| command
% \begin{oldcomments}
% \@afterheading ==
%  BEGIN
%    @nobreak :=G true
%    \everypar := BEGIN IF @nobreak = T
%                         THEN @nobreak  :=G false
%                              \clubpenalty := 10000 % local
%                              IF @afterindent = F
%                                THEN remove \lastbox
%                              FI
%                         ELSE \clubpenalty := \@clubpenalty % local
%                              \everypar := NULL
%                      FI
%                 END
%  END
% \end{oldcomments}
%
%
% \begin{macro}{\@ssect}
%    \begin{macrocode}
\def\@ssect#1#2#3#4#5{%
  \@tempskipa #3\relax
  \ifdim \@tempskipa>\z@
    \begingroup
%    \end{macrocode}
% \changes{v1.0s}{1996/05/21}
%         {(DPC) Moved brace to allow commands like
%           \cs{MakeUppercase} in 4th argument.
%            Changed \cs{par} to \cs{endgraf} to allow non-long
%            commands. internal/2148}
% \changes{v1.0t}{1996/06/10}
%         {(DPC) Changed \cs{endgraf} to \cs{@@par}}
% This |{| used to be after the argument to |\@hangfrom| but was moved
% here to allow commands such as |\MakeUppercase| to be used at the end
% of |#4|.
%    \begin{macrocode}
      #4{%
        \@hangfrom{\hskip #1}%
          \interlinepenalty \@M #5\@@par}%
    \endgroup
  \else
%    \end{macrocode}
% \changes{v1.0s}{1996/05/21}
%         {(DPC) Added extra braces for internal/2148}
%    \begin{macrocode}
    \def\@svsechd{#4{\hskip #1\relax #5}}%
  \fi
  \@xsect{#3}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@afterindent}
% \begin{macro}{\@afterindenttrue}
%    \begin{macrocode}
\newif\if@afterindent \@afterindenttrue
%    \end{macrocode}
% \end{macro}\end{macro}
%
% \begin{macro}{\@afterheading}
% \changes{v1.0v}{1996/08/02}{Removed \cs{global}
%                             before \cs{@nobreak...}}
%
% This hook is used in setting up custom-built headings in classes.dtx.
%
%    \begin{macrocode}
\def\@afterheading{%
  \@nobreaktrue
  \everypar{%
    \if@nobreak
      \@nobreakfalse
      \clubpenalty \@M
      \if@afterindent \else
        {\setbox\z@\lastbox}%
      \fi
    \else
      \clubpenalty \@clubpenalty
      \everypar{}%
    \fi}}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@hangfrom}
%
% |\@hangfrom{|\meta{text}|}| : Puts \meta{text} in a box, and makes a
% hanging indentation of the following material up to the first
% |\par|. Should be used in vertical mode.
%
% \changes{v1.0a}{1994/03/07}{(DPC)Extra groups for colour}
%    \begin{macrocode}
\def\@hangfrom#1{\setbox\@tempboxa\hbox{{#1}}%
      \hangindent \wd\@tempboxa\noindent\box\@tempboxa}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\c@secnumdepth}
% \begin{macro}{\c@tocdepth}
%    \begin{macrocode}
\newcount\c@secnumdepth
\newcount\c@tocdepth
%    \end{macrocode}
% \end{macro}\end{macro}
%
% \begin{macro}{\secdef}
%
% |\secdef{|\meta{unstarcmds}|}{|\meta{unstarcmds}|}{|%
%           \meta{starcmds}|}|\\
% When defining a |\chapter| or |\section| command without using
% |\@startsection|, you can use |\secdef| as follows:
% \begin{enumerate}
% \item |\def\chapter{| \ldots  |\secdef|
%                |\|\meta{starcmd} |\|\meta{unstarcmd} |}|
% \item |\def\|\meta{starcmd}|[#1]#2{| \ldots |}|
%            |%| Command to define |\chapter[|\ldots|]{|\ldots|}|
% \item |\def\|\meta{unstarcmd}|#1{| \ldots |}|
%   |%| Command to define |\chapter*{|\ldots|}|
% \end{enumerate}
%
%    \begin{macrocode}
\def\secdef#1#2{\@ifstar{#2}{\@dblarg{#1}}}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Initializations}
% \begin{macro}{\sectionmark}
% \begin{macro}{\subsectionmark}
% \begin{macro}{\subsubsectionmark}
% \begin{macro}{\paragraphmark}
% \begin{macro}{\subparagraphmark}
% \changes{v1.0q}{1995/10/25}{Use \cs{let} not \cs{def} to save space.}
%    \begin{macrocode}
\let\sectionmark\@gobble
\let\subsectionmark\@gobble
\let\subsubsectionmark\@gobble
\let\paragraphmark\@gobble
\let\subparagraphmark\@gobble
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
\message{contents,}
%    \end{macrocode}
%
% \subsection{Table of Contents etc.}
%
% \subsubsection{Convention}
% |\tf@|\meta{foo} = file number for output for table foo.
%       The file is opened only if |@filesw| = |true|.
%
% \subsubsection{Commands}
%
%
%  A |\l@|\meta{type}|{|\meta{entry}|}{|\meta{page}|}| Macro needs to
%  defined by document style for making an entry of type \meta{type}
%  in a table of contents, etc.  E.g., the document style
%  should define |\l@chapter|, |\l@section|, etc.
%
%  \textbf{Note:} When the |\protect| command is
%  used in the \meta{entry} or \meta{text} of one of the commands
%  below, it causes the following control sequence to be written on
%  the file without being expanded.  The sequence will be expanded
%  when the table of contents entry is processed.
%
%  \textbf{Surprise:} Inside an |\addcontentsline| or |\addtocontents|
%  command argument, the commands: |\index|, |\glossary|,  and |\label|
%  are  no-ops .  This could cause a problem if the user puts an
%  |\index| or |\label| into one of the commands he writes, or into the
%  optional `short version' argument of a |\section| or |\caption|
%  command.
%
% \begin{macro}{\@starttoc}
% The |\@starttoc|\marg{ext} command is used to define the commands:\\
% |\tableofcontents|, |\listoffigures|, etc.
%
% For example:
% |\@starttoc{lof}| is used in |\listoffigures|.  This command
% reads the |.|\meta{ext} file and sets up to write the new
% |.|\meta{ext} file.
%
% \begin{oldcomments}
% \@starttoc{EXT} ==
%   BEGIN
%     \begingroup
%        \makeatletter
%        read file \jobname.EXT
%        IF @filesw = true
%          THEN  open \jobname.EXT as file \tf@EXT
%        FI
%        @nobreak :=G FALSE  %% added 24 May 89
%     \endgroup
%   END
% \end{oldcomments}
%
% \changes{0.0}{1992/01/14}{(RmS) added \cs{immediate} to \cs{openout}
%               as all \cs{write} commands
%               are also executed \cs{immediate}}
% \changes{v1.0u}{1996/07/26}{removed \cs{global}
%                             before \cs{@nobreak...}}
%    \begin{macrocode}
\def\@starttoc#1{%
  \begingroup
    \makeatletter
    \@input{\jobname.#1}%
    \if@filesw
      \expandafter\newwrite\csname tf@#1\endcsname
      \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
    \fi
    \@nobreakfalse
  \endgroup}
%    \end{macrocode}
% \end{macro}
%
%  \begin{macro}{\addcontentsline}
%  The |\addcontentsline{|\meta{table}|}{|\meta{type}|}{|%
%  \meta{entry}|}| command allows the user to  add
%  his/her own entry to a table of contents, etc. The command adds the
%  entry |\contentsline{|\meta{type}|}{|\meta{entry}|}{|\meta{page}|}|
%  to the |.|\meta{table} file.
%
%  This macro is implemented as an application of |\addtocontents|.
%  Note that |\thepage| is not expandable during |\protected@write|
%  therefore one gets the page number at the time of the |\shipout|.
%
% \changes{v1.0c}{1994/05/20}{Correct setting of \cs{protect}.}
% \changes{v1.0j}{1995/04/23}{Use \cs{contentsline} internally.}
% \changes{v1.0h}{1994/11/04}{Added \cs{protected@write} to
%                \cs{addcontentsline}.  ASAJ.}
% \changes{v1.1c}{2018/09/26}{Sometimes mask the endline char when
%    writing to files (github/73)}
% \changes{v1.1e}{2020/10/01}{add a fourth argument for better
%    hyperref compatibility}
%    \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2020/10/01}%
%<latexrelease>                 {\addcontentsline}{fourth argument}%
\def\addcontentsline#1#2#3{%
%    \end{macrocode}
%    We add an empty brace pair at the end of \cs{contentsline}
%    so that the number of argument is identical in documents
%    with and without hyperref.
%    \begin{macrocode}
  \addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}{}%
                     \protected@file@percent}}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{2018/12/01}%
%<latexrelease>                 {\addcontentsline}{Mask line endings}%
%<latexrelease> \def\addcontentsline#1#2#3{%
%<latexrelease>  \addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}%
%    \end{macrocode}
%    We add \cs{protected@file@percent} at the end which is turned inside
%   \cs{@writefile} into a percent character to mask the newline after
%   the closing argument brace.
%    \begin{macrocode}
%<latexrelease>            \protected@file@percent}}
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease>                 {\addcontentsline}{Mask line endings}%
%<latexrelease>\def\addcontentsline#1#2#3{%
%<latexrelease>  \addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}}}
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
%    \end{macrocode}
%  \end{macro}
%
% \changes{v1.0c}{1994/05/20}{Correct setting of \cs{protect}.}
% \changes{v1.0h}{1994/11/04}{Added \cs{protected@write} to
%    \cs{addtocontents}.  ASAJ.}
% \begin{macro}{\addtocontents}
%
%   The |\addtocontents{|\meta{table}|}{|\meta{text}|}| command
%   adds \meta{text} to the |.|\meta{table} file, with no
%   page number.
%
%    \begin{macrocode}
\long\def\addtocontents#1#2{%
  \protected@write\@auxout
      {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
      {\string\@writefile{#1}{#2}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\contentsline}
% The |\contentsline{|\meta{type}|}{|\meta{entry}|}{|\meta{page}|}|
% macro produces a \meta{type} entry in a table of contents, etc.
% It will appear in the |.toc| or other file.  For example,
% The entry for subsection 1.4.3 in the table of contents for
% example, might be produced by:
%
%  \begin{verbatim}
%       \contentsline{subsection}
%           {\makebox{30pt}[r]{1.4.3} Gnats and Gnus}{22}
%  \end{verbatim}
%
%  The |\protect| command causes command sequences to be written
%  without expanding them.
%
%    \begin{macrocode}
\def\contentsline#1{\csname l@#1\endcsname}
%    \end{macrocode}
% \end{macro}
%
% |\@dottedtocline{|\meta{level}|}{|\meta{indent}|}{|\meta{numwidth}%
%        |}{|\meta{title}|}{|\meta{page}|}|:
%   Macro to produce a table of contents line with the following
%   parameters:
%   \begin{description}
%   \item[level] If \meta{level} $>$ |\c@tocdepth|, then no line
%                produced.
%   \item[indent] Total indentation from the left margin.
%   \item[numwidth] Width of box for number if the \meta{title} has a
%                |\numberline| command.
%                As of 25 Jan 1988, this is also the amount of extra
%                indentation added to second and later lines of a
%                multiple line entry.
%   \item[title] Contents of entry.
%   \item[page] Page number.
%  \end{description}
%
%  Uses the following parameters, which must be set by the document
%  style. They should be defined with |\def|'s.
%  \begin{description}
%  \item[|\@pnumwidth|]  Width of box in which page number is set.
%  \item[|\@tocrmarg|] Right margin indentation for all but last line
%        of multiple-line entries.
%  \item[|\@dotsep|] Separation between dots, in mu units.
%                  Should be |\def|'d to a number like 2 or 1.7
%  \end{description}
%
% \begin{macro}{\@dottedtocline}
% \changes{LaTeX2.09}{1991/09/29}
%         {(RmS) added \cs{reset@font} for page number}
% \changes{v1.0e}{1994/05/25}{Put braces around argument 4
%          (the actual toc entry) to avoid font (and possibly other)
%           changes leaking out to the leaders.}
% \changes{v1.0g}{1994/10/18}{Added \cs{normalcolor} for page number}
% \changes{v1.0z}{1996/12/20}{Added \cs{nobreak} for latex/2343}
%    \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2018/12/01}%
%<latexrelease>                 {\@dottedtocline}{Prevent protrusion}%
\def\@dottedtocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth \else
    \vskip \z@ \@plus.2\p@
    {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
%    \end{macrocode}
% \changes{v1.0z}{1996/12/20}{Added \cs{nobreak} for latex/2343}
%    \begin{macrocode}
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {#4}\nobreak
     \leaders\hbox{$\m@th
%    \end{macrocode}
%    If a document uses fonts other than computer modern, the use of a
%    dot from math can be very disturbing despite the fact that this
%    might be the only place in a document that then uses computer
%    modern.
%    Therefore we surround the dot with an |\hbox| to escape to the
%    surrounding text font.
% \changes{v1.0k}{1995/04/25}{Added \cs{hbox} around dots.}
% \changes{v1.0l}{1995/05/02}{Don't reset to \cs{rmfamily}}
%    \begin{macrocode}
        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
        mu$}\hfill
     \nobreak
     \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5%
%    \end{macrocode}
%    We finish off by preventing
%    any protrusion if that is enabled. If protrusion happens the
%    number may shift to the right and as a result you may end up with
%    an additional dot in the toc line in some situations.
% \changes{v1.1b}{2018/09/02}{Prevent protrusion
%     (\url{https://tex.stackexchange.com/q/172785/10109})}
%    \begin{macrocode}
                        \kern-\p@\kern\p@}%
     \par}%
  \fi}
%    \end{macrocode}
% \end{macro}
%
%

%  \begin{macro}{\noprotrusion}
%    This command, if placed directly to the right (or left) of a
%    word, will prevent protrusion of that word into the
%    margin. It is used in the toc entry lines as they shouldn't
%    protrude. It is implemented as to kerns that cancel each other
%    but being there hide the word so that protrusion is not
%    added. Note that a zero kern or an empty box would not work as
%    the protrusion mechanism will skip over those.
%    \begin{macrocode}
\DeclareRobustCommand\noprotrusion{\leavevmode\kern-\p@\kern\p@}
%    \end{macrocode}
%  \end{macro}
%
%
%    \begin{macrocode}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease>                 {\@dottedtocline}{Prevent protrusion}%
%<latexrelease>\def\@dottedtocline#1#2#3#4#5{%
%<latexrelease>  \ifnum #1>\c@tocdepth \else
%<latexrelease>    \vskip \z@ \@plus.2\p@
%<latexrelease>    {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
%<latexrelease>     \parindent #2\relax\@afterindenttrue
%<latexrelease>     \interlinepenalty\@M
%<latexrelease>     \leavevmode
%<latexrelease>     \@tempdima #3\relax
%<latexrelease>     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
%<latexrelease>     {#4}\nobreak
%<latexrelease>     \leaders\hbox{$\m@th
%<latexrelease>        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
%<latexrelease>        mu$}\hfill
%<latexrelease>     \nobreak
%<latexrelease>     \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%
%<latexrelease>     \par}%
%<latexrelease>  \fi}
%<latexrelease>
%<latexrelease>\let\noprotrusion\@undefined
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
%    \end{macrocode}
%
%
%
% \textbf{Note:} |\nobreak|'s added 7 Jan 86 to prevent bad line break
% that left the page number dangling by itself at left edge of a new
% line.
%
% Changed 25 Jan 88 to use |\leftskip| instead of |\hangindent| so
% leaders of multiple-line contents entries would line up properly.
% \begin{macro}{\numberline}
% |\numberline{|\meta{number}|}|: For use in a |\contentsline| command.
%   It puts \meta{number} flushleft in a box of width |\@tempdima|
%   (Before 25
%   Jan 88 change, it also added |\@tempdima| to the hanging
%   indentation.)
%
%    \begin{macrocode}
\def\numberline#1{\hb@xt@\@tempdima{#1\hfil}}
%</2ekernel>
%    \end{macrocode}
% \end{macro}
%
% \Finale
%