summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/titlesec/ttlps.def
blob: 6246743cf99720c142934287c9abea4af53185f0 (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
% +--------------------------------------------------+
% | Typeset titlesec.tex to get the documentation.   |
% +--------------------------------------------------+
%
% Copyright (c) 1998-2005 by Javier Bezos.
% All Rights Reserved.
%
% This file is part of the titlesec distribution release 2.6
% -----------------------------------------------------------
%
% 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 (actually not 1.0)
% ~~~~~~~~~~~~~~~
% 99/11/03: Split from titlesec.sty
% 99/11/03: Changed \setmarks, \ttl@sethead, \ttl@setfoot to follow
%           the new scheme
% 99/11/03: Removed the redefinition of \markboth. The arguments are
%           expanded on the fly by the corresponding \...mark. 
% 00/01/06: Added the \newtitlemark device.
% 00/01/19: Rejected the idea of a separate package (for the time 
%           being). Now it's ttlps.def.
% 00/01/20: Starred versions of \widenhead, \sethead, \setfoot.
% 00/01/23: Added \ifthe..., \iftitle, etc.
% 00/02/05: Modified \ifthe... mechanism
% 00/02/25: Fixed a bug which made enter in an endless loop.
%           Now \ttl@marks is just \relax. The new scheme made
%           compatible with babel. (2.3.1)
% 00/03/01: Fixed a bug in the previous bug fix. (2.3.2)
% 00/03/08: Removed the code for AMS and babel. A general procedure
%           to catch the changes of \markboth is introduced, with
%           \ttl@enccode and \ttl@running. (2.3.3)
% 00/05/05: \setmarks may be used outside of \newpagestyle, with
%           the help of \ttl@setmarks and \ttl@marksset (2.3.4)
% 00/05/25: Tests for \ttl@toclabel moved to the redefinition of
%           \secdef in titlesec. (2.3.5)
% 00/06/07: Added the first attempt for pagestyles with floats.
%           With slight changes, it will become the final form
%           for that. (2.3.5)
% 00/06/14: The default \ifthe... are now defined with \ttl@setifthe
%           so that they are robust from the very beginning. (2.3.5)
% 01/01/21: Replaced some \defs by \newcommand
%
% As before, all marks has two parts but now they don't refer to left or 
% right pages at all.  There are some issues related to top marks which 
% are explained by Knuth in \textit{The \TeX book}, pp.  259f, as well 
% as an uncompatibility between them and \LaTeX{} floats.  To overcome 
% both limitations, in the \textsf{titlesec} page styles, the second 
% part in |\cs{firstmark}| is a \emph{fixed} top mark and the first one 
% the actual first mark; the right way to get the bot mark is from the 
% second part.  Marks are stored at each section and used before and 
% after the title (straight class); the first part contains the values 
% of current title, but the second one contains the previolusly stored 
% values in the mark before the title, and the current values in the 
% mark after.

\ProvidesFile{ttlps.def}[2005/01/22]

% 
% Page Styles
% ~~~~~~~~~~~

\ifx\ttl@compatps\@undefined\else
  \PackageWarningNoLine{titlesec}
      {You are using an old interface for page styles\MessageBreak
      You could proceed but don't complain if you run\MessageBreak
      into errors}
\fi

\ttl@pstrue

\let\parttitle\@empty
\let\chaptertitle\@empty
\let\sectiontitle\@empty
\let\subsectiontitle\@empty
\let\subsubsectiontitle\@empty
\let\paragraphtitle\@empty
\let\subparagraphtitle\@empty

\newcommand\iftitle[1]{%
  \expandafter\ifx\csname #1title\endcsname\@empty
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi}

\newcommand\newtitlemark{%
  \@ifstar{\@tempswafalse\ttl@newmk@i}%
          {\@tempswatrue\ttl@newmk@i}}
  
\def\ttl@newmk@i#1{%
  \edef\ttl@a{{\expandafter\@gobble\string#1}}%
  \expandafter\ttl@newmk@ii\ttl@a}

\def\ttl@newmk@ii#1{%
  \if@tempswa
    \expandafter\def\expandafter\ttl@moremarks\expandafter{%
      \ttl@moremarks
      \protect\@namedef{#1}{\@nameuse{#1}}}%
  \else
    \expandafter\def\expandafter\ttl@moremarks\expandafter{%
      \ttl@moremarks
      \protect\@nameuse{#1}=\the\@nameuse{#1}\relax}%
  \fi}

\def\ttl@prevmarks{\ttl@marks}
\let\ttl@marks\relax

\let\ttl@moremarks\@empty

% The following command sets the ifthe... commands to
% be used in heads. When the call is from inside a sectioning
% command, toclabel is either true (in most of cases) or false
% (a chapter in the front matter, for example). Otherwise (an
% explicit \...mark) is false

\def\ttl@setifthe#1{%
  \expandafter\protected@edef\csname ifthe#1\endcsname{%
    \ifttl@toclabel
      \protect\@firstoftwo
    \else
      \protect\@secondoftwo
    \fi}}

% At this point \ttl@toclabel is always false

\ttl@setifthe{part}
\ttl@setifthe{chapter}
\ttl@setifthe{section}
\ttl@setifthe{subsection}
\ttl@setifthe{subsubsection}
\ttl@setifthe{paragraph}
\ttl@setifthe{subparagraph}

\newtitlemark{\ttl@running}
\let\ttl@enccode\relax
\def\ttl@running{\ttl@enccode}

\def\ttl@markboth#1{%
 \begingroup
   \let\protect\@unexpandable@protect
   \let\@mkboth\@gobbletwo
   \let\ttl@enccode\relax
   \let\label\relax
   \let\index\relax
   \let\glossary\relax
   \let\ttl@c\mark
   \def\mark##1{\xdef\ttl@running{\expandafter\@gobble##1}}%
   \markboth{}{\ttl@enccode}%
   \expandafter\let\csname#1mark\endcsname\@gobble
   \xdef\ttl@marks{\ttl@marks}%
   \gdef\@themark{{\ttl@marks}{\ttl@prevmarks}}%
   \ttl@c{\@themark}%
   \if@nobreak\ifvmode\nobreak\fi\fi
 \endgroup}

\newcommand\setmarks[2]{\def\ttl@marksset{{#1}{#2}}}

\def\ttl@setmarks#1#2{%
  \expandafter\def\csname#1mark\endcsname##1{%
    \expandafter\gdef\csname#1title\endcsname{##1}%
    \ttl@setifthe{#1}%
    \def\ttl@marks{%
      \protect\@namedef{#1title}{##1}%
      \protect\@namedef{#2title}{}%
      \protect\@namedef{the#1}{\@nameuse{the#1}}%
      \protect\@namedef{the#2}{}%
      \protect\@namedef{ifthe#1}{\@nameuse{ifthe#1}}%
      \protect\@namedef{ifthe#2}{\protect\@secondoftwo}%
      \ttl@moremarks}%
    \ttl@markboth{#1}}%
  \expandafter\def\csname#2mark\endcsname##1{%
    \expandafter\gdef\csname#2title\endcsname{##1}%
    \ttl@setifthe{#2}%
    \def\ttl@marks{%
      \protect\@namedef{#1title}{\@nameuse{#1title}}%
      \protect\@namedef{#2title}{##1}%
      \protect\@namedef{the#1}{\@nameuse{the#1}}%
      \protect\@namedef{the#2}{\@nameuse{the#2}}%
      \protect\@namedef{ifthe#1}{\@nameuse{ifthe#1}}%
      \protect\@namedef{ifthe#2}{\@nameuse{ifthe#2}}%
      \ttl@moremarks}%
    \ttl@markboth{#1}}}%

\newcommand\headrule{\setheadrule{.4\p@}}
\newcommand\footrule{\setfootrule{.4\p@}}

\newcommand\setheadrule[1]{%
  \ifdim#1=\z@
    \let\makeheadrule\@empty
  \else
    \def\makeheadrule{\rule[-.3\baselineskip]{\linewidth}{#1}}%
  \fi}
\newcommand\setfootrule[1]{%
  \ifdim#1=\z@
    \let\makefootrule\@empty
  \else
    \def\makefootrule{\rule[.7\baselineskip]{\linewidth}{#1}}%
  \fi}
  
\renewcommand\newpagestyle[1]{%
  \begingroup
  \catcode`\^^M=9
  \@ifnextchar[%
    {\ttl@pagestyle\newcommand{#1}}%
    {\ttl@pagestyle\newcommand{#1}[]}}
    
\renewcommand\renewpagestyle[1]{%
  \begingroup
  \catcode`\^^M=9
  \@ifnextchar[%
    {\ttl@pagestyle\renewcommand{#1}}%
    {\ttl@pagestyle\renewcommand{#1}[]}}

\def\ttl@pagestyle#1#2[#3]#4{%
  \endgroup
  \expandafter#1\csname ps@#2\endcsname{%
    \ttl@defaultps
    \def\ttl@headfmt{#3}%
    #4%
    \def\setmarks####1####2{\def\ttl@marksset{{####1}{####2}}}}}

\def\ttl@userunning#1#2{\csname ttlr@#1#2\endcsname}

\def\ttl@defaultps{%
    \let\makeheadrule\@empty
    \let\makefootrule\@empty
    \def\@mkboth{\ttl@savemark\@gobbletwo}%
    \def\@oddfoot{\ttl@userunning of}%
    \def\@evenfoot{\ttl@userunning ef}%
    \def\@oddhead{\ttl@userunning oh}%
    \def\@evenhead{\ttl@userunning eh}%
    \def\ttlr@of{\ttl@makefoot\@empty\@@\ttl@hiol\ttl@hior}%
    \def\ttlr@ef{\ttl@makefoot\@empty\@@\ttl@hiel\ttl@hier}%
    \def\ttlr@oh{\ttl@makehead\@empty\@@\ttl@hiol\ttl@hior}%
    \def\ttlr@eh{\ttl@makehead\@empty\@@\ttl@hiel\ttl@hier}%
    \let\ttlr@of@b\relax  \let\ttlr@of@p\relax
    \let\ttlr@ef@b\relax  \let\ttlr@ef@p\relax
    \let\ttlr@oh@t\relax  \let\ttlr@oh@p\relax
    \let\ttlr@eh@t\relax  \let\ttlr@eh@p\relax
    \let\setmarks\ttl@setmarks
    \expandafter\setmarks\ttl@marksset}

\@ifundefined{chapter}%
    {\setmarks{section}{subsection}}%
    {\setmarks{chapter}{section}}

\newcommand\usepage{\protect\thepage}

\newcommand\toptitlemarks    {\expandafter\@secondoftwo\firstmark{}{}{}}
\def\firsttitlemarks{%
   \toks@\expandafter\expandafter\expandafter{%
      \expandafter\@secondoftwo \firstmark{}{}{}}%
   \@temptokena\expandafter\expandafter\expandafter{%
      \expandafter\@secondoftwo \botmark{}{}{}}%
   \edef\ttl@a{\the\toks@}%
   \edef\ttl@b{\the\@temptokena}%
   \ifx\ttl@a\ttl@b
     \expandafter\@secondoftwo\firstmark{}{}{}%
   \else
     \expandafter\@firstoftwo \firstmark{}{}{}%
   \fi}
\newcommand\bottitlemarks    {\expandafter\@secondoftwo\botmark{}{}{}}
\newcommand\nexttoptitlemarks{\expandafter\@firstoftwo \botmark{}{}{}}
\newcommand\outertitlemarks{%
  \if@twoside
    \ifodd\c@page\relax
      \bottitlemarks
    \else
      \toptitlemarks
    \fi
  \else
    \toptitlemarks
  \fi}
\newcommand\innertitlemarks{%
  \if@twoside
    \ifodd\c@page\relax
      \firsttitlemarks
    \else
      \bottitlemarks
    \fi
  \else
    \bottitlemarks
  \fi}


\def\ttl@duplthreeargs#1#2#3#4{#1[#2][#3][#4]{#2}{#3}{#4}}
\def\ttl@dupltwoargs#1#2#3{#1[#2][#3]{#2}{#3}}
\def\ttl@duplthreeargsrev#1#2#3#4{#1[#4][#3][#2]{#2}{#3}{#4}}
\def\ttl@dupltwoargsrev#1#2#3{#1[#3][#2]{#2}{#3}}

\def\ttl@setany#1{%
  \@ifstar{\ttl@duplthreeargsrev#1}%
          {\@ifnextchar[{#1}{\ttl@duplthreeargs#1}}}

\newcommand\setfoot{\ttl@setany\ttl@setfoot}
\newcommand\sethead{\ttl@setany\ttl@sethead}

\def\ttl@setfoot[#1][#2][#3]#4#5#6{%
  \def\ttlr@ef{\ttl@makefoot{#1}{#2}{#3}\@@\ttl@hiel\ttl@hier}%
  \def\ttlr@of{\ttl@makefoot{#4}{#5}{#6}\@@\ttl@hiol\ttl@hior}}

\def\ttl@sethead[#1][#2][#3]#4#5#6{%
  \def\ttlr@eh{\ttl@makehead{#1}{#2}{#3}\@@\ttl@hiel\ttl@hier}%
  \def\ttlr@oh{\ttl@makehead{#4}{#5}{#6}\@@\ttl@hiol\ttl@hior}}

\def\ttl@headinline#1#2#3{%
  \ttl@headfmt
  \def\ttl@a{#1#3}\def\ttl@b{#2}%
  \ifx\ttl@a\@empty
    \hfil{#2}\hfil
  \else\ifx\ttl@b\@empty
    {#1}\hfil{#3}%
  \else
    \sbox\z@ {#1}%
    \sbox\tw@{#3}%
    \copy\z@
    \ifdim\wd\z@<\wd\tw@
      \kern-\wd\z@\kern\wd\tw@
    \fi
    \hfil{#2}\hfil
    \ifdim\wd\z@>\wd\tw@
      \kern-\wd\tw@\kern\wd\z@
    \fi
    \box\tw@
  \fi\fi}

\def\ttl@makeboth#1#2#3#4{%
  \ttl@calcneg\hspace{#3}%
  \normalsize
  \linewidth\textwidth
  \addtolength\linewidth{#3}%
  \addtolength\linewidth{#4}%
  \ifx#2\@empty\else   
    \setbox\z@\hb@xt@\linewidth{%
	\color@begingroup
        #2%
	\color@endgroup}%
	\wd\z@\z@
	\ht\z@\z@
	\dp\z@\z@
	\box\z@
  \fi
  \ttl@titlemarks   % Must precede the format. Defines \ttl@running
  \def\ttl@enccode{\ttl@headinline#1{}{}{}}%which contains ttl@enccode
  \ttl@running
  \ttl@calcneg\hspace{#4}}% 
	  
\def\ttl@makehead#1\@@{\ttl@makeboth{#1}\makeheadrule}
\def\ttl@makefoot#1\@@{\ttl@makeboth{#1}\makefootrule}
		
\renewcommand\widenhead{%
  \@ifstar{\ttl@dupltwoargsrev\ttl@widenhd}%
          {\@ifnextchar[{\ttl@widenhd}{\ttl@dupltwoargs\ttl@widenhd}}}
  
\def\ttl@widenhd[#1][#2]#3#4{%
  \def\ttl@hiel{#1}\def\ttl@hier{#2}%
  \def\ttl@hiol{#3}\def\ttl@hior{#4}}
  
\let\setheadindent\widenhead
  
\def\ttl@hiel{\z@}\def\ttl@hier{\z@}
\def\ttl@hiol{\z@}\def\ttl@hior{\z@}

% Pagestyles with floats. There macros are defined only with the
% psfloats package option.

\@ifundefined{ttl@replace}{\endinput}{}

% User interface

\newcommand\setfloatfoot{%
  \let\ttl@c\@empty % <- current float, empty if general
  \ttl@setany\ttl@setftfoot}

\newcommand\setfloathead{%
  \let\ttl@c\@empty % <- current float, empty if general
  \ttl@setany\ttl@setfthead}

\def\ttl@setftfoot[#1][#2][#3]#4#5#6#7{%
  \@ifnextchar[{\ttl@setftfoot@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}}%
               {\ttl@setftfoot@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}[bp]}}

\def\ttl@setfthead[#1][#2][#3]#4#5#6#7{%
  \@ifnextchar[{\ttl@setfthead@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}}%
               {\ttl@setfthead@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}[tp]}}

\def\ttl@setftfoot@i#1#2#3#4#5#6#7[#8]{%
  \@tfor\ttl@b:=#8\do{%
    \@namedef{ttlr@ef@\ttl@b\ttl@c}%
       {#7\ttl@makefoot{#1}{#2}{#3}\@@\ttl@hiel\ttl@hier}%
    \@namedef{ttlr@of@\ttl@b\ttl@c}%
       {#7\ttl@makefoot{#4}{#5}{#6}\@@\ttl@hiol\ttl@hior}}}

\def\ttl@setfthead@i#1#2#3#4#5#6#7[#8]{%
  \@tfor\ttl@b:=#8\do{%
    \@namedef{ttlr@eh@\ttl@b\ttl@c}%
       {#7\ttl@makehead{#1}{#2}{#3}\@@\ttl@hiel\ttl@hier}%
    \@namedef{ttlr@oh@\ttl@b\ttl@c}%
       {#7\ttl@makehead{#4}{#5}{#6}\@@\ttl@hiol\ttl@hior}}}

\newcommand\nextfloathead{%
  \ttl@nextfree  % returns ttl@c with the next float
  \ttl@setany\ttl@setfthead}

\newcommand\nextfloatfoot{%
  \ttl@nextfree  % returns ttl@c with the next float
  \ttl@setany\ttl@setftfoot}

% Compat mode with floatps

\ifx\ttl@replace\space

  \let\ttl@setnewfoot\ttl@setftfoot
  \let\ttl@setnewhead\ttl@setfthead

  \def\ttl@setftfoot[#1][#2][#3]#4#5#6{%
    \ttl@setnewfoot[#1][#2][#3]{#4}{#5}{#6}{}}
  \def\ttl@setfthead[#1][#2][#3]#4#5#6{%
    \ttl@setnewhead[#1][#2][#3]{#4}{#5}{#6}{}}

\fi

% The simple default value of \ttl@userunning is
% replaced by one more elaborated

\def\ttl@userunning#1#2{%
  \if@fcolmade  % From a post by D. Arseneau to comp.text.tex
    \def\@elt##1{\edef\ttl@pageft{\string##1}}%
    \@flsucceed
    \let\@elt\relax
    \if#2h%
      \ttl@replace #1hp\ttl@pageft
    \else
      \ttl@replace #1fp\ttl@pageft
      \ttl@killftps\ttl@pageft
    \fi
  \else\if#2h%
    \ifx\ttl@topft\@empty\else
      \ttl@replace #1ht\ttl@topft
    \fi
  \else
    \ifx\ttl@botft\@empty\else
      \ttl@replace #1fb\ttl@botft
    \fi
  \fi\fi
  \csname ttlr@#1#2\endcsname}

% [Don't move above as \ttl@replace is used as a flag.]

\def\ttl@replace#1#2#3#4{%
    \@ifundefined{ttlr@#1#2@#3#4}%
      {\@ifundefined{ttlr@#1#2@#3}{}%
          {\@namedef{ttlr@#1#2}{\@nameuse{ttlr@#1#2@#3}}}}%
      {\csname ttlr@xx@x#4\endcsname\@gobble
       {\expandafter\let\csname ttlr@#1#2\expandafter\endcsname
         \csname ttlr@#1#2@#3#4\endcsname}}}

\def\ttl@nextfree{%
  \def\@elt##1{%
    \edef\ttl@c{\string##1}%
    \let\@elt\@gobble}%
  \@freelist
  \let\@elt\relax
  \@ifundefined{ttlr@xx@x\ttl@c}%
    {\expandafter\let\csname ttlr@xx@x\ttl@c\endcsname\@secondoftwo
     \@tfor\ttl@a:={eh@t}{oh@t}{ef@b}{of@b}{eh@p}{oh@p}{ef@p}{of@p}\do{%
       \expandafter\global\expandafter
       \let\csname ttlr@\ttl@a\ttl@c\endcsname\relax}}{}}

\def\ttl@killftps#1{%
  \expandafter\global\expandafter
  \let\csname ttlr@xx@x#1\endcsname\relax}

\let\ttl@topft\@empty
\let\ttl@botft\@empty
\let\ttl@pageft\@empty

\def\ttl@combinefloats{%
 \ifx\@toplist\@empty\else   
   \def\@elt##1{%
     \edef\ttl@topft{\string##1}%
     \def\@elt####1{\ttl@killftps{\string####1}}}%
   \@toplist
  \fi
  \ifx\@botlist\@empty\else
    \def\@elt##1{%
      \def\@elt####1{%
        \def\@elt####1{\ttl@killftps\ttl@botft}%
        \edef\ttl@botft{\string####1}}%
      \edef\ttl@botft{\string##1}}%
    \@botlist
  \fi
  \let\@elt\relax
  \ttl@combinefloats@x}

\AtBeginDocument{%
  \let\ttl@combinefloats@x\@combinefloats
  \let\@combinefloats\ttl@combinefloats}

\endinput