-
Notifications
You must be signed in to change notification settings - Fork 5
/
titlesec.sty
1361 lines (1182 loc) · 39.7 KB
/
titlesec.sty
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
% +--------------------------------------------------+
% | Typeset titlesec.tex to get the documentation. |
% +--------------------------------------------------+
%
% Copyright (c) 1998-2002 by Javier Bezos.
% All Rights Reserved.
%
% This file is part of the titlesec distribution release 2.5
% -----------------------------------------------------------
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or any later version.
% History of v1.0
% ~~~~~~~~~~~~~~~
% 1998/02/25: Added nops option
% 1998/02/28: Added \@mkboth stuff in \setmarks
% 1998/03/01: Changed test in \ttl@secnum
% 1998/03/03: Corrected some \fil... commands
% 1998/03/03: Replaced the faulty \@hangfrom by new commands
% 1998/03/03: Some \def replaced by \newcommand
% 1998/03/04: .dtx/.ins scheme finally rejected. Useless
% for users, obtrusive for `readers' and proned
% to errors
% 1998/03/04: Tidied up documentation
% 1998/03/06: \wordsep renamed and documented
% 1998/03/06: Added dummy asignation in \ttl@chap.
% 1998/03/06: Removed \ttl@xsect and merged into \tl@sect
% 1998/03/06: Added \ProvidesPackage
% History of v1.1
% ~~~~~~~~~~~~~~~~
% 1998/03/25: \chapter corrected, as well as the size options
% 1998/03/26: Added compact option
% 1998/03/26: Added flushleft, flushright and center options
% 1998/04/08: Changed all instances of \noindent by \parindent\z@
% 1998/04/14: Added \filinner, \filouter
% 1998/04/14: Added drop shape
% 1998/05/01: Added rightmargin shape (and margin renamed to
% leftmargin)
% 1998/05/03: Added \setheadindent
%
% History of v1.2 (unreleased)
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%
% 1998/06/01: Compatibility with AMS classes
% 1998/06/08: On-demand loading of shapes
% 1998/06/11: Frame shape. Some \fil... command
% modified to work in the label of this
% chapter shape.
% 1998/07/03: Bottomtitle option (at last...)
% 1998/07/14: ...margin styles bug fixed using a method
% similar to bottomtitle.
% 1998/07/29: \titleline
%
% History of v2.0
% ~~~~~~~~~~~~~~~~
%
% 1998/08/05 to
% 1998/08/29: Fully reimplemented
%
% History of v2.1
% ~~~~~~~~~~~~~~~~
% 1999/01/05: We define in this file the three basic shapes.
% Additional ones remain defined in external files.
% Unified the shapes for sections and chapters.
% 1999/01/05: \ttl@shape merged into \ttl@format@iii.
% 1999/01/05: \titlerule
% 1999/01/07: \ttl@defkeys splitted from \ttl@keys
% 1999/01/10: Added the \part stuff, including a definition of \@openright
% 1999/01/11: Removed unnecessary \ttl@numsecfalse in \ttl@sect@i.
% 1999/01/14: Optimized \titlerule
% 1999/01/27: Changed \titleline to correct the spacing at the
% top page and to fix a bug which changed the mode
% to horizontal, thus introducing unwanted space
% (\makebox -> \@makebox).
% 1999/02/02: \ttl@secnum renamed to \ttl@write and introduced the
% \ttl@savewrite mechanism to sincronize the toc/marks
% with the title in case there is a \newpage in <after>.
% 1999/02/03: wrap shape
% 1999/02/03: Added a \kern\z@ for not to avoid hyphenation
% of the last word. Not strictly necessary, but
% it is more LaTeX-like.
% 1999/02/05: \partmark defined (and in \setmarks, too).
% 1999/02/08: \ttl@row@i simplified.
% 1999/02/08: \ttl@savefn mechanism.
% 1999/02/10: Removed extra \leavevmode in display
% 1999/02/13: Now \titleline doesn't add the width. It's set.
% 1999/02/17: The part mark is catched, even if unused.
% 1999/02/17: old/newparttoc added.
% 1999/02/18: Changed many TeX assignments to the LaTeX
% counterpart.
% 1999/02/19: Introduced \ttl@startargs.
%
% History of v2.1.1
% ~~~~~~~~~~~~~~~~~
% 1999/08/04: Moved misplaced lines in \ttl@makeboth
%
% History of v2.2 (unreleased)
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% 1999/11/03: We load titleps if pagestyles are required, but
% some old definitions are restored.
% 1999/11/06: Improved outermarks test in \ttl@sect@i. Formerly
% the section number could be printed if a page ended
% with an unnumebered section followed by a numbered one.
% 1999/11/06: \ttl@startargs now adds (and passes) automatically the
% section name. Involved macros modified accordingly.
% 1999/11/06: Replaced explicit part names by the parameter in
% \ttl@part@i. The same for chapter.
% 1999/11/21: \ttl@try's are not given explicitly, but built by
% \ttl@setkeys. Intruduced the \ttl@key@... and
% \ttl@extra@... commands.
% 1999/11/23: Minor problems with keys fixed.
% 1999/12/10: Added the nobottomtitles* option and \ttl@addstretch.
% 2000/01/07: First steps towards the calcwidth feature (basic code).
% 2000/01/08: (Continued.) \titleline* for rules of width \titlewidth.
% Option calcwidth implemented.
% 2000/01/12: Finished with changes in wrap.tss (no longer
% "experimental" :-) )
%
% History of v2.3
% ~~~~~~~~~~~~~~~
% 2000/01/19: All keys are grouped in a single file tttkeys. Removed
% page.tsk and deleted the corresponding code in the sty.
% 2000/01/19: Classes begun.
% 2000/01/19: The level numbers are stored in \ttll@ macros, and not
% passed as arguments.
% 2000/01/21: Introduced the new mark scheme. It's mostly compatible
% with the old one, but a compatibility mode seems
% imposible (it was introduced in a preliminary test
% but eventually removed).
% 2000/01/23: loadonly package option.
% 2000/02/01: Classes finished. Many things had to be rewritten.
% 2000/02/02: Made partially compatible with hyperref (dvips).
% 2000/02/08: \ttl@savewrite moved from shapes to classes. But
% explicit page breaks expand it, too, to avoid wrong
% toc entries.
% 2000/02/18: A new box named \ttl@box stores the title in runin
% leftmargin etc shapes, to increase reliability.
%
% (2.3.1 -- 2.3.3: No changes on this file)
%
% History of v2.3.4
% ~~~~~~~~~~~~~~~~~
% 2000/05/12: nonindentfirst redefine \titlespacing instead of
% \@afterindent... so that they don't interfere with
% the first entry in tocs.
% 2000/05/17: The marks in \ttl@select are protected to prevent
% endless loop if the title is expanded, say, by
% \MakeUppercase.
%
% History of v2.3.5
% ~~~~~~~~~~~~~~~~~
% 2000/05/21: Restores missing test for secnumdepth in \ttl@mkchap,
% and instead of setting \ttl@toclevel in ttlps now is
% done in \secdef. Except inside the macros, \ttl@toclevel
% is false, so that an explicit \...mark works.
% 2000/06/04: \partmark defined with \providecommand
% 2000/06/14: A patch mechanism added, for small bug fixes.
%
% History of v2.4
% ~~~~~~~~~~~~~~~~
% 2001/01/18: Minor changes in code. Essentialy an incremental
% update.
% 2001/01/22: \titleformat has a new "easy" starred variant.
%
% History of v2.5
% ~~~~~~~~~~~~~~~
% 2002/01/02 New macros for \ttl@assign. Now * length allow
% non integer values.
% 2002/03/22 Added \ttl@calc and \ttl@calcneg to make titlesec
% calc-savvy.
% - Merged bug fixes of .new into this file.
% - Bugs in frame fixed -- gap in lines, misplaced
% label, wrong margins (sometimes),
% - \leftskip, \rightskip and \linewidth (re)set in
% margin shapes.
% - Removed obsolete flush... options.
% - indentafter and noindentafter, new names for
% indentfirst and nonindentfirst.
% - A new level (\titleclass) without its "location"
% now raises a meaningful error.
% - Bug in top-level \titleclass fixed.
% 2002/03/23 Tests for undefined and unformatted sectioning levels,
% and horizontal material in <format>.
% - Missing \if@openright inside \if@twoside in
% page class added.
% - Removed extra (but inoffensive) \expandafter
% in \ttl@class@iii.
% 2002/03/27 Added \titlewidthfirst and ...last
% - �Not definable� gives a more meaningful message in
% the context of the package.
%
% Notes
% ~~~~~
%
% The following tags are used:
% ttl@ : the generic tag used through the style
% ttlh@ : a shape definition
% ttlf@ : a macro containing the title format
% ttls@ : id. the title space
% ttlp@ : page key related macros
% ttll@ : level number
%
% The ttlf@ and ttls@ contains data in the form {..}{..}.
% Perhaps in future releases they should be converted
% to a prop-like list, similar to that proposed by the
% latex team.
%
% Admittedly, the current implementation seems too
% complicated, but that's necessary in order to provide
% certain compatibility with the sections as defined by the
% used class. Other packages opt for providing the sections
% as defined by standard classes ignoring the class; for
% instance sectsty which does a simple task in a simple and
% nice way. However, that was not my goal.
%
% Release
% ~~~~~~~
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{titlesec}[2002/04/07 v2.5 Sectioning titles]
% Initialization
% ~~~~~~~~~~~~~~
\newif\ifttl@ps
\ttl@psfalse
% The \ttl@label switch is used when printing the label in titles.
% A numberless variant makes it to true.
% There is a \ttl@toclabel as well, which is true iff the
% title is numbered; used in toc entries (except default part
% and chapter) and marks (only in titlesec pagestyles).
\newif\ifttl@label
\newif\ifttl@toclabel
\newbox\ttl@box
% A provision for the report style:
\@ifundefined{if@mainmatter}
{\let\if@mainmatter\iftrue}{}
\@ifundefined{if@openright}
{\let\if@openright\iftrue}{}
% and the ams styles as well
\@ifundefined{@chapapp}
{\let\@chapapp\chaptername}{}
\def\ttl@trylist{\ttl@try{}}
\def\ttl@getkeys#1#2{%
\if\expandafter @\@gobble#1@\@empty
\edef\ttl@b{\expandafter\@gobble\string#1}%
\let\ttl@a\ttl@b
\else
\makeatletter
\input{ttlkeys.def}%
\makeatother
\ttl@getkeys{#1}{#2}%
\fi}
% A more meaningful error for \@notdefinable
\expandafter\AtEndOfPackage\expandafter{\expandafter
\gdef\expandafter\@notdefinable\expandafter{\@notdefinable}}
\def\@notdefinable{%
\PackageError{titlesec}%
{Incompatible package}%
{Titlesec cannot continue defining its own macros
because\MessageBreak
\@backslashchar\reserved@a\space is already used by other package,
the class\MessageBreak
or the document.}}
% +-----------------+
% | C L A S S E S |
% +-----------------+
\def\ttl@useclass#1#2{%
\@ifstar
{\ttl@labelfalse#1{#2}[]}%
{\ttl@labeltrue\@dblarg{#1{#2}}}}
\def\ttl@straightclass{\ttl@useclass\ttl@straight@i}
\def\ttl@partclass{\ttl@useclass\ttl@part@i}
\def\ttl@topclass{\ttl@useclass\ttl@top@i}
\def\ttl@pageclass{\ttl@useclass\ttl@page@i}
\newcommand\titleclass[1]{%
\edef\ttl@a{\expandafter\@gobble\string#1}%
\@ifnextchar[{\@tempswatrue\ttl@class@i{#1}}%
{\@tempswafalse\ttl@class@ii{#1}}}
\def\ttl@class@i#1[#2]{%
\@namedef{ttll@\ttl@a}{#2}%
\expandafter\providecommand\csname\ttl@a title\endcsname{}%%%%
\@ifundefined{ttl@toplevel}{}%
{\expandafter\let\csname ttlss@\ttl@a\expandafter\endcsname
\csname ttlss@\ttl@toplevel\endcsname}%
\edef\ttl@toplevel{\ttl@a}%
\ttl@class@ii{#1}}
\def\ttl@class@ii#1#2{%
\@ifundefined{ttl@#2class}%
{\PackageError{titlesec}{Unknown sectioning class}%
{Valid names are top, page and stright}}%
{\expandafter\let\csname ttl@compat\ttl@a\endcsname\relax
\@ifundefined{\ttl@a mark}%
{\@namedef{\ttl@a mark}{\@gobble}}%
{}%
\edef#1{%
\expandafter\noexpand\csname ttl@#2class\endcsname{\ttl@a}}}%
\if@tempswa
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi
{\@ifnextchar[%
{\ttl@class@iii}%
{\@ifundefined{ttll@\ttl@a}%
{\PackageError{titlesec}{Unknown sectioning level}%
{\string\titleclass\space with no optional arguments\MessageBreak
only changes the class of an *existing* level}}}}}
\def\ttl@class@iii[#1]{%
\edef\ttl@b{\expandafter\@gobble\string#1}%
\expandafter\let\csname ttlss@\ttl@a\expandafter\endcsname
\csname ttlss@\ttl@b\endcsname
\expandafter\edef\csname ttlss@\ttl@b\endcsname{\ttl@a}%
\let\ttl@a\ttl@toplevel
\count@\csname ttll@\ttl@toplevel\endcsname
\ttl@class@iv}% \expandafter
\def\ttl@class@iv{%
\@ifundefined{ttlss@\ttl@a}{}%
{\advance\count@\@ne
\edef\ttl@a{\csname ttlss@\ttl@a\endcsname}%
\expandafter\edef\csname ttll@\ttl@a\endcsname{\the\count@}%
\ttl@class@iv}}
% Typesetting Classes: General tools
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% The following command handles the *n spacing
% Some tricks are necessary to multiply a
% skip by a non integer number
\newskip\beforetitleunit
\beforetitleunit=1ex\@plus.3ex\@minus.06ex
\newskip\aftertitleunit
\aftertitleunit=1ex\@plus.1ex
\newdimen\ttl@plus
\newdimen\ttl@minus
\def\ttl@assign#1{%
\@ifstar
{\ttl@assign@i{#1}}%
{\ttl@assign@d{#1}}}
\def\ttl@assign@i#1#2\relax#3{%
\ttl@plus\z@
\ttl@minus\z@
\afterassignment\ttl@assign@ii
\dimen@\the#3, % <- space
#1 = #2\dimen@
plus #2\ttl@plus
minus #2\ttl@minus}
\def\ttl@assign@ii#1 {% <- space
\if#1,\else\afterassignment\ttl@assign@ii\fi
\csname ttl@\string#1\endcsname}
\def\ttl@assign@d#1#2\relax#3{\setlength#1{#2}}
% To be used with \v/vspace to make them calc-savvy
\def\ttl@calc#1#2{%
{\setlength\@tempskipa{#2}%
#1\@tempskipa}}
\def\ttl@calcneg#1#2{%
{\setlength\@tempskipa{#2}%
#1{-\@tempskipa}}}
% Gets from ttls@ and passes the spacing parameters:
\def\ttl@startargs#1#2{% Get the first arguments, with the spacing
\@ifundefined{ttlp@#2}%
{\let\ttl@key@page\@empty}%
{\ttlp@fetch{#2}}%
\begingroup
\def\ttl@b{ttls@#2}%
\edef\ttl@key@numberless{\ifttl@label//\else/*\fi}%
\def\ttl@a##1{\csname ttl@key@##1\endcsname}% Used as elt in try
\ttl@trylist
\xdef\ttl@b{\ttl@c}%
\endgroup
\ifx\ttl@b\@empty
\PackageError{titlesec}{Format/spacing not found}%
{I was unable to find the format corresponding to #2.\MessageBreak
Maybe you haven't set it with \string\titleformat\space and
\string\titlespacing}
\fi
\expandafter#1\ttl@b{#2}}
% Used in ttl@select
\def\ttl@savefn#1[#2]#3{%
\ifcase#1%
\footnotemark[#2]%
\gdef\ttl@fn{\footnotetext[#2]{#3}}%
\else
\footnotemark
\gdef\ttl@fn{\footnotetext{#3}}%
\fi}
\def\ttl@nest@error{%
\PackageError{titlesec}{Nested titles}{Titles must not be nested}}
\def\ttl@hmode@error{%
\PackageError{titlesec}{Entered in horizontal mode}
{The <format> argument cannot contain horizontal material\MessageBreak
such as text, \string\noindent, \string\makebox, etc.}}
% \ttl@select not only selects the right version to be
% used. It also take steps to ensure that a mark
% is not lost inside a box by saving it into \ttl@mk,
% which in turn is used by the sect and chap commands.
\def\ttl@gmk#1{\gdef\ttl@mk{#1}}
\def\ttl@select#1#2#3#4{%
\ttl@Hy@saveanchor
\global\let\ttl@mk\@empty % global because of rigidchapters
\global\let\ttl@fn\@empty
\begingroup
\everypar{\setbox\z@\lastbox\strut}% or \hskip-\parindent?
\let\ttl@straight@i\ttl@nest@error
\let\ttl@top@i \ttl@nest@error
\let\ttl@part@i \ttl@nest@error
\let\ttl@page@i \ttl@nest@error
\let\ttl@newpage\newpage
\def\newpage{\ttl@savewrite\ttl@newpage}%
\def\markboth##1##2{\protect\ttl@gmk{\protect\markboth{##1}{##2}}}%
\def\markright##1{\protect\ttl@gmk{\protect\markright{##1}}}%
\def\@mkboth##1##2{\protect\ttl@gmk{\protect\@mkboth{##1}{##2}}}%
\def\footnote{\@ifnextchar[%
{\ttl@savefn\z@}{\ttl@savefn\@ne[]}}%
\edef\ttl@key@numberless{\ifttl@label//\else/*\fi}%
\def\ttl@b{ttlf@#1}%
\def\ttl@a##1{\csname ttl@key@##1\endcsname}% Used as elt in try
\ttl@trylist
\ttl@c{#2}{#3}{#4}% ttl@c is returned by ttl@try with ttlf@...
\endgroup}
\let\ttl@savewrite\@empty
\def\ttl@finmarks{%
\ttl@savewrite
\ttl@mk % Contains a possible mark, returned by \ttl@select
\ttl@fn} % And a footnote
\def\ttl@try#1{%
\edef\ttl@c{#1}% #1 is a list in the form \ttl@a{key}\ttl@a{key}
\@ifundefined{\ttl@b\ttl@c}{}{%
\edef\ttl@c{\expandafter\noexpand\csname\ttl@b\ttl@c\endcsname}%
\def\ttl@a##1{\csname ttl@extra@##1\endcsname}%
#1%
\let\ttl@try\@gobble}} % locally modified to `break' testings
% \ttl@write writes marks and toc. tocdepth is taken
% care of when the toc is typesetted and not here.
% Used always through ttl@savewrite
\def\ttl@write#1#2{%
\csname#1mark\endcsname{#2}%
\def\ttl@a{\protect\numberline{\@nameuse{the#1}}}%
\@nameuse{ttl@toc#1}% eg, \ttl@tocpart modifies \ttl@a
\addcontentsline{toc}{#1}{\ifttl@toclabel\ttl@a\fi#2}%
\global\ttl@toclabelfalse}
% Must be preceded by a default \ttl@savewrite, which is used
% in starred variants--\@empty in top and straight classes.
% In straight class, it is preceded by the setting of
% prev marks to provide a "fixed" top mark. Otherwise,
% the default prev mark (= curr mark) is used (restored
% after ttl@labelling in straight). This is the command
% to be hacked if you want to change the behaviour of
% starred variants.
\def\ttl@labelling#1#2{%
\let\ttl@Hy@saveanchor\@empty
\ifttl@label % First: if star
\def\ttl@savewrite{\ttl@write{#1}{#2}}%
\@nameuse{ttl@#1label}% eg, sets if mainmatter in chapter.
\ifttl@label % Second, eg, if not main matter
\ifnum\@nameuse{ttll@#1}>\c@secnumdepth\relax
\ttl@labelfalse % Third: if too deep
\else
\ttl@Hy@refstepcounter{#1}%
\fi
\fi
\fi
\let\ifttl@toclabel\ifttl@label
\ifx\ttl@savewrite\@empty\else % If marks
\ifttl@ps\@nameuse{#1mark}{#2}\fi
\ifttl@label\else\ttl@Hy@steplink{#1}\fi
\fi}
% Executed by ttl@labelling if the name of section is chapter:
\def\ttl@chapterlabel{%
\if@mainmatter\else\ttl@labelfalse\fi
\typeout{\chaptertitlename\space\thechapter.}}
% Straight class
% ~~~~~~~~~~~~~
% Default for nobottomtitles. Changed by nobottomtitles*
\def\ttl@addstretch{\advance\@tempskipa-\pagestretch}
% 1:name 2:level 3:indent 4:before 5:after 6:afind [7]:cap 8:title
% The second argument of ttl@sect is the level, which
% is empty if the star version is used. In this case
% neither the toc nor the marks are written.
\def\ttl@straight@i#1[#2]#3{%
\def\@currentlabelname{#2}% for nameref
\gdef\ttl@savemark{\csname#1mark\endcsname{#3}}%
\let\ttl@savewrite\@empty
\gdef\thetitle{\csname the#1\endcsname}%
\if@noskipsec \leavevmode \fi
\par
\ifttl@ps
\protected@xdef\ttl@prevmarks{\ttl@marks}%
\fi
\ttl@labelling{#1}{#2}%
\ifttl@ps
\gdef\ttl@prevmarks{\ttl@marks}%
\fi
\ttl@startargs\ttl@straight@ii{#1}{#3}}
% 1:left 2:right 3:before 4:after 5:afterindent 6:name 7:title
\def\ttl@straight@ii#1#2#3#4#5#6#7{%
\ttl@assign\@tempskipa#3\relax\beforetitleunit
\if@nobreak
\ttl@titlespace{\@tempskipa}%
\else
\@ifundefined{#6break}%
{\addpenalty{\@secpenalty}}%
{\csname#6break\endcsname}%
\addvspace{\@tempskipa}%
\ifdim\bottomtitlespace<\z@
\else
\begingroup
\@tempskipb\pagegoal
\@tempskipa\pagegoal
\ttl@addstretch % \relax if nobottomtitle*
\advance\@tempskipa-\bottomtitlespace\relax % not a register
\pagegoal\@tempskipa
\def\@textbottom{\vskip\z@\@plus.0001fil}%
\penalty9999
\pagegoal\@tempskipb
\endgroup
\fi
\fi
\@afterindenttrue
\ifcase#5 \@afterindentfalse\fi
\ttl@assign\@tempskipb#4\relax\aftertitleunit
\ttl@select{#6}{#1}{#2}{#7}%
\ttl@finmarks
\@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}%
\if@noskipsec
\global\@nobreakfalse
\everypar{%
\if@noskipsec
\global\@noskipsecfalse
\clubpenalty\@M
\hskip-\parindent
\begingroup
\@svsechd\unskip{\hspace{\@tempskipb}}%
\endgroup
\else
\clubpenalty\@clubpenalty\everypar{}%
\fi}%
\else
\par\nobreak
\vspace{\@tempskipb}%
\@afterheading
\fi
\ignorespaces}
% Part class
% ~~~~~~~~~~
\providecommand\partmark[1]{\markboth{}{}}
\def\ttl@part@i#1[#2]#3{%
\gdef\ttl@savemark{\csname#1mark\endcsname{#3}}%
\def\ttl@savewrite{\ttl@write{#1}{#3}}% A default value. Not #2!
\ttl@labelling{#1}{#2}%
\ttl@startargs\ttl@part@ii{#1}{#3}}
\def\ttl@part@ii#1#2#3#4#5#6#7{%
\ttl@assign\@tempskipa#3\relax\beforetitleunit
\vspace*{\@tempskipa}%
\global\@afterindenttrue
\ifcase#5 \global\@afterindentfalse \fi
\ttl@assign\@tempskipb#4\relax\aftertitleunit
\ttl@select{#6}{#1}{#2}{#7}%
\ttl@finmarks
\@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}%
\par\nobreak
\vspace{\@tempskipb}%
\@afterheading}
% Page class
% ~~~~~~~~~~
\def\ttl@page@i#1[#2]#3{%
\gdef\ttl@savemark{\csname#1mark\endcsname{#3}}%
\def\ttl@savewrite{\ttl@write{#1}{#3}}% A default value. Not #2!
\ttl@labelling{#1}{#2}%
\ttl@startargs\ttl@page@ii{#1}{#3}}
\def\ttl@page@ii#1#2#3#4#5#6#7{%
\ttl@assign\@tempskipa#3\relax\beforetitleunit
\if@openright
\cleardoublepage
\else
\clearpage
\fi
\thispagestyle{plain}%
\if@twocolumn
\onecolumn
\@tempswatrue
\else
\@tempswafalse
\fi
\vspace*{\@tempskipa}%
\@afterindenttrue
\ifcase#5 \@afterindentfalse\fi
\ttl@assign\@tempskipb#4\relax\aftertitleunit
\ttl@select{#6}{#1}{#2}{#7}%
\ttl@finmarks
\@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}%
\vspace{\@tempskipb}%
\newpage
\if@twoside
\if@openright
\null
\thispagestyle{empty}%
\newpage
\fi
\fi
\if@tempswa
\twocolumn
\fi
\ignorespaces}
% Top class and some makechapterhead stuff
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%
% \ttl@mkchap is the new make(s)chapterhead.
\def\ttl@mkchap#1#2#3#4#5#6#7{%
\gdef\ttl@savemark{\csname#6mark\endcsname{#7}}%
\let\ttl@savewrite\@empty
\let\ttl@Hy@saveanchor\@empty
\let\ifttl@toclabel\ifttl@label
\ttl@mkchap@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}}
% But \ttl@mkchap@i is used by both makechapterhead and
% the top class.
\def\ttl@mkchap@i#1#2#3#4#5#6#7{%
\ttl@assign\@tempskipa#3\relax\beforetitleunit
\vspace*{\@tempskipa}%
\global\@afterindenttrue
\ifcase#5 \global\@afterindentfalse\fi
\ttl@assign\@tempskipb#4\relax\aftertitleunit
\ttl@topmode{\@tempskipb}{%
\ttl@select{#6}{#1}{#2}{#7}}%
\ttl@finmarks % Outside the box!
\@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}}
\def\ttl@top@i#1[#2]#3{%
\gdef\ttl@savemark{\csname#1mark\endcsname{#3}}%
\let\ttl@savewrite\@empty
\ttl@labelling{#1}{#2}%
\ttl@startargs\ttl@top@ii{#1}{#3}}
\def\ttl@top@ii#1#2#3#4#5#6#7{%
\if@openright
\cleardoublepage
\else
\clearpage
\fi
\thispagestyle{plain}%
\global\@topnum\z@
\addtocontents{lof}{\protect\ttl@tocsep}%
\addtocontents{lot}{\protect\ttl@tocsep}%
\if@twocolumn
\@topnewpage[\ttl@mkchap@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}]%
\else
\ttl@mkchap@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}%
\@afterheading
\fi
\ignorespaces}
% \def\ttl@noskipsectrue{%
% \if@noskipsec
% \PackageError{titlesec}{Invalid shape for top class}%
% {The selected shape only makes sense when merged into\MessageBreak
% a paragraph. That is impossible in the top class}%
% \else
\newcommand\chaptertitlename{\@chapapp}
\def\ttl@tocsep{\addvspace{10\p@}}
% +-----------------+
% | S H A P E S |
% +-----------------+
%
% % Reformatting Titles: Interface
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% The surrounding space is stored in a macro
% named \ttls@<section> whose content is
% {left}{right}{before}{after}{afterindent}.
% But if there is the page key, the name is
% \ttls@<section>/<page>
\newcommand\titlespacing{%
\@ifstar{\ttl@spacing@i{\z@}}{\ttl@spacing@i{\@ne}}}
\def\ttl@spacing@i#1#2#3#4#5{%
\ttl@getkeys{#2}{titlesec}%
\@ifnextchar[{%
\ttl@spacing@ii{#1}{#3}{#4}{#5}%
}{%
\ttl@spacing@ii{#1}{#3}{#4}{#5}[\z@]}}
\def\ttl@spacing@ii#1#2#3#4[#5]{%
\expandafter\def\csname ttls@\ttl@a\endcsname
{{#2}{#5}{#3}{#4}{#1}}}
% The section name is built in \ttl@a.
% The format is stored in a macro named \ttlf@<section>,
% or \ttlf@<section>/<page> if there is the page spec,
% or \ttlf@.../* if numberless is true
% whose content is
% \ttl@<shape>{format}{label}{sep}{before}{after}
\newcommand\titleformat{%
\@ifstar{\ttl@format@s}%
{\ttl@format@i}}
\def\ttl@format@s#1#2{%
\edef\ttl@a{\expandafter\@gobble\string #1}%
\@ifundefined{ttlf@\ttl@a}%
{\PackageError{titlesec}{Not allowed in `easy' settings}
{The sectiong command you are trying to redefine\MessageBreak
is not handled by the starred variant (eg, \string\part)}}{}
\expandafter\expandafter\expandafter
\ttl@format@si\csname ttlf@\ttl@a \endcsname
{#2}}
\def\ttl@format@si#1#2#3#4#5#6#7{%
\@namedef{ttlf@\ttl@a}{#1{#7}{#3}{#4}{#5}{#6}}}
\def\ttl@format@i#1{%
\@ifnextchar[{\ttl@format@ii{#1}}{\ttl@format@ii{#1}[hang]}}
\def\ttl@format@ii#1[#2]#3#4#5#6{%
\ttl@getkeys{#1}{titlesec}%
\@ifnextchar[{%
\ttl@format@iii{#2}{#3}{#4}{#5}{#6}%
}{%
\ttl@format@iii{#2}{#3}{#4}{#5}{#6}[]}}
% First, we get the shape -- if not defined it loads
% the corresponding file.
\def\ttl@format@iii#1#2#3#4#5[#6]{%
\@ifundefined{ttlh@#1}{%
\begingroup
\makeatletter
\InputIfFileExists{#1.tss}{}{%
\PackageError{titlesec}{Unknown shape}%
{Shapes are defined in files with extension tss\MessageBreak
Either you have misspelled the shape\MessageBreak
or there is no a #1.tss file}}%
\endgroup}{}%
\expandafter\def\csname ttlf@\ttl@a\expandafter\endcsname
\expandafter{\csname ttlh@#1\endcsname{#2}{#3}{#4}{#5}{#6}}%
\csname ttl@compat\ttl@a\endcsname}
% Styles
% ~~~~~~
% 1:global 2:label 3:sep 4:style 5:after 6:left 7:right 8:title
% \ttl@<shape> and \ttlh@<shape> take the following eight
% arguments:
% {format}{label}{sep}{before}{after}{left}{right}{title}
% where before and after refer to the format.
\def\ttlh@display#1#2#3#4#5#6#7#8{%
\gdef\ttl@makeline##1{\ttl@calc\hspace{#6}##1\ttl@calc\hspace{#7}}%
\setlength\leftskip{#6}%
\setlength\rightskip{#7}%
\interlinepenalty\@M
\ttl@beginlongest
#1\ifhmode\ttl@hmode@error\fi
\ttl@glcmds
\parindent\z@
\ifttl@label
{#2\strut\@@par}\nobreak\ttl@calc\vspace{#3}%
\fi
#4{#8}%
\kern\z@\strut\@@par
\nobreak\ttl@midlongest#5\@@par
\ttl@endlongest}
\def\ttlh@hang#1#2#3#4#5#6#7#8{%
\gdef\ttl@makeline##1{\ttl@calc\hspace{#6}##1\ttl@calc\hspace{#7}}%
\setlength\leftskip{#6}%
\setlength\rightskip{#7}%
\interlinepenalty\@M
\ttl@beginlongest
#1{\ifhmode\ttl@hmode@error\fi
\ttl@glcmds
\parindent\z@
\leavevmode
\begingroup
\ifttl@label
\sbox\z@{#2\strut\ttl@calc\hspace{#3}}%
\advance\leftskip\wd\z@
\llap{\box\z@}%
\fi
#4{#8}\kern\z@\strut\@@par
\endgroup
\nobreak\ttl@midlongest#5\@@par}%
\ttl@endlongest}
\def\ttlh@runin#1#2#3#4#5#6#7#8{%
\global\@noskipsectrue
\gdef\ttl@makeline##1{##1}%
#1{\ifhmode\ttl@hmode@error\fi
\global\sbox\ttl@box{%
\ttl@calc\hspace{#6}%
\ifttl@label{\strut#2}\ttl@calc\hspace{#3}\fi
#4{#8}#5\unskip}}%
\gdef\@svsechd{\unhbox\ttl@box}}
% +-----------------+
% | T O O L S |
% +-----------------+
%
% calcwidth
% ~~~~~~~~~
% Implemented after code from soul (but much modified...)
\newdimen\titlewidth
\newdimen\titlewidthlast
\newdimen\titlewidthfirst
\let\ttl@glcmds\relax
\let\ttl@beginlongest\@empty
\let\ttl@midlongest\@empty
\let\ttl@endlongest\@empty
\def\ttl@xbeginlongest#1\ttl@endlongest{%
\titlewidth\z@
\titlewidthlast\z@
\setbox\@ne\vbox{%
\def\ttl@glcmds{%
\def\\{\@ifstar{\@ifnextchar[{\ttl@bs}{\newline}}%
{\@ifnextchar[{\ttl@bs}{\newline}}}%
\def\ttl@bs[####1]{\newline}%
\let\@centercr\\%
\def\ttl@midlongest####1\@@par{}% Very dirty...
\advance\rightskip 1\leftskip plus 1fil
\leftskip=\z@}%
#1}%
\ttl@boxprocess
#1}
\def\ttl@boxprocess{%
\setbox\@ne=\vbox{%
\unvcopy\@ne
\unskip\unpenalty
\global\setbox\tw@=\lastbox}%
\ifvoid\tw@
\else
\setbox\thr@@=\hbox{\hskip-\leftskip\unhbox\tw@\hskip-\rightskip}%
\titlewidthfirst\wd\thr@@
\ifdim\titlewidth<\titlewidthfirst
\titlewidth\titlewidthfirst
\fi
\ifdim\titlewidthlast=\z@
\titlewidthlast\titlewidthfirst
\fi
\expandafter\ttl@boxprocess
\fi}
% Rules
% ~~~~~
\providecommand\titleline{%
\@ifstar{\ttl@line@i{\hb@xt@\titlewidth}}%
{\ttl@line@i{}}}
\def\ttl@line@i#1{%
\@ifnextchar[{\ttl@line{#1}}{\ttl@line{#1}[s]}}
\def\ttl@line#1[#2]#3{%
\vskip\topskip
\hrule \@height \z@
\nobreak
\vskip-\topskip
\begingroup
\parindent\z@
\everypar{}%
\leftskip\z@
\rightskip\z@ % #1 is either \hb@xt@\titlewidth or empty:
\@makebox[\hsize][#2]{\ttl@makeline{#1{#3}}}%
\par
\endgroup
\hrule height \z@
\nobreak}
\providecommand\titlerule{\@ifstar{\ttl@row}{\ttl@rule}}
\let\ttl@leaders\xleaders % For titletoc compatibility
\def\ttl@row{\@ifnextchar[{\ttl@row@i}{\ttl@row@i[\wd\z@]}}
\def\ttl@row@i[#1]#2{%
\ifvmode\expandafter\titleline\fi
{\sbox\z@{#2}%
\ttl@calcneg\hspace{#1}%
\hskip\wd\z@
\ttl@leaders\hb@xt@#1{\hss\box\z@}%
\hfill\kern\z@}}
\def\ttl@rule{\@ifnextchar[{\ttl@rule@i}{\ttl@rule@i[.4\p@]}}
\def\ttl@rule@i[#1]{%
\ifvmode\expandafter\titleline\fi
{\leaders\hrule height #1\hfill\kern\z@}}
% Par shapes and space
% ~~~~~~~~~~~~~~~~~~~~
\providecommand\filright{%
\gdef\ttl@filleft##1{\hskip##1}%
\gdef\ttl@filright##1{\hfill}%
\let\\\@centercr
\advance\rightskip\z@ \@plus 1fil\relax}
\providecommand\filleft{%
\gdef\ttl@filleft##1{\hfill}%
\gdef\ttl@filright##1{\hskip##1}%
\let\\\@centercr
\advance\leftskip\z@ \@plus 1fil
\parfillskip\z@}
\providecommand\filcenter{\filleft\filright
\gdef\ttl@filleft##1{\hfill}}
\providecommand\fillast{%
\gdef\ttl@filleft##1{\hfill}%
\gdef\ttl@filright##1{\hfill}%
\let\\\@centercr
\filleft\advance\rightskip\z@ \@plus -1fil
\parfillskip\z@ \@plus 2fil\relax}
\newcommand\filinner{%
\if@twoside
\ifodd\count\z@\filleft\else\filright\fi
\else
\filleft
\fi}
\newcommand\filouter{%
\if@twoside
\ifodd\count\z@\filright\else\filleft\fi
\else
\filright
\fi}
\newcommand\wordsep{\fontdimen\tw@\font \@plus
\fontdimen\thr@@\font \@minus \fontdimen4\font}
% +-----------------+