summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/titlesec/ttlps.def
blob: b68c4ece33c1e4295b6e347cfdc27f25901d4a2d (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
% +--------------------------------------------------+
% | Typeset titlesec.tex to get the documentation.   |
% +--------------------------------------------------+
%
% Copyright (c) 1998-2011 by Javier Bezos.
% All Rights Reserved.
%
% This file is part of the titlesec distribution release 2.10.0
% -----------------------------------------------------------
%
% It may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2003/12/01 or later.
% 
% This work has the LPPL maintenance status "maintained".
% 
% The Current Maintainer of this work is Javier Bezos.

% 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
% 10/12/03: A little addition to the warning, for those who don't
%           read the docs.
%
% History of v1.1
% ~~~~~~~~~~~~~~~
% 11/11/26: Add the extra mark mechanim
% 11/12/07: Enlarged, eg, multilevel \newtitlemark, \newtitlemark*,
%           premarks
%
% 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}[2011/12/15]

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

\ifx\ttl@compatps\@undefined\else
  \PackageWarningNoLine{titlesec}
      {You are using an old interface for page styles\MessageBreak
      (or you forgot the package option 'pagestyles').\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}

% \newtitlemarks belongs to a nameless markset (ie, \@empty).
% For named extra marksets see below. 

\newcommand\newtitlemark{%
  \@ifstar{\@tempswafalse\ttl@newmk@i\@empty}%
          {\@tempswatrue\ttl@newmk@i\@empty}}

\def\ttl@newmk@i#1#2{%   markset, macro/var
  \edef\ttl@a{\expandafter\@gobble\string#2}%
  \expandafter\ifx\csname\ttl@a\endcsname#2\else
    \edef\ttl@a{c@#2}%
  \fi
  \expandafter\ttl@newmk@ii\expandafter{\ttl@a}{#1}}

\def\ttl@newmk@ii#1#2{%   macro/var, markset
  \expandafter\let\expandafter\ttl@a\csname ttl@mks@#2\endcsname
  \if@tempswa
    \expandafter\def\expandafter\ttl@a\expandafter{%
      \ttl@a
      \protect\@namedef{#1}{\@nameuse{#1}}}%
  \else
    \expandafter\def\expandafter\ttl@a\expandafter{%
      \ttl@a
      \protect\@nameuse{#1}=\the\@nameuse{#1}\relax}%
  \fi
  \expandafter\let\csname ttl@mks@#2\endcsname\ttl@a}

\let\ttl@mks@\@empty
\def\ttl@moremarks{\ttl@mks@} % backward compat
  
\def\ttl@prevmarks{\ttl@marks}
\let\ttl@marks\relax

% 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}

% Putting marks
% -------------

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

% \ttl@markboth redefines temporarily \mark to fetch changes made by
% babel or ams, saved in \ttl@running.  When this is done, the actual
% \mark es emitted, which has \ttl@running as part of the markset (see
% the \newtitlemark above). 

\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}%
   \@nameuse{ttl@tem@#1}%
   \if@nobreak\ifvmode\nobreak\fi\fi
 \endgroup}

\newcommand\settitlemarks{\@ifstar\ttl@svmarks@s\ttl@svmarks@x}

\def\ttl@svmarks@x#1{\def\ttl@marksset{{#1}}}
\def\ttl@svmarks@s#1{\def\ttl@marksset{*{#1}}}

\newcommand\setmarks[2]{\settitlemarks{#1,#2}} % back compat

\def\ttl@settopmark#1\@@{%
  \expandafter\def\csname#1mark\endcsname##1{%
    \expandafter\gdef\csname#1title\endcsname{##1}%
    \ttl@setifthe{#1}%
    \expandafter\let\expandafter\ttl@marks\csname ttl@tm@#1\endcsname
    \ttl@markboth{#1}}%
  \global\@namedef{ttl@tm@#1}{%
    \protect\@namedef{#1title}{\@nameuse{#1title}}%
    \protect\@namedef{the#1}{\@nameuse{the#1}}%
    \protect\@namedef{ifthe#1}{\@nameuse{ifthe#1}}}%
  \def\ttl@elt##1{%
    \expandafter\ttl@setsubmark\ttl@a\@@{##1}}%
  \ttl@c}%

\def\ttl@setsubmark#1\@@#2{%
  \expandafter\g@addto@macro\csname ttl@tm@#2\endcsname{%
    \protect\@namedef{#1title}{}%
    \protect\@namedef{the#1}{}%
    \protect\@namedef{ifthe#1}{\protect\@secondoftwo}}
  \expandafter\g@addto@macro\csname ttl@tm@#1\endcsname{%
    \protect\@namedef{#2title}{\@nameuse{#2title}}%
    \protect\@namedef{the#2}{\@nameuse{the#2}}%
    \protect\@namedef{ifthe#2}{\@nameuse{ifthe#2}}}}%

\def\ttl@setmarks@x#1{%
  \let\ttl@c\@empty % sub list
  \@for\ttl@a:=#1\do{%
    \expandafter\ttl@settopmark\ttl@a\@@
    \let\ttl@elt\relax
    \xdef\ttl@c{\ttl@c\ttl@elt{\ttl@a}}}%
  \@for\ttl@a:=#1\do{%
    \expandafter\g@addto@macro\csname ttl@tm@\ttl@a\endcsname{%
      \ttl@moremarks}}}

\def\ttl@setmarks@s#1{% Solo con extramarks
  \PackageError{titlesec}%
     {You need `extramarks' for \string\settitlemarks*}%
     {\string\settitlemarks* requires the package option `extramarks'}}

\newcommand\pretitlemark{%
  \global\ttl@premarktrue
  \@ifstar{\ttl@pretitlemark\z@}%
          {\ttl@pretitlemark\@ne}}

\def\ttl@pretitlemark#1#2#3{%
  \addtocounter{#2}#1%
  \ttl@premark{#2}{#3}%
  \addtocounter{#2}{-#1}}
  
% Rules
% -----

\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\settitlemarks{\@ifstar\ttl@svmarks@s\ttl@svmarks@x}}}

\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
  \def\settitlemarks{\@ifstar\ttl@setmarks@s\ttl@setmarks@x}%
  \expandafter\settitlemarks\ttl@marksset}

\@ifundefined{chapter}%
  {\settitlemarks{section,subsection}}%
  {\settitlemarks{chapter,section}}

\newcommand\usepage{\protect\thepage} % back compat

\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@}

% A tool:

\def\ifsamemark#1#2{%
  {#1\global\let\ttl@c#2}%
  \ifx\ttl@c#2%
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}

% ===========
% EXTRA MARKS
% ===========

\ifx\ttl@fetchmark\@empty

\ifx\newmarks\@undefined
  \PackageInfo{titleps}{%
    You have requested `extramarks' but etex or similar\MessageBreak
    has not been loaded. I'll do it for you.}
  \RequirePackage{etex}
\fi

\def\ttl@setmarks@s#1{%
   \@for\ttl@a:=#1\do{%
     \@ifundefined{ttl@mkc@\ttl@a}{%
       \expandafter\newmarks\csname ttl@mkc@\ttl@a\endcsname}{}%
     \expandafter\xdef\csname ttl@tem@\ttl@a\endcsname{%
       \marks\expandafter\noexpand\csname ttl@mkc@\ttl@a\endcsname
       {\noexpand\@themark}}}%
  \ttl@setmarks@x{#1}}%

\newcommand\newmarkset[1]{%
  \expandafter\newmarks\csname ttl@mkc@#1\endcsname
  \@namedef{ttl@mks@#1}{}%
  \@namedef{ttl@premks@#1}{\@nameuse{ttl@mks@#1}}}

\newcommand\newextramark{%
  \@ifstar{\@tempswafalse\ttl@newmk@i}%
          {\@tempswatrue\ttl@newmk@i}}

\def\ttl@extramark#1{%
 \begingroup
   \let\protect\@unexpandable@protect
   \let\@mkboth\@gobbletwo
   \let\label\relax
   \let\index\relax
   \let\glossary\relax\endgroup}

\newcommand\extramark[1]{%
  \begingroup
    \let\protect\@unexpandable@protect
    \let\@mkboth\@gobbletwo
    \let\label\relax
    \let\index\relax
    \let\glossary\relax
    \marks\csname ttl@mkc@#1\endcsname{%
      {\@nameuse{ttl@mks@#1}}%
      {\@nameuse{ttl@mks@#1}}}%
    \expandafter\xdef\csname ttl@premks@#1\endcsname
      {\@nameuse{ttl@mks@#1}}%
  \endgroup
  \if@nobreak\ifvmode\nobreak\fi\fi}%
  
\newcommand\preextramark[1]{%
  \begingroup
    \let\protect\@unexpandable@protect
    \let\@mkboth\@gobbletwo
    \let\label\relax
    \let\index\relax
    \let\glossary\relax
    \marks\csname ttl@mkc@#1\endcsname{%
      {\csname ttl@mks@#1\endcsname}%
      {\csname ttl@premks@#1\endcsname}}%
  \endgroup
  \if@nobreak\ifvmode\nobreak\fi\fi}

\newcommand\newshortmark[1]{%
  \newmarkset{\string#1}%
  \newextramark{\string#1}#1}

\newcommand\shortmark[1]{\extramark{\string#1}}
\newcommand\preshortmark[1]{\preextramark{\string#1}}

\newcommand\topshortmark[1]{{\topextramarks{\string#1}#1}}
\newcommand\firstshortmark[1]{{\firstextramarks{\string#1}#1}}
\newcommand\botshortmark[1]{{\botextramarks{\string#1}#1}}
\newcommand\nexttopshortmark[1]{{\nexttopextramarks{\string#1}#1}}

\def\ttl@fetchmark#1#2#3{%
  \expandafter#1#2\csname ttl@mkc@#3\endcsname{}{}{}}

\newcommand\topextramarks[1]{\ttl@fetchmark\@secondoftwo\firstmarks{#1}}
\newcommand\firstextramarks[1]{%
   \toks@\expandafter\expandafter\expandafter{%
      \ttl@fetchmark\@secondoftwo\firstmarks{#1}}%
   \@temptokena\expandafter\expandafter\expandafter{%
      \ttl@fetchmark\@secondoftwo\botmarks{#1}}%
   \edef\ttl@a{\the\toks@}%
   \edef\ttl@b{\the\@temptokena}%
   \ifx\ttl@a\ttl@b
     \ttl@fetchmark\@secondoftwo\firstmarks{#1}%
   \else
     \ttl@fetchmark\@firstoftwo\firstmarks{#1}%
   \fi}
\newcommand\botextramarks[1]{\ttl@fetchmark\@secondoftwo\botmarks{#1}}
\newcommand\nexttopextramarks[1]{\ttl@fetchmark\@firstoftwo\botmarks{#1}}

\newcommand\outerextramarks[1]{%
  \if@twoside
    \ifodd\c@page\relax
      \botextramarks{#1}%
    \else
      \topextramarks{#1}%
    \fi
  \else
    \topextramarks{#1}%
  \fi}
\newcommand\innerextramarks[1]{%
  \if@twoside
    \ifodd\c@page\relax
      \firstextramarks{#1}%
    \else
      \botextramarks{#1}%
    \fi
  \else
    \botextramarks{#1}%
  \fi}

\fi

% ======
% FLOATS
% ======
%
% 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