Debian Codegraph @

texmf-dist/source/latex/fancyhdr/fancyhdr.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 1994-2025 by Pieter van Oostrum <[email protected]>
4 % -------------------------------------------------------
5 %
6 % This file may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either version 1.3
8 % of this license or (at your option) any later version.
9 % The latest version of this license is in:
10 %
11 % http://www.latex-project.org/lppl.txt
12 %
13 % and version 1.3 or later is part of all distributions of LaTeX
14 % version 2005/12/01 or later.
15 %
16 % \fi
17 %
18 % \iffalse
19 %<*driver>
20 \ProvidesFile{\jobname.dtx}
21 %</driver>
22 %
23 % \begin{macrocode}
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 % \changes{V5.2}{2025/01/15}{Require \LaTeX{} version at least 2018-04-01.}
26 %<fancyhdr|extramarks|extramarks-v4>\NeedsTeXFormat{LaTeX2e}[2018-04-01]
27 %<fancyheadings>\NeedsTeXFormat{LaTeX2e}
28 %<fancyhdr>\ProvidesPackage{fancyhdr}%
29 %<fancyheadings>\ProvidesPackage{fancyheadings}
30 %<extramarks|extramarks-v4>\ProvidesPackage{extramarks}
31 %<fancyhdr|extramarks> [2025/02/07 v5.2
32 %<fancyhdr> Extensive control of page headers and footers]%
33 %<fancyheadings> [2022/11/09 v4.1
34 %<fancyheadings> Legacy package to call fancyhdr]
35 %<extramarks> Extra marks for LaTeX]
36 %<fancyhdr|extramarks>% Copyright (C) 1994-2025 by Pieter van Oostrum <[email protected]>
37 %<extramarks-v4> [2024/11/30 v4.5
38 %<extramarks-v4> Legacy version of extramarks for LaTeX]
39 %<extramarks-v4>% Copyright (C) 1994-2024 by Pieter van Oostrum <[email protected]>
40 %<extramarks-v4>%%
41 %<extramarks-v4>%% This is a legacy version (v4) of extramarks.sty
42 %<extramarks-v4>%%
43 %<fancyheadings>% Public domain
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 % \end{macrocode}
46 %
47 %<*driver>
48 % Specify options for the url and hyperref packages
49 \PassOptionsToPackage{hyphens}{url}
50 \PassOptionsToPackage{colorlinks,linktocpage}{hyperref}
51 \documentclass[a4paper]{l3doc}
52 \addtolength\textheight{2cm}
53 \usepackage{multicol}
54 \usepackage{float}
55 \usepackage{makeidx}
56 \usepackage{robustindex}
57 \makeindex
58 \usepackage{layout}
59 \usepackage{array}
60 \usepackage{booktabs}
61 \usepackage{boxedminipage}
62 \usepackage{tikz}
63 \usetikzlibrary{decorations.fractals}
64
65 % The package fourier-orns defines \danger, which conflicts
66 % with the 'danger' environment of l3doc.
67 % We save, clear and restore \danger arounf this \usepackage
68 \let \liiidocxxxsavedanger\danger
69 \let\danger\undefined
70 \usepackage{fourier-orns}
71 \let\danger\liiidocxxxsavedanger
72 % End of conflict resolution
73 \usepackage[T1]{fontenc}
74 \usepackage[hyphens]{url}
75 \usepackage[fit]{truncate}
76 \usepackage{fancyvrb}
77 \usepackage{graphicx}
78 \usepackage{subcaption}
79 \usepackage[colorlinks,linktocpage]{hyperref}
80 \usepackage{ifthen}
81 \ifdefined\NewDocumentCommand\else\usepackage{xparse}\fi
82 \usepackage{enumitem}
83 \setlist{itemsep=1pt}
84 \usepackage{fancyhdr}
85 \GetFileInfo{fancyhdr.sty}
86 \def\ams/{\protect\pAmS}
87 \def\pAmS{{\the\textfont2
88 A\kern-.1667em\lower.5ex\hbox{M}\kern-.125emS}}
89 \newcommand{\bs}{\symbol{'134}}
90 \providecommand\env{}
91 \renewcommand{\env}[1]{\texttt{#1}}
92 \renewcommand{\partname}{Part}
93 \DisableCrossrefs
94 \CodelineIndex
95 \RecordChanges
96 \newcommand\bsbs{\char`\\\char`\\}
97 \newcommand{\Cmd}[1]{\texttt{\def\{{\char`\{}\def\}{\char`\}}\bs#1}}
98 %\newcommand{\CmdIndex}[1]{\index{#1=\string\texttt{\bs#1}}}
99 \newcommand{\CmdIndex}[1]{\setbox0\hbox{\cs{#1}}}
100 \newcommand{\TTindex}[1]{\index{#1=\string\texttt{#1}}\ignorespaces}
101 \newcommand{\PSindex}[1]{\index{page style>#1=\string\texttt{#1}}}
102 \newcommand{\OPTindex}[1]{\index{option>#1=\string\texttt{#1}}}
103 \newcommand{\PKGindex}[1]{\index{package>#1=\string\pkg{#1}}\ignorespaces}
104 \renewcommand{\topfraction}{0.9}
105 \renewcommand{\bottomfraction}{0.9}
106 \renewcommand{\textfraction}{0.05}
107 \setlength{\emergencystretch}{4em}
108 \addtolength{\textheight}{-0.5in} % make it print better on US letter paper
109 \setlength\IndexMin{4cm}
110 \makeatletter
111 \renewcommand\l@section {\@dottedtocline{1}{1.5em}{2.3em}}
112 \makeatother
113 \newenvironment{block}{\vspace{8pt}\noindent\begin{minipage}{\textwidth}}{\end{minipage}\vspace{8pt}}
114 \newenvironment{fblock}{\vspace{8pt}\noindent\begin{boxedminipage}{\textwidth}}{\end{boxedminipage}\vspace{8pt}}
115 \newcommand{\showrule}{\\[-1.5ex]\noindent\makebox[\textwidth]{\hrulefill}\\[\baselineskip]}
116 \newenvironment{xvspace}{\vspace{1ex}}{{\vspace{1ex}}}
117 \setcounter{tocdepth}{1}
118
119 % Compare section numbers in references
120 \usepackage{refcount}
121 \newcounter{secnum}
122 % #1=current section label #2=ref section label
123 \newcommand{\smartref}[2]{%
124 \setcounterref{secnum}{#1}%
125 \addtocounter{secnum}{-1}%
126 \ifnum\value{secnum}=\getrefnumber{#2}
127 the previous section%
128 \else
129 \addtocounter{secnum}{2}%
130 \ifnum\value{secnum}=\getrefnumber{#2}
131 the next section%
132 \else
133 section~\ref{#2}%
134 \fi
135 \fi
136 }
137
138 % Our own page style:
139 \NewMarkClass{whichpage}
140 \newcommand\whichpage{}
141
142 \newcommand\checkposinpage{
143 \ifthenelse{\lengthtest{\pagetotal<4\baselineskip}}%
144 {\renewcommand{\whichpage}{top\thepage}}%
145 {\renewcommand{\whichpage}{\thepage}}%
146 }
147
148 \pagestyle{fancy}
149 \setlength{\headheight}{16.0pt}
150 \addtolength{\headwidth}{\marginparsep}
151 \addtolength{\headwidth}{0.5\marginparwidth}
152 \newcommand\normalheader{%
153 \ifthenelse{\equal{\FirstMark{whichpage}}{\thepage}}%
154 {\TopMark{2e-right-nonempty}}%
155 % whichpage != page
156 {\IfMarksEqualTF{whichpage}{top}{first}%
157 {\TopMark{2e-right-nonempty}}% no mark on this page
158 {\rightmark}% title at/near the top of the page
159 }%
160 }
161
162 \fancyhf{}
163 \fancyhead[L]{\normalheader}
164 \fancyhead[R]{\textbf{\thepage}}
165
166 \AddToHook{cmd/section/before}{\checkposinpage}
167 \AddToHook{cmd/subsection/before}{\checkposinpage}
168
169 \newcommand\setmarks[1]{%
170 \InsertMark{whichpage}{\whichpage}%
171 \markright{#1}%
172 }
173
174 \renewcommand{\sectionmark}[1]{%
175 \setmarks{\thesection\quad#1}%
176 }%
177
178 \renewcommand{\subsectionmark}[1]{%
179 \setmarks{\thesubsection\quad#1}%
180 }%
181
182 % Page style for demonstrating struts, \headruleskip and \footruleskip.
183
184 \newcommand{\strutheader}{%
185 \texttt{\textbackslash strut}:\{
186 \rule{10pt}{0.7\normalbaselineskip}%
187 \hspace{-3pt}\rule[-0.3\normalbaselineskip]{10pt}{0.3\normalbaselineskip}%
188 \raisebox{-0.3\normalbaselineskip}[0pt][0pt]%
189 {\ifdim \headruleskip>0pt
190 \rule[-\headruleskip]{10pt}{\headruleskip}
191 \else
192 \rule{10pt}{-\headruleskip}
193 \fi}%
194 \raisebox{-0.3\normalbaselineskip}[0pt][0pt]{$\swarrow$}\texttt{\textbackslash headruleskip}%
195 }
196 \newcommand{\strutfooter}{%
197 \raisebox{0pt}[0pt][0pt]{%
198 \texttt{\textbackslash strut}:\{
199 \rule[-0.3\normalbaselineskip]{10pt}{0.3\normalbaselineskip}%
200 \hspace{-3pt}\rule{10pt}{0.7\normalbaselineskip}%
201 \rule[0.7\normalbaselineskip]{10pt}{\footruleskip}
202 \raisebox{0.3\normalbaselineskip}{$\nwarrow$}\texttt{\textbackslash footruleskip}}%
203 }
204 \fancypagestyle{showstruts}{%
205 \fancyhead[L]{%
206 \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
207 {\strutheader}%
208 {\normalheader}%
209 }
210 \fancyfoot[L]{%
211 \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
212 {\strutfooter}%
213 {}%
214 }
215 \fancyheadinit{%
216 \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
217 {\renewcommand{\headruleskip}{4pt}}%
218 {\renewcommand{\headruleskip}{0pt}}%
219 }
220 \fancyfootinit{%
221 \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
222 {\renewcommand{\footrulewidth}{0.4pt}}%
223 {\renewcommand{\footrulewidth}{0pt}}%
224 }
225 }
226
227 \fancypagestyle{copyright}{%
228 \fancyfoot[L]{%
229 Copyright \copyright~1994-2025 by Pieter van Oostrum. Distributed under the \LaTeX{}\\
230 Project Public License (LPPL), see \url{http://www.latex-project.org/lppl.txt}}
231 }
232
233 \newcommand\exampleindex{}
234 \def\exampleindex#1#2#3\relax{%
235 \ifx \relax#2\relax \index{Example 0#1=Example #1}\else \index{Example #1#2#3}\fi}
236
237 \newcommand{\ExampleLabel}{}
238 \NewDocumentCommand \Example { m o }
239 {
240 \renewcommand{\ExampleLabel}{Example~#1\IfNoValueF{#2}{\\#2}}%
241 \exampleindex#1\relax\relax%
242 }
243
244 \newcommand{\NoExample}[1]
245 {%
246 \renewcommand{\ExampleLabel}{#1}%
247 % \index{Example `#1'}%
248 }
249 \newcommand{\formatexample}{\hbox{\hspace{-2.5cm}%
250 \raisebox{-2\baselineskip}[0pt][0pt]{%
251 \parbox[t]{2.5cm}{\normalfont\normalsize
252 \centering
253 \ExampleLabel}}}\nopagebreak}
254
255 \newcommand{\FExample}[1]{%
256 \noindent\makebox[0pt][l]{\hspace{-2.5cm}\parbox[t][0pt]{2.5cm}{%
257 \normalfont\normalsize
258 \centering
259 Example #1}}%
260 \exampleindex#1\relax\relax%
261 }%
262
263 \newcommand{\VL}{0.008} % size of vertical line segments
264 \newcommand{\upperline}{%
265 \hbox to 0pt{%
266 \kern\leftmargin
267 \begin{picture}(0pt,0pt)
268 \setlength{\unitlength}{\linewidth}
269 \put(0,0){\line(1,0){1}}
270 \put(0,0){\line(0,-1){\VL}}
271 \put(1,0){\line(0,-1){\VL}}
272 \end{picture}\hss}%
273 \nopagebreak
274 }
275
276 \newcommand{\lowerline}{
277 \nopagebreak\noindent
278 \begin{picture}(0pt,0pt)
279 \setlength{\unitlength}{\linewidth}
280 \put(0,\VL){\line(1,0){1}}
281 \put(0,\VL){\line(0,1){\VL}}
282 \put(1,\VL){\line(0,1){\VL}}
283 \end{picture}\par
284 }
285
286 % fancyvrb hacking
287 \makeatletter
288 \def\FV@Frame@mylines{%
289 \let\FV@BeginListFrame\upperline
290 \let\FV@LeftListFrame\relax
291 \let\FV@RightListFrame\relax
292 \let\FV@EndListFrame\lowerline}
293 \makeatother
294
295 % print the Example number in the margin and gobble the % sign of ltxdoc
296 \DefineVerbatimEnvironment{example}{Verbatim}{formatcom=\formatexample,gobble=1,
297 vspace=0pt,frame=mylines}
298 \DefineVerbatimEnvironment{code}{Verbatim}{gobble=1,vspace=0pt,frame=mylines}
299
300 \newlength{\normalparindent}
301 \setlength{\normalparindent}{\parindent}
302
303 % Macro to print a header in the running text
304 \makeatletter
305 \newcommand\showheader[2][O]{%
306 % #1 optional = O/E (odd/even header)
307 % #2 = fancyhdr code for the header
308 %
309 \begingroup
310 \let\headwidth\textwidth
311 #2
312 \noindent\makebox[\textwidth][c]{\if O#1\@oddhead\else\@evenhead\fi}
313 \endgroup
314 }
315 \makeatother
316
317 % l3doc resets section counters at \part.
318 % I don't want that.
319 \makeatletter
320 \@removefromreset{section}{part}
321 \makeatother
322
323 \begin{document}
324 \DeleteShortVerb{\|}
325 \DocInput{\jobname.dtx}
326 \end{document}
327 %</driver>
328 % \fi
329 %
330 % \CheckSum{0}
331 %
332 % \CharacterTable
333 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
334 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
335 % Digits \0\1\2\3\4\5\6\7\8\9
336 % Exclamation \! Double quote \" Hash (number) \#
337 % Dollar \$ Percent \% Ampersand \&
338 % Acute accent \' Left paren \( Right paren \)
339 % Asterisk \* Plus \+ Comma \,
340 % Minus \- Point \. Solidus \/
341 % Colon \: Semicolon \; Less than \<
342 % Equals \= Greater than \> Question mark \?
343 % Commercial at \@ Left bracket \[ Backslash \\
344 % Right bracket \] Circumflex \^ Underscore \_
345 % Grave accent \` Left brace \{ Vertical bar \|
346 % Right brace \} Tilde \~}
347 %
348 % \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ }
349 % \expandafter\DoNotIndex\expandafter{\bslash} ^^A BUG in l3doc
350 % \DoNotIndex{\@ne,\box,\box_new:N,\csx,\csn,\copy,\color}
351 % \DoNotIndex{\@opcol,\@opcol:,\expandafter,\errorcontextlines}
352 % \DoNotIndex{\advance,\begingroup,\catcode,\closein,\centering,\dbltextfloatsep}
353 % \DoNotIndex{\begin,\end,\bgroup,\egroup}
354 % \DoNotIndex{\closeout,\day,\def,\edef,\else,\empty,\endgroup,\everypar}
355 % \DoNotIndex{\cs_gset_eq:NN,\cs_gset_protected:Npn,\cs_if_exist:NTF,\cs_if_exist:cTF}
356 % \DoNotIndex{\cs_new:Nn,\cs_new_eq:NN,\cs_new_protected:Npn,\cs_set_eq:NN}
357 % \DoNotIndex{\csname,\endcsname,\end,\endinput,\def,\dimen,\do,\dp}
358 % \DoNotIndex{\dim_set:Nn,\c_max_dim,\endlinechar,\errmessage}
359 % \DoNotIndex{\exp_args:Nc,\exp_last_unbraced:Nv,\exp_not:n,\exp_not:v}
360 % \DoNotIndex{\ExplSyntaxOn,\ExplSyntaxOff,\fi,\gdef,\global}
361 % \DoNotIndex{\group_begin:,\group_end:,\hbox,\hfil,\hfill,\hsize,\hskip,\hss,\ht}
362 % \DoNotIndex{\hrule,\hrulefill,\if,\ifdim,\ifnum,\ifx,\ifvmode,\ifvoid,\ifdefined}
363 % \DoNotIndex{\index,\int_new:N,\int_set:Nn,\int_set_eq:NN,\c_max_int}
364 % \DoNotIndex{\label,\leavevmode,\let,\llap,\LM,\long,\macro}
365 % \DoNotIndex{\makeatletter,\makeatother,\MessageBreak,\mark,\maxdimen}
366 % \DoNotIndex{\msg_error:nnn,\msg_error:nnnn,\msg_new:nnn,\mysaved,\newif}
367 % \DoNotIndex{\newmarks,\newtoks,\nobreak,\noexpand,\noindent,\output,\outputdblcol}
368 % \DoNotIndex{\parbox,\patchcmd,\plain,\pretocmd,\protect,\providecommand}
369 % \DoNotIndex{\protect,\ProvidesPackage,\quad,\relax,\renewcommand,\RequirePackage,\restorecr}
370 % \DoNotIndex{\restylefloat,\rlap,\rm,\rmfamily,\scan_stop:}
371 % \DoNotIndex{\seq_map_inline:Nn,\seq_new:N,\seq_put_right:Nn,\setAP,\setbox}
372 % \DoNotIndex{\setcounter,\setlength,\settowidth,\sl,\slshape,\space,startAP,\string}
373 % \DoNotIndex{\strut,\temp@a,\temp@a:,\@[xy]lhead,\@botlist,\@chapapp,\@currbox,\@currsize,\@empty}
374 % \DoNotIndex{\@firstoftwo,\@for,\@forloop,\@fortmp,\@gobble,\@gobbletwo,\@height}
375 % \DoNotIndex{\@ifnextchar,\@ifpackageloaded,\@ifstar,\@ifundefined,\@makecol,\@minus}
376 % \DoNotIndex{\@mkboth,\@namedef,\@nameuse,\@newbaseline,\@nil,\@normalcr,\@normalsize}
377 % \DoNotIndex{\@outputbox,\@outputdblcol,\@outputpage,\@parboxrestore,\@plus}
378 % \DoNotIndex{\@secondoftwo,\@spaces,\@tempa,\@tempboxa,\@tempdima,\@tempdimb,\@tempdimc}
379 % \DoNotIndex{\@tempskipa,\@tempskipb,\@temptokena,\@temptokenb,\@tfor,\@themark}
380 % \DoNotIndex{\@toplist,\@topnewpage,\@undefined,\@unexpandable@protect,\@width}
381 % \DoNotIndex{\c@page,\c@secnumdepth,\col@number,\color@begingroup,\color@endgroup}
382 % \DoNotIndex{\color@endbox,\color@vbox,\f@nch@,\insert@nonemptymarks,\latex@makecol}
383 % \DoNotIndex{\m@ne,\partial@page,\pcol@@outputpage,\pcol@combinefloats}
384 % \DoNotIndex{\pcol@getcurrcol,\pcol@imakeflushedpage,\pcol@ioutputelt,\pcol@makecol,\pcol@prevdepth}
385 % \DoNotIndex{\pcol@makeflushedpage,\pcol@outputpage@l,\pcol@outputpage@r,\pcol@prec_depth}
386 % \DoNotIndex{\pcol@rightpage,\pcol@spanning,\pcol@synccolumn,\ps@xxx,\return@nonemptymark}
387 % \DoNotIndex{\scr@topnewpage,\set@keptmarks,\temp@a,\temp@b,\temp@c,\temp@ty,\tmpf@ra}
388 % \DoNotIndex{\toks@,\unrestored@protected@xdef,\voidb@x,\z@,\z@skip}
389 % \DoNotIndex{\tex_marks:D,\tex_splitmaxdepth:D,\tex_vbadness:D,\textbf,\textsl,\texttt}
390 % \DoNotIndex{\textfraction,\textwidth,\the,\c_empty_tl}
391 % \DoNotIndex{\tl_gset:cn,\tl_gset:Nn,\tl_gset:No,\tl_gset:co,\tl_gset_eq:NN,\tl_gset_eq:cc,\tl_gset_eq:cN}
392 % \DoNotIndex{\tl_if_empty:cF,\tl_if_empty:cTF,\tl_if_empty:cT,\tl_if_empty:NF,\tl_if_empty:NTF}
393 % \DoNotIndex{\tl_new:N,\tl_new:c,\tl_set_eq:cc,\tl_to_str:c,\token_to_str:c,\token_to_str:N}
394 % \DoNotIndex{\undefined,\unskip,\unvbox,\unvcopy,\use:n,\use:N,\use:c,\use_none:n,\usepackage}
395 % \DoNotIndex{\var,\vbox,\vbox_set:Nn,\vbox_set_split_to_ht:NNn,\vboxed,\vskip,\vspace}
396 % \DoNotIndex{\vsplit,\vss,\xdef,\xlap,\xxxx,\xmarks}
397 % \DoNotIndex{\newcommand,\NewDocumentCommand,\NewExpandableDocumentCommand,\newlength,\newtoks}
398 %
399 % \ProvideDocElement[printtype=\textit{hook},idxtype=hook,idxgroup=Hooks]{Hook}{hookdecl}%
400 % \newcommand\makedate{}
401 % \def\makedate#1/#2/#3/{%
402 % \date{%
403 % \ifcase #2\or
404 % Jan\or Feb\or March\or Apr\or May\or June\or
405 % July\or Aug\or Sept\or Oct\or Nov\or Dec\fi~\number #3,
406 % #1}%
407 % }
408 % \expandafter\makedate\filedate/
409 %
410 % \title{The \pkg{fancyhdr} and \pkg{extramarks}
411 % packages\\{\normalsize version \fileversion.}}
412 % \author{Pieter van Oostrum\thanks{Part of this documentation was
413 % written by George
414 % Gr\"atzer (University of Manitoba) in \emph{Notices Amer. Math. Soc.}
415 % Thanks, George!}\\
416 % Dept.\ of Computer Science\thanks{This was my employer at the time I developed this package.
417 % I am now retired.}\\
418 % Utrecht University}
419 %
420 % \maketitle
421 % \begin{abstract}
422 % This document describes how to customize the page layout of your LaTeX
423 % documents, i.e., how to change page margins and sizes,
424 % headers and footers, and the
425 % proper placement of figures and tables (collectively called floats) on
426 % the page.
427 %
428 % This documentation describes version 5.0 or later of the
429 % \pkg{fancyhdr} and \pkg{extramarks} packages. The user
430 % documentation is also mostly valid for the versions 4.0 or later of
431 % the \pkg{fancyhdr} and \pkg{extramarks} packages (except
432 % for the changes mentioned in sections~\ref{sec:version-4} and
433 % \ref{sec:version-5}).
434 % \end{abstract}
435 %
436 % \tableofcontents
437 % \thispagestyle{copyright}
438 % \newpage
439 % \checkposinpage
440 % \setmarks{Introduction}
441 %
442 % \begin{documentation}
443 % \part{Introduction}
444 %
445 % This document contains four parts:
446 %
447 % Part I is a short documentation on
448 % the user commands of the \pkg{fancyhdr} and \pkg{extramarks} packages.
449 %
450 % Part II contains elaborate documentation on page layout in \LaTeX.
451 %
452 % Part III contains Questions and Answers.
453 %
454 % Part IV contains the annotated implementation.
455 %
456 % This document describes version 5 of \pkg{fancyhdr}. This version
457 % is an extension of \pkg{fancyhdr} version 4, which is described in
458 % the \emph{The \LaTeX{} Companion, Third Edition}. It just
459 % has some additional commands that are not mentioned in \emph{The
460 % \LaTeX{} Companion}.
461 % The differences between these versions
462 % are summarized in section~\ref{sec:version-4} on
463 % page~\pageref{sec:version-4}, and section~\ref{sec:version-5} on
464 % page~\pageref{sec:version-5}.
465 % Throughout this documentation it is mentioned when a specific feature
466 % is only available in version 4 or a later version, or when there are
467 % differences between version 4 and 5.
468 %
469 % This document also describes version 5 of \pkg{extramarks}. This
470 % is a new implementation that differs significantly from the previous
471 % versions. See section~\ref{sec:extramarks-5} on
472 % page~\pageref{sec:extramarks-5} for more details.
473 %
474 % This documentation contains several examples. Most of the examples are
475 % available for download from Github, see section~\ref{sec:contact}.
476 % These examples are indicated with their name in the margin. If the
477 % margin says ``Example \meta{n}'', where \meta{n} is numeric, maybe
478 % followed by a letter, then the file name will be
479 % \texttt{example\meta{n}.tex}. When it is followed by a letter in
480 % parentheses like (A), it means an item in the file. Other names
481 % without the word ``Example'' are just the file name without extension,
482 % for example ``with-beamer'' indicates the file name \texttt{with-beamer.tex}.
483 %
484 % \section{Installation}
485 % \label{sec:installation}
486 %
487 % The preferred way to install this package is with a package installer.
488 % If you want to install it by hand, then first run the command
489 % `\verb+tex fancyhdr.ins+' and then move the files \pkg{fancyhdr.sty},
490 % \pkg{extramarks.sty}, \pkg{extramarks-v4.sty}
491 % and \pkg{fancyheadings.sty} to a place
492 % where \LaTeX{} can find it, preferably in a directory similar to
493 % \texttt{.../texmf/tex/latex/fancyhdr/} in your \TeX{} directory tree.
494 % To get the documentation, run `\verb+pdflatex fancyhdr.dtx+'.
495 %
496 % \section{Using \pkg{fancyhdr}}
497 % \label{sec:using-fancyhdr}
498 %
499 % The package \pkg{fancyhdr} gives you several commands to define
500 % headers and footers of the pages in a \LaTeX{} document.
501 % You load the package with the following command in the preamble:
502 % \begin{quote}
503 % \cs{usepackage}\oarg{options}\verb|{fancyhdr}|
504 % \end{quote}
505 % (Options are available since version~4.0.
506 % See \smartref{sec:using-fancyhdr}{sec:options} for the details.)
507 %
508 % \begin{function}{\fancyhead,\fancyfoot,\fancyhf}
509 % \begin{syntax}
510 % \cmd{\fancyhead}\oarg{places}\marg{field} \\
511 % \cmd{\fancyfoot}\oarg{places}\marg{field} \\
512 % \cmd{\fancyhf}\oarg{places}\marg{field}
513 % \end{syntax}
514 % Here \meta{places} is a comma-separated list of places where
515 % \meta{field} will be placed. There are 12 places defined: Left,
516 % Center and Right Headers and Footers, and both can be on Even or Odd
517 % pages. Each place therefore has 3 coordinates which are the inital
518 % letters of the above description: (1) \texttt{E} or \texttt{O}, (2) \texttt{L}, \texttt{C} or
519 % \texttt{R}, (3) \texttt{H} or \texttt{F}. So a place is given with 3
520 % letters, like \texttt{EOH}. A missing coordinate means: all
521 % possibilities, except for \cs{fancyhead} where \texttt{H} is implied
522 % and \cs{fancyfoot} where \texttt{F} is implied. Although in this
523 % documentation always uppercase letters are used in the \meta{places},
524 % lowercase is also acceptable.
525 % \end{function}
526 %
527 % \begin{function}{\fancyheadoffset,\fancyfootoffset,\fancyhfoffset}
528 % \begin{syntax}
529 % \cmd{\fancyheadoffset}\oarg{places}\marg{length} \\
530 % \cmd{\fancyfootoffset}\oarg{places}\marg{length} \\
531 % \cmd{\fancyhfoffset}\oarg{places}\marg{length}
532 % \end{syntax}
533 % These define offsets to let the headers stick into the margin (or to
534 % the inside if negative). Places cannot contain the \texttt{C}
535 % specifier. See sections~\ref{sec:book-examples} and
536 % \ref{sec:headwidth} for more details.
537 % \end{function}
538 %
539 % \begin{function}{\fancyheadwidth,\fancyfootwidth,\fancyhfwidth}
540 % \begin{syntax}
541 % \cmd{\fancyheadwidth}\oarg{places}\oarg{alignment}\marg{length} \\
542 % \cmd{\fancyfootwidth}\oarg{places}\oarg{alignment}\marg{length} \\
543 % \cmd{\fancyhfwidth}\oarg{places}\oarg{alignment}\marg{length} \\[1ex]
544 % \cmd{\fancyheadwidth}*\oarg{places}\oarg{alignment}\marg{length} \\
545 % \cmd{\fancyfootwidth}*\oarg{places}\oarg{alignment}\marg{length} \\
546 % \cmd{\fancyhfwidth}*\oarg{places}\oarg{alignment}\marg{length}
547 % \end{syntax}
548 % These define widths and optionally the alignments for the header and
549 % footer fields. The fields will be typeset in a \cs{parbox} of this
550 % width, which can be different for each \emph{place}. If the width of a
551 % field is not specified, it defaults to \cs{headwidth}, which may cause
552 % them to overlap. The alignment option and the \texttt{*} version are
553 % available in \pkg{fancyhdr} version 5.2 and later. See
554 % section~\ref{sec:field-width} for more details.
555 % \end{function}
556 %
557 % \begin{variable}{\headrulewidth, \footrulewidth, \headruleskip,
558 % \footruleskip, \headwidth}
559 % \cs{headrulewidth} and \cs{footrulewidth} are macros to define the
560 % thickness of a line under the header and above the footer.
561 % \cs{headruleskip} and \cs{footruleskip} are macros that define the
562 % distance between the lines and the header and footer text,
563 % respectively. (But \cs{headruleskip} is only available since version~4.0.)
564 % And \cs{headwidth} is a length parameter that defines the
565 % total width of the headers and footers. See section~\ref{sec:headwidth} for more details.
566 % \end{variable}
567 %
568 % \begin{function}{\headrule, \footrule}
569 % \cs{headrule} and \cs{footrule} are macros to completely redefine
570 % these lines.
571 % \end{function}
572 %
573 % \begin{function}{\fancyheadinit, \fancyfootinit, \fancyhfinit}
574 % \cs{fancyheadinit} and \cs{fancyfootinit} can be used to define
575 % initialisation code for the header and footer, respectively, and
576 % \cs{fancyhfinit} defines both of these. These commands are only
577 % available in \pkg{fancyhdr} version~4.0 and later. See section~\ref{sec:curpagestyle}.
578 % \end{function}
579 %
580 % \begin{function}{\fancyfootalign}
581 % \begin{syntax}
582 % \cmd{\fancyfootalign}\texttt{\{\}}\\
583 % \cmd{\fancyfootalign}\marg{length}
584 % \end{syntax}
585 % \end{function}
586 % The command \cs{fancyfootalign} allows you to fine-tune the vertical
587 % position of the footer with respect to the page bottom. This command
588 % is only available in \pkg{fancyhdr} 5.0 and later.
589 % See section~\ref{sec:fancyfootalign}.
590 %
591 % \begin{function}{\fancycenter}
592 % \begin{syntax}
593 % \cs{fancycenter}\oarg{dist}\oarg{stretch}\marg{left-field}\marg{center-field}\marg{right-field}
594 % \end{syntax}
595 % (Only in version~4.0 and later.) The command \cs{fancycenter} packs 3
596 % header fields into a full-width header. See section~\ref{sec:fancycenter}.
597 % \end{function}
598 %
599 % \begin{function}{\fancyhdrbox}
600 % \begin{syntax}
601 % \cs{fancyhdrbox}\oarg{alignment}\oarg{width}\marg{lines separated by \cmd{\\}}
602 % \end{syntax}
603 % (Only in version~5.0 and later.) The command \cs{fancyhdrbox} can be
604 % used to align multi-line parts vertically and horizontally.
605 % See section~\ref{sec:fancyhdrbox}.
606 % \end{function}
607 %
608 % \begin{function}{\iftopfloat, \ifbotfloat, \iffloatpage, \iffootnote}
609 % The macros \cs{iftopfloat}, \cs{ifbotfloat}, \cs{iffloatpage} and
610 % \cs{iffootnote} are used to detect if there is a float on the top or
611 % the bottom of the page, or the page is a float page, or if there is
612 % a footnote at the bottom of the page. These can be used to choose
613 % different headers and/or footers if these conditions are met. See
614 % section~\ref{sec:float} for more details.
615 % \end{function}
616 %
617 % \begin{function}{\fancypagestyle,\fancypagestyle*}
618 % \begin{syntax}
619 % \cs{fancypagestyle}\marg{style-name}\oarg{base-style}\marg{definitions}\\
620 % \cs{fancypagestyle}*\marg{style-name}\oarg{base-style}\marg{definitions}
621 % \end{syntax}
622 % This command lets you (re)define page styles for use in special
623 % situations. See sections~\ref{sec:pagestyle-plain} and
624 % \ref{sec:fancypagestyle} for more details.
625 % \end{function}
626 %
627 % \begin{function}{\fancypagestyleassign}
628 % \begin{syntax}
629 % \cs{fancypagestyleassign}\marg{ps1}\marg{ps2}
630 % \end{syntax}
631 % This command assigns page style \meta{ps2} to \meta{ps1}. This causes
632 % \meta{ps1} to be an exact copy of \meta{ps2}, but completely
633 % independent of \meta{ps2}. Or you could say that \meta{ps1} becomes a
634 % new name for page style \meta{ps2}.
635 % See section~\ref{sec:tocstyle} for an example.
636 % \end{function}
637 %
638 % \begin{function}{\fancyhdrsettoheight}
639 % \begin{syntax}
640 % \cs{fancyhdrsettoheight}\marg{lengthvar}\marg{header/footer}
641 % \end{syntax}
642 % Sets \meta{lengthvar} to the height of the \meta{header/footer}, which must
643 % be one of \texttt{oddhead}, \texttt{evenhead}, \texttt{oddfoot} or \texttt{evenfoot}.
644 % Please note: You usually use this outside of a header or a footer (for
645 % example in the \emph{preamble}, but then if you use marks with a non-standard height
646 % in your headers or footers, the calculated height may be wrong, as marks don't work well
647 % outside of a header or footer.
648 % \end{function}
649 %
650 % \section{Package \pkg{fancyhdr} options}
651 % \label{sec:options}
652 %
653 % \textbf{NOTE:} This section applies to \pkg{fancyhdr} version~4.0 and later.
654 %
655 % You can supply options to the \cs{usepackage} command:
656 % \begin{quote}
657 % \verb|\usepackage|\oarg{options}\verb|{fancyhdr}|
658 % \end{quote}
659 % The following options are supported:
660 % \begin{center}
661 % \OPTindex{nocheck}\OPTindex{compatV3}\OPTindex{twoside}\OPTindex{headings}\OPTindex{myheadings}%
662 % \begin{tabular}{ l l }
663 % \toprule
664 % Option & Meaning \\
665 % \midrule
666 % \texttt{nocheck} & do not check the heights of the header and footer \\
667 % \texttt{compatV3} & keep some behaviour (now considered undesirable) as in version~3 \\
668 % \texttt{twoside} & use two-sided headers and footers even in one-sided documents \\
669 % & for \pkg{fancyhdr}-based page styles (version 4.1 or later) \\
670 % \texttt{headings} & redefine the \texttt{headings} page style to be fancy-based \\
671 % \texttt{myheadings} & redefine the \texttt{myheadings} page style to be fancy-based \\
672 % \bottomrule
673 % \end{tabular}
674 % \end{center}
675 %
676 % \begin{itemize}
677 % \item Options \texttt{nocheck} and \texttt{compatV3} are described in
678 % section~\ref{sec:warning} on page~\pageref{page:warning}.
679 %
680 % \item \OPTindex{compatV3}Option \texttt{compatV3} keeps two \pkg{fancyhdr}
681 % version~3.x (or earlier) features that are now considered undesirable.
682 % \begin{enumerate}
683 % \item The automatic adjustment of \cs{headheight} or \cs{footskip}
684 % when these are too small. This causes the page layout to become
685 % inconsistent.
686 % \item In these previous versions the changes to the
687 % \pkg{fancyhdr} headers and footers (including those by
688 % \cs{fancyhead}, \cs{fancyheadoffset} and similar commands) are
689 % made globally, except within a page style defined by
690 % \cs{fancypagestyle}. That is, when these commands are given inside
691 % a \LaTeX{} group, they affect the whole document, not only the
692 % group. If your document depends on this behaviour, you can give
693 % the \texttt{compatV3} package option. However, this is only
694 % considered a short-time solution. You should change your document
695 % as soon as possible to work around this problem. In version~4.0 and
696 % later, without this option, the changes are always local.
697 % \end{enumerate}
698 % This option is deprecated in version~5.0 of
699 % \pkg{fancyhdr}. It will disappear in a later release. Please
700 % don't use this option anymore, but rather change your document.
701 %
702 % \item \OPTindex{twoside}Option \texttt{twoside} implements two-sided headers
703 % and footers in one-sided documents (version 4.1 or later). This applies only
704 % for \pkg{fancyhdr}-based page styles. This option doesn't do anything
705 % special for two-sided documents (\texttt{twoside} documentclass option), as
706 % these already have that functionality. And with the \texttt{twoside}
707 % documentclass option that does apply to other page styles as well.
708 %
709 % \item \PSindex{headings}\PSindex{myheadings}\OPTindex{headings}\OPTindex{myheadings}
710 % The options \texttt{headings} and \texttt{myheadings} redefine the
711 % corresponding page style with \pkg{fancyhdr} commands (including a
712 % decorative line under the header), so that you can later select this
713 % page style as the page style for (part of) the
714 % document\footnote{These options were copied from the
715 % \PKGindex{nccfancyhdr}
716 % \pkg{nccfancyhdr} package, but contrary to that package, they are
717 % not automatically selected.}.
718 % \end{itemize}
719 %
720 % \PSindex{headings}
721 % The page style \texttt{headings} is in some aspects similar to the default page
722 % style \texttt{fancy} settings. In the \texttt{fancy} page style, the
723 % page number is in the footer, but in the \texttt{headings}
724 % page style it is in the header. The header fields look similar, however.
725 %
726 % Please note that these page styles redefine the \cs{chaptermark} and/or
727 % \Cmd{[sub]sectionmark} commands (see section~\ref{sec:scoop}), as do the
728 % standard \LaTeX{} page styles. The consequence is, that if you select
729 % e.g., \Cmd{pagestyle\{headings\}}, the definitions of
730 % \Cmd{pagestyle\{fancy\}} are overridden.
731 % Also when you change the headers and/or footers
732 % while such a page style is in effect, and you then switch back to this
733 % page style, for
734 % example with \verb|\pagestyle{headings}|, they revert to the built-in
735 % settings. Therefore it is not advisable to change the headers or
736 % footers in this way, but instead define your
737 % own page style, as explained in section~\ref{sec:fancypagestyle}.
738 %
739 % \section{Using \pkg{extramarks}}
740 % \label{sec:using-extramarks}
741 %
742 % Standard \LaTeX{} has two marks: a left one and a right one. The standard
743 % command \cs{leftmark} gives you the last left mark on a page, and
744 % \cs{rightmark} gives you the first right one. These are to be used in
745 % the headers and footers of a page. These are derived from information
746 % that is given by the \cs{markboth} and \cs{markright} commands in the
747 % text body.
748 %
749 % \begin{function}{\firstleftmark, \lastrightmark, \firstrightmark, \lastleftmark}
750 % These macros give you the other combinations, where
751 % \cs{firstrightmark} = \cs{rightmark} and \cs{lastleftmark} = \cs{leftmark}.
752 % \end{function}
753 %
754 % \begin{function}{\extramarks, \extramarksleft, \extramarksright}
755 % \begin{syntax}
756 % \cs{extramarks}\marg{left-text}\marg{right-text}
757 % \cs{extramarksleft}\marg{left-text}\\
758 % \cs{extramarksright}\marg{right-text}
759 % \end{syntax}
760 %
761 % The command \cs{extramarks}\marg{$m_1$}\marg{$m_2$} defines two extra marks,
762 % similar to the standard ones by \LaTeX, where \meta{$m_1$} is the left
763 % mark and \meta{$m_2$} is the right mark.
764 %
765 % \label{sec:extramarks-5}
766 % In versions before 5.0, the \texttt{extramarks} are connected to each
767 % other and to the original \LaTeX{} marks; they are not independent.
768 % For example, if you use \cs{markboth} or \cs{markright}, this
769 % introduced empty \texttt{extramarks} or duplicated existing ones. This is
770 % also true in the other direction. This sometimes caused unwanted effects.
771 %
772 % Since version 5.0 this is no longer the case.
773 % Now the \texttt{extramarks} are independent of the traditional marks,
774 % and they can also be set independently of each other by the commands
775 % \cs{extramarksleft}\marg{$m_1$} and \cs{extramarksright}\marg{$m_2$}.
776 % \end{function}
777 %
778 % \begin{variable}{extramarks-left, extramarks-right}
779 % \begin{syntax}
780 % \texttt{extramarks-left}\\
781 % \texttt{extramarks-right}
782 % \end{syntax}
783 % These are the `mark classes' for the two marks.
784 % \end{variable}
785 %
786 % \medskip
787 %
788 % \textbf{NOTE}: The implementation of \pkg{extramarks} version 5
789 % only is available if your \LaTeX{} release is the
790 % November 2022 \LaTeX{} release or newer. It uses the new \LaTeX{}
791 % marks introduced in that release. These marks are described in \emph{The \LaTeX{}
792 % Companion, Third Edition}, section 5.3.5 (Part I). Of course you can
793 % also use these new marks directly, or use additional ones if you need
794 % more. Some examples in this manual use these.
795 %
796 % This manual contains several examples of the use of \pkg{extramarks},
797 % where its features are essential, but in future releases of this
798 % manual these examples will be rewritten to use the new \LaTeX{} marks directly.
799 %
800 % \subsubsection*{Extramarks commands to be used in the headers or footers}
801 %
802 % \begin{function}{\firstleftxmark, \firstrightxmark, \topleftxmark,
803 % \toprightxmark, \lastleftxmark, \lastrightxmark, \firstxmark,
804 % \lastxmark, \topxmark}
805 % \begin{flushleft}
806 % These commands are used to extract the marks defined by
807 % \cs{extramarks}\marg{$m_1$}\marg{$m_2$}, \cs{extramarksleft}\marg{$m_1$}\ and
808 % \cs{extramarksright}\marg{$m_2$} described above.\\
809 % They are used in the headers or footers, similar to the ones without
810 % the \texttt{x}.
811 % \end{flushleft}
812 % \end{function}
813 %
814 % If you want to keep the old behaviour of \pkg{extramarks}, you can use:
815 % \begin{verbatim}
816 % \usepackage{extramarks}[=v4]
817 % \end{verbatim}
818 % Please note that in that case the
819 % \cs{topleftxmark}, \cs{toprightxmark} and \cs{topxmark} commands may
820 % give you unexpected results.
821 %
822 % See sections~\ref{sec:scoop} and \ref{sec:xmarks} for more details
823 % about the use of the package.
824 %
825 % \newpage
826 % \part{Page Layout in \LaTeX}
827 %
828 % \section{Introduction}
829 % \label{sec:intro}
830 %
831 % A page in a \LaTeX{} document is built from various elements as shown in
832 % figure \ref{fig:layout}.
833 % \begin{figure}[htbp]
834 % \begin{center}
835 % \leavevmode
836 % \layout
837 % \vspace{1.5cm}
838 % \caption{Page elements. The values shown are those in effect in the current document, not the defaults.}
839 % \label{fig:layout}
840 % \end{center}
841 % \end{figure}
842 % \thispagestyle{plain}
843 % The body contains the main text of the document
844 % together with the so called floats (tables and figures).
845 %
846 % The pages are constructed by \LaTeX's output routine, which is quite
847 % complicated and should therefore not be modified. Some of the packages
848 % described in this paper contains small modifications to the output routine
849 % to accomplish things that cannot be done in another way. You should use
850 % these packages to get the desired result rather than fiddling with the
851 % output routine yourself.
852 %
853 % There are a number of things that you must be aware of:
854 % \begin{enumerate}
855 % \item The margins on the left are not called \cs{leftmargin}, but
856 % \cs{evensidemargin} (on even-numbered pages) and \cs{oddsidemargin}
857 % (on odd-numbered pages). In one-sided documents
858 % \cs{oddsidemargin} is used for either. \cs{leftmargin} is also a valid
859 % \LaTeX{} parameter but it has a different use (namely the indentation of
860 % lists).
861 % \item Most of the parameters should not be changed in the middle of a
862 % document. Some changes might work at a page break. If you want to change
863 % the height of a single page, you can use the \cs{enlargethispage}
864 % command.
865 % \end{enumerate}
866 %
867 % The margin notes
868 % area contains small pieces of information created by the \cs{marginpar}
869 % command. On two-sided documents the margin notes appear on the left and right
870 % alternatively. The margin notes are not on fixed places with respect to the
871 % paper but at approximately the same height as the paragraph in which they
872 % appear. Due to the algorithm used to decide the placement of margin notes,
873 % in a two-sided document unfortunately
874 % they may appear on the wrong side if they are close
875 % to a page break.
876 % If you want to put information on fixed places in the margins you may use
877 % the technique described in sections \ref{sec:movie} and \ref{sec:thumb}.
878 %
879 % The first part of this paper describes how to change the header and footer
880 % areas. The last part describes how to get your floats at the desired place.
881 %
882 % \section{Page headers and footers}
883 %
884 % The page headers and footers in \LaTeX{} are defined by the
885 % \cs{pagestyle} and \cs{pagenumbering} commands. \cs{pagestyle}
886 % defines the general contents of the headers and footers (e.g., where the
887 % page number will be printed), while
888 % \cs{pagenumbering} defines the format of the page number.
889 % \LaTeX{} has four standard page styles:
890 %
891 % \begin{center}
892 % \noindent
893 % \begin{tabular}{>{\tt}lp{9cm}}
894 % \toprule
895 % empty & no headers or footers \\
896 % plain & no header, footer contains page number centered \\
897 % headings & no footer, header contains name of chapter/section and/or
898 % subsection and page number \\
899 % myheadings & no footer, header contains page number and user
900 % supplied information \\
901 % \bottomrule
902 % \end{tabular}
903 % \end{center}
904 %
905 % Although these are useful styles, they are quite limited. Additional page
906 % styles can be defined by defining commands of the form \cs{ps@xxx}. This
907 % command is executed when a \Cmd{pagestyle\{xxx\}} is given in the document.
908 % The \cs{ps@xxx} command should define the following
909 % commands for the contents of the headers and footers:
910 %
911 % \begin{center}
912 % \noindent
913 % \begin{tabular}{lp{9cm}}
914 % \toprule
915 % \cs{@oddhead} & header on odd numbered pages in two-sided documents
916 % (on all pages in one-sided) \\
917 % \cs{@evenhead} & header on even numbered pages in two-sided documents \\
918 % \cs{@oddfoot} & footer on odd numbered pages in two-sided documents
919 % (on all pages in one-sided) \\
920 % \cs{@evenfoot} & footer on even numbered pages in two-sided documents \\
921 % \bottomrule
922 % \end{tabular}
923 % \end{center}
924 %
925 % These are not user commands, but rather ``variables'' that are used by
926 % \LaTeX's output routine.
927 % As the command names contain the character `\texttt{@}', they should
928 % be defined in a package file, or otherwise be sandwiched between the commands
929 % \cs{makeatletter} and \cs{makeatother}.
930 %
931 % The \cs{pagenumbering} command defines the layout of the page number. It
932 % has a parameter from the following list:
933 %
934 % \begin{center}
935 % \begin{tabular}{>{\tt}ll}
936 % \toprule
937 % arabic & arabic numerals \\
938 % roman & lower case roman numerals \\
939 % Roman & upper case roman numerals \\
940 % alph & lower case letter \\
941 % Alph & upper case letter \\
942 % \bottomrule
943 % \end{tabular}
944 % \end{center}
945 %
946 % The \Cmd{pagenumbering\{xxx\}} defines the command \cs{thepage} to be the
947 % expansion of the page number in the given notation \texttt{xxx}.
948 % The page style command
949 % then would include \cs{thepage} in the appropriate place. Additionally
950 % the \cs{pagenumbering} command resets the page number to~1.
951 % The \cs{pagestyle} and \cs{pagenumbering} apply to the page that is
952 % being constructed, so they should be used at a location where it is clear
953 % to what page they apply (see section \ref{sec:change}).
954 %
955 %
956 % \section{What is \pkg{fancyhdr}}
957 %
958 % The \pkg{fancyhdr} macro package allows you to customize
959 % in \LaTeX{} your page headers and footers in an easy way. You can
960 % define:
961 % \begin{itemize}
962 % \item three-part headers and footers
963 % \item decorative lines in headers and footers
964 % \item headers and footers wider than the width of the text
965 % \item multi-line headers and footers
966 % \item separate headers and footers for even and odd pages
967 % \item different headers and footers for chapter pages
968 % \item different headers and footer on pages with floats
969 % \end{itemize}
970 %
971 % Of course, you also have complete control over fonts, uppercase
972 % and lowercase displays, etc.
973 %
974 % \section{Simple use of \pkg{fancyhdr}} To use this package
975 % install it in a place where \LaTeX{} can find it (see
976 % section~\ref{sec:installation})\footnote{In most modern \TeX{}
977 % installation the package is already included.}, and include in the preamble of your document
978 % the commands:
979 %
980 % \PSindex{fancy}
981 % \begin{code}
982 % \usepackage{fancyhdr}
983 % \pagestyle{fancy}
984 % \end{code}
985 %
986 % We can visualize the page layout we can create with \pkg{fancyhdr}
987 % as follows:
988 %
989 % \begin{fblock}
990 % \noindent\makebox[\textwidth]{LeftHeader\hfill
991 % CenteredHeader\hfill RightHeader}\showrule
992 % \noindent\makebox[\textwidth]{\hfill page body\hfill}\\[\baselineskip]
993 % \noindent\makebox[\textwidth]{\hrulefill}
994 % \noindent\makebox[\textwidth]{LeftFooter\hfill
995 % CenteredFooter\hfill RightFooter}
996 % \end{fblock}
997 %
998 % The LeftHeader and LeftFooter are left justified; the
999 % CenteredHeader and CenteredFooter are centered; the
1000 % RightHeader and RightFooter are right justified.
1001 %
1002 % We define each of the six ``fields'' and the two decorative lines
1003 % separately.
1004 %
1005 % \section{A simple example}
1006 % \label{sec:simple}
1007 %
1008 % K. Grant is writing a report to Dean
1009 % A. Smith, on ``The performance of new graduates'' with the
1010 % following page layout:
1011 %
1012 % \begin{fblock}
1013 % \noindent\makebox[\textwidth]{\hfill\textbf{The performance of new
1014 % graduates}}\showrule
1015 % \noindent\makebox[\textwidth]{\hfill page body\hfill}\\[\baselineskip]
1016 % \noindent\makebox[\textwidth]{\rule{\textwidth}{2pt}}
1017 % \noindent\makebox[\textwidth]{From: K. Grant\phantom{3}\hfill
1018 % To: Dean A. Smith\hfill \phantom{From: K. Grant}3}
1019 % \end{fblock}
1020 %
1021 % \noindent where ``3'' is the page number. The title: ``The
1022 % performance of new graduates'' is bold. The rule above the footer is a
1023 % bit thicker (2pt).
1024 %
1025 % This is accomplished by these commands following
1026 % \Cmd{pagestyle\{fancy\}}\footnote{Note that version 1 of \pkg{fancyheadings}
1027 % used the \cs{setlength} command to change the \texttt{\bs...rulewidth} parameters.}:
1028 % \CmdIndex{fancyhead}
1029 % \CmdIndex{fancyfoot}
1030 % \CmdIndex{headrulewidth}
1031 % \CmdIndex{footrulewidth}
1032 % \Example{1}
1033 % \begin{example}
1034 % \fancyhead[L,C]{}
1035 % \fancyhead[R]{\textbf{The performance of new graduates}}
1036 % \fancyfoot[L]{From: K. Grant}
1037 % \fancyfoot[C]{To: Dean A. Smith}
1038 % \fancyfoot[R]{\thepage}
1039 % \renewcommand{\headrulewidth}{0.4pt}
1040 % \renewcommand{\footrulewidth}{2pt}
1041 % \end{example}
1042 % (The \cs{thepage} macro displays the current page number.
1043 % \cs{textbf} puts its argument in bold face.)
1044 %
1045 % This is now fine, except that the first page does not need
1046 % all these headers and footers. To eliminate all but the
1047 % centered page number, issue the command
1048 %
1049 % \Example{2}
1050 % \CmdIndex{thispagestyle}
1051 % \begin{example}
1052 % \thispagestyle{plain}
1053 % \end{example}
1054 % after the
1055 % \Cmd{begin\{document\}}
1056 % and the
1057 % \CmdIndex{maketitle}
1058 % \cs{maketitle}
1059 % commands.
1060 %
1061 % Alternatively, issue
1062 % \begin{code}
1063 % \thispagestyle{empty}
1064 % \end{code}
1065 % if you do not want any headers or footers.
1066 %
1067 % In fact the standard \LaTeX{} classes have the command \cs{maketitle}
1068 % defined in such a way that a \Cmd{thispagestyle\{plain\}} is automatically
1069 % issued. So if you \emph{do} want the fancy layout on a page containing
1070 % \cs{maketitle} you must issue a \Cmd{thispagestyle\{fancy\}} after the
1071 % \cs{maketitle}.
1072 %
1073 % \section{The default layout}
1074 % \label{sec:default}
1075 % Let us use the \pkg{book.cls} documentclass and the default settings for
1076 % \pkg{fancyhdr}; so we don't use any of the page style options in
1077 % the \Cmd{usepackage\{fancyhdr\}} command, and we don't redefine any
1078 % headers or footers. So just:
1079 % \begin{code}
1080 % \usepackage{fancyhdr}
1081 % \pagestyle{fancy}
1082 % \end{code}
1083 % and let \pkg{fancyhdr} take care of everything. As mentioned
1084 % before, we get a layout that is similar to the page style
1085 % \texttt{headings}, but it is not exactly the same. If you want to have
1086 % the same layout as the page style \texttt{headings}, but with a line
1087 % under the header, use (you need \pkg{fancyhdr} version 4 or later
1088 % for this):
1089 % \PSindex{headings}
1090 % \begin{code}
1091 % \usepackage[headings]{fancyhdr}
1092 % \pagestyle{headings}
1093 % \end{code}
1094 %
1095 % On the pages where new chapters start, we get a centered page number
1096 % in the footer; there is nothing in the header, and there are no decorative lines.
1097 %
1098 % On an even page, we get the layout:
1099 %
1100 % \begin{fblock}
1101 % \noindent\makebox[\textwidth]{\textsl{1.2 EVALUATION}\hfill
1102 % \textsl{CHAPTER 1. INTRODUCTION}}\showrule
1103 % \noindent\makebox[\textwidth]{\hfill page body\hfill}\\[2\baselineskip]
1104 % \noindent\makebox[\textwidth]{\hfill2\hfill}
1105 % \end{fblock}
1106 %
1107 % On an odd page, we get the layout:
1108 %
1109 % \begin{fblock}
1110 % \noindent\makebox[\textwidth]{\textsl{CHAPTER 1. INTRODUCTION}\hfill
1111 % \textsl{1.2 EVALUATION}}\showrule
1112 % \noindent\makebox[\textwidth]{\hfill page body\hfill}\\[2\baselineskip]
1113 % \noindent\makebox[\textwidth]{\hfill
1114 % 3\hfill }
1115 % \end{fblock}
1116 %
1117 % \noindent where the header text is slanted uppercase.
1118 %
1119 % In the \texttt{article} documentclass, we get section and subsection
1120 % instead of chapter and section.
1121 %
1122 % And in a one-sided document, all pages get the same layout as the even pages
1123 % above. It would probably have been more logical to choose the odd page
1124 % layout, but changing that now would break some existing documents.
1125 % Anyway, you can change the layout easily yourself.
1126 %
1127 % This default layout is produced by the following commands:
1128 % \Example{5}
1129 % \CmdIndex{rightmark}
1130 % \CmdIndex{leftmark}
1131 % \begin{example}
1132 % \fancyhead[LE,RO]{\textsl{\rightmark}}
1133 % \fancyhead[LO,RE]{\textsl{\leftmark}}
1134 % \fancyfoot[C]{\thepage}
1135 % \end{example}
1136 %
1137 % The following settings are used for the decorative lines:
1138 %
1139 % \begin{tabbing}
1140 % \CmdIndex{headrulewidth}
1141 % \noindent \cs{headrulewidth}\qquad \qquad \qquad \=0.4\=pt\\
1142 % \CmdIndex{footrulewidth}
1143 % \Cmd{footrulewidth}\>0\>pt
1144 % \end{tabbing}
1145 %
1146 % The header text is turned into all uppercase by the standard \LaTeX{}
1147 % code in \pkg{book.cls}.
1148 %
1149 % \section{An example of two-sided printing}\label{two-sided}
1150 %
1151 % \TTindex{twoside}
1152 % Some document classes, such as \pkg{book.cls}, print two-sided by default: the even
1153 % pages and the odd pages have different layouts; other document classes
1154 % use the \texttt{twoside} option to print two-sided.
1155 %
1156 % Now let us print the report two-sided. Let the above page
1157 % layout be used for the odd (right-side) pages, and the
1158 % following for the even (left-side) pages:
1159 %
1160 % \begin{fblock}
1161 %
1162 % \noindent\makebox[\textwidth]{\textbf{The performance of new
1163 % graduates}\hfill}\showrule
1164 % \noindent\makebox[\textwidth]{\hfill page body\hfill}\\[\baselineskip]
1165 % \noindent\makebox[\textwidth]{\hrulefill}
1166 % \noindent\makebox[\textwidth]{4\phantom{To: Dean A. Smith}\hfill
1167 % From: K. Grant\hfill \phantom{4}To: Dean A. Smith}
1168 %
1169 % \end{fblock}
1170 % \noindent where ``4'' is the page number.
1171 %
1172 % Here are the commands:
1173 %
1174 % \Example{3}
1175 % \begin{example}
1176 % \fancyhead{} % clear all header fields
1177 % \fancyhead[RO,LE]{\textbf{The performance of new graduates}}
1178 % \fancyfoot{} % clear all footer fields
1179 % \fancyfoot[LE,RO]{\thepage}
1180 % \fancyfoot[LO,CE]{From: K. Grant}
1181 % \fancyfoot[CO,RE]{To: Dean A. Smith}
1182 % \renewcommand{\headrulewidth}{0.4pt}
1183 % \renewcommand{\footrulewidth}{0.4pt}
1184 % \end{example}
1185 %
1186 % \CmdIndex{fancyhead}
1187 % \CmdIndex{fancyfoot}
1188 % The commands \cs{fancyhead} and \cs{fancyfoot}
1189 % have an additional parameter between square brackets that specifies
1190 % for which pages and/or parts of the header/footer they apply. The first
1191 % \cs{fancyhead} command above omits this parameter, and thus applies to all
1192 % header fields. In general this is only useful to get rid of the defaults or
1193 % a previous definition, as is done here. Similarly the \cs{fancyfoot} command
1194 % without square brackets clears all footer fields. In this particular
1195 % example it could be omitted as all footer fields have a value specified.
1196 % The selectors that can be used
1197 % between the square brackets are given in figure~\ref{fig:sel}. Selectors can be combined so
1198 % \Cmd{fancyhead[LE,RO]\{text\}}
1199 % will define the field for both the left header on even pages and the right
1200 % header on odd pages. If you don't give an \texttt{E} or \texttt{O} the definition applies to
1201 % both. Similar for \texttt{LRC}.
1202 % The selectors may be given as uppercase or lowercase letters.
1203 % \begin{figure}[htb]
1204 % \begin{center}
1205 % \leavevmode
1206 % \begin{tabular}{|l|l|}
1207 % \hline
1208 % E & Even page \\
1209 % O & Odd page \\
1210 % \hline
1211 % L & Left field \\
1212 % C & Center field \\
1213 % R & Right field \\
1214 % \hline
1215 % H & Header \\
1216 % F & Footer \\
1217 % \hline
1218 % \end{tabular}
1219 % \end{center}
1220 % \caption{Selectors}
1221 % \label{fig:sel}
1222 % \end{figure}
1223 %
1224 % \CmdIndex{fancyhf}
1225 % There is also a more general command \cs{fancyhf} that you can use to
1226 % combine the specifications for headers and footers. This allows additional
1227 % selectors \texttt{H} (header) and \texttt{F} (footer). In fact \cs{fancyhead} and
1228 % \cs{fancyfoot} are just \cs{fancyhf} with \texttt{H} and \texttt{F} pre-specified, respectively.
1229 %
1230 % Again, you may
1231 % use \Cmd{thispagestyle\{plain\}} for a simple page layout for
1232 % page~1.
1233 %
1234 % \section{Specifying the widths of the header and footer fields}
1235 % \label{sec:field-width}
1236 %
1237 % In \pkg{fancyhdr} version 5.0 and later you can specify the width of
1238 % each header and footer field individually. In older versions each of
1239 % the fields was typeset in a \cs{parbox} of width \cs{headwidth}, which
1240 % could cause them to overlap (see e.g., section~\ref{sec:longtitles}).
1241 %
1242 % In \pkg{fancyhdr} version 5.0 and later, this is still the default but
1243 % now you can override this with the commands \cs{fancyheadwidth},
1244 % \cs{fancyfootwidth} or \cs{fancyhfwidth}. These work exactly like the
1245 % \cs{fancyhead} etc. commands but instead of a header/footer value they
1246 % have a \meta{length} and an optional alignment as parameters.
1247 %
1248 % \begin{syntax}
1249 % \cmd{\fancyheadwidth}\oarg{places}\oarg{alignment}\marg{length} \\
1250 % \cmd{\fancyfootwidth}\oarg{places}\oarg{alignment}\marg{length} \\
1251 % \cmd{\fancyhfwidth}\oarg{places}\oarg{alignment}\marg{length} \\[1ex]
1252 % \cmd{\fancyheadwidth}*\oarg{places}\oarg{alignment}\marg{length} \\
1253 % \cmd{\fancyfootwidth}*\oarg{places}\oarg{alignment}\marg{length} \\
1254 % \cmd{\fancyhfwidth}*\oarg{places}\oarg{alignment}\marg{length}
1255 % \end{syntax}
1256 % Field widths that are not specified default to \cs{headwidth}.
1257 %
1258 % NOTE: In the non-\texttt{*} versions of these commands, the widths
1259 % will be stored as expressions, not as calculated values. The values
1260 % will be calculated when the header or footer is constructed. So they
1261 % can change, for example when different pages have different
1262 % \cs{headwidth} and you use e.g., \texttt{0.3\cs{headwidth}} or another
1263 % expression with a `variable' as value. Note, however, that at
1264 % definition time, the width is assigned to a temporary length variable,
1265 % to check if it is a legal \meta{length}. So any variables used in it
1266 % should have a value, although this may be different from the value at
1267 % its final use.
1268 %
1269 % In the \texttt{*} versions of these commands, the width will be
1270 % calculated at the call of the command, and the calculated value will
1271 % be stored. So for example if you use an expression like
1272 % `\texttt{0.4\cs{headwidth}}', and \cs{headwidth} is 10~cm, the value
1273 % `4~cm' will be stored. If then then later \cs{headwidth} is changed to
1274 % 15~cm when the header or footer is constructed, the value
1275 % used for the field will still be 4~cm, which no longer is
1276 % `\texttt{0.4\cs{headwidth}}'. With the non-\texttt{*} version,
1277 % however, the value `6~cm' will be used, i.e. 0.4 of the then current
1278 % \cs{headwidth}.
1279 %
1280 % The fields are typeset in a \cs{parbox} with the specified width or
1281 % the default \cs{headwidth}. It is still possible to get overlaps if
1282 % the sum of the width in a particular header or footer is larger than \cs{headwidth}.
1283 %
1284 % The fields will be positioned in a space of width \cs{headwidth} as
1285 % follows:
1286 % \begin{itemize}
1287 % \item the left field will be positioned at the left edge of this space
1288 % \item the right field will be positioned at the right edge of this space
1289 % \item the position of the center field by default will be in the
1290 % horizontal center of the header/footer. But it depends on the available space:\\[1ex]
1291 % Let $W_L$, $W_C$, and $W_R$ be the width of the left, center and
1292 % right field, respectively.
1293 % \begin{itemize}
1294 % \item if the total width of the three fields
1295 % $ \sum_{i \in \{L, C, R\}}{W_i} > \cs{headwidth}$,
1296 % the center field will be centered in the
1297 % header/footer, i.e., its midpoint will be at
1298 % $\frac{1}{2}\cs{headwidth}$ from each side.\\
1299 % NOTE: this also includes the default situation if no widths are
1300 % specified. This ensures that documents that don't specify widths
1301 % get the same output as before version 5.0.
1302 % \item otherwise ($ \sum_{i \in \{L, C, R\}}{W_i} \le \cs{headwidth}$):
1303 % \item if there would be an overlap between any of the fields, i.e.,\\
1304 % $ W_L +\frac{1}{2}W_C > \frac{1}{2}\cs{headwidth}$ or
1305 % $ W_R +\frac{1}{2}W_C > \frac{1}{2}\cs{headwidth}$, then the
1306 % center field will be centered between the left and right fields,
1307 % with equal distances to both.
1308 % \item otherwise (there is enough space, and no overlap), the center
1309 % field is centered in the header/footer, like the first case above.
1310 % \end{itemize}
1311 % \end{itemize}
1312 % Here are some examples. The header fields have a colored bar in them
1313 % that indicates their width.
1314 %
1315 % In the first example, the sum of the field widths $> \cs{headwidth}$,
1316 % so the center field will be in the center of the header, but there
1317 % will be overlaps.
1318 % \NoExample{testheadwidth\\(1.2)}
1319 % \begin{example}
1320 % \usepackage{fancyhdr}
1321 % \pagestyle{fancy}
1322 % \fancyhead[L]{llllll llllll llllll llllll llllll llllll llllll\\
1323 % \color{red}\rule {\linewidth}{4mm}}
1324 % \fancyhead[C]{cccc cccc cc cc cccc cccc\\
1325 % \color{green}\rule{\linewidth}{2mm}}
1326 % \fancyhead[R]{rrrrrr rrrrrr rrrrrr rrrrrr rrrrrr rrrrrr rrrrrr\\
1327 % \color{blue}\rule {\linewidth}{4mm}}
1328 % \fancyheadwidth[L]{0.3\headwidth}
1329 % \fancyheadwidth[C]{0.5\headwidth}
1330 % \fancyheadwidth[R]{0.4\headwidth}
1331 % \end{example}
1332 % \showheader{%
1333 % \setlength{\headheight}{40pt}
1334 % \fancyhead[L]{llllll llllll llllll llllll llllll llllll llllll\\
1335 % \color{red}\rule {\linewidth}{5mm}}
1336 % \fancyhead[C]{cccc cccc cc cc cccc cccc\\
1337 % \color{green}\rule{\linewidth}{3mm}}
1338 % \fancyhead[R]{rrrrrr rrrrrr rrrrrr rrrrrr rrrrrr rrrrrr rrrrrr\\
1339 % \color{blue}\rule {\linewidth}{2mm}}
1340 % \fancyheadwidth[L]{0.3\headwidth}
1341 % \fancyheadwidth[C]{0.5\headwidth}
1342 % \fancyheadwidth[R]{0.4\headwidth}
1343 % }
1344 %
1345 % In the second example, the sum of the field widths $\le \cs{headwidth}$.
1346 % And there is no overlap between the center field and the other ones
1347 % (the center and right fields just touch each other), so the center
1348 % field is still centered in the header.
1349 % \NoExample{testheadwidth\\(1.3)}
1350 % \begin{example}
1351 % \fancyheadwidth[L]{0.3\headwidth}
1352 % \fancyheadwidth[C]{0.2\headwidth}
1353 % \fancyheadwidth[R]{0.4\headwidth}
1354 % \end{example}
1355 % \showheader{%
1356 % \setlength{\headheight}{40pt}
1357 % \fancyhead[L]{llllll llllll llllll llllll llllll llllll llllll\\
1358 % \color{red}\rule {\linewidth}{5mm}}
1359 % \fancyhead[C]{cccc cccc cc cc cccc cccc\\
1360 % \color{green}\rule{\linewidth}{3mm}}
1361 % \fancyhead[R]{rrrrrr rrrrrr rrrrrr rrrrrr rrrrrr rrrrrr rrrrrr\\
1362 % \color{blue}\rule {\linewidth}{2mm}}
1363 % \fancyheadwidth[L]{0.3\headwidth}
1364 % \fancyheadwidth[C]{0.2\headwidth}
1365 % \fancyheadwidth[R]{0.4\headwidth}
1366 % }
1367 %
1368 % In the last example, the sum of the field widths still is $\le \cs{headwidth}$.
1369 % But there would be overlap between the center field and the right
1370 % field if the center field was centered horizontally in the
1371 % header. So now it is centered between the left and right fields.
1372 % \NoExample{testheadwidth\\(1.4)}
1373 % \begin{example}
1374 % \fancyheadwidth[L]{0.3\headwidth}
1375 % \fancyheadwidth[C]{0.25\headwidth}
1376 % \fancyheadwidth[R]{0.4\headwidth}
1377 % \end{example}
1378 % \showheader{%
1379 % \setlength{\headheight}{40pt}
1380 % \fancyhead[L]{llllll llllll llllll llllll llllll llllll llllll\\
1381 % \color{red}\rule {\linewidth}{5mm}}
1382 % \fancyhead[C]{cccc cccc cc cc cccc cccc\\
1383 % \color{green}\rule{\linewidth}{3mm}}
1384 % \fancyhead[R]{rrrrrr rrrrrr rrrrrr rrrrrr rrrrrr rrrrrr rrrrrr\\
1385 % \color{blue}\rule {\linewidth}{2mm}}
1386 % \fancyheadwidth[L]{0.3\headwidth}
1387 % \fancyheadwidth[C]{0.25\headwidth}
1388 % \fancyheadwidth[R]{0.4\headwidth}
1389 % }
1390 % \smallskip
1391 %
1392 % The \meta{alignment} optional parameter consists of two letters: a
1393 % vertical alignment, which indicates where the baseline of the
1394 % \cs{parbox} will be, followed by a horizontal alignment that specifies
1395 % how the lines will be positioned horizontally in the \cs{parbox}. The
1396 % alignment option is available in \pkg{fancyhdr} version 5.2 and later.
1397 % \\[1ex]
1398 % The possibilities for the vertical alignment are:
1399 % \begin{description}[font=\texttt]
1400 % \item[T] The baseline of the \cs{parbox} is on the top of the first line, i.e., just
1401 % where the top of the tallest character or item in the line is.
1402 % \item[t] The baseline of the \cs{parbox} is the baseline of the first line.
1403 % \item[c] The baseline of the \cs{parbox} is on the vertical center
1404 % of the \cs{parbox}.
1405 % \item[b] The baseline of the \cs{parbox} is the baseline of the last line.
1406 % \item[B] The baseline of the \cs{parbox} is on the bottom of the last line, i.e., just
1407 % where the bottom of the deepest character or item in the line is.
1408 % \item[-] Use the default vertical alignment.
1409 % \end{description}
1410 % The letters are the same as the vertical alignment in \cs{fancyhdrbox}
1411 % (see section~\ref{sec:fancyhdrbox} for examples). The \texttt{t},
1412 % \texttt{c} and \texttt{b} are the standard options for \cs{parbox}.
1413 % \\[1ex]
1414 % The horizontal alignment can be:
1415 % \begin{description}[font=\texttt]
1416 % \item[l] left aligned
1417 % \item[c] centered
1418 % \item[r] right aligned
1419 % \item[j] fully justified
1420 % \end{description}
1421 % These are the same as the horizontal alignment in \cs{fancyhdrbox},
1422 % except that the \texttt{j} option is extra. This one gives the default
1423 % behavior in a \cs{parbox}.
1424 %
1425 % The default for the vertical alignment is \texttt{b} for a header
1426 % field, and \texttt{t} for a footer field. The default for the
1427 % horizontal alignment is \texttt{l} for an \texttt{L} field, \texttt{c}
1428 % for a \texttt{C} field, \texttt{r} for an \texttt{R} field.
1429 %
1430 % Please note that a single \texttt{c} as the alignment counts as a
1431 % vertical alignment, and the horizontal alignment will then be the
1432 % default. If you want to specify only the horizontal alignment and take
1433 % the default for the vertical alignment, specify the vertical alignment
1434 % as \texttt{-}. For the horizontal alignment just omit it to get the default.
1435 %
1436 % See section~\ref{sec:with-fancyheadwidth} for examples.
1437 %
1438 % \textbf{NOTE:} The \cs{fancyheadwidth},
1439 % \cs{fancyfootwidth} and \cs{fancyhfwidth} commands are still
1440 % experimental. This means that they have not been thoroughly tested, so
1441 % there can still be bugs in them. And the implementation could change
1442 % in a following release. Use at your own risk, and please, report any bugs.
1443 %
1444 % \section{Fancy Centering}
1445 % \label{sec:fancycenter}
1446 %
1447 % \textbf{Note:} This section only applies to \pkg{fancyhdr} version~4.0
1448 % and later\footnote{This comes from the \pkg{nccfancyhdr}
1449 % \PKGindex{nccfancyhdr}
1450 % package by Alexander I. Rozhenko.}.
1451 %
1452 % The fields in a fancy header and footer are prepared using \cs{parbox}
1453 % command. So, you can use multi-line fields. In the header, they are
1454 % aligned to the bottom line, but, in the footer, they are aligned to
1455 % the top line. The maximum width of every field is by default equal to the
1456 % \cs{headwidth} (unless changed by the commands \cs{fancyheadwidth},
1457 % \cs{fancyfootwidth} or \cs{fancyhfwidth} from section~\ref{sec:field-width}.)
1458 % This can lead to overlapping of neighbouring fields.
1459 %
1460 % \CmdIndex{fancycenter}
1461 % If you want to prepare headers/footers in more traditional way in a line
1462 % not exceeding the \cs{headwidth}, you can use
1463 % the following command in any header/footer command:
1464 % \begin{quote}
1465 % \cs{fancycenter}\oarg{distance}\oarg{stretch}\\
1466 % \verb| |\marg{left-field}\marg{center-field}\marg{right-field}
1467 % \end{quote}
1468 % \CmdIndex{fancycenter}
1469 % This command works like
1470 % \begin{center}
1471 % \verb|\hbox to\linewidth{|\marg{left-field}\cs{hfil}\marg{center-field}\cs{hfil}\marg{right-field}\verb|}|
1472 % \end{center}
1473 % but does this more carefully trying to exactly center the central part of
1474 % the text if possible. The solution for exact centering
1475 % is applied if the width of \meta{center-field} is less than
1476 % \begin{quote}
1477 % \verb|\linewidth - 2*(|\meta{stretch}\verb|*|\meta{distance}\verb| +|\\
1478 % \verb| max(width(|\meta{left-field}\verb|), width(|\meta{right-field}\verb|)))|.
1479 % \end{quote}
1480 % Otherwise the \meta{center-field} will slightly migrate to a shorter item
1481 % (\meta{left-field} or \meta{right-field}), but at least \meta{distance}
1482 % space between all parts of line is provided.
1483 % The default values of \meta{distance} and \meta{stretch}
1484 % are 1em and 3.
1485 %
1486 % If the \meta{center-field} is empty, the \cs{fancycenter} is equivalent to
1487 % the following command:
1488 % \begin{center}
1489 % \verb|\hbox to\linewidth {|\marg{left-field}\verb|\hfil |\marg{right-field}\verb|}|
1490 % \end{center}
1491 %
1492 % You would use this in a header for example with
1493 % \begin{quote}
1494 % \verb|\fancyhead[C]{|\cs{fancycenter}\oarg{distance}\oarg{stretch}\\
1495 % \verb| |\marg{left-field}\marg{center-field}\marg{right-field}\verb|}|
1496 % \end{quote}
1497 % and leave the \texttt{[L,R]} parts empty.
1498 %
1499 % \textbf{Note 1}:
1500 % When \cs{fancycenter} is used inside a header or
1501 % \CmdIndex{linewidth}%
1502 % \CmdIndex{headwidth}%
1503 % footer, \cs{linewidth} usually is the same as \cs{headwidth}. Only
1504 % when \cs{fancycenter} is used inside a box with a different width,
1505 % \cs{linewidth} will be the width of that box.
1506 %
1507 % \textbf{Note 2}:
1508 % If the whole of the \cs{fancycenter} is wider than
1509 % \cs{linewidth} it will stick out on the right. See
1510 % section~\ref{sec:longtitles} for possible solutions.
1511 %
1512 % \textbf{Note 3}: The usage of the \cs{fancycenter} command is not limited to the
1513 % argument of headers/footers. You can use it anywhere in your
1514 % document. Then \cs{linewidth} will be the width of the box or text in
1515 % which it is used.
1516 %
1517 % \section{The \Cmd{fancyhdrbox} command}
1518 % \label{sec:fancyhdrbox}
1519 %
1520 % The \cs{fancyhdrbox} command can be used to align multi-line header
1521 % and footer fields and, for example, images. It is modelled after the
1522 % \PKGindex{makecell}
1523 % \pkg{makecell} package by Olga Lapko, but it is a bit simplified, and also has extra
1524 % vertical alignments \texttt{T} and \texttt{B}. And the vertical
1525 % centering of \cs{fancyhdrbox} is better than the one from
1526 % \pkg{makecell}. The \cs{fancyhdrbox} command is primarily meant for
1527 % use in headers and footers, but can be used anywhere in a document.
1528 %
1529 % The command is used as follows:
1530 %
1531 % \cs{fancyhdrbox}\oarg{alignment}\oarg{width}\marg{lines separated by \cmd{\\}}
1532 %
1533 % Here \meta{alignment} specifies both the vertical and the horizontal
1534 % alignment of the contents with respect to other text on the same line
1535 % (including other \cs{fancyhdrbox} instances). The result of the
1536 % command is a box in horizontal mode (in \LaTeX{} parlance an \textbf{LR
1537 % box}), similar to \cs{parbox} or \cs{makebox}.
1538 %
1539 % The \meta{alignment} optional parameter consists of two letters: a vertical
1540 % alignment, which indicates where the baseline of the complete box will
1541 % be, followed by a horizontal alignment that specifies how the lines will be
1542 % positioned horizontally in the box.
1543 %
1544 % The possibilities for the vertical alignment are:
1545 % \begin{description}
1546 % \item [\texttt{T}] The baseline of the box is on the top of the first line, i.e., just
1547 % where the top of the tallest character or item in the line is.
1548 % \item [\texttt{t}] The baseline of the box is the baseline of the first line.
1549 % \item [\texttt{c}] The baseline of the box is on the vertical center
1550 % of the box.
1551 % \item [\texttt{b}] The baseline of the box is the baseline of the last line.
1552 % \item [\texttt{B}] The baseline of the box is on the bottom of the last line, i.e., just
1553 % where the bottom of the deepest character or item in the line is.
1554 % \end{description}
1555 % The horizontal alignment can be
1556 % \begin{description}
1557 % \item[\texttt{l}] left aligned
1558 % \item[\texttt{c}] centered
1559 % \item[\texttt{r}] right aligned
1560 % \end{description}
1561 % These are the same as, for example, in \texttt{tabular} columns.
1562 %
1563 % Each of the vertical and horizontal alignments can be omitted. The
1564 % default is \texttt{c} for the vertical alignment, and \texttt{l} for
1565 % the horizontal alignment. If a single \texttt{c} is specified, it
1566 % counts as both the vertical and horizontal alignment, i.e., as \texttt{cc}.
1567 %
1568 % When multiple boxes are put next to each other (i.e., on the same
1569 % line), their baselines will be aligned. Therefore in general it makes
1570 % not much sense to specify different vertical alignments for them,
1571 % unless you want a special effect. And in that case the results may be surprising.
1572 %
1573 % The second optional parameter, \meta{width}, specifies the width of
1574 % the box. If this is not given, the box has its ``natural'' width,
1575 % determined by its contents. With the \meta{width} parameter, the width
1576 % of the box is fixed to this value, independent of the contents. Note
1577 % that there will be no automatic line breaking of the lines if they
1578 % don't fit in the specified width. If a line is too long it will just
1579 % stick out of the box, and may overlap the following text. If you want
1580 % automatic line breaking, use a \cs{parbox}, a \texttt{tabular} with a
1581 % \texttt{p\{..\}} column, or something similar.
1582 %
1583 % The lines (rows) in the box are separated by \cmd{\\} just like in a
1584 % tabular. You can even use \cmd{\\}\oarg{length} to add extra
1585 % vertical space (or decrease the vertical space with a negative length).
1586 % Also allowed is \cs{hline} after \cmd{\\}.
1587 %
1588 % Here are examples of all the vertical alignment options, with some
1589 % variations of the horizontal alignment. Some lines use a bigger font
1590 % than others, in order to make the alignment non-trivial. All the
1591 % \cs{fancyhdrbox} boxes are enclosed in a tight \cs{fbox} to show how
1592 % big they are. The red horizontal line is the common baseline.
1593 %
1594 % \begingroup ^^A for some local definitions
1595 % \setlength\fboxsep{0pt}
1596 % ^^A Vertical bar to indicate measurements
1597 % \newcommand{\R}{\rule[-0.3\baselineskip]{0.1pt}{\baselineskip}\hspace{-0.1pt}}
1598 % \newcommand{\showbaseline}{^^A
1599 % \begin{picture}(0,0)
1600 % \put(-1cm,0){\color{red}\rule{7cm}{0.1pt}}
1601 % \end{picture}^^A
1602 % }
1603 %
1604 % \subsubsection*{T-aligned boxes:}
1605 %
1606 % \begin{code}
1607 % \fancyhdrbox[T]{%
1608 % ABC \\
1609 % xyz \\ XYZ \\
1610 % \Huge DEF ghij
1611 % }%
1612 % \fancyhdrbox[T]{%
1613 % {\Huge ABC} \\
1614 % DEF ghij}
1615 % \end{code}
1616 %
1617 % \fbox{\showbaseline\fancyhdrbox[T]{^^A
1618 % ABC \\
1619 % xyz \\ XYZ \\
1620 % \Huge DEF ghij
1621 % }^^A
1622 % \fancyhdrbox[T]{{\Huge ABC} \\
1623 % DEF ghij}}
1624 %
1625 % \subsubsection*{t-aligned boxes:}
1626 %
1627 % This example also uses right-alignment in the boxes, but the first
1628 % line in the left box has a 1cm space added to the right, so it is
1629 % shifted left 1cm.
1630 %
1631 % \begin{code}
1632 % \fancyhdrbox[tr]{%
1633 % ABC\hspace{1cm} \\
1634 % xyz \\ XYZ \\
1635 % \Huge DEF ghij
1636 % }%
1637 % \fancyhdrbox[tr]{%
1638 % {\Huge ABC} \\
1639 % DEF ghij
1640 % }
1641 % \end{code}
1642 %
1643 % \fbox{\showbaseline\fancyhdrbox[tr]{^^A
1644 % ABC\hspace{1cm} \\
1645 % xyz \\ XYZ \\
1646 % \Huge DEF ghij
1647 % }^^A
1648 % \fancyhdrbox[tr]{^^A
1649 % {\Huge ABC} \\
1650 % DEF ghij
1651 % }}
1652 %
1653 % \subsubsection*{b-aligned boxes:}
1654 %
1655 % \begin{code}
1656 % \fancyhdrbox[b]{%
1657 % ABC \\
1658 % xyz \\ XYZ \\
1659 % \Huge DEF ghij
1660 % }%
1661 % \fancyhdrbox[b]{%
1662 % {\Huge ABC} \\
1663 % DEF ghij}
1664 % \end{code}
1665 %
1666 % \fbox{\showbaseline\fancyhdrbox[b]{^^A
1667 % ABC \\
1668 % xyz \\ XYZ \\
1669 % \Huge DEF ghij
1670 % }^^A
1671 % \fancyhdrbox[b]{^^A
1672 % {\Huge ABC} \\
1673 % DEF ghij}}
1674 %
1675 % \subsubsection*{B-aligned boxes:}
1676 %
1677 % \begin{code}
1678 % \fancyhdrbox[B]{%
1679 % ABC \\
1680 % xyz \\ XYZ \\
1681 % \Huge DEF ghij
1682 % }%
1683 % \fancyhdrbox[B]{%
1684 % {\Huge ABC} \\
1685 % DEF ghij}
1686 % \end{code}
1687 %
1688 % \fbox{\showbaseline\fancyhdrbox[B]{^^A
1689 % ABC \\
1690 % xyz \\ XYZ \\
1691 % \Huge DEF ghij
1692 % }^^A
1693 % \fancyhdrbox[B]{^^A
1694 % {\Huge ABC} \\
1695 % DEF ghij}}
1696 %
1697 % \subsubsection*{c-aligned boxes:}
1698 %
1699 % The first box has an explicit \texttt{[c]} positioning, which implies
1700 % both vertical and horizontal centering. The second one uses the
1701 % default positioning (i.e., it is not explicitly specified), which make
1702 % it \texttt{[cl]}, i.e., horizontally left aligned.
1703 %
1704 % \begin{code}
1705 % \fancyhdrbox[c]{%
1706 % ABC \\
1707 % xyz \\ XYZ \\
1708 % \Huge DEF ghij
1709 % }%
1710 % \fancyhdrbox{%
1711 % {\Huge ABC} \\
1712 % DEF ghij}
1713 % \end{code}
1714 %
1715 % \fbox{\showbaseline\fancyhdrbox[c]{^^A
1716 % ABC \\
1717 % xyz \\ XYZ \\
1718 % \Huge DEF ghij
1719 % }^^A
1720 % \fancyhdrbox{^^A
1721 % {\Huge ABC} \\
1722 % DEF ghij}}
1723 %
1724 % \subsubsection*{c-aligned with \meta{width}:}
1725 %
1726 % This example shows the use of the second optional argument of
1727 % \cs{fancyhdrbox}, the width of the box.
1728 %
1729 % \begin{code}
1730 % \fancyhdrbox[c][5cm]{%
1731 % ABC \\ xyz \\ XYZ\texttt{\textbackslash\textbackslash[10pt]} \\[10pt]
1732 % \Huge DEF ghij%
1733 % }%
1734 % \fancyhdrbox[c][3cm]{%
1735 % {\Huge ABC}\\
1736 % DEF ghij}
1737 % \end{code}
1738 %
1739 % \noindent\R\makebox[5cm]{5cm}\R\makebox[3cm]{3cm}\R\\[2pt]
1740 % \fbox{\showbaseline\fancyhdrbox[c][5cm]{^^A
1741 % ABC \\ xyz \\ XYZ\texttt{\textbackslash\textbackslash[10pt]} \\[10pt]
1742 % {\Huge DEF ghij}^^A
1743 % }^^A
1744 % \fancyhdrbox[c][3cm]{^^A
1745 % {\Huge ABC}\\
1746 % DEF ghij}}
1747 %
1748 % \subsubsection*{Different vertical alignments}
1749 %
1750 % Here is an example with two different vertical alignments in boxes
1751 % next to each other, one with the \texttt{[b]} alignment and the other
1752 % one with \texttt{[t]}.
1753 %
1754 % \begin{code}
1755 % \fbox{\showbaseline\fancyhdrbox[b]{%
1756 % first line \\
1757 % second line [b]
1758 % }}
1759 % baseline
1760 % \fbox{\fancyhdrbox[t]{%
1761 % first line [t] \\
1762 % second line}}
1763 % \end{code}
1764 %
1765 % \fbox{\showbaseline\fancyhdrbox[b]{^^A
1766 % first line \\
1767 % second line [b]
1768 % }}
1769 % baseline
1770 % \fbox{\fancyhdrbox[t]{^^A
1771 % first line [t] \\
1772 % second line}}
1773 %
1774 % \endgroup
1775 %
1776 % \bigskip
1777 %
1778 % It may be surprising that the \texttt{[b]} box is on top and the
1779 % \texttt{[t]} box on the bottom of the total line, but if you look at
1780 % the baselines, it should become clear why this is so. This is just the
1781 % way vertical alignment works in \LaTeX. So if that is what you want,
1782 % just use it.
1783 %
1784 % \subsubsection*{Two headers with \cs{fancyhdrbox} parts}
1785 % Finally, two headers with \cs{fancyhdrbox} parts. Note that these are
1786 % in different header fields (left and right).
1787 %
1788 % \NoExample{image+\\twolineheader}
1789 % \begin{example}
1790 % \setlength{\headheight}{68pt}
1791 % \pagestyle{fancy}
1792 % \fancyhf{}
1793 % \rhead{\fancyhdrbox{\Large First Long Title \\ \large Second title}}
1794 % \lhead{\fancyhdrbox{\includegraphics[width=3cm]{example-image}}}
1795 % \end{example}
1796 %
1797 % \bigskip
1798 %
1799 % \showheader{%
1800 % \setlength{\headheight}{68pt}
1801 % \pagestyle{fancy}
1802 % \fancyhf{}
1803 % \rhead{\fancyhdrbox{\Large First Long Title \\ \large Second title}}
1804 % \lhead{\fancyhdrbox{\includegraphics[width=3cm]{example-image}}}
1805 % }
1806 %
1807 % In the next example the left header has an image in a \cs{fancyhdrbox}
1808 % with the default alignment. The right header has two
1809 % \cs{fancyhdrbox}|es, one with an explicit width of 4cm, the second
1810 % one with its natural width.
1811 %
1812 % \NoExample{threeboxes}
1813 % \begin{example}
1814 % \setlength{\headheight}{20pt}
1815 % \pagestyle{fancy}
1816 % \fancyhf{}
1817 % \fancyhead[L]{\sffamily
1818 % \fancyhdrbox{\includegraphics[height=3\normalbaselineskip]
1819 % {example-image}}
1820 % }
1821 % \fancyhead[R]{%
1822 % \fancyhdrbox[][4cm]{Our Office \\ Street 1 \\ City1 }%
1823 % \fancyhdrbox[l]{ Our Factory \\ Street 2 \\ City2 }
1824 % }
1825 % \end{example}
1826 %
1827 % \bigskip
1828 %
1829 % \showheader{%
1830 % \setlength{\headheight}{40pt}
1831 % \pagestyle{fancy}
1832 % \fancyhf{}
1833 % \fancyhead[L]{\sffamily
1834 % \fancyhdrbox{\includegraphics[height=3\normalbaselineskip]
1835 % {example-image}}
1836 % }
1837 % \fancyhead[R]{%
1838 % \fancyhdrbox[][4cm]{Our Office \\ Street 1 \\ City1 }%
1839 % \fancyhdrbox[l]{ Our Factory \\ Street 2 \\ City2 }
1840 % }
1841 % }
1842 %
1843 % \bigskip
1844 %
1845 % \section{Redefining page style \texttt{plain}}
1846 % \label{sec:pagestyle-plain}
1847 %
1848 % Some \LaTeX{} commands, like \cs{chapter}, use the \cs{thispagestyle}
1849 % command to automatically switch to the \texttt{plain} page style, thus
1850 % ignoring the page style currently in effect.
1851 %
1852 % They do this by issuing a \Cmd{thispagestyle\{plain\}} command. The most
1853 % well-known places where this could happen are:
1854 % \begin{itemize}
1855 % \item The first pages of chapters in the \texttt{book} and \texttt{report} class
1856 % \item The first page of a document in the \texttt{article} class when \cs{maketitle} is used
1857 % \item The first page of an index
1858 % \end{itemize}
1859 % but it could happen at other places depending on the class and the packages used.
1860 %
1861 % To customize even such pages you must redefine the \texttt{plain}
1862 % page style. As we indicated before you could do this by defining the
1863 % \cs{ps@plain} command, but \pkg{fancyhdr} gives you an easier way
1864 % \CmdIndex{fancypagestyle}
1865 % with the \cs{fancypagestyle} command. This command can be used to
1866 % redefine existing page styles (like \texttt{plain}) or to define new ones,
1867 % e.g., if part of your document needs a different page style. This command
1868 % has two mandatory parameters and an optional one in between: the first parameter
1869 % is the name of the page style to be defined, then an optional
1870 % parameter of an existing base page style can be given, and the last
1871 % parameter consists of commands that change the headers and/or footers, i.e.,
1872 % \verb|\fancyhead| etc. Also allowed are changes to \cs{headrulewidth} and
1873 % \cs{footrulewidth} or even \cs{headrule} and \cs{footrule}.
1874 % The (re)defined page style uses the standard
1875 % \texttt{fancy} definitions, amended by the optional base style, and
1876 % finally the definitions in the last
1877 % parameter. For details see \smartref{sec:pagestyle-plain}{sec:fancypagestyle}.
1878 % In particular, if the last parameter is empty, i.e., given
1879 % as \verb+{}+, then the new page style is equal to base style.
1880 %
1881 % As an example, let us redefine the \texttt{plain} style so that it will
1882 % be the same as the standard page style \texttt{fancy}:
1883 % \begin{code}
1884 % \fancypagestyle{plain}[fancy]{}
1885 % \end{code}
1886 % If you have not redefined page style \texttt{fancy} with \cs{fancypagestyle},
1887 % this is equivalent to:
1888 % \begin{code}
1889 % \fancypagestyle{plain}{}
1890 % \end{code}
1891 % Now when these special pages use the \texttt{plain} page style, they use your redefined version.
1892 %
1893 % As another example, let us
1894 % redefine the \texttt{plain} style for the report in section~\ref{two-sided} by
1895 % making the page number bold and enclosing it in en-dashes without any rules.
1896 % \PSindex{plain}
1897 %
1898 % \Example{4}
1899 % \begin{example}
1900 % \fancypagestyle{plain}{%
1901 % \fancyhf{}% clear all header and footer fields
1902 % \fancyfoot[C]{\textbf{--~\thepage~--}} % except the center
1903 % \renewcommand{\headrulewidth}{0pt}%
1904 % \renewcommand{\footrulewidth}{0pt}%
1905 % }
1906 % \end{example}
1907 %
1908 %
1909 % \section{Defining other page styles}
1910 % \label{sec:fancypagestyle}
1911 %
1912 % Just like redefining the \texttt{plain} page style in the previous
1913 % section, you can define or redefine other page styles based on page
1914 % style \texttt{fancy}. This is also done with the \cs{fancypagestyle}
1915 % command.
1916 % With \texttt{*} it defines a ``\emph{closed}'' page style, otherwise an
1917 % ``\emph{open}'' one. The difference is that the \emph{open} page style
1918 % does not necessarily have all the information in itself that is
1919 % necessary to construct the headers and footers. So it will need to pick up the
1920 % remaining elements from the environment of the text.
1921 % The \emph{closed} page style, however, will pick up all necessary
1922 % elements from the environment at the moment it is \textbf{defined},
1923 % rather than when it is used, and carries that with it.
1924 % The information that is picked up consists of:
1925 % \begin{itemize}
1926 % \item The header and footer fields in all variants (EO,LRC,HF) (12 items)
1927 % \item The header and footer field widths in all variants (EO,LRC,HF) (12 items)
1928 % \item The header and footer field alignments in all variants (EO,LRC,HF) (12 items)
1929 % \item The header and footer offsets (EO,LR,HF) (8 items), see
1930 % section~\ref{sec:book-examples} and~\ref{sec:headwidth}
1931 % \item The header and footer init values (2 items), see section~\ref{sec:curpagestyle}
1932 % \item \cs{headrule}, \cs{headrulewidth}, \cs{footrule}, \cs{footrulewidth} (4 items)
1933 % \item the \texttt{[nocheck]} option
1934 % \end{itemize}
1935 % The \emph{closed} versions can come handy when you are switching back
1936 % and forth between different page styles, as explained in section~\ref{sec:change}.
1937 %
1938 % Here is an example of a simple (\emph{open}) definition:
1939 % \begin{code}
1940 % \fancypagestyle{toc}{%
1941 % \fancyhf{}%
1942 % \fancyhead[RO]{\thepage}%
1943 % \fancyhead[RO]{\textsl{TABLE OF CONTENTS}}%
1944 % \fancyfoot[C]{\thepage}
1945 % }
1946 % \end{code}
1947 % This defines a special page style \texttt{toc} for use in the table
1948 % of contents with \Cmd{pagestyle\{toc\}}.
1949 % Inside the definition you can define the headers and/or footers,
1950 % change the header and footer rules, and redefine commands like
1951 % \cs{chaptermark} (see section~\ref{sec:scoop} for an example). The
1952 % headers and footers and marks that are not redefined inside the
1953 % \cs{fancypagestyle} definition, are taken from the global fancy page style
1954 % values.
1955 %
1956 % The general form of the command is:
1957 % \begin{quote}
1958 % \CmdIndex{fancypagestyle}
1959 % \verb|\fancypagestyle|\marg{style-name}\oarg{base-style}\marg{definitions}
1960 % \verb|\fancypagestyle*|\marg{style-name}\oarg{base-style}\marg{definitions}
1961 % \end{quote}
1962 % As you see, there is an optional \oarg{base-style} argument between the two mandatory arguments.
1963 %
1964 % If you give this optional base page style to the
1965 % \cs{fancypagestyle} command, then the new page style will be based on
1966 % that base style. This base style must be a \texttt{fancyhdr}-defined
1967 % style. Also you should take care not to
1968 % create circular dependencies.
1969 % When no base style is given, an internal base style, which has the
1970 % default values is used. This is the same as page style
1971 % \texttt{fancy}, unless the latter has been redefined.
1972 % The order of picking up the
1973 % definitions (headers, footers, marks, etc.) is:
1974 % \begin{enumerate}
1975 % \item The definitions from the base style are taken.
1976 % \item The definitions given in the \cs{fancypagestyle} command
1977 % override and/or augment these.
1978 % \item Any definitions that are not given by the two rules above, are taken
1979 % from the environment, for an \emph{open} page style at the time the
1980 % new page style is used, for a \emph{closed} page style at the time it
1981 % is defined.
1982 % \end{enumerate}
1983 % In an \emph{open} page style, i.e., if you use the form \cs{fancypagestyle}\oarg{base-style}\marg{style-name}\ldots\ {}
1984 % only the first two parts are embedded in the page style.
1985 %
1986 % The optional base style argument is only available in \pkg{fancyhdr} version~4.0 and later.
1987 % In these versions it is also possible to redefine page style \texttt{fancy}
1988 % in this way. In version~3.x and earlier this was not possible.
1989 % The starred (\emph{closed}) version is only available in
1990 % \pkg{fancyhdr} version~5.0 and later.
1991 %
1992 % \subsubsection*{The page style \texttt{fancydefault}}
1993 % \label{sec:fancydefault}
1994 %
1995 % If you want to restore the original default definitions
1996 % from page style \texttt{fancy} as described in section~\ref{sec:default}, you can use
1997 % \begin{code}
1998 % \fancypagestyle{myfancy}[fancydefault]{
1999 % . . . override some here
2000 % }
2001 % \end{code}
2002 % \PSindex{fancydefault}
2003 % Page style \texttt{fancydefault} is the version of page style
2004 % \texttt{fancy} that has all the initialisation embedded, including the relevant
2005 % definitions of \cs{chaptermark} and \Cmd{[sub]sectionmark}. Contrary to
2006 % this, page style \texttt{fancy} as defined in the package uses the
2007 % same defaults, but doesn't have them embedded. It picks them up from
2008 % the environment. So if the environment changes, because you redefine
2009 % headers, footers, mark commands, etc, the functioning of page style
2010 % \texttt{fancy} changes with it. The page style \texttt{fancydefault}
2011 % does not change, however. It is in fact the \emph{closed} version of
2012 % page style \texttt{fancy}, defined with
2013 % \Cmd{fancypagestyle*\{fancydefault\}}\marg{initialisation code} just after
2014 % \pkg{fancyhdr}'s initialisation. However, \texttt{fancydefault}
2015 % is only available since \pkg{fancyhdr} version~4.0.
2016 %
2017 % If you don't like the defaults, you can redefine it yourself. For
2018 % example if you don't want to include the \Cmd{...mark} definitions,
2019 % just put \Cmd{fancypagestyle*\{fancydefault\}\{\}} after
2020 % \Cmd{usepackage\{fancyhdr\}}. Or if you want to include your own
2021 % header and/or footer definitions, use
2022 % \Cmd{fancypagestyle*\{fancydefault\}}\marg{your definitions}.
2023 %
2024 %\subsection{The \Cmd{fancypagestyleassign} command}
2025 % \label{sec:fancypagestyleassign}
2026 %
2027 % The \cs{fancypagestyleassign} command is only available in
2028 % \pkg{fancyhdr} version 5.0 and later.
2029 % \begin{raggedright}
2030 % The command \cs{fancypagestyleassign}\marg{ps1}\marg{ps2} makes
2031 % page style \meta{ps1} an exact copy of page style \meta{ps1}.
2032 % The effect is similar to the command
2033 % \cs{fancypagestyle}\marg{ps1}\oarg{ps2}\texttt{\{\}}, but there are
2034 % important differences:
2035 % \begin{itemize}
2036 % \item with \cs{fancypagestyleassign}\marg{ps1}\marg{ps2} the page
2037 % style \meta{ps1} will be completely independent from \meta{ps2}. On
2038 % the other hand, with
2039 % \cs{fancypagestyle}\marg{ps1}\oarg{ps2}\texttt{\{\}} the page
2040 % style \meta{ps1} will depend on \meta{ps2}. If
2041 % \meta{ps2} later changes (for example with a redefinition with
2042 % \cs{fancypagestyle}), the page style \meta{ps1} will change accordingly.
2043 % \item with \cs{fancypagestyle}\marg{ps1}\oarg{ps2}\texttt{\{\}} you
2044 % must take care that you don't get cyclical dependencies, whereas with
2045 % \cs{fancypagestyleassign}\ you can't create cyclical dependencies.
2046 % \item with \cs{fancypagestyle}\marg{ps1}\oarg{ps2}\texttt{\{\}} the
2047 % page style \meta{ps2} must be a page style that is defined by
2048 % \pkg{fancyhdr} (with \cs{fancypagestyle} or predefined), but
2049 % \cs{fancypagestyleassign}\marg{ps1}\marg{ps2} can also be used if
2050 % \meta{ps2} is not defined by \pkg{fancyhdr}, for example a standard
2051 % \LaTeX{} page style like \texttt{plain}.
2052 % \end{itemize}
2053 % If \meta{ps2} is defined by \pkg{fancyhdr}, then also \meta{ps1} is
2054 % considered to be defined by \pkg{fancyhdr}. If \meta{ps2} is a
2055 % \emph{closed} page style, then \meta{ps1} is also \emph{closed}.
2056 % \end{raggedright}
2057 %
2058 % \cs{fancypagestyleassign} comes especially handy if you want to
2059 % temporarily redefine a page style, and later to restore it to its
2060 % original value. For example, if we have a page style
2061 % \texttt{special}, and we want temporarily to define page style
2062 % \texttt{plain} to be equal to this, but later to restore it to its
2063 % original definition, you can do this as follows:
2064 % \begin{code}
2065 % \fancypagestyleassign{origplain}{plain}
2066 % \fancypagestyleassign{plain}{special}
2067 % . . . code where plain is equal to special
2068 % \clearpage
2069 % \fancypagestyleassign{plain}{origplain}
2070 % . . . code where plain has its original meaning
2071 % \end{code}
2072 % Note that you couldn't do this with \cs{fancypagestyle} because (1)
2073 % this would introduce a cyclical dependency, (2) you cannot use
2074 % \texttt{plain} as the base page style, because it is not \pkg{fancyhdr}-based.
2075 %
2076 % See section~\ref{sec:tocstyle} for an example.
2077 %
2078 % \section{The scoop on \LaTeX's marks}
2079 % \label{sec:scoop}
2080 %
2081 % Usually, for documents of class \verb|book| and \verb|report|, you may
2082 % want to use chapter and section information in the headings (chapter only
2083 % for one-sided printing), and for documents of class \verb|article|,
2084 % section and subsection information (section only for one-sided
2085 % printing). \LaTeX{} uses a marker mechanism to remember the chapter and
2086 % section (section and subsection) information for a page; this is
2087 % discussed in detail in \emph{The \LaTeX{} Companion, Third Edition},
2088 % section 5.3.4 (Part I).
2089 %
2090 % There are two ways you can use and change the higher- and lower-level
2091 % sectioning information available to you. The macros:
2092 % \CmdIndex{rightmark}
2093 % \CmdIndex{leftmark}
2094 % \cs{leftmark}
2095 % (higher-level) and \cs{rightmark} (lower-level) contain the information
2096 % processed by \LaTeX, and you can use them directly as shown in
2097 % section~\ref{sec:default}.
2098 %
2099 % These marks are set by the commands
2100 % \cs{markboth}\marg{leftmark}\marg{rightmark} and \cs{markright}\marg{rightmark}.
2101 % These commands are usually used inside commands like \cs{chaptermark}
2102 % and \cs{sectionmark} but they can be also be given directly in your
2103 % document, although this not very usual.
2104 %
2105 % The \cs{leftmark} contains the \textbf{L}eft argument of the \emph{\textbf{L}ast}
2106 % \cs{markboth} on the page, the \cs{rightmark} contains the \textbf{R}ight
2107 % argument of the \emph{fi\textbf{R}st} \cs{markboth} or the only argument of the
2108 % \emph{fi\textbf{R}st} \cs{markright} on the page. If no marks are present on a
2109 % page they are ``inherited'' from the previous page.
2110 %
2111 % You can influence how chapter, section, and subsection
2112 % information (only two of them!) is displayed by redefining the
2113 % \CmdIndex{chaptermark}
2114 % \cs{chaptermark},
2115 % \CmdIndex{sectionmark}
2116 % \CmdIndex{subsectionmark}
2117 % \cs{sectionmark}, and \cs{subsectionmark} commands\footnote{There are
2118 % similar commands for \texttt{paragraph} and \texttt{subparagraph} but
2119 % they are seldom used.}. You must put the redefinition
2120 % after the first call of \Cmd{pagestyle\{fancy\}} as this
2121 % sets up the defaults.
2122 %
2123 % Let us illustrate this with chapter info. It is made up of three parts:
2124 % \begin{itemize}
2125 % \CmdIndex{thechapter}
2126 % \item the number (say, 2), displayed by the macro \cs{thechapter}
2127 % \item the name (in English, Chapter), displayed by the macro
2128 % \CmdIndex{chaptername}
2129 % \cs{chaptername}
2130 % \item the title, contained in the argument of
2131 % \cs{chapter}.
2132 % \end{itemize}
2133 % We combine these below with \cs{markboth} in \cs{chaptermark}.
2134 %
2135 % For the lower-level sectioning information, we do the same with
2136 % \cs{markright} in \cs{sectionmark}.
2137 %
2138 % So if ``2. Implementation'' is the current chapter
2139 % and ``2.1.\ First steps'' is the current section, then
2140 %
2141 % \Example{6}
2142 % \begin{example}
2143 % \renewcommand{\chaptermark}[1]{%
2144 % \markboth{\chaptername\ \thechapter.\ #1}{}}
2145 % \renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
2146 % \end{example}
2147 % will give
2148 % ``Chapter 2. Implementation'' and ``2.1.\ First steps''
2149 %
2150 % Redefining the \cs{chaptermark} and \cs{sectionmark} commands may
2151 % not eliminate all uppercaseness. E.g., the bibliography will have a title
2152 % \CmdIndex{uppercase}
2153 % \index{BIBLIOGRAPHY}
2154 % of \textsc{bibliography} in the header, as the \cs{MakeUppercase} is
2155 % explicitly given in the definition of \cs{thebibliography}. Similar for
2156 % \index{INDEX}
2157 % \textsc{index} etc.\ If you don't want to redefine these commands, you can
2158 % use the \cs{nouppercase} command that \pkg{fancyhdr} makes available in the header
2159 % and footer fields. Note that this may screw other things, like uppercase
2160 % roman numerals in your headers, so it should be used with care. Essentially
2161 % this command typesets its argument in an environment where
2162 % \cs{MakeUppercase} and \cs{uppercase} are changed into identity operations.
2163 %
2164 % \Example{7}
2165 % \begin{example}
2166 % \fancyhead[L]{\nouppercase{\rightmark}}
2167 % \fancyhead[R]{\nouppercase{\leftmark}}
2168 % \end{example}
2169 %
2170 % Figure~\ref{fig:markers} shows some variants for ``Chapter 2.\ Implementation''
2171 % (the last example is appropriate in some non-English languages). The \texttt{\%}
2172 % signs at the end of the lines are to prevent unwanted space. Normally you
2173 % would continue the lines and remove these \texttt{\%} signs\footnote{The \texttt{\bs
2174 % MakeUppercase} command is used in \LaTeX{} to generate uppercase text,
2175 % while \cs{uppercase} is the plain \TeX{} command for this. The difference is
2176 % that \cs{MakeUppercase} also deals with non-ASCII letters.}.
2177 %
2178 % \begin{figure}[tb]
2179 % \CmdIndex{chaptermark}
2180 % \CmdIndex{uppercase}
2181 % \CmdIndex{MakeUppercase}
2182 % \setlength{\columnsep}{20pt}\small
2183 % \begin{multicols}{2}
2184 % \noindent Code:\\
2185 % \mbox{}\\
2186 % \FExample{8}^^A
2187 % \verb|\renewcommand{\chaptermark}[1]{%|\\
2188 % \verb| \markboth{\chaptername|\\
2189 % \verb| \ \thechapter.\ #1}{}}|\\
2190 % \mbox{}\\
2191 % \FExample{9}^^A
2192 % \verb|\renewcommand{\chaptermark}[1]{%|\\
2193 % \verb| \markboth{\MakeUppercase{%|\\
2194 % \verb| \chaptername}\ \thechapter.%|\\
2195 % \verb| \ #1}{}}|\\
2196 % \mbox{}\\
2197 % \FExample{10}^^A
2198 % \verb|\renewcommand{\chaptermark}[1]{%|\\
2199 % \verb| \markboth{\MakeUppercase{%|\\
2200 % \verb| \chaptername\ \thechapter.%|\\
2201 % \verb| \ #1}}{}}|\\
2202 % \mbox{}\\
2203 % \FExample{11}^^A
2204 % \verb|\renewcommand{\chaptermark}[1]{%|\\
2205 % \verb| \markboth{#1}{}}|\\
2206 % \mbox{}\\
2207 % \FExample{12}^^A
2208 % \verb|\renewcommand{\chaptermark}[1]{%|\\
2209 % \verb| \markboth{\thechapter.\ #1}{}}|\\
2210 % \mbox{}\\
2211 % \FExample{13}^^A
2212 % \verb|\renewcommand{\chaptermark}[1]{%|\\
2213 % \verb| \markboth{\thechapter.%|\\
2214 % \verb| \ \chaptername.\ #1}{}}|\\
2215 % Prints:\\
2216 % \mbox{}\\
2217 % Chapter 2.\ Implementation\\
2218 % \mbox{}\\
2219 % \mbox{}\\
2220 % \mbox{}\\
2221 % CHAPTER 2.\ Implementation\\
2222 % \mbox{}\\
2223 % \mbox{}\\
2224 % \mbox{}\\
2225 % \mbox{}\\
2226 % CHAPTER 2.\ IMPLEMENTATION\\
2227 % \mbox{}\\
2228 % \mbox{}\\
2229 % \mbox{}\\
2230 % \mbox{}\\
2231 % Implementation\\
2232 % \mbox{}\\
2233 % \mbox{}\\
2234 % 2.\ Implementation\\
2235 % \mbox{}\\
2236 % \mbox{}\\
2237 % 2.\ Chapter.\ Implementation\\
2238 % \mbox{}\\
2239 % \end{multicols}
2240 % \caption{Marker variants}\label{fig:markers}
2241 % \end{figure}
2242 %
2243 % It should be noted that the \LaTeX{} marking mechanism works fine with
2244 % chapters (which always start on a new page) and sections (which are
2245 % reasonably long). It does not work quite as well with short sections and
2246 % subsections. This is a problem with \LaTeX, not with
2247 % \pkg{fancyhdr}.
2248 %
2249 % As an example let's take a page layout where the leftmarks are generated by
2250 % the sections and the rightmarks by the subsections (as is default in the
2251 % \texttt{article} class). Take a page with some short sections, e.g.,
2252 %
2253 % \begin{samepage}
2254 % \noindent Section 1.\\
2255 % subsection 1.1\\
2256 % subsection 1.2\\
2257 % Section 2.
2258 % \end{samepage}
2259 %
2260 % As the leftmark contains the \emph{last} mark of the page it will be
2261 % ``Section 2.'', and the rightmark will be ``subsection 1.1'' as it will be
2262 % the \emph{first} mark of the page. So the page header info will combine
2263 % section 2 with subsection 1.1 which isn't very nice.
2264 % One thing you can do in these cases is use only the \cs{rightmark}s and
2265 % redefine \cs{sectionmark} accordingly.
2266 %
2267 % However, the \pkg{extramarks} package described in section~\ref{sec:xmarks}
2268 % contains a command
2269 % \CmdIndex{firstleftmark}
2270 % \cs{firstleftmark} that can be used to get the first of the leftmarks
2271 % on the page in the header. This might be the best solution in this
2272 % situation. Now the header will contain ``Section 1.'' in the situation
2273 % described above.
2274 %
2275 % \Example{14}
2276 % \begin{example}
2277 % \usepackage{extramarks}
2278 % . . .
2279 % \fancyhead[R]{\firstleftmark}
2280 % \end{example}
2281 %
2282 % Another problem with the marks in the standard \LaTeX{} classes is that the
2283 % higher level sectioning commands (e.g., \cs{chapter}) call
2284 % \cs{markboth} with an empty right argument. This means that on the first
2285 % page of a chapter (or a section in article style) the \cs{rightmark}
2286 % will be empty. The underlying problem is that the original \TeX{} machinery had
2287 % only one \cs{mark}. All the marks had to be packed together in
2288 % this one. So there were no independent left or right marks.
2289 % Modern \LaTeX{} distributions, however, do have independent marks, so
2290 % this problem can be solved. See Example~35 in
2291 % section~\ref{sec:firstsubsection} for an example.
2292 %
2293 % \section{Headers for unnumbered chapters, sections, etc.}
2294 % \label{sec:unnumbered}
2295 %
2296 % In the standard \LaTeX{} documentclasses the \verb|*| forms of the
2297 % \cs{chapter} etc.\ commands do \emph{not} call the mark commands. So
2298 % these don't appear in the header. Neither are they put in the Table of
2299 % Contents.
2300 % So, for example, if you want your Preface to set the header info but
2301 % not be numbered, you must issue the \cs{markboth} command yourself,
2302 % e.g.,
2303 %
2304 % \begin{code}
2305 % \chapter*{Preface}
2306 % \markboth{Preface}{}
2307 % \end{code}
2308 %
2309 % Or for a section:
2310 % \begin{code}
2311 % \section*{Preface}
2312 % \markboth{Preface}{}
2313 % \end{code}
2314 %
2315 % It can be a bit annoying to have to repeat the title. If you don't
2316 % want that, it is possible to redefine the \cs{chapter} and/or
2317 % \cs{section} command, in such a way that the \texttt{*} version
2318 % \emph{does} set the header info. For a chapter this is usually done
2319 % with the \cs{markboth} command. For a section in a chapter-oriented
2320 % documentclass with \cs{markright}, otherwise also with \cs{markboth}.
2321 %
2322 % Here is a definition that accomplishes this.
2323 % Redefine the \cs{chapter} command:\\
2324 % \cs{chapter}\oarg{header}\marg{title}\\
2325 % \cs{chapter*}\marg{title}\\
2326 % For the \cs{chapter*} version, we insert a \cs{markboth} command.
2327 % For the non-\texttt{*} version we just pass the arguments to the
2328 % original \cs{chapter} command.
2329 %
2330 % We use the \cs{RenewDocumentCommand} to redefine the \cs{chapter}
2331 % command because it allows us to redefine also the \texttt{*} variant,
2332 % which is much more difficult with \cs{renewcommand}\footnote{If you
2333 % have an older \LaTeX{} distribution that doesn't have the
2334 % \cs{RenewDocumentCommand}, include \PKGindex{xparse}\Cmd{usepackage\{xparse\}} in your
2335 % preamble. Or better: update your \LaTeX{} installation.}.
2336 %
2337 % The \verb|{som}| in the definition defines the arguments of the
2338 % \cs{chapter} command:
2339 % \begin{enumerate}
2340 % \item \texttt{s} - a \texttt{*} which can be present or absent. This
2341 % is checked with \Cmd{IfBooleanTF\{\#1\}}
2342 % \item \texttt{o} - an optional argument. the presence of the optional
2343 % argument is checked with \Cmd{IfNoValueTF\{\#2\}}
2344 % \item \texttt{m} - a mandatory argument
2345 % \end{enumerate}
2346 % We first save the original definition of \cs{chapter} in
2347 % \cs{originalchapter} with the \cs{let} statement. The
2348 % \Cmd{newcommand\cs{originalchapter}\{\}} is just a precaution to get an error message
2349 % if \cs{originalchapter} was already defined, for example by
2350 % another package.
2351 %
2352 % \NoExample{unnumbered}
2353 % \begin{example}
2354 % \newcommand\originalchapter{}% check that we can define this name
2355 % \let\originalchapter\chapter
2356 % \RenewDocumentCommand \chapter {som}{%
2357 % \IfBooleanTF{#1}
2358 % {% \chapter*
2359 % \originalchapter*{#3}%
2360 % \markboth{#3}{}%
2361 % % we can also put it in the Table of Contents
2362 % \addcontentsline{toc}{chapter}{#3}
2363 % }%
2364 % {% normal \chapter
2365 % \IfNoValueTF{#2}
2366 % {\originalchapter{#3}}
2367 % {\originalchapter[#2]{#3}}%
2368 % }%
2369 % }
2370 % \end{example}
2371 % We can do the same for the \cs{section} command, but we use
2372 % \cs{markright} instead of \cs{markboth}. Note that the \cs{mark..}
2373 % commands are called \textbf{after} the original command, because the
2374 % \cs{chapter} command begins with a page break, and a \cs{section}
2375 % could have a page break before it, but not after it.
2376 %
2377 % \textbf{NOTE:} We don't use \cs{chaptermark} or \cs{sectionmark} here
2378 % because these often include the chapter/section number, which doesn't
2379 % make sense for an unnumbered one.
2380 %
2381 % \NoExample{unnumbered}
2382 % \begin{example}
2383 % \newcommand\originalsection{}% check that we can define this name
2384 % \let\originalsection\section
2385 % \RenewDocumentCommand \section {som}{%
2386 % \IfBooleanTF{#1}
2387 % {% \section*
2388 % \originalsection*{#3}%
2389 % \markright{#3}%
2390 % % we can also put it in the Table of Contents
2391 % \addcontentsline{toc}{section}{#3}
2392 % }%
2393 % {% normal \section
2394 % \IfNoValueTF{#2}
2395 % {\originalsection{#3}}
2396 % {\originalsection[#2]{#3}}%
2397 % }%
2398 % }
2399 % \end{example}
2400 %
2401 % Please note that, contrary to the original \LaTeX{} commands,
2402 % these new command do accept an optional argument with
2403 % the \texttt{*} version, but if it is given, they don't use it. It is
2404 % not difficult to add additional code to process this optional argument
2405 % similar to the non-\texttt{*} case.
2406 % This is left as an exercise for the reader, or look at the example
2407 % files \texttt{unnumberedart1.tex} and \texttt{unnumberedart2.tex}.
2408 %
2409 % \section{Dictionary style headers}
2410 %
2411 % \index{dictionary}
2412 % \index{concordance}
2413 % Dictionaries and concordances usually have a header containing the first
2414 % word defined on the page or both the first and the last words. This can
2415 % easily be accomplished with \pkg{fancyhdr} and \LaTeX's
2416 % \texttt{mark} mechanism. Of course if you use the marks for dictionary
2417 % style headers, you cannot use them for chapter and section information, so
2418 % if there are also chapters and sections present, you must redefine the
2419 % \cs{chaptermark} and \cs{sectionmark} to make them harmless:
2420 %
2421 % \begin{code}
2422 % \renewcommand{\chaptermark}[1]{}
2423 % \renewcommand{\sectionmark}[1]{}
2424 % \end{code}
2425 %
2426 % Now you do a \Cmd{markboth\{\#1\}\{\#1\}} for each dictionary or concordance
2427 % entry \verb|#1| and use \cs{rightmark} for the first entry defined on
2428 % the page and \cs{leftmark} for the last one.
2429 %
2430 % If you want to use a header entry of the form \textsf{firstword--lastword}
2431 % it would be nice if this would be reduced to just the form
2432 % \textsf{firstword} if both are the same. This could happen if there is just
2433 % one entry on the page. In this case a test must be made to check if the
2434 % marks are the same. However, \TeX's marks are strange beasts, which
2435 % cannot be compared out of the box with the plain \TeX{} \Cmd{if} commands.
2436 % Fortunately the \PKGindex{ifthen}\pkg{ifthen} package works well:
2437 %
2438 % \Example{15}
2439 % \begin{example}
2440 % \newcommand{\mymarks}{
2441 % \ifthenelse{\equal{\leftmark}{\rightmark}}
2442 % {\rightmark} % if equal
2443 % {\rightmark--\leftmark}} % if not equal
2444 % \fancyhead[LE,RO]{\mymarks}
2445 % \fancyhead[LO,RE]{\thepage}
2446 % \end{example}
2447 %
2448 % \section{Fancy layouts}
2449 % \label{sec:fancy}\label{sec:warning}
2450 %
2451 % \index{multi-line}
2452 % You can make a multi-line field with the \bsbs{} command. It is also
2453 % possible to put extra space in a field with the \cs{vspace} command.
2454 % Note that if you do this you will probably have to increase the height of
2455 % \CmdIndex{headheight}
2456 % \CmdIndex{footskip}
2457 % the header (\cs{headheight}) and/or of the footer (\cs{footskip}),
2458 % \index{Overfull \verb+\vbox+ \ldots}
2459 % otherwise you may get error messages ``Overfull \cs{vbox} \ldots has
2460 % occurred while \cs{output} is active''^^A
2461 % \footnote{If you use \texttt{11pt} or \texttt{12pt} you will probably also
2462 % have to do this, because \LaTeX's defaults are quite small}. See the
2463 % warning below.
2464 % See also section 5.1 and 5.2 of the \LaTeX{} \emph{Companion, Third Edition}, (Part I)
2465 % for detail.
2466 %
2467 % For instance, the following code will place the section title and the
2468 % subsection title of an article in two lines in the upper right hand
2469 % corner:
2470 %
2471 % \Example{16}
2472 % \begin{example}
2473 % \documentclass{article}
2474 % \usepackage{fancyhdr}
2475 % \pagestyle{fancy}
2476 % \addtolength{\headheight}{\baselineskip}
2477 % \renewcommand{\sectionmark}[1]{\markboth{#1}{}}
2478 % \renewcommand{\subsectionmark}[1]{\markright{#1}}
2479 % \fancyhead[R]{\leftmark\\\rightmark}
2480 % \end{example}
2481 %
2482 % Note that if you want to use header or footer layouts with multi-line
2483 % parts that have to be aligned, you can do this with
2484 % the \cs{fancyhdrbox} command. See section~\ref{sec:fancyhdrbox}.
2485 %
2486 % You can also customize the decorative lines. You can make the decorative
2487 % line in the header quite thick with
2488 %
2489 % \CmdIndex{headrulewidth}
2490 % \begin{code}
2491 % \renewcommand{\headrulewidth}{0.6pt}
2492 % \end{code}
2493 % or you can make the decorative line in the footer disappear with
2494 % \CmdIndex{footrulewidth}
2495 % \begin{code}
2496 % \renewcommand{\footrulewidth}{0pt}
2497 % \end{code}
2498 %
2499 % The decorative lines, themselves, are defined in the two macros
2500 % \cs{headrule} and \cs{footrule}. For instance,
2501 % if you want a dotted line rather than a solid line in the header,
2502 % redefine the command \cs{headrule}:
2503 %
2504 % \begin{code}
2505 % \renewcommand{\headrule}{\vbox to 0pt
2506 % {\makebox[\headwidth]{\dotfill}\vss}}
2507 % \end{code}
2508 %
2509 % The redefined \cs{headrule} should preferably take up no vertical space, as in the example above, and as in the standard definition. If it does take vertical space, the header may come too close to the text, or even intrude in the text. In that case \pkg{fancyhdr} will give you a warning that \cs{headheight} is too small. Like
2510 % \begin{code}
2511 % Package fancyhdr Warning: \headheight is too small (12.0pt):
2512 % (fancyhdr) Make it at least 14.0pt, for example:
2513 % (fancyhdr) \setlength{\headheight}{14.0pt}.
2514 % (fancyhdr) You might also make \topmargin smaller:
2515 % (fancyhdr) \addtolength{\topmargin}{-2.0pt}.
2516 % \end{code}
2517 % \label{page:warning}\index{Warning}
2518 % You will probably get this warning on every page.
2519 % \textbf{Note:} Before version 4.0, \pkg{fancyhdr} would change the
2520 % \cs{headheight} itself, causing the text on the following pages
2521 % to come out lower than on this page. This appeared to be confusing, so
2522 % since version~4.0 this is no longer done (except when you give the
2523 % \OPTindex{compatV3}%
2524 % \texttt{compatV3} package option. You should not give this as a
2525 % permanent solution, however, but solve the problem). Therefore you are strongly advised to
2526 % redefine \cs{headheight} in the preamble, like this:
2527 % \begin{code}
2528 % \setlength{\headheight}{14pt}
2529 % \end{code}
2530 % This would cause the main text to be put 2pt lower on the page, which
2531 % might be undesirable. You can compensate this by making \cs{topmargin}
2532 % correspondingly smaller, for example
2533 % \begin{code}
2534 % \addtolength{\topmargin}{-2pt}
2535 % \end{code}
2536 % A similar change would be necessary for \cs{footskip} if the footer comes out too tall.
2537 %
2538 % You can also eliminate this check completely by using the
2539 % \OPTindex{nocheck}
2540 % \texttt{nocheck} option of the package. But this may risk unwanted
2541 % run-ins of the header or footer with other text. So this is generally
2542 % discouraged. It is better to change \cs{headheight}, \cs{footskip},
2543 % and/or \cs{topmargin}. But in cases where you generate the \LaTeX{}
2544 % code automatically, and the software does not know how tall the header
2545 % or footer will be, this may be handy.
2546 %
2547 % As an alternative to changing \cs{headrulewidth} to 0 to have the rule
2548 % disappear, you can also make it empty with
2549 % \begin{code}
2550 % \renewcommand{\headrule}{}
2551 % \end{code}
2552 % Visually this makes no difference, but it is more difficult to restore
2553 % it later to its default value.
2554 %
2555 % Finally, let us make a real `decorative' line\footnote{Based upon an idea by Wayne Chan.}.
2556 % \PKGindex{fourier-orns}%
2557 % \begin{code}
2558 % \usepackage{fourier-orns}
2559 % ...
2560 % \renewcommand\headrule{%
2561 % \hrulefill
2562 % \raisebox{-2.1pt}
2563 % {\quad\decofourleft\decotwo\decofourright\quad}%
2564 % \hrulefill}
2565 % \end{code}
2566 % This gives us the following headrule:
2567 %
2568 % \noindent\makebox[\textwidth]{\hrulefill
2569 % \raisebox{-2.1pt}[10pt][10pt]{\quad\decofourleft\decotwo\decofourright\quad}\hrulefill}
2570 %
2571 % Note that we haven't taken care to make this decorative line occupy
2572 % zero vertical space. The consequence is that it will extend towards
2573 % the text and that we will get the warning about \cs{headheight} too small. So we
2574 % should change \cs{headheight} as given above. Another problem is that
2575 % the distance between the line and the header text is quite big. We can
2576 % reduce this by putting a negative \cs{vspace} above it, like
2577 % \Example{17}
2578 % \begin{example}
2579 % \renewcommand\headrule{%
2580 % \vspace{-6pt}
2581 % \hrulefill
2582 % \raisebox{-2.1pt}
2583 % {\quad\decofourleft\decotwo\decofourright\quad}%
2584 % \hrulefill}
2585 % \end{example}
2586 %
2587 % We can use the same code for the \cs{footrule}, but we wouldn't need
2588 % the \cs{vspace}. If you want to change the distance between that
2589 % decorative line and the footer text you need to adjust the
2590 % \CmdIndex{footruleskip}
2591 % parameter \cs{footruleskip}. It
2592 % defines the distance between the decorative line in the footer and the top
2593 % of the footer text line. By default it is set to 30\% of the normal line
2594 % distance. You may want to adjust it if you use unusually large or small
2595 % fonts in the footer. Change it with \cs{renewcommand}.
2596 %
2597 % You can also change the distance between the baseline of the header text and the
2598 % decorative line in the header. Normally this distance is determined by
2599 % the maximum depth of possible descenders in the text, which is 30\% of
2600 % the normal line distance. You can increase or decrease this distance
2601 % \CmdIndex{headruleskip}
2602 % by defining the macro \cs{headruleskip}, similar to \cs{footruleskip}.%
2603 % \footnote{But \cs{headruleskip} is only available since version~4.0.}
2604 % This defines the extra distance. The default value is 0pt, and
2605 % positive values make the distance larger, and negative values make the
2606 % distance shorter.
2607 % Please note that this does not change the position
2608 % of the decorative line with respect to the page, but it shifts the
2609 % header text. If you want to keep the header text fixed, but move the
2610 % decorative line, then you must also change the parameter \cs{headsep}
2611 % (see figure~\ref{fig:layout}). \strut
2612 %
2613 % \pagestyle{showstruts}
2614 % \noindent\begin{minipage}{\textwidth}
2615 % \parindent=\normalparindent
2616 % \phantomsection\label{showstruts}
2617 % \indent The header and footer in this page
2618 % show the \emph{strut} (the amount of space in the text area above and
2619 % below the baseline), and the \cs{headruleskip} and \cs{footruleskip}.
2620 % For this page \cs{headruleskip} is 4pt and \cs{footruleskip} is 3.6pt
2621 % (0.3\cs{normalbaselineskip}).
2622 %
2623 % The code for this can be found in section~\ref{sec:curpagestyle}.
2624 % \end{minipage}
2625 %
2626 % \paragraph{Fine-tuning the footer position.}
2627 % \label{sec:fancyfootalign}
2628 % By default \LaTeX{} positions the baseline of the footer on the bottom
2629 % edge of the bottom margin (the lower line of the footer box in
2630 % figure~\ref{fig:layout}). Most of the time this is what you want, but
2631 % it means that any descenders in the footer (symbols that extend below
2632 % the baseline, e.g., p and g or parentheses). See
2633 % figure~\ref{fig:footalign-default}, where the horizontal line denotes the
2634 % bottom border.
2635 %
2636 % \begin{figure}[hbpt]
2637 % \subcaptionsetup{format=hang}
2638 % \centering\LARGE\setlength\parindent{0pt}
2639 % \subcaptionbox{default footer positioning\label{fig:footalign-default}}
2640 % {\mbox{\rule{5cm}{0.2pt}\hspace{-4cm}\fbox{\strut Page Footer}}}
2641 % \hspace{2cm}
2642 % \subcaptionbox{\raggedright footer positioning with \cmd{\fancyfootalign}\marg{length}\label{fig:footalign-length}}[0.5\linewidth][l]
2643 % {\mbox{\rule{6cm}{0.2pt}\hspace{-5.5cm}%
2644 % \raisebox{0.7\baselineskip}[0.8\baselineskip][0pt]{\fbox{\strut Page Footer}}%
2645 % \normalsize\hspace{-4pt}\raisebox{5pt}{$\swarrow$}\raisebox{10pt}{\meta{length}}}}
2646 % \caption{Vertical footer positioning}
2647 % \end{figure}
2648 %
2649 % In some cases this is undesirable, for example when the bottom border
2650 % is completely missing (\texttt{0pt}). In that case the descenders are
2651 % cut off because they are outside of the paper, and even if there are
2652 % no descenders, the resulting layout with the footer at the edge of the
2653 % paper isn't esthetic. The beamer class has this layout.
2654 %
2655 % In this case we can shift the footer up with the \cs{fancyfootalign}
2656 % command (only available in \pkg{fancyhdr} 5.0 and later).
2657 % This command has two versions:
2658 % \begin{flushleft}
2659 % \cs{fancyfootalign}\texttt{\{\}} -- This selects the default alignment,
2660 % as in figure~\ref{fig:footalign-default}.\\
2661 % \cs{fancyfootalign}\marg{length} -- This gives extra space of
2662 % \meta{length} between \emph{the bottom of the footer, (including the
2663 % space for descenders and the interline space)}, and the border. See
2664 % figure~\ref{fig:footalign-length}.
2665 % \end{flushleft}
2666 % Usually a \meta{length} of \texttt{0pt} is sufficient; this means that
2667 % the bottom of the footer box coincides with the bottom border. You can
2668 % also use negative \meta{length} values, so that the footer box only
2669 % partially sticks out under the border. A given \meta{length} applies
2670 % to all subsequent footers (but is subject to the local group
2671 % structure). It can be cancelled by \cs{fancyfootalign}\texttt{\{\}}.
2672 % See section~\ref{sec:beamer} for an example.
2673 %
2674 % \section{Two book examples}
2675 % \label{sec:book-examples}
2676 %
2677 % The following definitions give an approximation of the style
2678 % used in L. Lamport's \LaTeX{} book.
2679 %
2680 % Lamport's header overhangs the outside margin. This is done as follows.
2681 %
2682 % The width of headers and footers is \cs{headwidth}, which by default
2683 % equals the width of the text: \cs{textwidth}. You can make the width
2684 % \CmdIndex{headwidth}
2685 % wider (or narrower) by redefining \cs{headwidth} with the
2686 % \cs{setlength} and \cs{addtolength} commands.
2687 % To overhang the outside margin where the marginal notes are
2688 % \CmdIndex{marginparsep}
2689 % \CmdIndex{marginparwidth}
2690 % printed, add both \cs{marginparsep} and \cs{marginparwidth} to
2691 % \cs{headwidth} with the commands:
2692 %
2693 % \begin{code}
2694 % \addtolength{\headwidth}{\marginparsep}
2695 % \addtolength{\headwidth}{\marginparwidth}
2696 % \end{code}
2697 %
2698 % \begin{flushleft}
2699 % It is safest to issue these commands \emph{after} the first
2700 % \Cmd{pagestyle\{fancy\}} command.
2701 % \end{flushleft}
2702 %
2703 % And now a complete definition of Lamport's book style. The header has
2704 % the width of the text plus the marginpar area. The header on even
2705 % pages has the page number on the left, and the chapter title on the
2706 % right. On odd pages it has the section title preceded by the section
2707 % number on the left and the page number on the right. All in boldface.
2708 % There is no footer. The \texttt{plain} style is redefined to have no
2709 % header and no footer. (In the \LaTeX{} book this makes sense because
2710 % each chapter begins with a page that contains only a drawing. In most
2711 % other cases you probably would want a page number on the page.)
2712 %
2713 % \Example{18}
2714 % \begin{example}
2715 % \documentclass{book}
2716 % \usepackage{fancyhdr}
2717 % \pagestyle{fancy}
2718 % \addtolength{\headwidth}{\marginparsep}
2719 % \addtolength{\headwidth}{\marginparwidth}
2720 % \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
2721 % \renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
2722 % \fancyhf{}
2723 % \fancyhead[LE,RO]{\textbf{\thepage}}
2724 % \fancyhead[LO]{\textbf{\rightmark}}
2725 % \fancyhead[RE]{\textbf{\leftmark}}
2726 % \fancypagestyle{plain}{%
2727 % \fancyhead{} % get rid of headers
2728 % \renewcommand{\headrulewidth}{0pt} % and the line
2729 % }
2730 % \end{example}
2731 % \PSindex{plain}
2732 %
2733 % Notice that the \cs{chaptermark} and \cs{sectionmark} commands have
2734 % been redefined to eliminate the chapter numbers and the uppercaseness.
2735 %
2736 % For more control about the horizontal position of the headers and/or
2737 % footers, \pkg{fancyhdr} has additional commands to specify the
2738 % offset of the header and/or footer elements. Use
2739 % \Cmd{fancyhfoffset[place]\{length\}}
2740 % \CmdIndex{fancyhfoffset}
2741 % to offset one or more elements. The \texttt{place} parameter is like
2742 % the optional parameter of \cs{fancyhf}, like \texttt{L R E O}, except
2743 % that \texttt{C} cannot be used. It specifies for which elements the
2744 % offset should be applied. The \texttt{length} parameter specifies the
2745 % actual offset. Positive values move the element outward (into the
2746 % margin), negative values inward. There are also specialised commands
2747 % \cs{fancyheadoffset} and \cs{fancyfootoffset}, which have the
2748 % \texttt{H} and \texttt{F} parameter pre-applied, respectively.
2749 % \CmdIndex{fancyheadoffset}
2750 % \CmdIndex{fancyfootoffset}
2751 %
2752 % When you use these commands, \LaTeX{} will recalculate \cs{headwidth},
2753 % based on the given parameters.
2754 %
2755 % So the above example could also have been done with (N.B. You can only
2756 % use such an expression as a length parameter if the \PKGindex{calc}\pkg{calc}
2757 % package is used):
2758 %
2759 % \Example{19}
2760 % \begin{example}
2761 % \fancyheadoffset[LE,RO]{\marginparsep+\marginparwidth}
2762 % \end{example}
2763 %
2764 % \textbf{NOTE:} If you change the \cs{textwidth} in the middle of your
2765 % document, for example by using the \PKGindex{geometry}\pkg{geometry} package,
2766 % by default the \cs{headwidth} will not change, as it picks up the value
2767 % of \cs{textwidth} at the beginning of the document. If you want it to track
2768 % the changes to \cs{textwidth}, you should use the command \verb|\fancyhfoffset{0pt}|
2769 % in the neighborhood of your header/footer definitions, unless you
2770 % already use such an \texttt{\ldots offset} command, of course.
2771 % \vspace{\baselineskip}
2772 % For the second example, we take the \ams/-\LaTeX{} book\footnote{George Grätzer,
2773 % \textit{Math into LaTeX, An Introduction to \LaTeX{} and \ams/-\LaTeX}, Birkhauser, Boston.}.
2774 %
2775 % Chapter pages have no headers or footers. So we declare
2776 %
2777 % \begin{code}
2778 % \thispagestyle{empty}
2779 % \end{code}
2780 % for every chapter page, and we do not need to redefine plain.
2781 %
2782 % Chapter and section titles appear in the form: 2.\ IMPLEMENTATION, so we have
2783 % to redefine \cs{chaptermark} and \cs{sectionmark} as follows (see
2784 % Section~\ref{sec:scoop}):
2785 %
2786 % \begin{code}
2787 % \renewcommand{\chaptermark}[1]%
2788 % {\markboth{\MakeUppercase{\thechapter.\ #1}}{}}
2789 % \renewcommand{\sectionmark}[1]%
2790 % {\markright{\MakeUppercase{\thesection.\ #1}}}
2791 % \end{code}
2792 %
2793 % On an even page, the page number is printed as the left header and
2794 % the chapter info as the right header; on an odd page, the section info
2795 % is printed as the left header and the page number as the right header. The
2796 % center headers are empty. There are no footers.
2797 %
2798 % There is a decorative line in the header. It is 0.5pt wide, so we need
2799 % the commands:
2800 %
2801 % \begin{code}
2802 % \renewcommand{\headrulewidth}{0.5pt}
2803 % \renewcommand{\footrulewidth}{0pt}
2804 % \end{code}
2805 %
2806 % The font used in the headers is 9 pt bold Helvetica. The \textsf{PSNFSS} system
2807 % (originally by the late Sebastian Rahtz) uses the short (Karl Berry) name \texttt{phv} for
2808 % Helvetica. The more modern \LaTeX{} solution is to use the \TeX{} Gyre font
2809 % Heros, which uses the short name \texttt{qhv} so this font is selected with the commands^^A
2810 % \footnote{See \emph{The \LaTeX{} Companion, Third Edition}, Part I, section
2811 % 9.5.2, and Part II, section 10.8.16.}:
2812 % \begin{code}
2813 % \fontfamily{qhv}\fontseries{b}\fontsize{9}{11}\selectfont
2814 % \end{code}
2815 % Let us define a shorthand for this:
2816 % \begin{code}
2817 % \newcommand{\helv}{%
2818 % \fontfamily{qhv}\fontseries{b}\fontsize{9}{11}\selectfont}
2819 % \end{code}
2820 %
2821 % Now we are ready for the page layout:
2822 %
2823 % \Example{20}
2824 % \begin{example}
2825 % \documentclass{book}
2826 % \usepackage{fancyhdr}
2827 % \pagestyle{fancy}
2828 % \renewcommand{\chaptermark}[1]%
2829 % {\markboth{\MakeUppercase{\thechapter.\ #1}}{}}
2830 % \renewcommand{\sectionmark}[1]%
2831 % {\markright{\MakeUppercase{\thesection.\ #1}}}
2832 % \renewcommand{\headrulewidth}{0.5pt}
2833 % \renewcommand{\footrulewidth}{0pt}
2834 % \newcommand{\helv}{%
2835 % \fontfamily{qhv}\fontseries{b}\fontsize{9}{11}\selectfont}
2836 % \fancyhf{}
2837 % \fancyhead[LE,RO]{\helv \thepage}
2838 % \fancyhead[LO]{\helv \rightmark}
2839 % \fancyhead[RE]{\helv \leftmark}
2840 % \end{example}
2841 %
2842 %
2843 % \section{Summary of \Cmd{headwidth} calculation}
2844 % \label{sec:headwidth}
2845 %
2846 % Here is a summary of the calculation of the widths of headers and
2847 % footers, as illustrated in \smartref{sec:headwidth}{sec:book-examples}.
2848 % \begin{itemize}
2849 % \CmdIndex{headwidth}%
2850 % \CmdIndex{textwidth}%
2851 % \CmdIndex{fancyhfoffset}%
2852 % \CmdIndex{fancyheadoffset}%
2853 % \CmdIndex{fancyfootoffset}%
2854 % \item If no \cs{fancy...offset} commands are given, the default value
2855 % for \cs{headwidth} is \cs{textwidth}. This is used for the width of
2856 % both the header and the footer. It is possible to change the value of
2857 % \cs{headwidth}, for example with \cs{setlength} or \cs{addtolength}.
2858 % The excess or deficit will be applied to the right for a one-sided
2859 % document, and for a two-sided document to the right on odd pages and to
2860 % the left on even pages. The header and the footer will have the same
2861 % width, \cs{headwidth}.
2862 % \item If some \cs{fancy...offset} command is given, the header and
2863 % footer widths are independently calculated by adding the appropriate
2864 % offsets to \cs{textwidth}. Any changes made to \cs{headwidth} will not
2865 % be taken into account. The header/footer will stick in/out at the proper
2866 % side(s) specified by the offsets.
2867 % \end{itemize}
2868 % The file \texttt{example-headwidth.tex} in the \texttt{Examples}
2869 % branch of the repository illustrates this.
2870 %
2871 % \section{Special page layout for float pages}
2872 % \label{sec:float}
2873 %
2874 % \index{float page}
2875 % Some people want to have a special layout for float pages (pages only
2876 % containing floats). As these pages
2877 % are generated autonomically by \LaTeX, the user doesn't have any control
2878 % over them. There is no \cs{thispagestyle} for float pages and any change
2879 % of the page style will at least also affect the page before the float page.
2880 % With \pkg{fancyhdr}, however, you can specify in each of
2881 % the header- or footer fields
2882 %
2883 % \medskip
2884 % \Cmd{iffloatpage\{}\meta{value for float page}\verb|}{|\meta{value for other pages}\verb|}|
2885 % \medskip
2886 %
2887 % You can even use this to get rid of the decorative line on float pages only
2888 % by defining:
2889 %
2890 % \Example{21}
2891 % \begin{example}
2892 % \renewcommand{\headrulewidth}{\iffloatpage{0pt}{0.4pt}}
2893 % \end{example}
2894 %
2895 % \textbf{NOTE:} There is also a package \PKGindex{floatpag}%
2896 % \pkg{floatpag}\footnote{\url{https://www.ctan.org/pkg/floatpag}} by Vytas
2897 % Statulevičius and Sigitas Tolušis that has a command
2898 % \cs{floatpagestyle}\marg{pagestyle}, that applies \meta{pagestyle} to
2899 % all float pages, where \meta{pagestyle} can be defined with
2900 % \cs{fancypagestyle} (or by any other means). In some cases this might
2901 % be simpler than putting \cs{iffloatpage} in various headers or footers.
2902 %
2903 % Sometimes you may want to change the layout also for pages that contain a
2904 % float on the top of the page, a float on the bottom of the page or a footnote on the bottom of the page.
2905 %
2906 % \pkg{fancyhdr} gives you the commands \cs{iftopfloat}, \cs{ifbotfloat} and \cs{iffootnote}
2907 % similar to \cs{iffloatpage}. For example:
2908 % \begin{code}
2909 % \fancyhead[R]{\iftopfloat{This page has a topfloat}
2910 % {There is no topfloat here}}
2911 % \end{code}
2912 %
2913 % Note: Marks in floats will not be visible in \LaTeX's output routine, so
2914 % it is not useful to put marks in floats. So there is currently no way to
2915 % let a float (e.g., a figure caption) influence the page header or footer.
2916 %
2917 % \section{Those blank pages}
2918 % \label{sec:blank}
2919 %
2920 % In the \texttt{book} class when the \texttt{openany} option is not given or
2921 % in the \texttt{report} class when the \texttt{openright} option is given,
2922 % chapters start at odd-numbered pages, half of the time causing a blank page
2923 % to be inserted. Some people prefer this page to be completely empty, i.e.,
2924 % without headers and footers. This cannot be done with \cs{thispagestyle}
2925 % as this command would have to be issued on the \emph{previous} page. There
2926 % is, however, no magic necessary to get this done:
2927 %
2928 % \PSindex{empty}
2929 % \CmdIndex{clearpage}
2930 % \CmdIndex{cleardoublepage}
2931 % \begin{code}
2932 % \clearpage\begingroup\pagestyle{empty}\cleardoublepage\endgroup
2933 % \end{code}
2934 %
2935 % As the \Cmd{pagestyle\{empty\}} is enclosed in a group it only affects the
2936 % page that may be generated by the \cs{cleardoublepage}. You can of
2937 % course put the above in a private command. If you want to have this done
2938 % automatically at each chapter start or when you want some other text on the
2939 % page then you must redefine the \cs{cleardoublepage} command.
2940 % \index{blank page}
2941 % \begin{code}
2942 % \makeatletter
2943 % \def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
2944 % \begingroup
2945 % \mbox{}
2946 % \vspace*{\fill}
2947 % \begin{center}
2948 % This page intentionally contains only this sentence.
2949 % \end{center}
2950 % \vspace{\fill}
2951 % \thispagestyle{empty}
2952 % \newpage
2953 % \if@twocolumn\mbox{}\newpage\fi
2954 % \endgroup\fi\fi}
2955 % \makeatother
2956 % \end{code}
2957 %
2958 % \section{\textsf{N} of \textsf{M} style page numbers}
2959 % \label{sec:nofm}
2960 %
2961 % Some document writers prefer the pages to be numbered as \textsf{n} of
2962 % \textsf{m} where \textsf{m} is the number of pages in the document.
2963 % There is a package \PKGindex{lastpage}\pkg{lastpage}
2964 % available which you can use with \pkg{fancyhdr} as follows:
2965 %
2966 % \Example{22}
2967 % \begin{example}
2968 % \usepackage{lastpage}
2969 % ...
2970 % \fancyfoot[C]{\thepage\ of \pageref{LastPage}}
2971 % \end{example}
2972 % Because you want the pages with page style \texttt{plain} to contain
2973 % the same style of page numbers, you will have to redefine this
2974 % page style too.
2975 % \begin{code}
2976 % \fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrule}{}}
2977 % \end{code}
2978 % We clear all the headers including its rule. The footer will be
2979 % ``inherited'' from the page style \texttt{fancy}.
2980 %
2981 % The value of the \TTindex{LastPage}\texttt{LastPage} label can be used to
2982 % make different headers or footers on the last page of a document. E.g., if
2983 % you want the footer of every odd page, except if it is the last one, to
2984 % contain the text ``Please turn over'', this can be done by checking if
2985 % the page number is odd, and if it is equal to the number of the last page.
2986 %
2987 % We use the macro \cs{getpagerefnumber} from the package
2988 % \PKGindex{refcount}%
2989 % \pkg{refcount}, because \cs{pageref} isn't always usable in a
2990 % numerical context (it is meant for typesetting only). This is also done in
2991 % following similar examples.
2992 %
2993 % \PKGindex{ifthen}\PKGindex{lastpage}\PKGindex{refcount}
2994 % \begin{code}
2995 % \usepackage{ifthen}
2996 % \usepackage{lastpage}
2997 % \usepackage{refcount}
2998 % ...
2999 % \fancyfoot[R]{%
3000 % \ifthenelse{\isodd{\value{page}} \and
3001 % \not \( \value{page}=\getpagerefnumber{LastPage} \) }%
3002 % {Please turn over}{}%
3003 % }
3004 % \end{code}
3005 %
3006 % In order to get the number of pages correctly used, you usually have
3007 % to do one additional \LaTeX{} run.
3008 %
3009 %
3010 % \section{Chapter or section related page numbers}
3011 %
3012 % In technical documentation very often page numbers are used of the form
3013 % 2-10 where the first number is the chapter number and the second is the
3014 % page number relative to the chapter. Sometimes section is used rather than
3015 % chapter. The package \PKGindex{chappg}\pkg{chappg} can be used to get this format.
3016 %
3017 % Basically this package redefines \cs{thepage} as
3018 % \cs{thechapter}\cs{chappgsep}\Cmd{arabic\{page\}}, where
3019 % \cs{chappgsep} by default is `-'. If you want do use a different
3020 % separator, you must redefine \cs{chappgsep}, for example to use an
3021 % en-dash:
3022 %
3023 % \begin{code}
3024 % \renewcommand{\chappgsep}{--}
3025 % \end{code}
3026 %
3027 % To use a different prefix, for example the section number, use the
3028 % \Cmd{pagenumbering\{bychapter\}} command with an optional argument
3029 % specifying the prefix.
3030 % \CmdIndex{pagenumbering}
3031 %
3032 % \Example{23}
3033 % \begin{example}
3034 % \clearpage
3035 % \pagenumbering[\thesection]{bychapter}
3036 % \end{example}
3037 %
3038 % What the package also does is reset the page number to 1 at the beginning
3039 % of each chapter.
3040 %
3041 % In general it is advisable to give a \cs{clearpage} or
3042 % \cs{cleardoublepage} before changing the page numbering.
3043 %
3044 % In the frontmatter of your document (for example the Table of
3045 % Contents) there will be no chapter numbers. Therefore a simple page
3046 % number will be used there. This may be confusing, so you might prefer to use roman page numbers
3047 % in the front matter. Do this by using \verb+\pagenumbering{roman}+ in
3048 % the beginning of the document and \verb+pagenumbering{bychapter}+
3049 % after the first \cs{chapter} command. If you want to do it before the
3050 % \cs{chapter} command you must precede it
3051 % by a \cs{newpage} command (see the next section).
3052 % \begin{code}
3053 % \pagenumbering{roman}
3054 % \tableofcontents
3055 % \newpage
3056 % \pagenumbering{bychapter}
3057 % \chapter{Introduction}
3058 % \end{code}
3059 %
3060 % There is a caveat when you have appendices in your document. Before the
3061 % \cs{appendix} command you should give a \cs{clearpage} or
3062 % \cs{cleardoublepage}. See the \pkg{chappg} documentation for
3063 % details.
3064 %
3065 % There is a fundamental difference between the page numbering of the style
3066 % ``\emph{m} of \emph{n}'' as described in the previous section and the
3067 % current one. The \emph{m} of \emph{n} style is only used in the page header
3068 % or footer, but not in the table of contents, index, or references like
3069 % ``\emph{See page \emph{xx}}''. Therefore it does not change the command
3070 % \cs{thepage}. The page numbering style ``2-10'', however should be used
3071 % in all references to the page number, therefore it must be done by redefining
3072 % \cs{thepage}.
3073 %
3074 % \section{Switching page styles}
3075 % \label{sec:switching}
3076 %
3077 % Page style \texttt{fancy}, if not redefined, does not have the definitions of the
3078 % headers and footers built-in, but they are defined in the document,
3079 % globally, or locally in a group. This also applies to the definitions of the
3080 % \cs{chaptermark} and/or \Cmd{[sub]sectionmark} commands. So if you want
3081 % to switch from another page style to the \texttt{fancy} page style
3082 % later in the document, and that other page style has changed for
3083 % example the \cs{chaptermark} and/or \Cmd{[sub]sectionmark} commands,
3084 % you will have to redefine these yourself and maybe also
3085 % the definitions of the headers and footers, at that point.
3086 % For example
3087 % \begin{code}
3088 % \pagestyle{fancy}
3089 % \renewcommand{\chaptermark}[1]{\markboth{Chapter \thechapter. #1}{}}
3090 % \renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
3091 % \end{code}
3092 %
3093 % If the previous page style was one of the standard \LaTeX{} page
3094 % styles, or some page style that is not based on \pkg{fancyhdr},
3095 % then the definitions of \cs{fancyhead} or \cs{fancyfoot} are not
3096 % affected. So strictly you don't have to include them. But if it was
3097 % based on \pkg{fancyhdr} and had different definitions, you will
3098 % get the wrong headers and/or footers when you switch back to page
3099 % style \texttt{fancy}. So it is safer to include them anyway.
3100 %
3101 % A better possibility is to define your own page style, and include
3102 % these definitions in that page style:
3103 % \begin{code}
3104 % \fancypagestyle{myfancy}{
3105 % \renewcommand{\chaptermark}[1]{\markboth{Chapter \thechapter. ##1}{}}
3106 % \renewcommand{\sectionmark}[1]{\markright{\thesection\ ##1}}
3107 % \fancyhead{...}
3108 % }
3109 % ...
3110 % \pagestyle{myfancy}
3111 % \end{code}
3112 % Please note that you now have to double the \verb|#| signs, because the
3113 % definitions are inside a macro.
3114 %
3115 % In general, when you use only one page style \texttt{fancy} in your
3116 % document, with the occasional \cs{thispagestyle} excursion to page
3117 % style \texttt{plain} or \texttt{empty}, you can just keep the
3118 % definitions globally in your document, but as soon as you use more
3119 % than one page style, and switch between them, it is highly advisable
3120 % to define them (including page style \texttt{fancy}) with
3121 % \cs{fancypagestyle} and put all the relevant definitions inside them.
3122 %
3123 % There is another caveat, when switching page styles, if they have
3124 % different definitions of \cs{chaptermark} in the \texttt{book} or
3125 % \texttt{report} document class or similar ones. When you put the
3126 % \cs{pagestyle} command \emph{after} the \cs{chapter} command, then the
3127 % \cs{chapter} command calls the \cs{chaptermark} of the previous page
3128 % style, which is probably not what you intended. So you must issue the
3129 % \cs{pagestyle} command \emph{before} the \cs{chapter} command. But
3130 % this would probably change the page style of the previous page, which
3131 % is too early. Therefore you would have to give a \cs{newpage},
3132 % \cs{clearpage} or \cs{cleardoublepage} command
3133 % before the \cs{pagestyle} command, so that the last page will be
3134 % finished with the previous page style. I.e., the proper sequence is:
3135 % \begin{code}
3136 % \newpage % (or \clearpage or \cleardoublepage)
3137 % \pagestyle{newstyle}
3138 % \chapter{My New Chapter}
3139 % \end{code}
3140 %
3141 % Finally, in this section, we give an example that illustrates why
3142 % using \emph{closed} page styles is recommendable.
3143 %
3144 % Suppose we have a part of our document, maybe one or more chapters,
3145 % that need a different style headers and/or footers than the rest of
3146 % the document. We can do this by defining a new page style for this
3147 % part with \cs{fancypagestyle}. First we use the traditional
3148 % (\emph{open}) form:
3149 % \NoExample{switchstyle1}
3150 % \begin{example}
3151 % \pagestyle{fancy}
3152 % \fancyhf{}
3153 % \fancyhead[L]{\leftmark}
3154 % \fancyhead[R]{\rightmark}
3155 % \fancyfoot[C]{\thepage}
3156 %
3157 % \fancypagestyle{special}{%
3158 % \fancyhf{}
3159 % \renewcommand{\headrulewidth}{0pt}
3160 % \fancyhead[L]{Special Page Style \nouppercase\leftmark}
3161 % \fancyfoot[R]{\thepage}
3162 % }
3163 % . . .
3164 % \chapter{Special Chapter}
3165 % \pagestyle{special}
3166 % Chapter text
3167 %
3168 % \chapter{Another Chapter}
3169 % \pagestyle{fancy}
3170 % Chapter text
3171 % \end{example}
3172 % Now the last chapter will not use the headers and footers that we
3173 % defined in the beginning, but those that are defined in page style
3174 % \texttt{special}. This is because the command
3175 % \Cmd{pagestyle\{special\}} will just execute the definitions inside
3176 % it, and so it changes the definitions of \cs{fancyhead[]} etc. Also
3177 % the definition of \cs{headrulewidth} will not be restored.
3178 %
3179 % To remedy this we would need to put the relevant definitions inside
3180 % the page style \texttt{fancy}. First we try this with the \emph{open}
3181 % \cs{fancypagestyle}.
3182 %
3183 % \NoExample{switchstyle2}
3184 % \begin{example}
3185 % \fancypagestyle{fancy}{%
3186 % \renewcommand{\headrulewidth}{0.4pt}
3187 % \fancyhf{}
3188 % \fancyhead[L]{\leftmark}
3189 % \fancyhead[R]{\rightmark}
3190 % \fancyfoot[C]{\thepage}
3191 % }
3192 %
3193 % \fancypagestyle{special}{%
3194 % \fancyhf{}
3195 % \renewcommand{\headrulewidth}{0pt}
3196 % \fancyhead[L]{Special Page Style \nouppercase\leftmark}
3197 % \fancyfoot[R]{\thepage}
3198 % }
3199 % \pagestyle{fancy}
3200 % . . .
3201 % \chapter{Special Chapter}
3202 % \pagestyle{special}
3203 % Chapter text
3204 %
3205 % \chapter{Another Chapter}
3206 % \pagestyle{fancy}
3207 % Chapter text
3208 % \end{example}
3209 % We now have the relevant definitions also embedded in page style
3210 % \texttt{fancy}. Note that we have to include the (default) definition
3211 % of \cs{headrulewidth}, although it looks unlogical that we have to do this.
3212 % But we need it because page style \texttt{special} changes it. And if
3213 % we had another page style that would change for example the
3214 % \texttt{offsets} (see section~\ref{sec:book-examples}) then we would
3215 % also have to include these. This is the reason for the existence of
3216 % the \emph{closed} form \cs{fancypagestyle*}. So now we give the
3217 % solution with these. This solves the problem in an elegant and robust way.
3218 %
3219 % \NoExample{switchstyle3}
3220 % \begin{example}
3221 % \fancypagestyle*{fancy}{%
3222 % \fancyhf{}
3223 % \fancyhead[L]{\leftmark}
3224 % \fancyhead[R]{\rightmark}
3225 % \fancyfoot[C]{\thepage}
3226 % }
3227 %
3228 % \fancypagestyle*{special}{%
3229 % \fancyhf{}
3230 % \renewcommand{\headrulewidth}{0pt}
3231 % \fancyhead[L]{Special Page Style \nouppercase\leftmark}
3232 % \fancyfoot[R]{\thepage}
3233 % }
3234 % \pagestyle{fancy}
3235 % . . .
3236 % \chapter{Special Chapter}
3237 % \pagestyle{special}
3238 % Chapter text
3239 %
3240 % \chapter{Another Chapter}
3241 % \pagestyle{fancy}
3242 % Chapter text
3243 % \end{example}
3244 %
3245 % \section{When to change the headers and footers?}
3246 % \label{sec:change}
3247 %
3248 % In \smartref{sec:change}{sec:switching} we switched page styles at a
3249 % point that has a clear page break (the beginning of a chapter).
3250 % Sometimes you want to change only a header or footer without changing
3251 % the whole page style.
3252 %
3253 % It should be noted that although the \pkg{fancyhdr} commands like
3254 % \cs{fancyhead} take effect immediately, this does not mean that any
3255 % ``variables'' used in these commands get the value they have at the place
3256 % where these commands are given. E.g., if \Cmd{fancyfoot[C]\{}\Cmd{thepage\}} is given
3257 % the page number that will be inserted in the footer is not the page number
3258 % of the page where this command is given, but rather the page number of
3259 % the actual page where the footer is constructed. Of course for the page
3260 % number this is what you expect, but it is also true for other
3261 % commands. There is a difference, however. The page number is
3262 % incremented \emph{after} the page has been constructed. When we have
3263 % our own ``variables'', however, these are usually changed in the
3264 % middle of our text.
3265 %
3266 % As an example we take a book where each chapter is written by a different author.
3267 % If we want the name of the author in the header opposite the chapter
3268 % title, we can use the following commands:
3269 %
3270 % \Example{24}
3271 % \begin{example}
3272 % \newcommand{\TheAuthor}{}
3273 % \newcommand{\Author}[1]{\renewcommand{\TheAuthor}{#1}}
3274 % \fancyhead[LE,RO]{\TheAuthor}
3275 % \end{example}
3276 %
3277 % \noindent and start each chapter with the command
3278 % \Cmd{Author\{Real Name\}}.
3279 % If, however, the author name would be changed before a page is
3280 % completed the wrong author could come in the header. This would be the case
3281 % if you gave the above command \emph{before} the \cs{chapter} command
3282 % rather than after it. So we give the \cs{Author} command after the
3283 % \cs{chapter} command:
3284 % \begin{code}
3285 % \chapter{Chapter Title}
3286 % \Author{Author Name}
3287 % \end{code}
3288 % As a chapter starts on a new page, we can be sure that the \cs{Author}
3289 % command comes at the same page as the chapter start.
3290 %
3291 % Another source of problems is the fact that \TeX's output routine processes
3292 % commands ahead, so it may already have processed some commands that produce
3293 % text that will appear on the next page. So if our book was not divided
3294 % into chapters, but into sections, we cannot use the similar system:
3295 % \begin{code}
3296 % %%% NOTE: This may not work %%%%
3297 % \section{Chapter Title}
3298 % \Author{Author Name}
3299 % \end{code}
3300 % because in this case, when this command comes at the end of a page,
3301 % the ``variable'' \cs{TheAuthor} could be set at that page, but then
3302 % \TeX{} could decide to move the section title to the next page. And
3303 % then the author name would appear one page too early. This problem can
3304 % be solved using marks. In fact this is the whole reason the mark
3305 % mechanism was developed in \TeX. See section~\ref{sec:xmarks}.
3306 %
3307 % The same applies to other changes in the middle of a page, e.g., to change the page
3308 % numbering from roman to arabic (with \cs{pagenumbering}). For the same
3309 % reason \Cmd{thispagestyle\{mystyle\}} will not always work in the
3310 % middle of a page.
3311 %
3312 % Some of these changes can be accomplished by using the mark
3313 % mechanism as may be seen in \smartref{sec:change}{sec:scoop} and
3314 % \smartref{sec:change}{sec:xmarks}.
3315 %
3316 % In the remainder of this section we look at two different cases of
3317 % changing the page style in the middle of a page: changing the style of
3318 % the current page and changing the style of the next page.
3319 %
3320 % \subsection{Changing the page style of the current page}
3321 % \label{sec:curpagestyle}
3322 %
3323 % So now we are giving an example how to change the headers and footers,
3324 % only on the current page. In some cases this can be done by the
3325 % \CmdIndex{thispagestyle}%
3326 % \cs{thispagestyle} command. This changes the page style for the
3327 % ``current'' page only. But then we may be hit by the problem mentioned
3328 % above. \LaTeX{} may have a different idea about
3329 % the ``current'' page than you. The use of \cs{thispagestyle} is OK if
3330 % you can be sure that the text where the command \cs{thispagestyle} is
3331 % executed is the same page as where the surrounding text appears. So
3332 % for example directly after a \cs{chapter} command, or after a
3333 % \cs{newpage}. However, when the command is given near the end of a
3334 % page, \LaTeX{} may execute the command, and then decide that the page
3335 % is full and move the text that contains the command to the next page.
3336 % So now the page style is changed on one page earlier than was intended.
3337 %
3338 % A good solution to this problem is to put a label, like
3339 % \Cmd{label\{otherpagestyle\}} in the text where you want the different
3340 % page style, and then in the header and/or footer definitions compare
3341 % the page number with the label page number and choose the proper
3342 % value. For example, if we want to replace the section title on the
3343 % special page with ``MYFANCY SECTION'', like in
3344 % \begin{code}
3345 % \fancypagestyle{myfancy}{
3346 % \fancyhead[LE,RO]{MYFANCY SECTION}
3347 % }
3348 % \end{code}
3349 % \Example{25 (a)}
3350 % we define a new page style that makes the choice:
3351 % \PKGindex{ifthen}\PKGindex{refcount}
3352 % \begin{example}
3353 % \usepackage{ifthen}
3354 % \usepackage{refcount}
3355 % . . .
3356 % \fancypagestyle{switch}{
3357 % \fancyhead[LE,RO]{%
3358 % \ifthenelse{\value{page}=\getpagerefnumber{otherpagestyle}}
3359 % {MYFANCY SECTION}
3360 % {\textsl{\rightmark}}}
3361 % }
3362 % \end{example}
3363 % \CmdIndex{ifthenelse}
3364 % where \verb|\textsl{\rightmark}| is the normal value of the header
3365 % field from \Cmd{pagestyle\{fancy\}}.
3366 % Now we choose \Cmd{pagestyle\{switch\}} before our text, or even for
3367 % the whole document.
3368 %
3369 % There can still be some ambiguity on which page gets the different
3370 % header. For example, if the text says:
3371 % \begin{quote}
3372 % This page gets a different header than the surrounding pages.
3373 % \end{quote}
3374 % where do you put the \cs{label}? \LaTeX{} could break the page between
3375 % ``This'' and ``page'', and then would you want the special heading on
3376 % the page where ``This'' appears, or on the page where ``page''
3377 % appears. It depends on the positioning of the \cs{label} command.
3378 % Probably it is safer to make sure the sentence isn't broken. This can
3379 % be done by putting the text in a \cs{parbox} or \texttt{minipage} environment.
3380 % \begin{code}
3381 % \noindent
3382 % \begin{minipage}{\textwidth}
3383 % This page should have a different header than the surrounding pages.
3384 % \label{otherpagestyle}
3385 % It is done with the \verb|\pagestyle{switch}| command, that
3386 % has tests in the header field definitions. This chooses the actual
3387 % header depending on the page number.
3388 % \end{minipage}
3389 % \end{code}
3390 % The \cs{noindent} is necessary, otherwise the whole \texttt{minipage}
3391 % will be shifted right by the paragraph indentation.
3392 %
3393 % Note that you cannot reset the page style immediately after this code,
3394 % as this may still influence the current page. If you want to reset it,
3395 % for example to \Cmd{pagestyle\{fancy\}}, you must be sure that it
3396 % happens on a following page. But in this case it isn't even necessary,
3397 % as the special page style acts as the default on all pages except the
3398 % special page.
3399 %
3400 % The special header and footer in page~\pageref{showstruts}, which
3401 % show the struts are done in a similar way, although the header and
3402 % footer are a bit more elaborated there.
3403 % Also there is another complication there, as we also want to make both
3404 % \cs{headruleskip} and \cs{footrulewidth} dependent on the page number.
3405 % Unfortunately, this cannot be done with a simple \cs{ifthenelse}
3406 % \CmdIndex{ifthenelse}
3407 % command.
3408 % Both \cs{headruleskip} and \cs{footrulewidth} are eventually
3409 % used as length parameters, and this requires that they are
3410 % \emph{expandable}. However, the \cs{ifthenelse} construct is not
3411 % expandable, so you will get strange error messages if you use
3412 % something like
3413 % \begin{code}
3414 % %%% NOTE: This does not work %%%%
3415 % \renewcommand{\footrulewidth}{%
3416 % \ifthenelse{\value{page}=\getpagerefnumber{otherpagestyle}}{0.4pt}{0pt}%
3417 % }
3418 % \end{code}
3419 % \DescribeMacro{\fancyheadinit}
3420 % \DescribeMacro{\fancyfootinit}
3421 % \DescribeMacro{\fancyhfinit}
3422 % \phantomsection\label{sec:hfinit}
3423 % For cases like this \pkg{fancyhdr} version~4.0 and later has some
3424 % new commands \cs{fancyheadinit}, \cs{fancyfootinit} and \cs{fancyhfinit}.
3425 % \CmdIndex{fancyheadinit}
3426 %
3427 % With \Cmd{fancyheadinit\{\meta{code}\}} you can define some code that will be executed
3428 % just before the construction of the header. As it is executed in the
3429 % header, it can test the correct page number, because the counter
3430 % \texttt{page} is guaranteed to have the correct value in the headers
3431 % and footers. Similarly, the code in \Cmd{fancyfootinit\{\meta{code}\}} is executed in
3432 % \CmdIndex{fancyfootinit}
3433 % the footer. And \Cmd{fancyhfinit\{\meta{code}\}} sets its code for both the header
3434 % \CmdIndex{fancyhfinit}
3435 % and the footer. Now we can set for example \cs{headruleskip} or
3436 % \cs{footrulewidth} depending on the page number. So instead of putting
3437 % the test inside the definition of \cs{headruleskip}, we can put it
3438 % outside, and then we can use the command \cs{ifthenelse}. So we put
3439 % the following in \Cmd{pagestyle\{switch\}}\footnote{Assuming we have
3440 % already loaded package \PKGindex{refcount}\pkg{refcount}.}:
3441 % \begin{code}
3442 % \fancyheadinit{%
3443 % \ifthenelse{\value{page}=\getpagerefnumber{otherpagestyle}}
3444 % {\renewcommand{\headruleskip}{4pt}}
3445 % {\renewcommand{\headruleskip}{0pt}}
3446 % }
3447 % \fancyfootinit{%
3448 % \ifthenelse{\value{page}=\getpagerefnumber{otherpagestyle}}
3449 % {\renewcommand{\footrulewidth}{0.4pt}}
3450 % {\renewcommand{\footrulewidth}{0pt}}
3451 % }
3452 % \end{code}
3453 % Now here is the definition of the page style used for page~\pageref{showstruts}.
3454 % \Example{25 (b)}
3455 % \begin{example}
3456 % \fancypagestyle{showstruts}{%
3457 % \fancyhead[L]{%
3458 % \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
3459 % {\strutheader}%
3460 % {\rightmark}%
3461 % }
3462 % \fancyfoot[L]{%
3463 % \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
3464 % {\strutfooter}%
3465 % {}%
3466 % }
3467 % \fancyheadinit{%
3468 % \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
3469 % {\renewcommand{\headruleskip}{4pt}}%
3470 % {\renewcommand{\headruleskip}{0pt}}%
3471 % }
3472 % \fancyfootinit{%
3473 % \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
3474 % {\renewcommand{\footrulewidth}{0.4pt}}%
3475 % {\renewcommand{\footrulewidth}{0pt}}%
3476 % }
3477 % }
3478 % \end{example}
3479 % The label used on that page is \texttt{showstruts}. \cs{strutheader}
3480 % and \cs{strutfooter} are macros that contain the code to draw these
3481 % pictures. In this example the values for \cs{headruleskip} and
3482 % \cs{footrulewidth} in the \emph{else} case are the same as the global
3483 % values. So we could have left these \emph{else} parts empty. Then they
3484 % would keep the global values.
3485 % However, often explicit is better than implicit.
3486 %
3487 % These initialisation commands cannot be used to make global changes to
3488 % the page, for example to \cs{headheight}. Neither can you use them to
3489 % change \cs{fancyhead} or \cs{fancyfoot}, because these have already
3490 % been set up. But you can use it to set the color and font of the
3491 % header and/or footer, for example to get large, red text in the
3492 % headers and footers on this specific page:
3493 % \begin{code}
3494 % \fancyhfinit{%
3495 % \ifthenelse{\value{page}=\getpagerefnumber{otherpagestyle}}
3496 % {\color{red}\Large}
3497 % {}
3498 % }
3499 % \end{code}
3500 %
3501 % \subsection{Changing the page style of the next page}
3502 % \label{sec:nextpagestyle}
3503 %
3504 % If you want the change of the page style to take effect
3505 % at the next page you must make sure that the current page is finished. In
3506 % most cases this can be done by issuing a
3507 % \CmdIndex{clearpage}\CmdIndex{newpage}%
3508 % \cs{newpage} or \cs{clearpage} command before % any changes. However,
3509 % this will immediately end the current page, possibly leaving you with a
3510 % half-empty page, which may be undesirable.
3511 %
3512 % If this is not what you want, you can use the
3513 % \PKGindex{afterpage}%
3514 % \pkg{afterpage} package with:\\[1ex]
3515 % \CmdIndex{afterpage}\Cmd{afterpage\{}\Cmd{fancyhead[L]\{new value\}\}} or\\
3516 % \CmdIndex{pagenumbering}\Cmd{afterpage\{}\Cmd{pagenumbering\{roman\}\}}.
3517 % \\[1ex]
3518 % You cannot use \cs{afterpage}
3519 % to change the \cs{pagestyle} as the commands issued by \cs{afterpage}
3520 % are local in a group, and the \cs{pagestyle} command makes only local
3521 % changes. The \cs{pagenumbering} and the \cs{thispagestyle}
3522 % command make global changes, as well as changes to \LaTeX's counters,
3523 % such as \cs{setcounter} and \cs{addtocounter}.
3524 % So these can be used\footnote{In \pkg{fancyhdr} version~3 and
3525 % earlier the commands like \cs{fancyhead} and \cs{fancyfoot} also made
3526 % global changes. This is no longer the case in version~4.0 and later.}.
3527 % Here is an example to change the page style of the next page with \cs{afterpage}:
3528 %
3529 % \Example{26}
3530 % \begin{example}
3531 % \usepackage{afterpage}
3532 % \usepackage{fancyhdr}
3533 % \fancypagestyle{myfancy}{
3534 % \fancyhead[LE,RO]{\textbf{MYFANCY SECTION}}
3535 % \fancyhead[LO,RE]{\textbf{MYFANCY CHAPTER}}
3536 % \fancyfoot[C]{\textbf{--~\thepage~--}}
3537 % }
3538 % . . .
3539 % \afterpage{\thispagestyle{myfancy}}
3540 % \end{example}
3541 % Then the page after this code will have the page style \texttt{myfancy}.
3542 %
3543 % \subsection{Changing the page style in a \TeX{} group}
3544 % \label{sec:change-group}
3545 %
3546 % Special care has to be taken when you change the page style inside a
3547 % \TeX{} group. This can be any environment, text between
3548 % \cs{begingroup} and \cs{endgroup}, between \{~and~\}, and other
3549 % similar situations. \TeX{} definitions inside such a group are local
3550 % to this group, unless they are declared to be global. All
3551 % definitions pertaining to the page style (i.e., \cs{fancypagestyle},
3552 % \cs{pagestyle}, \cs{fancyhead}, etc.) are local definitions, i.e.,
3553 % they disappear at the end of the group. The only
3554 % exception is \cs{thispagestyle}, which is global, i.e., its setting
3555 % survives the end of the group.
3556 %
3557 % An example is the \env{appendices} environment of the package
3558 % \PKGindex{appendix}\pkg{appendix}\footnote{Use the command `\texttt{texdoc appendix}' to
3559 % see its documentation.} that you use to get special layout for your
3560 % appendices. If you also want to change the page headers and/or footers
3561 % for the appendices, you could use
3562 % \begin{code}
3563 % \clearpage
3564 % \begin{appendices}
3565 % \pagestyle{appendices}
3566 % \chapter{My Appendix}
3567 % Appendix text.
3568 % \end{appendices}
3569 % \chapter*{Bibliograpy}
3570 % \end{code}
3571 % Note that we put a \cs{clearpage} before the environment to prevent
3572 % that the page before this environment gets the new page style, as
3573 % indicated in sections~\ref{sec:curpagestyle} and \ref{sec:nextpagestyle}.
3574 % In the example above, it is probable that the \texttt{appendices}
3575 % environment does not end with a \verb|\newpage| or \verb|\clearpage|.
3576 % Then a page break will be given by the following \verb|\chapter|
3577 % command, but then the `Special' page style will no longer be current,
3578 % so the last page of the \texttt{appendices} environment will have the
3579 % headers and footers that were current before the environment started.
3580 % If there were still floats to be output at the end of the
3581 % \texttt{appendices} environment, this could even be several pages. So
3582 % we should put a \verb|\clearpage| before the \verb|\end{appendices}|.
3583 %
3584 % \smallskip
3585 %
3586 % Here follows a more stylized example. The intention is to give the
3587 % pages of the environment the header ``Special Header''. First, the
3588 % ``wrong'' implementation.
3589 % \Example{26G}[(a)]
3590 % \begin{example}
3591 % \fancypagestyle{Special}{
3592 % % setting the header in beginning of environment
3593 % \fancyhead[C]{Special Header}
3594 % }%
3595 %
3596 % \newenvironment{Special}[1]{%
3597 % \pagestyle{Special}%
3598 % \section*{Special Environment #1}
3599 % }{%
3600 % }
3601 % ...
3602 % \begin{Special}{a}
3603 %
3604 % Some text or a lot of text.
3605 %
3606 % \end{Special}
3607 % \end{example}
3608 % Now the last page of this environment, which may be the first page if
3609 % the environment fits on one page, will get the wrong page header.
3610 %
3611 % The first solution would be to end the environment with a \cs{newpage}
3612 % or \cs{clearpage} as described above. Generally, it is best to use
3613 % \cs{clearpage}, because it also takes care of extra pages with floats.
3614 % \Example{26G}[(b)]
3615 % \begin{example}
3616 % \begin{Special}{b}
3617 %
3618 % Some text or a lot of text.
3619 %
3620 % \clearpage
3621 % \end{Special}
3622 % \end{example}
3623 % It is also possible to add the \cs{clearpage} to the definition of the
3624 % \env{Special} environment if you define this environment yourself. If
3625 % you use an existing environment you may use a \LaTeX{} environment
3626 % hook to inject a \cs{clearpage}, for example in the case of the
3627 % \env{appendices} environment:
3628 % \begin{code}
3629 % \AddToHook{env/appendices/end}{\clearpage}
3630 % \end{code}
3631 %
3632 % Of course this will always cause a page break. If you don't want a
3633 % page break at the
3634 % end of your environment, you will have to decide
3635 % what to do with the page that is partially filled with the special
3636 % environment and partially with the following text. Which page style to
3637 % use: the Special page style or the normal page style? If you do
3638 % nothing it will be the normal page style. If you still want the
3639 % Special page style, you can put a \Cmd{thispagestyle\{Special\}} at
3640 % the end of the environment. Again, at the use of the environment, at
3641 % the definition, or using a hook.
3642 % \Example{26G}[(c)]
3643 % \begin{example}
3644 % \begin{Special}{c}
3645 %
3646 % Some text or a lot of text.
3647 %
3648 % \thispagestyle{Special}
3649 % \end{Special}
3650 % \end{example}
3651 % Note, however, that this only works if the \texttt{Special} page style
3652 % is defined outside of the environment, as is done in this example.
3653 % However if the \texttt{Special} page style was defined inside the environment,
3654 % it will have disappeared at the end of the page, and \LaTeX{} will
3655 % silently ignore it. It doesn't even give an error message. The
3656 % following pages will then get the normal header again.
3657 %
3658 % \section{\pkg{Fancyhdr} hooks}
3659 % \label{sec:hooks}
3660 %
3661 % \LaTeX{} has a system of \emph{hooks}\index{hooks} since the 2020/10/01 release.
3662 % This allows packages and classes (and other \LaTeX{} software) to
3663 % define points in its code where other \LaTeX{} code can insert a piece
3664 % of code. For more details, see \emph{The \LaTeX{} Companion, Third
3665 % Edition}, part I, pp. 671 ff. or the documentation that can be read
3666 % with the command `\texttt{texdoc lthooks-doc}'.
3667 %
3668 % \pkg{Fancyhdr} version 4.5 or later defines a number of hooks to be executed at the
3669 % beginning or end of the header and/or footer, if your \LaTeX{} version
3670 % supports it. The hooks are defined in
3671 % mirrored pairs, which means the second one of the pair is executed in the
3672 % reverse order compared to the first one (see the hooks documentation).
3673 % \begin{description}
3674 % \item[\texttt{fancyhdr/before}, \texttt{fancyhdr/after}]
3675 % \TTindex{fancyhdr/before}\TTindex{fancyhdr/after}
3676 % these are executed before the
3677 % header or footer is constructed, and after the header or footer is
3678 % finished, respectively.
3679 % \item[\texttt{fancyhdr/head/begin}, \texttt{fancyhdr/head/end}]
3680 % \TTindex{fancyhdr/head/begin}\TTindex{fancyhdr/head/end}
3681 % these are run at the
3682 % beginning and the end of the header construction, respectively
3683 % \item[\texttt{fancyhdr/foot/begin}, \texttt{fancyhdr/foot/end}]
3684 % \TTindex{fancyhdr/foot/begin}\TTindex{fancyhdr/foot/end}
3685 % these are run at the
3686 % beginning and the end of the footer construction, respectively
3687 % \end{description}
3688 %
3689 % The interaction of the hooks and the \cs{fancyhfinit} code described
3690 % on page~\pageref{sec:hfinit} in section~\ref{sec:hfinit} with the
3691 % construction of the header and footer is as follows: for the header
3692 % construction
3693 % \begin{itemize}
3694 % \item first the \texttt{fancyhdr/before} hooks are run, then the
3695 % \texttt{fancyhdr/head/begin} hooks, then the \cs{fancyheadinit} code.
3696 % Then the header is constructed. Finally, the
3697 % \texttt{fancyhdr/head/end} hooks are run followed by the
3698 % \texttt{fancyhdr/after} hooks.
3699 % \item For the construction of the footer, it is similar, just replace
3700 % \texttt{head} by \texttt{foot}.
3701 % \item Note that between the construction of the header and the footer,
3702 % \LaTeX{} builds the body of the page. This process consists mainly of
3703 % putting boxes next to each other, and \pkg{fancyhdr} does not
3704 % interfere with this, and neither should the hook code.
3705 % \end{itemize}
3706 %
3707 % The reason there are separate \texttt{fancyhdr/before} and
3708 % \texttt{fancyhdr/after} hooks and the \texttt{head} and \texttt{foot}
3709 % hooks, is
3710 % \begin{enumerate}
3711 % \item If you want to use the same hooks for headers and footers, use
3712 % the \texttt{fancyhdr/before} and \texttt{fancyhdr/after} hooks. This
3713 % prevents you to have to specify the same hook code twice.
3714 % \item If you want to have different hooks for the header and footer,
3715 % use the \texttt{head} and \texttt{foot} hooks.
3716 % \end{enumerate}
3717 % The \texttt{after} and \texttt{end} hooks are meant to undo changes
3718 % made in the \texttt{before} and \texttt{begin} hooks, respectively. If
3719 % the hooks make only local changes (which is recommended), the \TeX{}
3720 % grouping mechanism will take care of this, so you can leave out the
3721 % \texttt{after} and \texttt{end} hooks in that case.
3722 %
3723 % At first sight it may seem that the \cs{fancyhfinit} mechanism is no
3724 % longer useful with the introduction of hooks. One reason it exists is
3725 % that hooks were not available at the time it was introduced, and for
3726 % compatibility reasons it remains. However, there are some significant
3727 % differences between the \cs{fancyhfinit} mechanism and the hook
3728 % mechanism, so you should choose carefully which one to use.
3729 % \begin{itemize}
3730 % \item Hooks are global, but the \cs{fancyhfinit} declarations are
3731 % local. That is, if \cs{fancyhfinit} (or its siblings
3732 % \cs{fancyheadinit} or \cs{fancyfootinit}) are given in a \TeX{}
3733 % group, they last until the end of the group. They will disappear
3734 % outside of the group, or be reset to the value they had outside of the group.
3735 % \item \cs{fancyhfinit} is meant to be used by the user who writes the
3736 % document, i.e., it is meant for the current document.
3737 % \cs{fancyhfinit} \emph{should not be used by package or class writers
3738 % and similar. They should use the hooks mechanism.} On the other hand
3739 % the user can also use hooks in the document instead of, or in addition
3740 % to the \cs{fancyhfinit} mechanism.
3741 % \item Hooks can be added multiple times, but the \cs{fancyhfinit} code
3742 % can only be given once (i.e., a new one overwrites the previous one).
3743 % \item The \cs{fancyhfinit} code is stored in a \emph{closed} page
3744 % style (see section~\ref{sec:fancypagestyle}). Hooks are not.
3745 % \item \cs{fancyhfinit} has no corresponding \texttt{exit} function, so
3746 % if you need some code to be executed after the construction of the header or
3747 % footer, you have to use hooks.
3748 % \item The hooks can also be given if \pkg{fancyhdr} is not used.
3749 % This can be used as a precautionary measure in packages and classes
3750 % that may have a bad interaction with \pkg{fancyhdr} otherwise. If
3751 % \pkg{fancyhdr} is not used in a document, the hooks don't do anything.
3752 % \end{itemize}
3753 %
3754 % \begin{fblock}
3755 % \textbf{NOTE:} In \pkg{fancyhdr} version 4.3 and later, paragraph
3756 % hooks will not work inside \pkg{fancyhdr} headers and footers to
3757 % avoid unwanted interactions with the main text.
3758 % However, in version 5.1 and later, the hooks defined in the main text
3759 % will still be disabled in the headers and footers. But it is possible
3760 % to use paragraph hooks locally in headers and footers. Se the example below.
3761 %
3762 % \textbf{NOTE: This is experimental and may change in the future.}
3763 % \end{fblock}
3764 % \NoExample{parahooks}
3765 % \begin{example}
3766 % \AddToHook{fancyhdr/before}{%
3767 % \AddToHook{para/begin}{XXXX}%
3768 % }
3769 % \end{example}
3770 %
3771 % \section{Headers and footers induced by the text}
3772 % \label{sec:xmarks}
3773 %
3774 % We have seen how we can use \LaTeX's marks to get information from the
3775 % document contents to the headers and footers. The marks mechanism is the
3776 % only reliable mechanism that you can use to get changing information to the
3777 % headers or footers. This is because \LaTeX{} may be processing your document
3778 % ahead before deciding to break the page.
3779 %
3780 % Sometimes the two marks that \LaTeX{} offers are not enough. An example is
3781 % the following:
3782 % \begin{quote}
3783 % If a solution to an exercise goes across a page break, then I would like
3784 % to have ``(Continued on next page\ldots)'' at the bottom of the
3785 % \index{Continued\ldots}
3786 % first page and ``(Continued\ldots)'' at the top in the margin of the next page.
3787 % \end{quote}
3788 %
3789 % You cannot use \LaTeX's mark mechanisms for this if you also want to use
3790 % chapter and section information.
3791 %
3792 % The \pkg{extramarks} package gives you
3793 % two extra marks that can be used in this situation.
3794 % Here is a way to use this package:
3795 %
3796 % \Example{27}
3797 % \begin{example}
3798 % \usepackage{extramarks}
3799 % ...
3800 % \pagestyle{fancy}
3801 % \fancyhead[L]{\firstleftxmark} % = \firstxmark
3802 % \fancyfoot[R]{\lastrightxmark} % = \lastxmark
3803 % \fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrule}{}}
3804 % ...
3805 % \extramarks{}{}% 1
3806 % \extramarks{Continued\ldots}{Continued on next page\ldots}% 2
3807 % ...
3808 % Some text that may or may not cross a page boundary...
3809 % ...
3810 % \extramarks{Continued\ldots}{}% 3
3811 % \extramarks{}{}% 4
3812 % \end{example}
3813 %
3814 % \CmdIndex{extramarks}
3815 % Note that we redefine the \texttt{plain} page style, so that on the
3816 % first page of a chapter also the footer will be given if necessary. We
3817 % assume that a `Continued' block will not cross chapter boundaries, so no
3818 % header will be necessary on these pages.
3819 % Also the \cs{extramarks} command must be close to the text, i.e., no
3820 % empty lines (paragraph boundaries) should intervene. Otherwise the page may
3821 % be broken at that boundary and the \texttt{extramarks} would come on the wrong page.
3822 %
3823 % Explanation: There are two new marks that can be used in the page layout with this
3824 % package: If commands of the form
3825 % \verb|\extramarks{|$m_1$\verb|}{|$m_2$\verb|}| are given
3826 % \CmdIndex{firstxmark}
3827 % \CmdIndex{lastxmark}
3828 % \cs{firstxmark} gives you the first $m_1$ value and
3829 % \cs{lastxmark} gives you the last $m_2$ value
3830 % of the current page. In the above example, when the complete block
3831 % falls on the same page, the \cs{firstxmark} will be the empty
3832 % parameter of the first \cs{extramarks} command (indicated by
3833 % \texttt{\%~1}), and
3834 % the \cs{lastxmark} will be the empty parameter from the last
3835 % \cs{extramarks} command (indicated by \texttt{\%~4}).
3836 %
3837 % However, when the page break falls inside the block, the mark generated by
3838 % \texttt{\%~2} will be the last one on the first page. Therefore on that page
3839 % \cs{lastxmark} will be `Continued on next page\ldots'. On the following
3840 % pages, there are two possibilities: (1) when the block ends
3841 % on that page the first mark will be \texttt{\%~3}, therefore
3842 % \cs{firstxmark} will be `Continued\ldots'; (2) the block ends at a
3843 % later page, therefore it does not contribute any marks to that page,
3844 % and the marks are `inherited' from the last values of the previous page,
3845 % i.e., those from \texttt{\%~2}.
3846 % On all of the pages after the block the values of \texttt{\%~4} will be used,
3847 % i.e., empty ones.
3848 % This final \verb+\extramarks{}{}+ is to prevent the `Continued\ldots'
3849 % header to spill over to the following pages.
3850 % Of course in real life you would leave out the numbers.
3851 %
3852 % In case you want the last $m_1$ value or the first $m_2$ value, you
3853 % can use the \cs{lastleftxmark} or \cs{firstrightxmark}, respectively.
3854 % For symmetry reasons there are also commands \cs{firstleftxmark}
3855 % (=\cs{firstxmark}), \cs{lastrightxmark} (=\cs{lastxmark}),
3856 % \cs{topleftxmark} (=\cs{topxmark}) and \cs{toprightxmark}. The
3857 % top-marks are basically the last-marks of the previous page.
3858 % \CmdIndex{lastleftxmark}
3859 % \CmdIndex{firstrightxmark}
3860 % \CmdIndex{firstleftxmark}
3861 % \CmdIndex{lastrightxmark}
3862 % \CmdIndex{topleftxmark}
3863 % \CmdIndex{toprightxmark}
3864 %
3865 % The package also gives you the \cs{firstleftmark} and \cs{lastrightmark}
3866 % commands that complement the standard \LaTeX{} marks.
3867 % \CmdIndex{firstleftmark}
3868 % \CmdIndex{lastrightmark}
3869 %
3870 % \medskip
3871 %
3872 % In the above example the text ``Continued'' appears in the page header. It
3873 % \index{margin}
3874 % may be nicer to put it in the margin. This can be easily
3875 % accomplished by positioning it at a fixed place relative to the page header.
3876 % In plain \TeX{} you would use a concoction of \Cmd{hbox to 0pt},
3877 % \Cmd{vbox to 0pt}, \cs{hskip},\cs{vskip}, \cs{hss} and
3878 % \cs{vss} but fortunately
3879 % \LaTeX's \texttt{picture} environment gives a much cleaner way to do this.
3880 % In order not to disturb the normal header layout we put the text in a zero-sized
3881 % \texttt{picture}. Generally this is the best way to position things on fixed
3882 % places on the page. You can then also use the normal headings. See also
3883 % section~\ref{sec:thumb} for another example of
3884 % this technique.
3885 %
3886 % \Example{28}
3887 % \TTindex{picture}
3888 % \begin{example}
3889 % \fancyhead[L]{\setlength{\unitlength}{\baselineskip}%
3890 % \begin{picture}(0,0)
3891 % \put(-2,-3){\makebox(0,0)[r]{\firstxmark}}
3892 % \end{picture}\rightmark} % \rightmark = section title
3893 % \end{example}
3894 %
3895 % This solution can of course also be used for the footer. Make sure you put the
3896 % \texttt{picture} as the first thing in left-handside entries and last in right-handside
3897 % ones.
3898 %
3899 % \medskip
3900 %
3901 % Finally you may want to put ``(Continued\ldots)'' in the \emph{text}
3902 % rather than in the header or the margin. Then you have to use the
3903 % \PKGindex{afterpage}%
3904 % \pkg{afterpage} package. We also decide to make a separate
3905 % environment \env{continued} for it\footnote{In the example files for
3906 % examples 27 and 28 this is also done; it is just not documented here.}.
3907 %
3908 % The first thought might be to use
3909 % \cs{afterpage}\texttt{\{\cs{firstxmark}\}}. But the marks can only be
3910 % used in the headers and footers, not in the running text%
3911 % \footnote{NOTE: This used to be different in \pkg{extramarks} version 4 and earlier.}.
3912 % Moreover, we
3913 % need the value that will become \cs{firstxmark} (=\cs{firstleftxmark})
3914 % on the next page, but on the current page it will be in \cs{lastleftxmark}.
3915 %
3916 % Then you might think that the \cs{afterpage} command could be put in
3917 % a header or footer, but unfortunately it appears that then the timing is wrong.
3918 % The \cs{afterpage} text will appear one page too late.
3919 %
3920 % So what we do is, we put the \cs{lastleftxmark} in a variable during the
3921 % footer processing and then use this variable in \cs{afterpage}. As the
3922 % footer processing is done inside a \TeX{} group, we must use a global
3923 % definition. Also the mark must be expanded so that we get the contents
3924 % of the mark in our variable and not just the name. We can do this with
3925 % the primitive \TeX{} command \cs{xdef}. There is no \LaTeXe{} command
3926 % for this.
3927 %
3928 % First we give a simple (but
3929 % incomplete) solution.
3930 %
3931 % \NoExample{Incomplete!}
3932 % \begin{example}
3933 % \newcommand\ContiText{}
3934 % \fancyhead[L]{Example 29a}
3935 % \fancyhead[R]{\rightmark}
3936 % \fancyfoot[R]{\lastrightxmark}
3937 % \fancyfoot[L]{\xdef\ContiText{\lastleftxmark}}
3938 %
3939 % \newenvironment{continued}{%
3940 % \par
3941 % \extramarks{}{}%
3942 % \extramarks{\noindent Continued\ldots\\[1ex]}%
3943 % {Continued on next page\ldots}%
3944 % \afterpage{\ContiText}%
3945 % \ignorespaces
3946 % }{%
3947 % \unskip
3948 % \extramarks{\noindent Continued\ldots\\[1ex]}{}%
3949 % \extramarks{}{}\par
3950 % }
3951 % \end{example}
3952 %
3953 % The header contains document information: the name of the document on
3954 % the left and the section title on the right. The footer contains the
3955 % ``Continued'' information like in the previous examples. The
3956 % \cs{extramarks} contain essentially the same information as in the
3957 % previous examples, just formatted a little differently.
3958 % But the \Cmd{...leftxmark} is not put in the header, but is eventually used as
3959 % the argument in \cs{afterpage} so that it will appear at the top of the
3960 % next page body. This is also the reason for the \verb|\\[1ex]|, to
3961 % separate it from the rest of the page text.
3962 %
3963 % Note how we use \cs{ignorespaces}, \cs{unskip} and \texttt{\%} to
3964 % prevent unwanted spaces to creep into the text.
3965 %
3966 % However, there are some problems with this simple solution:
3967 % \begin{enumerate}
3968 % \item If the block spans more than one page boundary, the
3969 % \cs{afterpage} is not repeated on the following page breaks
3970 % (\cs{afterpage} only applies to the next page). So on
3971 % these pages the ``Continued'' header will be missing.
3972 %
3973 % We can solve this by repeating the \cs{afterpage} command in the
3974 % \cs{afterpage} text. To do this we have to put it in a macro
3975 % (\texttt{AP} stands for \texttt{afterpage}):
3976 % \begin{code}
3977 % \newcommand{\setAP}{\afterpage{\ContiText\setAP}}
3978 % \end{code}
3979 % There is a disadvantage that the \cs{afterpage} will be continued on
3980 % all pages after the block has ended. But as \cs{lastleftxmark} will be
3981 % empty then, no harm will be done. However, the following subsection (\ref{sec:afterpage2})
3982 % will give a solution that stops this repetition.
3983 % \item If the page break comes out such that the beginning of the block
3984 % is pushed to the next page, but the \cs{afterpage} is given while
3985 % \LaTeX{} was still at the previous page, the \cs{afterpage} text will
3986 % be inserted before the block begins.
3987 %
3988 % Fortunately the \cs{lastleftxmark} on this page is empty, so the
3989 % \cs{afterpage} on this page is essentially harmless, and because we have it made
3990 % repeating by the previous point, it will be picked up at the
3991 % proper place.
3992 % \item If there is more than one \env{continue} block on the same
3993 % page (with the last one crossing the page boundary) there will be an
3994 % \cs{afterpage} for each block, thereby repeating the ``Continued''
3995 % text multiple times at the top of the page. Therefore we should start
3996 % the \cs{afterpage} only once, not once for each block. As the
3997 % \cs{afterpage} is repeated on each page by the previous solution we
3998 % don't need multiple starts of \cs{afterpage}.
3999 %
4000 % We could do this by inserting the \cs{afterpage} command before the
4001 % first block instead of inside it, but that is error-prone.
4002 %
4003 % The solution is to define a command \cs{startAP} that sets the
4004 % \cs{afterpage} command, and then redefines itself do do nothing.
4005 % Because the \cs{startAP} is called inside a \TeX{} group (the
4006 % \env{continued} environment) we must do a \emph{global} redefine.
4007 % \LaTeXe{} does not have a command for this, so we use the low-level
4008 % \TeX{} command \cs{gdef} for this.
4009 % \begin{code}
4010 % \newcommand{\startAP}{\setAP\gdef\startAP{}}
4011 % . . .
4012 % \newenvironment{continued}{%
4013 % . . .
4014 % \startAP
4015 % } . . .
4016 % \end{code}
4017 % \end{enumerate}
4018 %
4019 % We also put some thick black rules around the environment.
4020 % And because the text for the left mark is used twice we put that in
4021 % a macro \cs{LM}. The order of the commands is chosen such that the
4022 % `Continued' marks don't go to the wrong page.
4023 % This makes the total solution like this:
4024 %
4025 % \Example{29a}
4026 % \begin{example}
4027 % \newcommand\ContiText{}
4028 % \newcommand{\LM}{\noindent\hl{Continued from previous page\ldots}\\[1ex]}
4029 % \newcommand{\setAP}{\afterpage{\ContiText\setAP}}
4030 % \newcommand{\startAP}{\setAP\gdef\startAP{}}
4031 %
4032 % \fancyhead[L]{Example 29a}
4033 % \fancyhead[R]{\rightmark}
4034 % \fancyfoot[R]{\lastrightxmark}
4035 % \fancyfoot[L]{\xdef\ContiText{\lastleftxmark}}
4036 %
4037 % \newenvironment{continued}{%
4038 % \par\startAP
4039 % \extramarks{}{}%
4040 % \noindent\rule{\textwidth}{1mm}%
4041 % \extramarks{\LM}{Continued on next page\ldots}%
4042 % \\*\ignorespaces
4043 % }{%
4044 % \unskip\noindent\rule{\textwidth}{1mm}%
4045 % \extramarks{\LM}{}%
4046 % \extramarks{}{}\par
4047 % }
4048 % \end{example}
4049 %
4050 % \subsection{More sophisticated solutions}
4051 % \label{sec:afterpage2}
4052 %
4053 % In this subsection we present some more sophisticated, and therefore
4054 % a little more tricky solutions and variations to the previous example.
4055 % If you want to avoid that trickery, you can just skip this subsection.
4056 %
4057 % First we change the example such that the sequence of \cs{afterpage}
4058 % invocations will stop as soon as possible. We do this by not using a
4059 % fixed text as argument for \cs{afterpage} but by using a macro \cs{APcommand}
4060 % as argument. When we want to stop the sequence of \cs{afterpage} calls,
4061 % we make this macro empty. To get a proper timing we reset this macro
4062 % in the right-hand footer field when this is empty, which indicates that
4063 % we are outside of a `Continued' block.
4064 %
4065 % We must then take care of restarting the \cs{afterpage} sequence when
4066 % a new `Continued' block is started, and making sure that we don't get
4067 % more than one such sequence activated. We do this by changing
4068 % \cs{startAP} such that it only start an \cs{afterpage} if
4069 % \cs{APcommand} is empty.
4070 %
4071 % \Example{29b}
4072 % \newcommand{\R}{\color{red}}
4073 % \begin{example}[numbers=left,numbersep=1pt,commandchars=|\(\)]
4074 % \newcommand\ContiText{}
4075 % \newcommand*{\LM}{\noindent Continued from previous page\ldots\\[1ex]}
4076 % |R\newcommand*{\APcommand}{}|label(line:apcommand)
4077 % |R\newcommand*{\setAPcommand}{\gdef\APcommand{\ContiText\setAP}}|label(line:set)
4078 % |R\newcommand*{\clearAPcommand}{\gdef\APcommand{}}|label(line:clr)
4079 % |R\newcommand*{\setAP}{\afterpage{\APcommand}}|label(line:setap)
4080 % |R\newcommand*{\startAP}{\ifx\APcommand\empty\setAPcommand\setAP\fi}|label(line:startap)
4081 %
4082 % \fancyhead[L]{Example 29b}
4083 % \fancyhead[R]{\rightmark}
4084 % \fancyfoot[R]{\lastrightxmark}
4085 % \fancyfoot[L]{\xdef\ContiText{\lastleftxmark}}
4086 % \fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrule}{}}
4087 %
4088 % \newenvironment{continued}{%
4089 % \par\startAP
4090 % \extramarks{}{}%
4091 % \noindent\rule{\textwidth}{1mm}%
4092 % \extramarks{\LM}{Continued on next page\ldots}%
4093 % \\*\ignorespaces
4094 % }{%
4095 % \unskip\noindent\rule{\textwidth}{1mm}%
4096 % \extramarks{\LM}{}%
4097 % |R \extramarks{}{\protect\clearAPcommand}\par|label(line:callclr)
4098 % }
4099 % \end{example}
4100 %
4101 % We have numbered the lines for easy reference. The changes are in
4102 % the red lines (\ref{line:apcommand}--\ref{line:startap} and \ref{line:callclr}). \\
4103 % \ref{line:apcommand}.~Here we define \cs{APcommand}.\\
4104 % \ref{line:set},~\ref{line:clr}.~These are commands to set en clear \cs{APcommand}, respectively.\\
4105 % \ref{line:setap}.~The \cs{afterpage} now uses \cs{APcommand} as argument.\\
4106 % \ref{line:startap}.~\cs{startAP} now checks if \cs{APcommand} is empty, and if it is,
4107 % it first fills \cs{APcommand} with the required value and then starts a
4108 % new \cs{afterpage} (with the \cs{setAP} command).
4109 % When \cs{APcommand} is not empty this means that an \cs{afterpage} is
4110 % already active.\\
4111 % \ref{line:callclr}.~In the right part of the marks we now call \cs{clearAPcommand} to
4112 % clear our variable \cs{APcommand}. This effectively stops the
4113 % \cs{afterpage} sequence.
4114 %
4115 % \textbf{Note 1.} We use \cs{gdef} to change \cs{APcommand} because
4116 % these occur inside a \TeX{} group (\env{continued} environment and
4117 % footer). With \cs{renewcommand} they would be local to these groups
4118 % but we need them outside of these groups, therefore we use \cs{gdef}
4119 % to make the change globally.
4120 %
4121 % \textbf{Note 2.} We define \cs{APcommand} with \cs{newcommand*} rather
4122 % than \cs{newcommand} to make it compatible with \cs{gdef}. Without the
4123 % \texttt{*} it would be compatible with \cs{long}\cs{gdef}, but then it
4124 % would not compare equal to \cs{empty} in line \ref{line:startap}. For the other
4125 % definitions it does not make a difference, but it looks nicer to also use
4126 % it there.
4127 %
4128 % \textbf{Note 3.} In line \ref{line:callclr} we use \cs{protect} to
4129 % delay the expansion of \cs{clearAPcommand}. The marks in
4130 % \cs{extramarks} are expanded at the time they are given, so that they
4131 % can pick up section numbers and titles and similar information at that
4132 % point. However, \cs{clearAPcommand} should not be expanded at that
4133 % moment, but when it is used in the footer. That is exactly what
4134 % \cs{protect} does.
4135 %
4136 % \textbf{Note 4.} We test the value of \cs{APcommand} with \cs{ifx},
4137 % not with \cs{ifthenelse} from the \PKGindex{ifthen}\pkg{ifthen} package. The
4138 % latter completely expands its parameters, and because \cs{APcommand}
4139 % has a recursive definition when it is not empty, that would cause
4140 % \TeX{} to fail. We only want to check the definition of
4141 % \cs{APcommand}, not its expansion.
4142 %
4143 % \textbf{Note 5.} For debugging we can add some text in the
4144 % \cs{afterpage} command in line \ref{line:setap}, to see the difference between an
4145 % empty \cs{afterpage} and no \cs{afterpage} at all.
4146 % Similarly we can add some text in the footer in line \ref{line:callclr}, to see where
4147 % the \cs{clearAPcommand} is called.
4148 %
4149 % \subsubsection*{Another use}
4150 %
4151 % If you would need the information further on in the page you must
4152 % remember the state of the marks in your own variable. You can set this
4153 % in one of the \pkg{fancyhdr} header or footer fields, like in
4154 % example 29a. For example
4155 % if you want to add something \emph{after} the broken block of text you
4156 % can use the following:
4157 %
4158 % \Example{29c}
4159 % \begin{example}
4160 % \newcommand{\ContiText}{}
4161 % \fancyhead[L]{Example 29c}
4162 % \fancyhead[R]{\rightmark}
4163 % \fancyfoot[R]{\lastrightxmark}
4164 % \fancyfoot[L]{\xdef\ContiText{\lastleftxmark}}
4165 % \fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrule}{}}
4166 %
4167 % \newenvironment{continued}{%
4168 % \par
4169 % \extramarks{}{}%
4170 % \noindent\rule{\textwidth}{1pt}%
4171 % \extramarks{\\[1ex]\noindent\textbf{[Continued
4172 % from previous page]}}{Continued on next page\ldots}%
4173 % \\*\ignorespaces
4174 % }{%
4175 % \unskip\noindent\rule{\textwidth}{1pt}%
4176 % \extramarks{}{}%
4177 % \ContiText\par
4178 % }
4179 % \end{example}
4180 %
4181 % Now if the block crosses a page boundary, the \cs{lastleftxmark} has
4182 % the text that should be put under the block.
4183 % In the \texttt{[L]} footer field we put
4184 % this information in the macro \cs{ContiText}, and this is
4185 % typeset after the block ends. If the block doesn't cross the page
4186 % boundary, this text is empty.
4187 %
4188 % \textbf{NOTE:} This example is not completely safe; there can still be timing
4189 % issues. For example, when the end of the block has already been typeset,
4190 % including an empty value of \cs{ContiText}, but then is pushed to the
4191 % next page. So you have to be very careful in using this kind of mechanism.
4192 %
4193 % If you want to include one of the marks or other varying information in the
4194 % saved text, you must use \cs{xdef} rather than \cs{gdef}.
4195 %
4196 % \section{Page styles for Table of Content, List of Figures, Bibliography, etc.}
4197 % \label{sec:tocstyle}
4198 %
4199 % Some special sections of a documents, such as the Table of Contents,
4200 % List of Figures/Tables, Bibliography, Index, and similar ones
4201 % sometimes cause difficulties if you want them to have special page
4202 % styles, especially if you also want the first page of these to have
4203 % a special page style.
4204 %
4205 % Suppose you have defined a special page style \texttt{tocstyle} for the
4206 % Table of contents. The Table of contents is generated by the command
4207 % \cs{tableofcontents} and it can be several pages long, all generated
4208 % by this simple command. So if you want this to have the page style
4209 % \texttt{tocstyle}, you must give the command \Cmd{pagestyle\{tocstyle\}}
4210 % before the \cs{tableofcontents}. But then you have to make sure that
4211 % the previous page (for example a title page) doesn't get this page
4212 % style too. As we have seen before we can do this by inserting a
4213 % \cs{newpage} first. Like
4214 % \begin{code}
4215 % \newpage
4216 % \pagestyle{tocstyle}
4217 % \tableofcontents
4218 % \end{code}
4219 %
4220 % If we use a chapter based documentclass, like the standard classes
4221 % \pkg{report} and \pkg{book}, with this setup the first page of the Table
4222 % of Contents, and similar parts of the document will still use the
4223 % \texttt{plain} page style. Usually this is the best choice, but there
4224 % may be cases where you want these also to use the \texttt{tocstyle}
4225 % page style (or another special page style). The \texttt{plain} page
4226 % style is set by a \Cmd{thispagestyle\{plain\}} command embedded
4227 % in a \cs{chapter*} command that is used in \cs{tableofcontents}. So
4228 % it is not easy to overwrite. It can be overwritten by a
4229 % \Cmd{thispagestyle\{tocstyle\}} command, but that must be given after
4230 % the \cs{chapter*} command, but before the first page of the Table of
4231 % Contents is finished. So in fact we must break in into the
4232 % \cs{tableofcontents} command. The other special parts have similar challenges.
4233 % In this section we give a number of solutions.
4234 %
4235 % The first solution applies to the Table of Contents and List of Figures/Tables.
4236 % We can add additional code in these lists with the \cs{addtocontents}
4237 % command. We can use this to insert a \cs{thispagestyle} as the first
4238 % entry,
4239 % \NoExample{tocpagestyle\\(a)}
4240 % \begin{example}
4241 % \newpage
4242 % \pagestyle{tocstyle}
4243 % \addtocontents{toc}{\protect\thispagestyle{tocstyle}}
4244 % \tableofcontents
4245 % \end{example}
4246 % and similar for the List of Figures (use \texttt{lof}) and List of
4247 % Tables (use \texttt{lot} instead of \texttt{toc}). The \cs{protect} is
4248 % necessary to prevent the \cs{thispagestyle} to be executed too early.
4249 %
4250 % \textbf{NOTE:} If you are using the package
4251 % \pkg{tocloft}\PKGindex{tocloft}, some of the solutions given here for
4252 % the Table of Contents and List of Figures/Tables may not work (but
4253 % others may). This is because this package changes the layout of these.
4254 % In particular, the first page of these will by default have page style
4255 % \texttt{plain}, even in a documentclass that has no chapters, like
4256 % \cls{article}. However, the package has a command to set the page
4257 % style for these first pages. This will set it for all three.
4258 %\begin{code}
4259 % \tocloftpagestyle{tocstyle}
4260 % \end{code}
4261 %
4262 % Alternatively, you can use \Cmd{usepackage[titles]\{tocloft\}} which
4263 % will keep the original \LaTeX{} code, so then the solutions mentioned
4264 % in this section will apply.
4265 %
4266 % \medskip
4267 %
4268 % For the Bibliography and Index the above solutions cannot be used. So
4269 % we need a different solution for these.
4270 %
4271 % For the Bibliography we can use the \LaTeX{} hook system (available since the
4272 % 2020/10/01 \LaTeX{} release). The command \cs{bibliography} reads the
4273 % file \texttt{\meta{jobname}.bbl}, which contains a
4274 % \env{thebibliography} environment, that contains a \cs{bibitem} for
4275 % each reference. The \Cmd{begin\{bibliography\}} sets up the chapter
4276 % header and starts a \env{list} environment. Unfortunately, the
4277 % \LaTeX{} hook system doesn't have a hook that is executed just after
4278 % this point (i.e., before any bibliography items are added).
4279 %
4280 % However, we can add a hook at the first \cs{bibitem} as follows:
4281 % \NoExample{tocpagestyle\\(c)}
4282 % \begin{example}
4283 % \AddToHookNext{cmd/bibitem/before}{\thispagestyle{tocstyle}}
4284 % \end{example}
4285 %
4286 % An alternative would be to use an `\texttt{after}' hook on the
4287 % \cs{thebibliography} command. This command is internally used to do
4288 % the setup work for the \env{thebibliography} environment, but this
4289 % is an implementation detail, so theoretically this could change in a
4290 % future implementation, or an implementation in a different
4291 % documentclass. But this is the hook that is executed at the right
4292 % moment: after the setup, and before any bibliography items are added.
4293 %
4294 % \NoExample{tocpagestyle\\(c)}
4295 % \begin{example}
4296 % \AddToHook{cmd/thebibliography/after}{\thispagestyle{tocstyle}}
4297 % \end{example}
4298 %
4299 % For the Index there is no hook that can be used in a similar manner.
4300 % Maybe we could use a hook in the \cs{item} command that is used for
4301 % the index items, but this is just a too general command that is not
4302 % exclusively used in the Index. However, we can use a hook on the
4303 % \cs{thispagestyle} command that is used in the internal
4304 % \cs{chapter*} command in the \cs{printindex} command (the
4305 % \cs{thispagestyle} that gives us these problems). We just use an
4306 % `\texttt{after}' hook to insert another \cs{thispagestyle} that
4307 % replaces the built-in one. In fact we could have used this same
4308 % solution for each of the cases mentioned in this document.
4309 %
4310 % \NoExample{tocpagestyle\\(d)}
4311 % \begin{example}
4312 % \newpage
4313 % \pagestyle{tocstyle}
4314 % \AddToHookNext{cmd/thispagestyle/after}{\thispagestyle{tocstyle}}
4315 % \printindex
4316 % \end{example}
4317 %
4318 % Finally, we can use the solution from
4319 % section~\ref{sec:pagestyle-plain} (redefining page style
4320 % \texttt{plain}). For example:
4321 % \begin{code}
4322 % \fancypagestyle{plain}[tocstyle]{}
4323 % \end{code}
4324 % But this would also change the \texttt{plain} page style for the
4325 % chapters in the normal text, which we don't want. So the page style
4326 % \texttt{plain} should be reset in the main text. We can do this with
4327 % the new (\pkg{fancyhdr} version 5) command \cs{fancypagestyleassign}.
4328 % We can use this to `save' the original \texttt{plain} page style and
4329 % set it equal to \texttt{tocstyle}. And later we can reset
4330 % \texttt{plain} to the saved page style.
4331 %
4332 % \NoExample{tocpagestyle\\(b)}
4333 % \begin{example}
4334 % \fancypagestyleassign{origplain}{plain}
4335 % \fancypagestyleassign{plain}{tocstyle}
4336 % \listoftables % \tableofcontents / \listoffigures, etc.
4337 %
4338 % % Here the main document text starts
4339 %
4340 % \clearpage
4341 % \fancypagestyleassign{plain}{origplain}
4342 % \end{example}
4343 % All definitions for the page style (including the
4344 % \cs{fancypagestyleassign} commands above) are local to the \TeX{}
4345 % group in which they are defined (see section~\ref{sec:change-group}).
4346 % So we could eliminate the saving and restoring to \texttt{origplain}
4347 % if we do the change in a group. For example:
4348 %
4349 % \begin{code}
4350 % {
4351 % \fancypagestyleassign{plain}{tocstyle}
4352 % % or use the older method \fancypagestyle{plain}[tocstyle]{}
4353 % \listoftables
4354 % }
4355 % \end{code}
4356 % After the group, page style \texttt{plain} has its original value.
4357 % However, it is not advised to place large parts of your document
4358 % inside a group.
4359 %
4360 % \section{A movie}
4361 % \label{sec:movie}
4362 %
4363 % \index{movie}
4364 % \TTindex{picture}
4365 % If you put at each page on the same place a picture that slightly changes
4366 % from page to page you can get a movie-like effect by flipping through the
4367 % pages. You can create such a movie easily with \pkg{fancyhdr}. For
4368 % simplicity we assume that we use a PDF-producing \LaTeX{} (such as
4369 % \texttt{pdflatex}) and each picture is in a PNG file called
4370 % \texttt{pic}$\langle n\rangle$.\texttt{png}\footnote{With
4371 % \texttt{pdflatex} we could also use PDF or JPG
4372 % pictures. With a DVI based \texttt{latex} we could use PS or EPS
4373 % pictures. Or any other supported image format.}
4374 % where $\langle n\rangle$ is
4375 % the page number and that we use the \pkg{graphics} or \pkg{graphicx} package.
4376 % \PKGindex{graphics}
4377 % \PKGindex{graphicx}
4378 % To put the movie in the right-hand side bottom corner the following will work:
4379 %
4380 % \Example{30}
4381 % \begin{example}
4382 % \fancyfoot[R]{\setlength{\unitlength}{1mm}
4383 % \begin{picture}(0,0)
4384 % \put(5,-20){\includegraphics[width=1cm]{pic\thepage}}
4385 % \end{picture}}
4386 % \end{example}
4387 %
4388 % If the document is two-sided, it would be better to put them only on
4389 % the odd pages, by specifying \verb|\fancyfoot[RO]|.
4390 %
4391 % Notice that the \cs{unitlength} parameter should
4392 % be set locally in the \pkg{fancyhdr} field in order to avoid unwanted
4393 % interference with its value in the text.
4394 %
4395 % \section{Thumb-indexes}
4396 % \label{sec:thumb}
4397 %
4398 % \index{bible}
4399 % Some railroad guides and expensive bibles have so called
4400 % \index{thumb-index}
4401 % \emph{thumb-indexes}, i.e., there are marks on the sides of the pages that
4402 % indicate where the chapters are. You can create these by printing black
4403 % blobs in the margin of the pages. The vertical position should be
4404 % determined by the chapter number or some other counter. As the position is
4405 % independent of the contents of the page, we print these blobs as part of
4406 % the header in a zero-sized \texttt{picture} as described in the previous
4407 % section.
4408 %
4409 % Of course we have to take care of two-sided printing, and we may want to
4410 % have an index page with all the blobs in the correct position. The solution
4411 % requires some hand-tuning to get the blobs nicely spaced out vertically.
4412 % For the application that I originally designed this for, there were 12 sections,
4413 % so I made the blobs
4414 % 18 mm apart, i.e., 9~mm blob separated by 9~mm white space. In order to avoid
4415 % calculations they are set in a \texttt{picture} environment with the
4416 % \cs{unitlength} set to 18~mm. Page numbers are set in the headers at the
4417 % outer sides, and the blobs are attached to these. In this example the
4418 % chapter numbers are used to position the blobs, but you can replace this
4419 % with any numeric value.
4420 % See figure~\ref{fig:overview} for the resulting overview page.
4421 %
4422 % ^^A Picture with thumb index overview
4423 %
4424 % \begin{figure}[!htbp]
4425 % \setlength{\unitlength}{9mm}
4426 % \newcommand{\blob}{\rule[-.2\unitlength]{1\unitlength}{.5\unitlength}}
4427 % \newcounter{line}
4428 % \newcommand{\chapname}[1]{\addtocounter{line}{1}%
4429 % \put(1,-\value{line}){\blob}
4430 % \put(-7.5,-\value{line}){\arabic{line}}
4431 % \put(-7,-\value{line}){#1}}
4432 %
4433 % \newcommand{\overview}{1
4434 % \begin{picture}(0,0)
4435 % \chapname{Introduction}
4436 % \chapname{Another chapter}
4437 % \chapname{Third case}
4438 % \end{picture}}
4439 %
4440 % \begin{center}
4441 % \leavevmode
4442 % \begin{picture}(11.3,5)
4443 % \put(0,0){\framebox(11.3,5)[tr]{}}
4444 % \put(9,4.5){\overview}
4445 % \end{picture}
4446 % \end{center}
4447 % \caption{Thumb-index overview page}
4448 % \label{fig:overview}
4449 % \end{figure}
4450 %
4451 % ^^A The code
4452 % \Example{31}
4453 % \begin{example}
4454 % \setlength{\unitlength}{18mm}
4455 % \newcommand{\blob}{%
4456 % \rule[-.2\unitlength]{2\unitlength}{.5\unitlength}}
4457 %
4458 % \newcommand\rblob{\thepage
4459 % \begin{picture}(0,0)
4460 % \put(1,-\value{chapter}){\blob}
4461 % \end{picture}}
4462 %
4463 % \newcommand\lblob{%
4464 % \begin{picture}(0,0)
4465 % \put(-3,-\value{chapter}){\blob}
4466 % \end{picture}%
4467 % \thepage}
4468 %
4469 % \pagestyle{fancy}
4470 % \fancyfoot{}
4471 %
4472 % \newcounter{line}
4473 % \newcommand{\chapname}[1]{\addtocounter{line}{1}%
4474 % \put(1,-\value{line}){\blob}
4475 % % Adjust these numbers for the proper indentation
4476 % \put(-5.5,-\value{line}){\Large \arabic{line}}
4477 % \put(-5,-\value{line}){\Large #1}}
4478 %
4479 % \newcommand{\overview}{%
4480 % \begin{picture}(0,0)
4481 % \chapname{Introduction}
4482 % \chapname{Another chapter}
4483 % \chapname{Third case}
4484 % . . .
4485 % \end{picture}
4486 % }
4487 % \end{example}
4488 % The overview page:\\
4489 % The page doesn't have `contents' --
4490 % all the visual contents is generated
4491 % by the \verb|\overview| command in the header
4492 % \Example{31}[(continued)]
4493 % \begin{example}
4494 % \fancyhead[L]{Overview}
4495 % \fancyhead[R]{\overview}
4496 % \mbox{}\newpage % This produces the overview page
4497 %
4498 % % Front matter -- doesn't have blobs.
4499 %
4500 % \fancyhead[RE]{\rightmark}
4501 % \fancyhead[RO,LE]{}
4502 % \fancyhead[LO]{\leftmark}
4503 %
4504 % \pagenumbering{roman}
4505 % \thispagestyle{plain}
4506 % \tableofcontents
4507 % . . .
4508 % \newpage
4509 %
4510 % % Here the document begins
4511 %
4512 % \pagenumbering{arabic}
4513 %
4514 % % Now activate the blobs
4515 %
4516 % \fancyhead[RO]{\rblob}
4517 % \fancyhead[LE]{\lblob}
4518 %
4519 % % Page style 'plain' does not have the usual header,
4520 % % but it does have the blobs.
4521 %
4522 % \fancypagestyle{plain}{%
4523 % \fancyhead[RE,LO]{}
4524 % \renewcommand{\headrule}{}%
4525 % }
4526 % \end{example}
4527 %
4528 % \section{Float placement}
4529 %
4530 % \textbf{Note: This section is not about \pkg{fancyhdr}, but about
4531 % page layout, especially about the placement of floats.}
4532 %
4533 % Floats are page elements that float with respect to the rest of the
4534 % document. Standard floats are tables and figures, but with the
4535 % \PKGindex{float}%
4536 % \pkg{float} package you can easily make new ones, like algorithms. Most
4537 % of the time floats work satisfactory, but sometimes \LaTeX{} seems too
4538 % stubborn to do what you want. This section describes how you can influence
4539 % \LaTeX{} so that it will do most of the time what you want. There might,
4540 % however, be some pathological cases where it is impossible to convince
4541 % \LaTeX{} to do things your way. In the following we will use figures as an
4542 % example but everything applies to other floats as well.
4543 %
4544 % The most encountered problems with floats are:
4545 % \begin{enumerate}
4546 % \item You want a float at a certain position in the text, but \LaTeX{}
4547 % moves it, usually to the next page.
4548 % \item From a certain point, \LaTeX{} moves all your floats to the end of
4549 % the document or the end of a chapter.
4550 % \item \index{Too many floats}%
4551 % \LaTeX{} complains about ``Too many floats''.
4552 % \end{enumerate}
4553 %
4554 % In the first two cases you must first check if you have given the correct
4555 % ``placement'' parameter to you float, e.g., \Cmd{begin\{figure\}[htp]}
4556 % specifies that your figure may be placed either: Here (i.e., in the text
4557 % position where the command is given), on the Top of a page (which may be
4558 % the page where you put the command), or on a separate Page of floats. You
4559 % could also have specified ``\texttt{b}'' for Bottom of the page. The order of the
4560 % letters is insignificant, you cannot force \LaTeX{} to try Bottom first
4561 % and then Top by specifying \texttt{[bt]}.
4562 %
4563 % If \LaTeX{} doesn't put the float at the place where you expected it, it is
4564 % usually caused by the following:
4565 % \begin{enumerate}
4566 % \item The float didn't fit on the page. In this case it has to move to the
4567 % next page or even further. If you didn't specify either \texttt{[t]} or
4568 % \texttt{[b]} in the position parameter, \LaTeX{} must save it until it has
4569 % enough for a page of floats. So don't specify only \texttt{[h]}. If you
4570 % want to give \LaTeX{} a chance to put the float on a page of floats, you
4571 % must also specify ``\texttt{p}''.
4572 % \item The placement would violate the constraints imposed by \LaTeX's
4573 % float placement parameters. This is one of the most occurring causes and
4574 % it can easily be corrected by changing the parameters. Here is a list of
4575 % them with their default values:
4576 % \end{enumerate}
4577 % \begin{center}
4578 % \small
4579 % \CmdIndex{topfraction}
4580 % \CmdIndex{bottomfraction}
4581 % \CmdIndex{textfraction}
4582 % \CmdIndex{floatpagefraction}
4583 % \TTindex{topnumber}
4584 % \TTindex{bottomnumber}
4585 % \TTindex{totalnumber}
4586 % \begin{tabular}{>{\tt}llc}
4587 % \toprule
4588 % \multicolumn{3}{c}{Counters -- change with \cs{setcounter}}\\
4589 % \midrule
4590 % topnumber & max. number of floats at top of page & 2 \\
4591 % bottomnumber & max. number of floats at bottom of page & 1 \\
4592 % totalnumber & max. number of floats on a page & 3\\
4593 % \midrule
4594 % \multicolumn{3}{c}{Other -- change with \cs{renewcommand}}\\
4595 % \midrule
4596 % \bs topfraction & max fraction of page for floats at top & 0.7 \\
4597 % \bs bottomfraction & max fraction of page for floats at bottom & 0.3 \\
4598 % \bs textfraction & min fraction of page for text & 0.2 \\
4599 % \bs floatpagefraction & min fraction of floatpage that should have
4600 % floats & 0.5 \\
4601 % \bottomrule
4602 % \end{tabular}
4603 % \end{center}
4604 %
4605 % There are also some others for double column floats in two-column documents.
4606 %
4607 % The default values are for the standard
4608 % \LaTeX{} classes. Other classes could use different defaults. As you see
4609 % with the default values a float will not be put in the bottom of a page if
4610 % its height is more than 30\% of the page height. So if you specify \texttt{[hb]} for
4611 % a float which is taller it has to move to a float page. But if it is less
4612 % than 50\% of the page height it will have to wait until some more floats
4613 % are given before a float page can be filled to satisfy the
4614 % \phantomsection\label{page:floatpagefraction}^^A
4615 % \cs{floatpagefraction} parameter. If you have this kind of behaviour you
4616 % can easily adapt the parameters, e.g., with:
4617 % \begin{code}
4618 % \renewcommand{\textfraction}{0.05}
4619 % \renewcommand{\topfraction}{0.95}
4620 % \renewcommand{\bottomfraction}{0.95}
4621 % \renewcommand{\floatpagefraction}{0.35}
4622 % \setcounter{totalnumber}{5}
4623 % \end{code}
4624 % You may want to be careful not to make \cs{floatpagefraction} too small,
4625 % otherwise you may get too many small floatpages.
4626 %
4627 % You can force \LaTeX{} to ignore most of the parameters for one specific float
4628 % occurrence by
4629 % including an exclamation mark (\texttt{!}) in the placement parameters, e.g.,
4630 % \begin{code}
4631 % \begin{figure}[!htb]
4632 % \end{code}
4633 %
4634 % Floats which contain a ``\texttt{t}'' in the position parameter could be
4635 % placed before the place where they are referenced (but on the same page).
4636 % This is normal behaviour for \LaTeX{} but some people just don't like it.
4637 % There are a number of ways to prevent this:
4638 % \begin{enumerate}
4639 % \item Of course deleting the ``\texttt{t}'' will help, but in general this is
4640 % undesirable, as you may want the float to be placed at the top of the
4641 % next page.
4642 % \item \PKGindex{flafter}%
4643 % use the \pkg{flafter} package which causes floats never to be
4644 % placed ``backwards''.
4645 % \item use the command \cs{suppressfloats[t]}. This
4646 % \CmdIndex{suppressfloats}%
4647 % command will cause floats for the top position \emph{on this page} to be
4648 % moved to the next page. This can also be done with \texttt{[b]} or
4649 % without parameter for all floats on this page.
4650 % \end{enumerate}
4651 %
4652 % If in spite of all your attempts \LaTeX{} still moves your floats to the end
4653 % of the document or the end of a chapter, you can insert a \cs{clearpage}
4654 % command. This will start a new page and insert all pending floats before
4655 % continuing. If it is undesirable to have a page break you can use the
4656 % \pkg{afterpage} package and the following command:
4657 % \PKGindex{afterpage}\CmdIndex{afterpage}\CmdIndex{clearpage}%
4658 % \begin{code}
4659 % \afterpage{\clearpage}
4660 % \end{code}
4661 %
4662 % This will wait until the current page is finished and then flush all
4663 % outstanding floats. In some pathological circumstances \pkg{afterpage}
4664 % may give strange results, however.
4665 %
4666 % Finally, if you want a float only at the place where you define it, without
4667 % \LaTeX{} moving it whatsoever, you can use the \pkg{float} package and
4668 % give the command:
4669 % \PKGindex{float}\CmdIndex{restylefloat}%
4670 % \begin{code}
4671 % \restylefloat{figure}
4672 % \end{code}
4673 % in the preamble. Now you will be able to
4674 % specify \texttt{[H]} as the position parameter, which will mean ``HERE
4675 % and only HERE''. This may cause an unwanted page break however.
4676 % If you want to avoid the unwanted page break, i.e., let
4677 % \LaTeX{} move the float only if it doesn't fit on the page, then use the
4678 % \pkg{afterpage} package with:
4679 % \PKGindex{afterpage}\CmdIndex{afterpage}\CmdIndex{clearpage}%
4680 % \begin{code}
4681 % \afterpage{\clearpage \begin{figure}[H] ... \end{figure}}
4682 % \end{code}
4683 %
4684 % \index{Too many floats}%
4685 % Complaints from \LaTeX{} about ``Too many floats'' are usually caused by one
4686 % of the above problems: floats not being able to be placed and \LaTeX{}
4687 % collecting too many of them. The solutions given above, especially those
4688 % with \cs{clearpage} in them will usually help. In some cases there
4689 % really are too many floats, as \LaTeX{} has a limited number of ``boxes'' to
4690 % store the floats. The package
4691 % \PKGindex{morefloats}%
4692 % \pkg{morefloats} can be used to increase
4693 % this number. If you need still more then you must edit a private copy of
4694 % this file, but even then there will be some limit that you cannot pass.
4695 % Then your only resort will be to change your document.
4696 %
4697 % A much more elaborate article about float placement by Frank
4698 % Mittelbach appeared in 2014 in TUGboat\footnote{%
4699 % Frank Mittelbach, \emph{How to influence the position of float
4700 % environments like figure and table in LATEX?}, TUGboat, Volume 35
4701 % (2014), No. 3, pp. 248–254.\\
4702 % \url{https://www.latex-project.org/publications/2014-FMi-TUB-tb111mitt-float-placement.pdf}
4703 % \\Also on Stackexchange:\\
4704 % \url{https://tex.stackexchange.com/questions/39017/how-to-influence-the-position-of-float-environments-like-figure-and-table-in-lat}}.
4705 %
4706 % \section{Multi-page Floats}
4707 %
4708 % \LaTeX's floats cannot be split across pages. Sometimes, however, you want
4709 % to have a table or figure that doesn't fit on one page. The easiest way is
4710 % to split these into multiple table or figure environments, but this has a
4711 % number of undesirable effects:
4712 % \begin{itemize}
4713 % \item Where do you split it? This is generally a more difficult decision
4714 % for tables than for figures.
4715 % \item How do you keep them together?
4716 % \item You don't want more than one entry in the list of figures/tables.
4717 % \end{itemize}
4718 %
4719 % Although these problems are not fully solvable in all cases, here are a
4720 % couple of suggestions:
4721 %
4722 % \subsection{Tables}
4723 %
4724 % For tables longer than a page you can use the \pkg{longtable} package.
4725 % \PKGindex{longtable}
4726 % This package defines a \texttt{longtable} environment that is a kind of
4727 % amalgamation of \env{table} and \env{tabular}. It has approximately
4728 % the same syntax as the \env{tabular} environment, but it adds some
4729 % features of \env{table}, like captions. Longtables will be automatically
4730 % split when they don't fit on the page. And they will be entered in the list
4731 % of tables when a caption is given. They will not float, however, and cannot
4732 % be used inside a float environment. This could mean that another
4733 % \texttt{table} environment, which was defined before the
4734 % \texttt{longtable}, will float past it, and therefore the numbers may get
4735 % out of order. Another problem could be that the \texttt{longtable} starts
4736 % rather far down the page, which isn't a pleasant sight. If you want the
4737 % \texttt{longtable} to start at the top of the page, the best thing to do is
4738 % to include it in an \cs{afterpage} command (using the \PKGindex{afterpage}\pkg{afterpage}
4739 % package). As a \env{longtable} is by definition large, it is best to put
4740 % it in a separate file, and \cs{input} it in the \cs{afterpage} command:
4741 % \CmdIndex{afterpage}\PKGindex{afterpage}\CmdIndex{clearpage}%
4742 % \begin{code}
4743 % \afterpage{\input{mytable}}
4744 % \end{code}
4745 % or
4746 % \begin{code}
4747 % \afterpage{\clearpage\input{mytable}}
4748 % \end{code}
4749 % The last form has the additional advantage that most of the outstanding
4750 % floats will be printed first.
4751 %
4752 % \subsection{Figures}
4753 %
4754 % There isn't an equivalent ``\texttt{longfigure}'' solution, so for figures you
4755 % will have to split yourself. In general this is less of a
4756 % problem. However, the problem you get now is how to keep them together,
4757 % i.e., how to get the parts on subsequent pages, and how to get a single
4758 % entry in the list of figures.
4759 %
4760 % You will have to split the figure into pieces and put each part
4761 % in a separate \texttt{figure} environment. The first
4762 % part would then get a \cs{caption}, the subsequent parts would be used
4763 % without a caption, or a caption that will not go to the list of figures.
4764 % If you want to add a caption-like text, enter it as
4765 % normal text rather than a \cs{caption}, so that it will not be entered in
4766 % the list of figures. It may also be desirable to issue a \cs{clearpage}
4767 % first, just like we did for the \texttt{longtable}.
4768 %
4769 % We give a series of possible solutions here, which can be found in
4770 % Example 33.
4771 %
4772 % First we include the \texttt{figure}s with the \texttt{[!htbp]}
4773 % position option to give \LaTeX{} maximum freedom to place them. This
4774 % way we hope they keep them together, although there is no guarantee.
4775 %
4776 % \Example{33}[(A)]
4777 % \begin{example}
4778 % \newcommand{\fakecaption}[2]{% #1 = figure label #2 = caption
4779 % \par Figure~\ref{#1}: #2
4780 % }
4781 % \begin{figure}[!htbp]
4782 % \centering
4783 % \includegraphics[scale=0.5]{example-image-a}
4784 % \caption[This is a multi-part figure] % For the list of figures
4785 % {This is a multi-part figure (a)}
4786 % \label{fig:first}
4787 % \end{figure}
4788 % \begin{figure}[!htbp]
4789 % \centering
4790 % \includegraphics[scale=0.5]{example-image-b}
4791 % \fakecaption{fig:first}{This is a multi-part figure (b)}
4792 % \end{figure}
4793 % . . .
4794 % \end{example}
4795 %
4796 % There will probably be some of the normal text between the figure
4797 % parts, unless they happen to fit perfectly on the page, which isn't
4798 % very probable. But, what also can come between them is other floats,
4799 % such as a \env{table}. We can prevent that previous floats intrude
4800 % here by issuing a \cs{clearpage} command, but this will abruptly end
4801 % the current page. As we have seen before, we can do better by
4802 % \CmdIndex{afterpage}\CmdIndex{clearpage}%
4803 % including the \cs{clearpage} command in \cs{afterpage}, and we would
4804 % also put the figures in the \cs{afterpage}. To keep the \cs{afterpage}
4805 % command more tidy, it is advised to put the code for the figures in a
4806 % macro, or in a file that is included with \cs{input}. For example:
4807 %
4808 % \Example{33}[(B)]
4809 % \begin{example}
4810 % \newcommand{\myfigures}{%
4811 % \begin{figure}[!htbp]
4812 % \centering
4813 % \includegraphics[scale=0.5]{example-image-a}
4814 % \caption[This is a multi-part figure] % For the list of figures
4815 % {This is a multi-part figure (a)}
4816 % \label{fig:second}
4817 % \end{figure}
4818 % \begin{figure}[!htbp]
4819 % \centering
4820 % \includegraphics[scale=0.5]{example-image-b}
4821 % \fakecaption{fig:second}{This is a multi-part figure (b)}
4822 % . . .
4823 % }
4824 % . . .
4825 % \afterpage{\clearpage\myfigures}
4826 % \end{example}
4827 % \CmdIndex{afterpage}
4828 %
4829 % If you want your multi-page figure to start at a left-hand side
4830 % (even-numbered) page you can use a test in the \cs{afterpage} command
4831 % (using the \PKGindex{ifthen}\pkg{ifthen} package):
4832 % \CmdIndex{afterpage}
4833 % \CmdIndex{ifthenelse}
4834 % \begin{code}
4835 % \afterpage{\clearpage
4836 % \ifthenelse{\isodd{\value{page}}
4837 % {\afterpage{\myfigures}} % odd page
4838 % {\myfigures}}} % even page
4839 % \end{code}
4840 %
4841 % If there are too many floats on the skipped page, this may still fail to
4842 % start your multi-page figure on an even page, however.
4843 %
4844 % But if there is enough space left on a page, some of the text will go
4845 % between the figures. Also, if there is still some figure part of a
4846 % previous sequence that has not yet found a place, it will be forced out
4847 % because of the \cs{clearpage} and the a new page will start, with the
4848 % previous page not optimally filled.
4849 %
4850 % So using \cs{clearpage} may also not be optimal. We could also try
4851 % to put the figure parts only on float pages, so that no intervening
4852 % text will come between them. This can be done by using the position
4853 % parameter \texttt{[p]}. This could cause them to be pushed towards
4854 % the back of the document. This is because float pages need to be
4855 % reasonably full before they are generated. You could try to cure this
4856 % for example by adding some \cs{vspace} to the last part, or by
4857 % tweaking the \cs{floatpagefraction}
4858 % \CmdIndex{floatpagefraction} parameter (see
4859 % section~\ref{page:floatpagefraction} on page~\pageref{page:floatpagefraction}).
4860 % To prevent previous floats to intrude in the float page, we also
4861 % combine this with the \cs{afterpage} and \cs{clearpage}, as in the
4862 % previous example, but this will probably push the figures even further
4863 % towards the back.
4864 %
4865 % \Example{33}[(C)]
4866 % \begin{example}
4867 % \newcommand{\myfigures}{%
4868 % \begin{figure}[p]
4869 % \centering
4870 % \includegraphics[scale=0.5]{example-image-a}
4871 % \caption[This is a multi-part figure] % For the list of figures
4872 % {This is a multi-part figure (a)}
4873 % \label{fig:third}
4874 % \end{figure}
4875 % \begin{figure}[p]
4876 % \centering
4877 % \includegraphics[scale=0.5]{example-image-b}
4878 % \fakecaption{fig:third}{This is a multi-part figure (b)}
4879 % . . .
4880 % }
4881 % . . .
4882 % \afterpage{\clearpage\myfigures}
4883 % \end{example}
4884 %
4885 % So maybe just use the previous example without \cs{afterpage} and
4886 % \cs{clearpage}.
4887 %
4888 % \Example{33}[(D)]
4889 % \begin{example}
4890 % \myfigures % (with the [p] placement)
4891 % \end{example}
4892 %
4893 % The defects of the above approach are
4894 % \begin{enumerate}
4895 % \item It is clumsy to make the captions of all but the first part of the figure
4896 % \item It is hard to refer to the parts separately
4897 % \end{enumerate}
4898 % \PKGindex{subcaption}%
4899 % For this the \pkg{subcaption} package comes to the rescue. First it
4900 % \CmdIndex{ContinuedFloat}%
4901 % has a \cs{ContinuedFloat} command to indicate that a figure is a
4902 % continuation of a previous one, and therefore will not get a new
4903 % number, and if you wish, neither a separate entry in the list of figures.
4904 %
4905 % \CmdIndex{subcaptionbox}\TTindex{subfigure}%
4906 % Second, it has a \cs{subcaptionbox} command and a \env{subfigure}
4907 % environment for the parts, where a subcaption can be given, that can
4908 % also have a \cs{label} to refer to in the document. The
4909 % \cs{subcaptionbox} is a specialized \cs{parbox} but its \emph{width}
4910 % parameter is optional. The \env{subfigure} environment is a
4911 % specialized \env{minipage}, so it has the same parameters.
4912 %
4913 % These should be used inside a \env{figure} environment, so all the
4914 % placement methods of the previous part (Examples 33 A–D) should still apply.
4915 %
4916 % The \env{subfigure} environment has a \cs{subcaption} command for
4917 % the subcaption; the \cs{subcaptionbox} has the subcaption (with its
4918 % \cs{label} if desired) as its first argument. When more than one
4919 % \cs{subcaptionbox} is horizontally next to each other, the subcaptions
4920 % will be aligned.
4921 %
4922 % In the following example (figure~\ref{fig:subfigures})
4923 % we use a \cs{subcaptionbox} for the first two
4924 % parts, which are together in a single \env{figure} environment. We
4925 % use a \env{subfigure} environments for the other two, each one in
4926 % its own \env{figure} environment. These use a
4927 % \cs{caption}\texttt{[]\{\ldots\}}. The empty optional argument
4928 % \texttt{[]} causes the caption not to appear in the list of figures.
4929 % The last subfigure (\ref{subfig:last} on page~\pageref{subfig:last})
4930 % has a label on the \cs{subcaption} that we refer to in this sentence.
4931 %
4932 % \Example{33}[(E)]
4933 % \begin{example}
4934 % \begin{figure}[p]
4935 % \centering
4936 % \subcaptionbox{a subfigure in a \cs{subcaptionbox}}
4937 % {\includegraphics[scale=0.3]{example-image-a}}
4938 % \quad
4939 % \subcaptionbox{another subfigure, also in a \cs{subcaptionbox}}
4940 % {\includegraphics[scale=0.4]{example-image-b}}
4941 % \caption{A figure with subfigures}
4942 % \label{fig:subfigures}
4943 % \end{figure}
4944 %
4945 % \begin{figure}[p]\ContinuedFloat
4946 % \begin{subfigure}{\textwidth}
4947 % \centering
4948 % \includegraphics[scale=0.5]{example-image-c}
4949 % \subcaption{subfigure}
4950 % \end{subfigure}
4951 % \caption[]{A figure with subfigures}
4952 % \end{figure}
4953 %
4954 % \begin{figure}[p]\ContinuedFloat
4955 % \begin{subfigure}{\textwidth}
4956 % \centering
4957 % \includegraphics[scale=0.5]{example-image}
4958 % \subcaption{last subfigure}
4959 % \label{subfig:last}
4960 % \end{subfigure}
4961 % \caption[]{A fake caption just for demo}
4962 % \end{figure}
4963 % \end{example}
4964 %
4965 % \begin{figure}[p]
4966 % \centering
4967 % \subcaptionbox{a subfigure in a \cs{subcaptionbox}}
4968 % {\includegraphics[scale=0.3]{example-image-a}}
4969 % \quad
4970 % \subcaptionbox{another subfigure, also in a \cs{subcaptionbox}}
4971 % {\includegraphics[scale=0.4]{example-image-b}}
4972 % \caption{A figure with subfigures}
4973 % \label{fig:subfigures}
4974 % \end{figure}
4975 %
4976 % \begin{figure}[p]\ContinuedFloat
4977 % \begin{subfigure}{\textwidth}
4978 % \centering
4979 % \includegraphics[scale=0.5]{example-image-c}
4980 % \subcaption{subfigure}
4981 % \end{subfigure}
4982 % \caption[]{A figure with subfigures (cont.)}
4983 % \end{figure}
4984 %
4985 % \begin{figure}[p]\ContinuedFloat
4986 % \begin{subfigure}{\textwidth}
4987 % \centering
4988 % \includegraphics[scale=0.5]{example-image}
4989 % \subcaption{last subfigure}
4990 % \label{subfig:last}
4991 % \end{subfigure}
4992 % \caption[]{A fake caption just for demo}
4993 % \end{figure}
4994 %
4995 % \section{Deprecated commands}
4996 % \label{sec:depr}
4997 %
4998 % This section contains the description of deprecated commands. These
4999 % were parts of the original implementation of \pkg{fancyheadings}.
5000 % They continue to work for compatibility reasons,
5001 % but it is recommended not to use them anymore. This description is
5002 % given so that you know what they mean and how to convert them to the
5003 % standard commands. To be honest, I use these sometimes myself in quick
5004 % examples, because \cs{lhead} is less typing than \Cmd{fancyhead[L]}.
5005 %
5006 % These commands for specifying the header or footer fields and their translation to
5007 % the modern commands are given in table~\ref{tab:depr}.
5008 %
5009 % \begin{table}[h!t]
5010 % \begin{function}{\lhead, \chead, \rhead, \lfoot, \cfoot, \rfoot}
5011 % \begin{tabular}{ll}
5012 % \toprule
5013 % \Cmd{lhead\{xx\}} & \Cmd{fancyhead[L]\{xx\}} \\
5014 % \Cmd{lhead[xx]\{yy\}} & \Cmd{fancyhead[LE]\{xx\}} \Cmd{fancyhead[LO]\{yy\}} \\
5015 % \Cmd{chead\{xx\}} & \Cmd{fancyhead[C]\{xx\}} \\
5016 % \Cmd{chead[xx]\{yy\}} & \Cmd{fancyhead[CE]\{xx\}} \Cmd{fancyhead[CO]\{yy\}} \\
5017 % \Cmd{rhead\{xx\}} & \Cmd{fancyhead[R]\{xx\}} \\
5018 % \Cmd{rhead[xx]\{yy\}} & \Cmd{fancyhead[RE]\{xx\}} \Cmd{fancyhead[RO]\{yy\}} \\
5019 % \midrule
5020 % \Cmd{lfoot\{xx\}} & \Cmd{fancyfoot[L]\{xx\}} \\
5021 % \Cmd{lfoot[xx]\{yy\}} & \Cmd{fancyfoot[LE]\{xx\}} \Cmd{fancyfoot[LO]\{yy\}} \\
5022 % \Cmd{cfoot\{xx\}} & \Cmd{fancyfoot[C]\{xx\}} \\
5023 % \Cmd{cfoot[xx]\{yy\}} & \Cmd{fancyfoot[CE]\{xx\}} \Cmd{fancyfoot[CO]\{yy\}} \\
5024 % \Cmd{rfoot\{xx\}} & \Cmd{fancyfoot[R]\{xx\}} \\
5025 % \Cmd{rfoot[xx]\{yy\}} & \Cmd{fancyfoot[RE]\{xx\}} \Cmd{fancyfoot[RO]\{yy\}} \\
5026 % \bottomrule
5027 % \end{tabular}
5028 % \caption{Deprecated commands and their translation\label{tab:depr}}
5029 % \end{function}
5030 % \end{table}
5031 %
5032 % As you see, if there is an optional parameter, this one applies to the
5033 % even pages, whereas the required parameter applies to the odd pages. Of
5034 % course this only works if the \texttt{twoside} option is given in the
5035 % documentclass. If there is no optional parameter, the required
5036 % parameter applies to both even and odd pages.
5037 %
5038 % \begin{function}{\fancyplain}
5039 % \PSindex{fancyplain}
5040 % There was also a special page style \texttt{fancyplain} that could be
5041 % used to define both the page style \texttt{fancy} and to redefine the
5042 % page style \texttt{plain} at the same time. In order to use that you say
5043 % \begin{code}
5044 % \pagestyle{fancyplain}
5045 % \end{code}
5046 % and then in the headers/footers you use for example:
5047 % \begin{code}
5048 % \fancyhead[L]{\fancyplain{value for `plain' page}
5049 % {value for other pages}}}
5050 % \end{code}
5051 %
5052 % The \cs{fancyplain} command is only useful within the page style \texttt{fancyplain}.
5053 % Nowadays you would just redefine page style \texttt{plain} with the
5054 % \Cmd{fancypagestyle\{plain\}\{xxxx\}} command (see section~\ref{sec:pagestyle-plain}).
5055 % \end{function}
5056 %
5057 % \begin{variable}{\plainheadrulewidth, \plainfootrulewidth}
5058 % There are also \cs{plainheadrulewidth} and \cs{plainfootrulewidth}
5059 % commands to define the values of \cs{headrulewidth} and
5060 % \cs{footrulewidth} to be used on `\texttt{plain}' pages. This also
5061 % only works with the page style \texttt{fancyplain}, not when you
5062 % redefine page style \texttt{plain} with the \cs{fancypagestyle} command.
5063 % \end{variable}
5064 %
5065 % \end{documentation}
5066 %
5067 % \section{Contact information}
5068 % \label{sec:contact}
5069 %
5070 % Pieter van Oostrum\\
5071 % E-mail: [email protected] \\
5072 % WWW: http://pieter.vanoostrum.org
5073 % \\[1ex]
5074 % The source code can be found on Github:\\
5075 % \url{https://github.com/pietvo/fancyhdr}\\
5076 % Bugs and suggestions for improvements can be reported at\\
5077 % \url{https://github.com/pietvo/fancyhdr/issues}\\
5078 % Example files can be found at\\
5079 % \url{https://github.com/pietvo/fancyhdr-examples}
5080 %
5081 % \section{Version information}
5082 % \begin{itemize}
5083 % \item Version 1.0. March 11, 2003. This is the version that was distributed for a
5084 % long time on CTAN. Version history before this has been lost.
5085 % \item Version 2.0. August 27, 2016:
5086 % \begin{itemize}
5087 % \item Removed references to fixmarks.sty as that is no longer used.
5088 % \item References to older \LaTeX{} versions removed.
5089 % \item Removed obsolete source code of \pkg{extramarks.sty}
5090 % \item Changed font commands to \cs{textbf} and \cs{textsl}.
5091 % \item Added description of the \Cmd{fancy\ldots offset} commands.
5092 % \item Added various \Cmd{\ldots xmark} commands from \pkg{extramarks.sty}.
5093 % \item Various corrections applied.
5094 % \item Updated contact information.
5095 % \item Added Version information. :)
5096 % \end{itemize}
5097 % \item Version 2.1. August 28, 2016
5098 % \begin{itemize}
5099 % \item Explain what the top-marks are.
5100 % \end{itemize}
5101 % \item Version 2.1. Sept. 6, 2016
5102 % \begin{itemize}
5103 % \item Add \verb|\string| to special indexing commands to get a neater index file.
5104 % \item Add a decorative headrule example.
5105 % \end{itemize}
5106 % \item Version 3.9, October 13, 2016.
5107 % \begin{itemize}
5108 % \item Documentation integrated in \pkg{fancyhdr.dtx}.
5109 % \item Version number unified with \pkg{fancyhdr.sty}.
5110 % \item All deprecated commands moved to a separate section (\ref{sec:depr}).
5111 % \item Documentation expanded.
5112 % \end{itemize}
5113 % \item Version 3.9a, June 30, 2017.
5114 % \begin{itemize}
5115 % \item Updated contact information.
5116 % \item Restore \cs{newtoks}\cs{@temptokenb}
5117 % \end{itemize}
5118 % \item Version 3.10, January 25, 2019
5119 % \begin{itemize}
5120 % \item Distribution based on fancydhr.dtx.
5121 % \item Use \cs{f@nch@ifundefined} instead of \cs{ifx} or \cs{@ifundefined}.
5122 % \item Replace \cs{def} with \cs{newcommand} in several places.
5123 % \item Don't use \cs{global}\cs{setlength}.
5124 % \item Put \cs{footrule} in a \cs{vbox} to accommodate for flexible
5125 % footrules, and then \cs{unvbox} that. Move the \cs{footruleskip}
5126 % vertical space outside of the definition of \cs{footrule}.
5127 % \end{itemize}
5128 % \end{itemize}
5129 % \subsection{Changes in version 4}
5130 % \label{sec:version-4}
5131 % Version 4 is a significant rewrite of the package. It also introduces
5132 % a number of new features.
5133 % \begin{itemize}
5134 % \item Version 4.0, March 15, 2019--Jan 04, 2021
5135 % \begin{itemize}
5136 % \item Options introduced on the \cs{usepackage} command.
5137 % \item The check whether the header or footer fits in
5138 % \cs{headheight} and \cs{footskip}, respectively, no longer
5139 % adjusts these values for the following pages. This appeared to be too
5140 % confusing. However, when the package option \texttt{compatV3} is given, the old
5141 % behaviour is kept. \\
5142 % The \texttt{nocheck} option now eliminates these checks completely, on
5143 % your own risk. (See section~\ref{sec:warning} on page~\pageref{page:warning}.)
5144 % \item Eliminated global definitions. All definitions are now local.
5145 % The \cs{global} case was originally so that you could do definitions in
5146 % a group and they would be applied globally. This was a mistake. If
5147 % you make them locally they should stay local. And it caused
5148 % problems with switching page styles, because then the global style
5149 % would be changed, which you generally don't want.\\
5150 % However, when the package option \texttt{compatV3} is given, the old
5151 % behaviour is kept. (See section~\ref{sec:options}.)
5152 % \item The page style \texttt{fancydefault}.
5153 % \item The \cs{headruleskip} parameter.
5154 % \item The \cs{fancyheadinit}, \cs{fancyfootinit}, and
5155 % \cs{fancyhfinit} commands.
5156 % \item[] \textbf{Note:} The following changes were mostly copied from the
5157 % \PKGindex{nccfancyhdr}\pkg{nccfancyhdr} package by Alexander I. Rozhenko.
5158 % \item The \cs{fancycenter} command (section~\ref{sec:fancycenter}).
5159 % \item The \texttt{headings} and \texttt{myheadings} package options
5160 % (see section~\ref{sec:options}).
5161 % \item The \cs{fancypagestyle} command has an optional parameter \oarg{base-style}.
5162 %
5163 % \end{itemize}
5164 %
5165 % \item Version 4.0.1, Jan 28, 2021
5166 % \begin{itemize}
5167 % \item Some documentation corrections, especially in sections
5168 % \ref{sec:xmarks} and \ref{sec:movie}.
5169 % \end{itemize}
5170 % \item Version 4.0.2, May 9, 2022
5171 % \begin{itemize}
5172 % \item Added \cs{leavevmode}\cs{ignorespaces} to each header/footer
5173 % field. The \cs{leavevmode} prevents a bug when a field starts with a
5174 % \cs{color} command. The \cs{ignorespaces} skips initial spaces in
5175 % the parameter, as is usual in a \cs{parbox}, for backwards
5176 % compatibility. However, there are some rare cases where spurious
5177 % spaces can still show up in the header/footer fields. In that case
5178 % the user will have to eliminate these.
5179 % \end{itemize}
5180 % \item Version 4.0.3, May 18, 2022
5181 % \begin{itemize}
5182 % \item Initialize \cs{@mkboth} in \pkg{extramarks.sty} so that
5183 % it will pick up changes to \cs{markboth}.
5184 % \end{itemize}
5185 % \item Version 4.1, Sept 6-Nov 9, 2022
5186 % \begin{itemize}
5187 % \item Implement \texttt{twoside} package option to allow two-sided headers
5188 % and footers in one-sided documents.
5189 % \item Make \pkg{fancyhdr} compatible with the document class \pkg{newlfm}.
5190 % \item Make \cs{nouppercase} compatible with newer definitions of \cs{MakeUppercase}.
5191 % \end{itemize}
5192 % \item Version 4.2, April 19, 2024
5193 % \begin{itemize}
5194 % \item Reset catcodes to their default values in order to facilitate
5195 % \cs{input} in headers/footers when \texttt{verbatim} is active.
5196 % (Issue \# 8 \url{https://github.com/pietvo/fancyhdr/issues/8}.)
5197 % \end{itemize}
5198 % \item Version 4.3, July 17, 2024
5199 % \begin{itemize}
5200 % \item Changed \cs{f@nch@everypar}. If the LaTeX kernel has
5201 % \texttt{expl3}, use \cs{tex\_everypar:D}, and reset \cs{par},
5202 % \cs{@@par} and \cs{endgraf} to their original \TeX{} definitions, so that
5203 % no paragraph hooks will intrude in \pkg{fancyhdr} code\footnote
5204 % {See \url{https://tex.stackexchange.com/q/691262/113546}}.
5205 % Therefore paragraph hooks will not work inside \pkg{fancyhdr} headers and
5206 % footers to avoid unwanted interactions with the main text.
5207 % \end{itemize}
5208 % \item Version 4.3.1, July 23, 2024
5209 % \begin{itemize}
5210 % \item Also reset \cs{everypar} to its original \TeX{} value
5211 % \cs{tex\_everypar:D} in \cs{f@nch@resetpar}, otherwise environments
5212 % based on \cs{trivlist} will not work properly in \pkg{fancyhdr}
5213 % headers and footers.
5214 % \end{itemize}
5215 % \item Version 4.4, Nov 20, 2024
5216 % \begin{itemize}
5217 % \item Add setting the new style marks for \cs{leftmark}
5218 % (\texttt{2e-left}) and \cs{rightmark} (\texttt{2e-right} and
5219 % \texttt{2e-right-nonempty}) in \pkg{extramarks.sty}.
5220 % \end{itemize}
5221 % \item Version 4.5, Nov 21-30, 2024
5222 % \begin{itemize}
5223 % \item \pkg{extramarks}: Don't redefine \cs{leftmark} and \cs{rightmark} in
5224 % \LaTeX{} kernel 2025-06-01 and later.
5225 % \item \pkg{fancyhdr}: use a better method to disable paragraph
5226 % hooks than the v4.3 code.
5227 % \item \pkg{extramarks-v4} (legacy version): add commands
5228 % \cs{extramarksleft} and \cs{extramarksright}.
5229 % \item \pkg{fancyhdr}: added hooks.
5230 % \end{itemize}
5231 % \end{itemize}
5232 %
5233 % \subsection{Changes in version 5}
5234 % \label{sec:version-5}
5235 % Version 5 adds several new features. Most notable is a new
5236 % implementation of the \pkg{extramarks} package, which now has
5237 % independent marks.
5238 %
5239 % \begin{itemize}
5240 % \item Version 5.0, Feb 11, 2021-Jan 1, 2025
5241 % \begin{itemize}
5242 % \item Shorten Warning message about \cs{headheight}/\cs{footskip} too large.
5243 % \item If the option \texttt{[nocheck]} is given, just keep quiet and
5244 % don't change the \cs{headheight}/\cs{footskip} even if the
5245 % \texttt{[compatV3]} option is given.
5246 % \item Added \cs{fancypagestyle*} variant.
5247 % \item Added command \cs{fancyhdrsettoheight}.
5248 % \item New implementation of package \pkg{extramarks} with
5249 % fallback to \pkg{extramarks-v4}.
5250 % \item Mark the \texttt{compatV3} option deprecated.
5251 % \item Added command \cs{fancyfootalign}.
5252 % \item Added command \cs{fancyhdrbox} (section~\ref{sec:fancyhdrbox}).
5253 % \item Added command \cs{fancypagestyleassign} (section~\ref{sec:fancypagestyleassign}).
5254 % \item Added commands \cs{fancyheadwidth}, \cs{fancyfootwidth} and
5255 % \cs{fancyhfwidth} (section~\ref{sec:field-width}).
5256 % \item Many documentation improvements.
5257 % \end{itemize}
5258 % \item Version 5.1, Jan 4-6, 2025
5259 % \begin{itemize}
5260 % \item Bug fix in \pkg{extramarks}.
5261 % \item Better code to save, clear and restore paragraph hooks in headers/footers.
5262 % \end{itemize}
5263 % \item Version 5.1.1, Jan 7, 2025
5264 % \begin{itemize}
5265 % \item Bug fix in save, clear and restore paragraph hooks in headers/footers.
5266 % \end{itemize}
5267 % \item Version 5.2, Jan 14-Feb 7, 2025
5268 % \begin{itemize}
5269 % \item Use official interface to reset the paragraph hooks.
5270 % \item Conditionally require package \pkg{xparse} in fancyhdr.
5271 % \item Require \LaTeX{} version 2018-04-01 or later,
5272 % \item therefore cleanup some pre-2018 code.
5273 % \item Implement \cs{fancyhfwidth} etc. \meta{alignment} option and
5274 % the \texttt{*} form of these commands.
5275 % \item Documentation updates.
5276 % \end{itemize}
5277 % \end{itemize}
5278 %
5279 % \part{Questions \& Answers}
5280 %
5281 % This part contains answers to questions that have been emailed to me,
5282 % or have been asked at various internet forums, and don't have a
5283 % logical place in the other documentation. It is expected to grow
5284 % gradually.
5285 %
5286 %
5287 % \section{Long chapter/section titles}
5288 % \label{sec:longtitles}
5289 %
5290 % \index{long titles}
5291 % Sometimes a chapter or section title is too long to fit in the header
5292 % or footer. It may take more than one line in the header/footer, or it
5293 % may overwrite other parts. How can we shorten these titles in the
5294 % header/footer without changing the actual title?
5295 %
5296 % Here is an example:
5297 % \begin{code}
5298 % \fancyhead[LE,RO]{\nouppercase{\rightmark}} % Section title
5299 % \fancyhead[LO,RE]{\nouppercase{\leftmark}} % Chapter title
5300 % \fancyfoot[C]{\thepage}
5301 % . . .
5302 % \chapter{This is a very long chapter title}
5303 % . . .
5304 % \section{This is a very long section title that will not fit in the header}
5305 % . . .
5306 % \end{code}
5307 % With these settings the header will come out as:
5308 %
5309 % \medskip
5310 % {\noindent\hbox to \textwidth{^^A
5311 % \rlap{\parbox[b]{\textwidth}{\raggedright Chapter 1. This is a very long chapter title}}^^A
5312 % \hfill
5313 % \llap{\parbox[b]{\textwidth}{\raggedleft 1.2. This is a very long
5314 % section title that will not fit in the header}}^^A
5315 % }\strut
5316 % \hrule height\headrulewidth width\textwidth}
5317 % \bigskip
5318 % \noindent which isn't very nice.
5319 % Here I give four options to solve this problem.
5320 %
5321 % \subsection{Using optional arguments}
5322 %
5323 % As we have seen in section~\ref{sec:scoop}, the header info comes from
5324 % the marks. So if we want the text in the header to be shorter we have
5325 % to supply shorter marks. This can be done by giving these as optional
5326 % arguments in the \cs{chapter} and \cs{section} commands.\footnote{At
5327 % least in the \texttt{book} and \texttt{report} documentclasses. In the
5328 % \texttt{article} class this would be the \cs{section} and
5329 % \cs{subsection} commands.}
5330 % \Example{34a}
5331 % \begin{example}
5332 % \chapter[This is a not so long chapter title]
5333 % {This is a very long chapter title to see if we can give
5334 % fancyhdr a shorter one that fits in the header}
5335 % . . .
5336 % \section[Short section title]
5337 % {This is a very long section title that will not fit in
5338 % the header}
5339 % \end{example}
5340 % The short titles will now appear in the header. However, these will
5341 % also appear in the table of contents. If that is what you want then
5342 % you are ready. But if you want to use the long titles in the table of
5343 % contents, you have to use some trickery. In particular you have to
5344 % supply the marks yourself.
5345 %
5346 % \subsection{Using explicit marks}
5347 %
5348 % First we show how you can supply a different value for the chapter
5349 % title in the heading, because this is the easiest. Remember from
5350 % section~\ref{sec:scoop} that this mark is defined by calling
5351 % \cs{chaptermark}\CmdIndex{chaptermark}. Also, because it is used as \cs{leftmark}, the last
5352 % value of this mark on the page is used. So we can easily overrule the
5353 % value that is supplied by the \cs{chapter} command, by supplying an
5354 % additional \cs{chaptermark} command after the \cs{chapter} command,
5355 % like this:
5356 % \Example{34b}
5357 % \begin{example}
5358 % \chapter{This is a long chapter title that does not fit in the header}
5359 % \chaptermark{This is a not so long chapter title}
5360 % \end{example}
5361 % For the section titles the situation is more complicated. Here we use
5362 % the \cs{rightmark}, which uses the first mark of its kind on the page.
5363 % So you might think putting a \cs{sectionmark}\CmdIndex{sectionmark} before the \cs{section}
5364 % command would be the solution. Unfortunately, it is not that simple.
5365 % In many cases, this will work, but not when there is a page break just
5366 % before the section title, because in that case the \cs{sectionmark}
5367 % will stay behind on the previous page. However, we can put the
5368 % \cs{sectionmark} inside the argument of the \cs{section} command.
5369 % Because \LaTeX{} first typesets the title (which will execute the
5370 % included \cs{sectionmark} command), and after that executes its own
5371 % \cs{sectionmark}, our \cs{sectionmark} will be the first. But
5372 % there is one case in which this fails: if the next page does not have any
5373 % \cs{sectionmark} commands, it will inherit the \textbf{last} mark from the page
5374 % before it, which will be the long title. To correct this we must also
5375 % give an additional \cs{sectionmark} with the short title
5376 % \textbf{after} the \cs{section} command.
5377 %
5378 % As if this isn't enough, there is still a problem with this setup. Our
5379 % section title is not only used to typeset the title in the text, but
5380 % it is also included in the table of contents. But the table of
5381 % contents does not accept a \cs{sectionmark} in its title. It will
5382 % generate an ugly error message. To prevent this we must give the long
5383 % title (that we want to appear in the table of contents) also as the
5384 % optional argument to the \cs{section} command. Of course this will
5385 % also generate a mark for the header, but this will be overruled by
5386 % our included \cs{sectionmark} commands
5387 %
5388 % So the complete code would be:
5389 % \begin{code}
5390 % \section[Long title]{Long title\sectionmark{Short title}}
5391 % \sectionmark{Short title}
5392 % \end{code}
5393 % To avoid all the repetitions, it is better to make a macro:
5394 % \Example{34b}[(continued)]
5395 % \begin{example}
5396 % \newcommand{\Section}[2]{%
5397 % \section[#1]{#1\sectionmark{#2}}\sectionmark{#2}}
5398 % . . .
5399 % \Section{This is a long section title that will not fit in
5400 % the header}{Shortened section title}
5401 % \end{example}
5402 % And if you want to use yet a different text in the table of contents,
5403 % you can make a macro with three parameters. The third parameter is the
5404 % text to be put in the table of contents. We use this parameter as the
5405 % optional argument for the \cs{section} command.
5406 % \Example{34b}[(continued)]
5407 % \begin{example}
5408 % \newcommand{\Sectionx}[3]{%
5409 % \section[#3]{#1\sectionmark{#2}}\sectionmark{#2}}
5410 % . . .
5411 % \Sectionx{This is another long section title that will not
5412 % fit in the header}{Short section title 3}
5413 % {This is the section title in the table of contents}
5414 % \end{example}
5415 % Please note that if you use the \texttt{article} class, instead of
5416 % \cs{chaptermark} and \cs{sectionmark}, you would probably use
5417 % \cs{sectionmark} and \cs{subsectionmark}.
5418 %
5419 % \subsection{Using automatic truncation}
5420 %
5421 % For this solution we use the \PKGindex{truncate}\pkg{truncate} package by Donald
5422 % Arseneau. This has a \cs{truncate}\CmdIndex{truncate} command that
5423 % truncates a text to a maximum size, when it exceeds that size. We put
5424 % both headers in \cs{truncate} to limit it to half the \cs{headwidth}.
5425 % Of course it is also possible to make asymmetric arrangements.
5426 % \Example{34c}
5427 % \begin{example}
5428 % \usepackage[fit]{truncate}
5429 % \fancyhead[LE,RO]{\nouppercase{%
5430 % \truncate{0.5\headwidth}{\rightmark}}} % Section title
5431 % \fancyhead[LO,RE]{\nouppercase{%
5432 % \truncate{0.5\headwidth}{\leftmark}}} % Chapter title
5433 % \end{example}
5434 % We don't have to make any changes to the chapter and section titles
5435 % because \cs{truncate} will take care of this.
5436 % This arrangement gives the following header when both titles are too
5437 % big, like in the example above:
5438 %
5439 % \medskip
5440 % {\noindent\hbox to \textwidth{^^A
5441 % \truncate{0.5\textwidth}{Chapter 1. This is a very long chapter title that does not fit in the header}^^A
5442 % \hfill
5443 % \truncate{0.5\textwidth}{1.2. This is a very long section title that will not fit in the header}^^A
5444 % }\strut
5445 % \hrule height\headrulewidth width\textwidth}
5446 % \bigskip
5447 %
5448 % Note that we have used the \texttt{[fit]} option of the
5449 % \pkg{truncate} package. Otherwise the right header will not be
5450 % right aligned, but it will start at halfway the header.
5451 % Note also that, as each part can occupy half of the available width,
5452 % they could theoretically touch each other. This can be prevented by
5453 % making the widths slightly smaller. And when there is only one title
5454 % in the header, you can make the width equal to or slightly smaller
5455 % than \cs{headwidth}. A more sophisticated solution would be to check
5456 % if one of the header parts is small enough and then truncate the other
5457 % one for the remaining space.
5458 %
5459 % \subsection{Using \Cmd{fancyheadwidth}}
5460 % \label{sec:with-fancyheadwidth}
5461 %
5462 % For this solution we use the \cs{fancyheadwidth} command to give each
5463 % part a little less than half of the \cs{headwidth}. This command is
5464 % available in \texttt{fancyhdr} version 5.0 and later.
5465 % Of course it is also possible to make asymmetric arrangements.
5466 % \Example{34d}
5467 % \begin{example}
5468 % \setlength{\headheight}{35pt}
5469 % \fancyhead[LE,RO]{\nouppercase{\rightmark}} % Section title
5470 % \fancyhead[LO,RE]{\nouppercase{\leftmark}} % Chapter title
5471 % \fancyfoot[LE,RO]{\thepage}
5472 % \fancyheadwidth[L,R]{0.48\headwidth}
5473 % . . .
5474 % \chapter{This is a very long chapter title to see if we can
5475 % let fancyhdr fit it in the header}
5476 % \section{This is a very long section title that will not fit in the header}
5477 % \end{example}
5478 % We don't have to make any changes to the chapter and section titles.
5479 % This arrangement gives the following header when both titles are too
5480 % big, like in the example above:
5481 %
5482 % \bigskip
5483 % \showheader{
5484 % \setlength{\headheight}{35pt}
5485 % \fancyhead[L]{Chapter 1. This is a very long chapter title to see if we can
5486 % let fancyhdr fit it in the header}
5487 % \fancyhead[R]{1.1. This is a very long section title that will not fit in the header}
5488 % \fancyheadwidth[L,R]{0.48\headwidth}
5489 % }
5490 %
5491 % You may not like that the two parts of the header are aligned at the
5492 % bottom, which is the default for the header. We can use the second
5493 % optional parameter of \cs{fancyheadwidth} to specify a different
5494 % alignment (in \pkg{fancyhdr} version 5.2 or later). See the following example.
5495 % \Example{34e}
5496 % \begin{example}
5497 % \setlength{\headheight}{35pt}
5498 % \fancyhead[LE,RO]{\nouppercase{\rightmark}} % Section title
5499 % \fancyhead[LO,RE]{\nouppercase{\leftmark}} % Chapter title
5500 % \fancyfoot[LE,RO]{\thepage}
5501 % \fancyheadwidth*[L,R][tj]{0.48\headwidth}
5502 % \fancyfootwidth*[LE,RO][-c]{0.1\headwidth}
5503 % \end{example}
5504 % We use \texttt{t} for the vertical alignment, and also \texttt{j}
5505 % (justified) for the horizontal alignment. Just for fun we use the
5506 % \texttt{*} form of the command, and also add \cs{fancyfootwidth*}.
5507 % This puts the page number under the page a little bit away from the
5508 % edge of the text.
5509 %
5510 % The resulting header looks like:
5511 %
5512 % \bigskip
5513 % \showheader{
5514 % \setlength{\headheight}{35pt}
5515 % \fancyhead[L]{Chapter 1. This is a very long chapter title to see if we can
5516 % let fancyhdr fit it in the header}
5517 % \fancyhead[R]{1.1. This is a very long section title that will not fit in the header}
5518 % \fancyheadwidth*[L,R][tj]{0.48\headwidth}
5519 % }
5520 %
5521 % Please note, that these solutions also have disadvantages. The header
5522 % must be quite tall, and when a smaller title is used there is a gap
5523 % between the title and the line under the header.
5524 %
5525 % \section{I lost my chapter/section titles}
5526 %
5527 % Some time ago I got a question like this (edited to get the
5528 % essentials):
5529 %
5530 % ``I redefined the \Cmd{pagestyle\{fancy\}} to get my own kind of headings. Also, I
5531 % redefined the \cs{chaptermark}.
5532 % I need the \texttt{fancy} style from chapter 1 and on (mainmatter part), but, until the Introduction
5533 % chapter (that I included into the frontmatter part) I need the \texttt{myheadings}\PSindex{myheadings} style.
5534 %
5535 % When I set the \texttt{myheadings} style into
5536 % the frontmatter the \texttt{fancy} style doesn't show the chapter title any more.
5537 %
5538 % What can I do in order to reestablish the right behavior of the
5539 % \texttt{fancy} style?''
5540 %
5541 % The solution to this problem is actually very simple. The page style
5542 % \texttt{myheadings} (as well as \texttt{headings}\PSindex{headings}) redefines the
5543 % \cs{chaptermark} and \cs{sectionmark}, so when you return to page style
5544 % \texttt{fancy}, the definitions you had given before (or the ones that
5545 % \pkg{fancyhdr} provided) are lost. You
5546 % just have to repeat them at the point where you switch back to
5547 % page style \texttt{fancy}.
5548 %
5549 % \begin{code}
5550 % \begin{document}
5551 % \frontmatter
5552 % \pagestyle{myheadings}
5553 % . . .
5554 % \mainmatter
5555 % \pagestyle{fancy}
5556 % \renewcommand{\chaptermark}[1]{....}
5557 % \end{code}
5558 %
5559 %
5560 % \section{Can I use \pkg{fancyhdr} with the \pkg{beamer} class?}
5561 % \label{sec:beamer}
5562 %
5563 % \TTindex{beamer}%
5564 % The \pkg{beamer} class has its own provisions for headers and
5565 % footers with the \texttt{headline} and \texttt{footline} templates.
5566 % The advantage of these is that they blend well with the
5567 % \pkg{beamer} theme in use.
5568 %
5569 % Still people sometimes ask if \pkg{fancyhdr} can be used for
5570 % header and footers because they are more familiar with this. I would
5571 % advice to use the standard \pkg{beamer} features if possible, but
5572 % actually it isn't difficult to use \pkg{fancyhdr} if you take
5573 % provisions that the header and the footer don't
5574 % interfere with the \pkg{beamer} layout. This can be done with
5575 % \begin{code}[commandchars={+[]}]
5576 % \setbeamertemplate{headline}{\vspace{+meta[headheight]}}
5577 % \setbeamertemplate{footline}{\vspace{+meta[footskip]}}
5578 % \end{code}
5579 % \CmdIndex{headheight}\CmdIndex{footskip}%
5580 % Note that \pkg{beamer} sets \cs{headheight} and \cs{footskip} to
5581 % its own vales, so it doesn't make sense to set these in your document.
5582 % Instead you supply the desired values with \cs{setbeamertemplate} as above.
5583 % Also it is advised to add \cs{fancyfootalign}\texttt{\{0pt\}} to
5584 % prevent the footer to be too close to the bottom edge; see section~\ref{sec:fancyfootalign}
5585 % on page~\pageref{sec:fancyfootalign}.\\
5586 % Here is a complete example:
5587 % \NoExample{with-beamer}
5588 % \begin{example}
5589 % \documentclass{beamer}
5590 % \usepackage{graphicx}
5591 % \usepackage{fancyhdr}
5592 % \pagestyle{fancy}
5593 % \fancyhead[L]{\includegraphics[width=0.1\textwidth]{example-image}}
5594 % \fancyhead[R]{Course Name}
5595 % \fancyhead[C]{\textbf{Subject}\\Author}
5596 % \fancyfoot[L]{LEFT page footer}
5597 % \fancyfoot[R]{RIGHT page footer}
5598 % \fancyfoot[C]{{\thepage}}
5599 % \fancyfootinit{\tiny}
5600 % \renewcommand{\footrulewidth}{0.4pt}
5601 %
5602 % \setbeamertemplate{headline}{\vspace{30pt}}
5603 % \setbeamertemplate{footline}{\vspace{14pt}}
5604 % \fancyfootalign{0pt}
5605 %
5606 % \begin{document}
5607 %
5608 % \begin{frame}{Subject Title}
5609 % Text of the slide
5610 % \end{frame}
5611 %
5612 % \end{document}
5613 % \end{example}
5614 %
5615 % \section{I want the first section and the first subsection in my headers}
5616 % \label{sec:firstsubsection}
5617 %
5618 % A question that is regularly asked (e.g., on
5619 % \texttt{tex.stackexchange.com}\footnote{See for example
5620 % \url{https://tex.stackexchange.com/q/586066/113546}}) is how to get
5621 % both the first section title and the first subsection title in the
5622 % headers in the \pkg{article} documentclass. Unfortunately,
5623 % traditional \LaTeX{} (releases before November 2022) can't give you
5624 % the first subsection on the page. There are two problems:
5625 % \begin{itemize}
5626 % \item Traditional \LaTeX{} uses left marks for the section title and
5627 % right marks for the subsection title. But it only has commands to
5628 % extract the last left mark (\cs{leftmark}) and the first right mark
5629 % (\cs{rightmark}). This means that if there are two or more sections on
5630 % the page you get the last one, which can be counter-intuitive.
5631 % The newer \LaTeX{} releases (November 2022 or later) have a command
5632 % (\Cmd{FirstMark\{2e-left\}}) to
5633 % get the first of the left marks, however. \textbf{We assume in the
5634 % following code that your \LaTeX{} is recent enough.}
5635 % \item \LaTeX{} uses \cs{markboth} at a section title in the
5636 % \pkg{article} class. This also sets an empty right mark. So in
5637 % some cases you would get an empty subsection title in the header. Also
5638 % a \cs{part} command issues a \Cmd{markboth\{\}\{\}}, so it generates
5639 % empty marks too. To avoid this, \LaTeX{} now has an additional mark
5640 % \texttt{2e-right-nonempty} in which only the non-empty right marks are
5641 % saved. This is also set by \cs{markboth} and \cs{markright}.
5642 % \end{itemize}
5643 %
5644 % If there is no \cs{section} command on the page, it `inherits' the
5645 % last section title of a previous page. Similarly for subsections.
5646 % This gives us the following code:
5647 %
5648 % \Example{35}[(basic)]
5649 % \begin{example}
5650 % \usepackage{fancyhdr}
5651 % \pagestyle{fancy}
5652 % \fancyhead[L]{\FirstMark{2e-left}}
5653 % \fancyhead[R]{\FirstMark{2e-right-nonempty}}
5654 % \fancyfoot[C]{\thepage}
5655 %
5656 % \begin{document}
5657 % \section{Section One}
5658 % \subsection{Subsection One}
5659 % . . .
5660 % \end{example}
5661 % This mostly solves the problem, but it has some undesirable
5662 % properties, see below. Therefore, some refinement is
5663 % possible. But we need an extra mark for this. We are also going
5664 % to use new marks, instead of using the standard
5665 % marks to get more control. We need two marks for this,
5666 % one for the section title, and one for the subsection title. We call
5667 % these \texttt{section} and \texttt{subsection} respectively. We
5668 % replace the marking code above with the following, which gives
5669 % the same result:
5670 % \Example{35}[(new marks)]
5671 % \begin{example}
5672 % \usepackage{fancyhdr}
5673 % \pagestyle{fancy}
5674 % \NewMarkClass{section}
5675 % \NewMarkClass{subsection}
5676 % \fancyhead[L]{\FirstMark{section}}
5677 % \fancyhead[R]{\FirstMark{subsection}}
5678 % \renewcommand{\sectionmark}[1]{%
5679 % \InsertMark{section}{\thesection. #1}}
5680 % \renewcommand{\subsectionmark}[1]{%
5681 % \InsertMark{subsection}{\thesubsection. #1}}
5682 % \end{example}
5683 %
5684 % Now when you have a \cs{section} command on a page, but it doesn't
5685 % have a subsection for an extended length, then, the previous
5686 % subsection title is `inherited' on this page. This may be sub-optimal,
5687 % because it combines the title of section $n$ with a subsection title
5688 % that belongs to a previous section, so the subsection isn't even
5689 % present on the page, which looks unnatural. You may want to
5690 % suppress the subsection title in the right header in this case. With the new
5691 % \LaTeX{} marks this is possible.
5692 %
5693 % What we want is essentially the following:
5694 % \begin{enumerate}
5695 % \item If there is at least one subsection on the page, use the first one.
5696 % \item Otherwise, if the previous page ended in a subsection (i.e., the page
5697 % break was inside a subsection), use that subsection title.
5698 % \item Otherwise (the page break was inside a section that had no
5699 % subsections thus far), leave the right header empty.
5700 % \end{enumerate}
5701 %
5702 % The first test can be done by comparing the subsection `topmark' and
5703 % `firstmark'. The topmark is the last mark from the previous page
5704 % (which might even have been inherited from an earlier page). If there
5705 % is no subsection mark on the current page, firstmark is made equal to
5706 % topmark. If there is a subsection mark on the page, firstmark will be
5707 % a different mark. \LaTeX{} now has a command to compare the
5708 % marks, like this:\\
5709 % \hspace*{\parindent}\cs{IfMarksEqualTF}\marg{mark}\marg{pos1}\marg{pos2}\marg{true
5710 % code}\marg{false code}\\
5711 % where the \emph{pos} arguments are \texttt{top}, \texttt{first} or \texttt{last}.
5712 % Please note that this test makes only sense in a header or
5713 % footer\footnote{Or more generally, when \LaTeX's page building is active.}.
5714 % So if we use\\
5715 % \hspace*{\parindent}\cs{IfMarksEqualTF}\texttt{\{subsection\}\{top\}\{first\}}\ldots\\
5716 % the \meta{true code} is executed when there is no subsection title on the
5717 % current page, and the \meta{false code} when there is at least one.
5718 %
5719 % However, there is no command to see if the page break is at the section
5720 % or subsection level, because the two are independent. And we
5721 % cannot use \LaTeX{} variables for this, because of the asynchronous
5722 % processing of the page breaking. But we can do this if we introduce a
5723 % new mark `\texttt{which}', that is used by both \cs{section} and
5724 % \cs{subsection}. We let \cs{sectionmark} put ``0'' in it, and
5725 % \cs{subsectionmark} ``1''. The lastmark of `\texttt{which}' on a page then
5726 % indicates if the page ends within a subsection or not. And as the
5727 % topmark on the following page is the same as lastmark on the previous
5728 % page, we can use this topmark to see whether the text at the beginning
5729 % of the page comes from a section or a subsection (topmark = 0 means
5730 % section, 1 means subsection).
5731 %
5732 % So the interim new code for the right header becomes the following.\\
5733 % \textbf{if} there is no subsection on the page\\
5734 % \textbf{then}\\
5735 % \hspace*{2em}\textbf{if} the previous page ended in a subsection\\
5736 % \hspace*{2em}\textbf{then} use (inherit) that subsection\\
5737 % \hspace*{2em}\textbf{else} use an empty header\\
5738 % \hspace*{2em}\textbf{fi}\\
5739 % \textbf{else} (there is at least one subsection on the page)\\
5740 % \hspace*{2em}use the first subsection\\
5741 % \textbf{fi}\\[1ex]
5742 % We use the
5743 % package \PKGindex{ifthen}\pkg{ifthen} for the test.
5744 %
5745 % \Example{35}[(continued)]
5746 % \begin{example}
5747 % \NewMarkClass{which} % Preamble
5748 % \InsertMark{which}{0} % Initialize so there is always a valid value
5749 %
5750 % \fancyhead[R]{%
5751 % \IfMarksEqualTF{subsection}{top}{first}
5752 % {% no subsection mark on this page
5753 % \ifthenelse{\TopMark{which}=1} % previous page ended in a subsection
5754 % % then use (inherit) that subsection
5755 % {\TopMark{subsection}}%
5756 % {}% otherwise empty right header
5757 % }
5758 % {% there is a subsectionmark on the page, use it
5759 % \FirstMark{subsection}%
5760 % }%
5761 % }
5762 % \renewcommand{\sectionmark}[1]{%
5763 % \InsertMark{section}{\thesection. #1}%
5764 % \InsertMark{which}{0}%
5765 % }
5766 % \renewcommand{\subsectionmark}[1]{%
5767 % \InsertMark{subsection}{\thesubsection. #1}%
5768 % \InsertMark{which}{1}%
5769 % }
5770 % \end{example}
5771 %
5772 % There is one caveat, however. If the page begins immediately with a
5773 % section title, the topmark may indicate that the previous page ended
5774 % with a subsection, but that subsection did not extend past the
5775 % page break.
5776 % So we want to suppress the `inheritance' of the subsection if there
5777 % is a section title at the top of the page and the page contains no
5778 % subsection title. The information whether a section title is at the
5779 % top of the page is not available in the marks, so we need some other
5780 % way to detect this.
5781 %
5782 % \TeX{} has two variables that can help us, \cs{pagegoal} is the vertical size
5783 % that is available on the page, and \cs{pagetotal} is the amount we
5784 % have used so far\footnote{This doesn't include floats and footnotes.}.
5785 % So if \cs{pagetotal}=\texttt{0pt} we are at the top of
5786 % the page, otherwise somewhat further down. We can use this information to
5787 % communicate to the header that no inheritance should take place. In
5788 % reality, sometimes there is already a small amount of white space on
5789 % the page, so the test should be less strict than
5790 % \cs{pagetotal}=\texttt{0pt}. We might even choose to not inherit the
5791 % subsection title if only a few lines of the previous subsection are
5792 % present at the top of the page. Or maybe your design asks for no
5793 % inheritance if the subsection at the top of the page before the
5794 % section header is smaller than 1/3 of the page. The test would then be
5795 % \cs{pagetotal}$<$0.33\cs{pagegoal}. In the code below we choose a few
5796 % lines as the limit.
5797 %
5798 % We have to do the test at the beginning of the \cs{section} command
5799 % processing. This can be done with a \LaTeX{} \emph{hook}.
5800 %
5801 % The next question is how to communicate the fact that the section
5802 % starts at (or near) the top of the page to the header. A simple way to
5803 % do this could be to set the `\texttt{which}' mark to a different value, e.g,
5804 % $-1$ instead of 0. However, below we will present a better way.
5805 %
5806 % \begin{code}
5807 % \AddToHook{cmd/section/before}{%
5808 % % use whatever test your design requires
5809 % \ifthenelse{\lengthtest{\pagetotal<4\baselineskip}}
5810 % {indicate section at top of page}
5811 % {indicate section somewhere else}
5812 % }
5813 % \end{code}
5814 %
5815 % There is another situation where a section title could end up at the
5816 % top of the page: when it is processed at the bottom of the page, but
5817 % there isn't enough space left to place it there. It will then be
5818 % pushed to the next page. In that case the \cs{pagetotal} will be in
5819 % the neighbourhood of \cs{pagegoal}. However, it is very difficult to
5820 % find a proper value for the cutoff of \cs{pagetotal}. In many cases it
5821 % will be too small or too big, depending on the size of the section
5822 % title. So we need a different way.
5823 %
5824 % If the section title is pushed to the next page, the page number of
5825 % the page where the section title is processed will be different from
5826 % the page number that is current when the header is created. (We assume
5827 % that all page numbers are different.) So by storing the page number
5828 % atvthe time of processing the section title, and then comparing it in the header with
5829 % the \texttt{page} counter, we can check that the header was
5830 % moved to another page from an earlier page. This doesn't have
5831 % to be \textbf{the} next page, as there could be float pages in
5832 % between. The test has to be done while we are in the header, not while
5833 % we are processing the section title. And it is not enough to store the page
5834 % number in a variable because there can be subsequent section titles on
5835 % the next page and these would overwrite the saved value. So it must be stored in
5836 % yet another mark. Let's call this mark \texttt{whichpage}. We can save
5837 % this in the \cs{sectionmark} command.
5838 %
5839 % Now, in the right header, we can check if \Cmd{FirstMark\{whichpage\}}
5840 % is equal to \cs{thepage}. If they are different, the section title was
5841 % pushed across a page boundary, so it is at the top of the page. Note
5842 % that this test makes only sense if there is a section title on the
5843 % page, so we have to include a test for this also. This can be done
5844 % with \Cmd{IfMarksEqualTF\{section\}\{top\}\{first\}}. A compact way to
5845 % do this is:
5846 % \begin{code}
5847 % \equal{\IfMarksEqualTF{section}{top}{first}
5848 % {\thepage}{\FirstMark{whichpage}}}{\thepage}}%
5849 % \end{code}
5850 %
5851 % So if there is no section on the page, we don't compare
5852 % \texttt{whichpage} to \cs{thepage}, but instead compare \cs{thepage}
5853 % with itself, which gives \emph{true}, i.e. no section at the top of the page.
5854 %
5855 % We use a string comparison for the page number, not a numerical
5856 % comparison, because page numbers can be non-numeric, for example roman
5857 % numbers, which can't be compared numerically.
5858 %
5859 % This gives us now a way to indicate the previous case for a section
5860 % title at the top of the page: Just put a value in the
5861 % \texttt{whichpage} mark that is different from the actual page number.
5862 % But as the test is done in the hook, and the setting of the mark in
5863 % \cs{sectionmark}, we must communicate this through a variable. Let's
5864 % call this variable \cs{whichpage}. I have chosen to just put the text
5865 % ``top'' in front of the page number to make it different, but any
5866 % value that can't be a page number would be good.
5867 %
5868 % \Example{35}[(continued)]
5869 % \begin{example}
5870 % \NewMarkClass{whichpage}
5871 % \newcommand\whichpage{}
5872 %
5873 % \AddToHook{cmd/section/before}{%
5874 % % use whatever test your design requires
5875 % \ifthenelse{\lengthtest{\pagetotal<4\baselineskip}}
5876 % {\renewcommand{\whichpage}{top\thepage}}%
5877 % {\renewcommand{\whichpage}{\thepage}}%
5878 % }
5879 %
5880 % \renewcommand{\sectionmark}[1]{%
5881 % \InsertMark{section}{\thesection\ #1}%
5882 % \InsertMark{which}{0}%
5883 % \InsertMark{whichpage}{\whichpage}%
5884 % }
5885 % \end{example}
5886 %
5887 % In the example 35 file you can see this in section~6.
5888 %
5889 % The final code for the right header will now be:
5890 %
5891 % \Example{35}[(continued)]
5892 % \begin{example}
5893 % \fancyhead[R]{%
5894 % \IfMarksEqualTF{subsection}{top}{first}
5895 % {% no subsection mark on this page
5896 % \ifthenelse{%
5897 % % previous page ended in a subsection
5898 % \TopMark{which}=1\and
5899 % % Is there a section on the page?
5900 % \equal{\IfMarksEqualTF{section}{top}{first}
5901 % {\thepage}{\FirstMark{whichpage}}}{\thepage}}%
5902 % {
5903 % % use previous subsection unless suppressed by section on top
5904 % \TopMark{subsection}%
5905 % }
5906 % % otherwise use empty right header
5907 % {}%
5908 % }
5909 % {% if there is a subsectionmark on the page, use it
5910 % \FirstMark{subsection}%
5911 % }%
5912 % }
5913 % \end{example}
5914 % In the actual code in the Example 35 file there is also some debugging
5915 % code added.
5916 %
5917 % \subsection{The headers in this document}
5918 %
5919 % Now we will describe how the headers in the \pkg{fancyhdr}
5920 % documentation (this document) are constructed. This documentation
5921 % consists of a number of sections, some of which have one or more
5922 % subsections. There is only one title in the header, which is the
5923 % title of the [sub]section that is current at the top of the page. In
5924 % other words, the last one on a previous page. This asks for a `top mark'.
5925 %
5926 % Because both sections and subsections are treated the same, we use a
5927 % single mark for both, and we put the common code in macros. We could
5928 % have chosen a new mark for the titles, but \LaTeX's standard right
5929 % mark is sufficient for this\footnote{This is better than the left mark, bcause that
5930 % doesn't have a way to filter out empty ones which are generated by the
5931 % \cs{part} commands in the document, and also \cs{leftmark} will
5932 % produce the last title of the current page, which isn't useful.}.
5933 %
5934 % When a [sub]section title is at or near the top of the page, we will
5935 % use that title in the header instead of the one from the previous
5936 % page, because this look more natural (the previous one does have no or
5937 % very little text on the current page), just like in the previous
5938 % example (35). We use the same mechanism, with a mark \texttt{whichpage} to
5939 % achieve this. Because we put sections and subsections together, we
5940 % don't need a mark to distinguish them. Example~36 has essentially the
5941 % same headers as this documentation.
5942 %
5943 % The macro \cs{checkposinpage} checks whether the [sub]section starts
5944 % at or near the top of the page, and puts this information in the
5945 % variable \cs{whichpage}, just like in example~35. The macro
5946 % \cs{setmarks}, sets the marks, both the right mark for the title (with
5947 % \cs{markright}), and the extra mark \texttt{whichpage}.
5948 %
5949 % \Example{36}
5950 % \begin{example}
5951 % \NewMarkClass{whichpage}
5952 % \newcommand\whichpage{}
5953 %
5954 % \newcommand\checkposinpage{
5955 % \ifthenelse{\lengthtest{\pagetotal<4\baselineskip}}%
5956 % {\renewcommand{\whichpage}{top\thepage}}%
5957 % {\renewcommand{\whichpage}{\thepage}}%
5958 % }
5959 %
5960 % \AddToHook{cmd/section/before}{\checkposinpage}
5961 % \AddToHook{cmd/subsection/before}{\checkposinpage}
5962 %
5963 % \newcommand\setmarks[1]{%
5964 % \InsertMark{whichpage}{\whichpage}%
5965 % \markright{#1}%
5966 % }
5967 %
5968 % \renewcommand{\sectionmark}[1]{%
5969 % \setmarks{\thesection\quad#1}%
5970 % }%
5971 %
5972 % \renewcommand{\subsectionmark}[1]{%
5973 % \setmarks{\thesubsection\quad#1}%
5974 % }%
5975 % \end{example}
5976 %
5977 % Finally, the header code. For the last title of the/a previous page we
5978 % use \Cmd{TopMark\{2e-right-nonempty\}}, for a title that is at/near
5979 % the top of the page we use \cs{rightmark}. The algorithm is similar to
5980 % example~35, but simplified:\\[1ex]
5981 % ^^A
5982 % \textbf{if} \texttt{whichpage} = \verb|\thepage| (i.e., no [sub]section at or near top)\\
5983 % \textbf{then}\\
5984 % \hspace*{2em} use last [sub]section from a previous page\\
5985 % \textbf{else} (\texttt{whichpage} $\ne$ \verb|\thepage|)\\
5986 % \hspace*{2em} \textbf{if} there is no \texttt{whichpage} mark on this page\\
5987 % \hspace*{3em} (this means the \texttt{whichpage} mark is not valid for this page)\\
5988 % \hspace*{2em} \textbf{then} use last [sub]section from a previous page\\
5989 % \hspace*{2em} \textbf{else} (there is a [sub]section title at/near the top of the page)\\
5990 % \hspace*{3em} use first [sub]section of current page\\
5991 % \textbf{fi}
5992 %
5993 % \Example{36}[(Continued)]
5994 % \begin{example}
5995 % \fancypagestyle*{fancy}{%
5996 % \fancyhf{}
5997 % \fancyhead[L]{%
5998 % \ifthenelse{\equal{\FirstMark{whichpage}}{\thepage}}%
5999 % {\TopMark{2e-right-nonempty}}%
6000 % % whichpage != page
6001 % {\IfMarksEqualTF{whichpage}{top}{first}%
6002 % {\TopMark{2e-right-nonempty}}% no mark on this page
6003 % {\rightmark}% title at/near the top of the page
6004 % }%
6005 % }
6006 % \fancyhead[R]{\textbf{\thepage}}
6007 % }
6008 % \end{example}
6009 %
6010 % In the example~36 file there is some additional code for debugging
6011 % that we don't show here.
6012 %
6013 % In this documentation there are some cases that aren't covered by this
6014 % code: the \Cmd{part} commands do not have a corresponding
6015 % \Cmd{partmark}, and there are some hidden \Cmd{section*} commands that
6016 % do not call \Cmd{sectionmark}. In these cases we manually add the
6017 % \cs{checkposinpage} and \cs{setmarks} commands.
6018 %
6019 % \section{How to change shapes and traits of horizontal lines in headers/footers?}
6020 % \label{sec:headrules}
6021 %
6022 % Sometimes one wants a decorative line in the header or footer that is
6023 % a bit more sophisticated than a straight line\footnote{See \url{https://tex.stackexchange.com/q/717266/113546}}.
6024 %
6025 % If you just want to change the thickness, redefine \cs{headrulewidth}. For example:
6026 % \begin{code}
6027 % \renewcommand{\headrulewidth}{0.1pt}
6028 % \end{code}
6029 % For more complicated forms you have to redefine \cs{headrule}. One
6030 % example has already been given in section~\ref{sec:fancy}, and we will
6031 % repeat it here:
6032 % \PKGindex{fourier-orns}
6033 % \begin{code}
6034 % \usepackage{fourier-orns}
6035 % ...
6036 % \renewcommand\headrule{%
6037 % \vspace{-6pt}
6038 % \hrulefill
6039 % \raisebox{-2.1pt}
6040 % {\quad\decofourleft\decotwo\decofourright\quad}%
6041 % \hrulefill}
6042 % \end{code}
6043 % This gives us the following headrule:
6044 %
6045 % \noindent\makebox[\textwidth]{\hrulefill
6046 % \raisebox{-2.1pt}[10pt][10pt]{\quad\decofourleft\decotwo\decofourright\quad}\hrulefill}
6047 %
6048 % Here a simple \cs{headrule}, but with color, and a bit thicker.
6049 % \PKGindex{xcolor}
6050 % \begin{code}
6051 % \usepackage{xcolor}
6052 % . . .
6053 % \renewcommand\headrule{%
6054 % \nointerlineskip
6055 % \smash{\color{blue}\rule{\headwidth}{2.5pt}}%
6056 % }
6057 % \end{code}
6058 % The \cs{nointerlineskip} is to prevent \LaTeX{} to insert the normal
6059 % vertical space between lines, and the \cs{smash} to let the
6060 % \cs{headrule} not occupy any vertical space. Whether you want that is
6061 % up to you, but if it occupies vertical space it may distort the page layout.\\
6062 % This gives us the following headrule:
6063 %
6064 % \noindent\makebox[\textwidth]{\smash{\color{blue}\rule{\textwidth}{2.5pt}}}\\
6065 %
6066 % Now some dotted and dashed headrules:
6067 %
6068 % With spaced dashes:
6069 % \begin{code}
6070 % \newbox\dashbox\setbox\dashbox\hbox{-\,}
6071 % \renewcommand{\headrule}{%
6072 % \smash{\makebox[\headwidth][c]{\xleaders\copy\dashbox\hfill-}}%
6073 % }
6074 % \end{code}
6075 % This gives:
6076 %
6077 % \newbox\dashbox\setbox\dashbox\hbox{-\,}
6078 % \noindent\makebox[\textwidth][c]{\xleaders\copy\dashbox\hfill-}\\
6079 %
6080 % With longer dashes:
6081 % \begin{code}
6082 % \newbox\dashbox\setbox\dashbox\hbox{---\,}
6083 % \renewcommand{\headrule}{%
6084 % \smash{\makebox[\headwidth][c]{\xleaders\copy\dashbox\hfill---}}%
6085 % }
6086 % \end{code}
6087 % This gives:
6088 %
6089 % \newbox\dashbox\setbox\dashbox\hbox{---\,}
6090 % \noindent\makebox[\textwidth][c]{\xleaders\copy\dashbox\hfill---}\\
6091 %
6092 % With spaced dots:
6093 % \begin{code}
6094 % \newbox\dashbox\setbox\dashbox\hbox{.\,}
6095 % \renewcommand{\headrule}{%
6096 % \smash{\makebox[\headwidth][c]{\xleaders\copy\dashbox\hfill.}}%
6097 % }
6098 % \end{code}
6099 % This gives:
6100 %
6101 % \setbox\dashbox\hbox{.\,}
6102 % \noindent\makebox[\textwidth][c]{\xleaders\copy\dashbox\hfill.}\\
6103 %
6104 % With unspaced dots:
6105 % \begin{code}
6106 % \newbox\dashbox\setbox\dashbox\hbox{.}
6107 % \renewcommand{\headrule}{%
6108 % \smash{\makebox[\headwidth][c]{\xleaders\copy\dashbox\hfill.}}%
6109 % }
6110 % \end{code}
6111 % This gives:
6112 %
6113 % \setbox\dashbox\hbox{.}
6114 % \noindent\makebox[\textwidth][c]{\xleaders\copy\dashbox\hfill.}\\
6115 %
6116 % Here is an example with a color gradient, using \PKGindex{tikz}\pkg{tikz}:
6117 % \CmdIndex{tikz}
6118 % \begin{code}
6119 % \usepackage{tikz}
6120 % \renewcommand{\headrule}{%
6121 % \tikz \fill [left color=green,right color=yellow]
6122 % (0,0) rectangle (\headwidth,2.5pt);
6123 % }
6124 % \end{code}
6125 % This gives:
6126 %
6127 % \noindent\makebox[\textwidth][c]{%
6128 % \tikz \fill [left color=green,right color=yellow] (0,0) rectangle (\textwidth,2.5pt);}\\
6129 %
6130 % Here is a particularly interesting one. It draws a Koch Snowflake at
6131 % the end of the headrule\footnote{From Logan Weinert,
6132 % \url{https://tex.stackexchange.com/q/529474/113546}}.
6133 % \PKGindex{tikz}
6134 % \CmdIndex{tikz}
6135 % \begin{code}
6136 % \usepackage{tikz}
6137 % \usetikzlibrary{decorations.fractals}
6138 % . . .
6139 % \renewcommand\headrule{%
6140 % \vspace{-0.75in}
6141 % \hrulefill
6142 % {\tikz[decoration=Koch snowflake]{%
6143 % \draw decorate{ decorate{ decorate{ (0,-2) -- (3,-2) }}};}}
6144 % }
6145 % \end{code}
6146 % This gives:
6147 %
6148 % \noindent\makebox[\textwidth][c]{^^A
6149 % \hrulefill
6150 % {\tikz[decoration=Koch snowflake]{\draw decorate{ decorate{ decorate{ (0,-2) -- (3,-2) }}};}}
6151 % }\\
6152 % Of course you would have to make sure not to place anything in the
6153 % right part of the header.
6154 %
6155 % \MaybeStop{%
6156 % \setmarks{Change History}\PrintChanges
6157 % \setmarks{Index}
6158 % ^^A Temporary workaround for mark problems in `multicol'
6159 % \fancyhead[L]{Index}
6160 % \PrintIndex
6161 % }
6162 %
6163 % \newpage
6164 % \checkposinpage\setmarks{Implementation}
6165 % \part{Implementation}
6166 %
6167 % \begin{implementation}
6168 % \section{\pkg{fancyhdr.st}y}
6169 %
6170 %<*fancyhdr>
6171 % \changes{fancyhdr v1.4}{1994/09/16}{Correction for use with \cs{reversemarginpar}}
6172 %
6173 % \changes{fancyhdr v1.5}{1994/09/29}{Added the \cs{iftopfloat},
6174 % \cs{ifbotfloat} and \cs{iffloatpage} commands}
6175 %
6176 % \changes{fancyhdr v1.6}{1994/10/04}{Reset single spacing in headers/footers for use with
6177 % \pkg{setspace.sty} or \pkg{doublespace.sty}}
6178 %
6179 % \changes{fancyhdr v1.7}{1994/10/04}{Changed \cs{let}\cs{@mkboth}\cs{markboth} to
6180 % \texttt{\cs{def}\cs{@mkboth}\{\cs{protect}\cs{markboth}\}} to make it more robust.}
6181 %
6182 % \changes{fancyhdr v1.8}{1994/12/05}{corrections for
6183 % \pkg{amsbook}/\pkg{amsart}: define \cs{@chapapp} and (more
6184 % importantly) use the \cs{chapter/sectionmark} definitions from \texttt{ps@headings} if
6185 % they exist (which should be true for all standard classes).}
6186 %
6187 % \changes{fancyhdr v1.9}{1995/03/31}{The proposed
6188 % \texttt{\cs{renewcommand}\{\cs{headrulewidth}\}} \texttt{\{\cs{iffloatpage}\ldots}
6189 % construction in the doc did not work properly with the \texttt{fancyplain} style.}
6190 %
6191 % \changes{fancyhdr v1.91}{1995/06/01}{The definition of \cs{@mkboth} wasn't
6192 % restored on subsequent \texttt{\cs{pagestyle}\{fancy\}}'s.}
6193 %
6194 % \changes{fancyhdr v1.92}{1995/06/01}{The sequence
6195 % \texttt{\cs{pagestyle}\{fancyplain\} \cs{pagestyle}\{plain\}
6196 % \cs{pagestyle}\{fancy\}} would erroneously select the plain version.}
6197 %
6198 % \changes{fancyhdr v1.93}{1995/06/01}{\cs{fancypagestyle} command added.}
6199 %
6200 % \changes{fancyhdr v1.94}{1995/12/11}{(suggested by Conrad Hughes
6201 % \texttt{<[email protected]!>}): added \cs{footruleskip} to allow control over footrule
6202 % position (old hardcoded value of .3\cs{normalbaselineskip} is far too high
6203 % when used with very small footer fonts).}
6204 %
6205 % \changes{fancyhdr v1.95}{1996/01/31}{call \cs{@normalsize} in the reset code if that is defined,
6206 % otherwise \cs{normalsize}. This is to solve a problem with
6207 % \pkg{ucthesis.cls}, as this doesn't define \cs{@currsize}.
6208 % Unfortunately for latex209 calling \cs{normalsize} doesn't
6209 % work as this is optimized to do very little, so there \cs{@normalsize} should
6210 % be called. Hopefully this code works for all versions of LaTeX known to
6211 % mankind.}
6212 %
6213 % \changes{fancyhdr v1.96}{1996/04/25}{Initialise \cs{headwidth} to a
6214 % magic (negative) value to catch most common cases that people change
6215 % it before calling \texttt{\cs{pagestyle}\{fancy\}}.
6216 % Note it can't be initialised when reading in this file, because
6217 % \cs{textwidth} could be changed afterwards. This is quite probable.
6218 % We also switch to \cs{MakeUppercase} rather than \cs{uppercase} and introduce a
6219 % \cs{nouppercase} command for use in headers. and footers.}
6220 %
6221 % \changes{fancyhdr v1.97}{1996/05/03}{Two changes: \\
6222 % 1. Undo the change in version 1.8
6223 % (using the \texttt{\cs{pagestyle}\{headings\}} defaults
6224 % for the chapter and section marks). The current version of amsbook and
6225 % amsart classes don't seem to need them anymore. Moreover the standard
6226 % \LaTeX{} classes don't use \cs{markboth} if twoside isn't selected, and this is
6227 % confusing as \cs{leftmark} doesn't work as expected.\\
6228 % 2. Include a call to \cs{ps@empty}
6229 % in \cs{ps@@fancy}. This is to solve a problem
6230 % in the amsbook and amsart classes, that make global changes to \cs{topskip},
6231 % which are reset in \cs{ps@empty}. Hopefully this doesn't break other things.}
6232 %
6233 % \changes{fancyhdr v1.98}{1996/05/07}{Added \% after the line \cs{def}\cs{nouppercase}}
6234 %
6235 % \changes{fancyhdr v1.99}{1996/05/07}{This is the alpha version of fancyhdr 2.0\\
6236 % Introduced the new commands \cs{fancyhead}, \cs{fancyfoot}, and \cs{fancyhf}.
6237 % Changed \cs{headrulewidth}, \cs{footrulewidth}, \cs{footruleskip} to
6238 % macros rather than length parameters, In this way they can be
6239 % conditionalized and they don't consume length registers. There is no need
6240 % to have them as length registers unless you want to do calculations with
6241 % them, which is unlikely. Note that this may make some uses of them
6242 % incompatible (i.e., if you have a file that uses \cs{setlength} or \cs{xxxx}!=)}
6243 %
6244 % \changes{fancyhdr v1.99a}{1996/05/10}{Added a few more \% signs.}
6245 %
6246 % \changes{fancyhdr v1.99b}{1996/05/10}{Changed the syntax of
6247 % \cs{f@nch@for} to be resistant to catcode changes of \texttt{:!=}.\protect\\
6248 % Removed the \texttt{[1]} from the defs of \cs{lhead} etc. because the parameter is
6249 % consumed by the \cs{@[xy]lhead} etc. macros.}
6250 %
6251 % \changes{fancyhdr v1.99c}{1997/06/24}{Corrected \cs{nouppercase} to
6252 % also include the protected form of \cs{MakeUppercase}.\\
6253 % \cs{global} added to manipulation of \cs{headwidth}.\\
6254 % \cs{iffootnote} command added.\\
6255 % Some comments added about \cs{f@nch@head} and \cs{f@nch@foot}.}
6256 %
6257 % \changes{fancyhdr v1.99d}{1998/08/24}{Changed the default
6258 % \cs{ps@empty} to \cs{ps@@empty} in order to allow
6259 % \texttt{\cs{fancypagestyle}\{empty\}} redefinition.}
6260 %
6261 % \changes{fancyhdr v2.0}{2000/10/11}{Added LPPL license clause.\\
6262 % A check for \cs{headheight} is added. An errormessage is given (once) if the
6263 % header is too large. Empty headers don't generate the error even if
6264 % \cs{headheight} is very small or even 0pt. \\
6265 % Warning added for the use of '\texttt{E}' option when \texttt{twoside} option is not used.
6266 % In this case the '\texttt{E}' fields will never be used.}
6267 %
6268 % \changes{fancyhdr v2.1beta}{2002/03/10}{New command:
6269 % \texttt{\cs{fancyhfoffset}[place]\{length\}} defines offsets to be applied to
6270 % the header/footer to let it stick into the margins (if length $!>$ 0).
6271 % \texttt{place} is like in \cs{fancyhead}, except that only \texttt{E,O,L,R} can be used.
6272 % This replaces the old calculation based on \cs{headwidth} and the marginpar
6273 % area.
6274 % \cs{headwidth} will be dynamically calculated in the headers/footers when
6275 % this is used.}
6276 %
6277 % \changes{fancyhdr v2.1beta2}{2002/03/26}{\cs{fancyhfoffset} now also
6278 % takes \texttt{H,F} as possible letters in the argument to
6279 % allow the header and footer widths to be different.\\
6280 % New commands \cs{fancyheadoffset} and \cs{fancyfootoffset} added comparable to
6281 % \cs{fancyhead} and \cs{fancyfoot}.\\
6282 % Errormessages and warnings have been made more informative.}
6283 %
6284 % \changes{fancyhdr v2.1x=fancyhdr v2.1}{2002/12/09}{The defaults for
6285 % \cs{footrulewidth}, \cs{plainheadrulewidth} and
6286 % \cs{plainfootrulewidth} are changed from \cs{z@skip} to 0pt. In this
6287 % way when someone inadvertently uses \cs{setlength} to change any of these, the value
6288 % of \cs{z@skip} will not be changed, rather an errormessage will be given.}
6289 %
6290 % \changes{fancyhdr v3.0}{2004/03/03}{Release of version 3.0.}
6291 %
6292 % \changes{fancyhdr v3.1}{2004/10/07}{Added '\texttt{\cs{endlinechar}!=13}' to
6293 % \cs{f@nch@reset} to prevent problems with \cs{includegraphics} in
6294 % header/footer when \env{verbatiminput} is active.}
6295 %
6296 % \changes{fancyhdr v3.2}{2005/03/22}{Reset \cs{everypar} (the real one)
6297 % in \cs{f@nch@reset} because spanish.ldf does strange things with
6298 % \cs{everypar} between \guillemotleft\ and \guillemotright.}
6299 %
6300 % \changes{fancyhdr v3.3}{2016/08/20}{Replace
6301 % `\texttt{\cs{@ifundefined}\{chapter\}}' with `\cs{ifx}\cs{chapter}\cs{@undefined}'
6302 % because the former subtly makes \cs{chapter} equal to \cs{relax}, which may be
6303 % undesirable in some cases.}
6304 %
6305 % \changes{fancyhdr v3.4}{2016/08/21}{Replace \cs{rm} by
6306 % \cs{normalfont}\cs{rmfamily} and \cs{sl} by \cs{normalfont}\cs{slshape}.}
6307 %
6308 % \changes{fancyhdr v3.5}{2016/08/21}{Don't define \cs{footruleskip} if it is already defined.}
6309 %
6310 % \changes{fancyhdr v3.6}{2016/08/27}{Added a \cs{ProvidesPackage} line.\\
6311 % Updated contact information.}
6312 %
6313 % \changes{fancyhdr v3.7}{2016/08/28}{Removed \cs{normalfont} from default values, as every field
6314 % is already initialised with \cs{normalfont}.\\
6315 % Set \cs{hsize} to \cs{headwidth} in header/footer.}
6316 %
6317 % \changes{fancyhdr v3.8}{2016/09/06}{Reset \bsbs, \cs{raggedleft},
6318 % \cs{raggedright} and \cs{centering} to their default values to avoid a
6319 % clash with the tabu package.\\
6320 % Move the redefinition of \cs{@makecol} to \Cmd{begin\{document\}} to
6321 % avoid a clash with the \pkg{footmisc} package (and maybe others).\\
6322 % Define a working \cs{iffootnote} command.}
6323 %
6324 % \changes{fancyhdr v3.9}{2016/10/11}{Put everything in a \texttt{.dtx} file.}
6325 % \changes{fancyhdr v3.9}{2016/10/12}{Rename some macros to have 'f@nch@'
6326 % in their names, to get a more uniform naming scheme for internal macros.}
6327 % \changes{fancyhdr v5.2}{2025/01/15}{Conditionally require package \pkg{xparse}.}
6328 \ifdefined\NewDocumentCommand\else\RequirePackage{xparse}\fi
6329 %
6330 % \begin{macro}[internal]{\iff@nch@check}
6331 % Boolean for the \texttt{nocheck} option.
6332 % \changes{fancyhdr v4.0}{2019/03/15}{Implement the \texttt{nocheck} option}
6333 % \OPTindex{nocheck}
6334 % \begin{macrocode}
6335 \newif\iff@nch@check
6336 \f@nch@checktrue
6337 \DeclareOption{nocheck}{%
6338 \f@nch@checkfalse
6339 }
6340 % \end{macrocode}
6341 % \end{macro}
6342 %
6343 % \begin{macro}[internal]{\f@nch@gbl}
6344 % Initialise \cs{f@nch@gbl} to do nothing (except with the \texttt{compatV3}
6345 % option).
6346 % \changes{fancyhdr v4.0}{2019/03/19}{Remove the \cs{global} in definitions}
6347 % \changes{fancyhdr v4.0.2}{2021/02/24}{Untangle the code
6348 % for\cs{f@nch@gbl} and the \texttt{compatV3} option}
6349 % \begin{macrocode}
6350 \let\f@nch@gbl\relax
6351 % \end{macrocode}
6352 % \end{macro}
6353 %
6354 % \begin{macro}[internal]{\iff@nch@compatViii}
6355 % Define \cs{iff@nch@compatViii} to track the \texttt{compatV3} option.
6356 % \changes{fancyhdr v4.0}{2019/03/16}{Implement the \texttt{compatV3} option}
6357 % \changes{fancyhdr v5.0}{2024/05/08}{Add warning that the
6358 % \texttt{compatV3} option is deprecated}
6359 % \begin{macrocode}
6360 \newif\iff@nch@compatViii
6361 \DeclareOption{compatV3}{%
6362 \PackageWarningNoLine{fancyhdr}{The `compatV3' option is deprecated.\MessageBreak
6363 It will disappear in one of the following releases.\MessageBreak
6364 Please change your document to work\MessageBreak
6365 without this option}
6366 \let\f@nch@gbl\global
6367 \f@nch@compatViiitrue
6368 }
6369 % \end{macrocode}
6370 % \end{macro}
6371 %
6372 % \begin{macro}[internal]{\iff@nch@twoside}
6373 % Boolean for the \texttt{twoside} option.
6374 % \changes{fancyhdr v4.1}{2022/09/06}{Implement \texttt{twoside} option.}
6375 % \OPTindex{twoside}
6376 % This is only set if the document itself is not two-sided.
6377 % \begin{macrocode}
6378 \newif\iff@nch@twoside
6379 \f@nch@twosidefalse
6380 \DeclareOption{twoside}{%
6381 \if@twoside\else\f@nch@twosidetrue\fi
6382 }
6383 % \end{macrocode}
6384 % \end{macro}
6385 %
6386 % \begin{macro}[internal]{\f@nch@def}
6387 % This macro defines another macro (a header or footer field).
6388 % Depending on the value of \cs{f@nch@gbl} the definition will be
6389 % global or local.
6390 % Default it is always local. But with the \texttt{compatV3} option it
6391 % is \cs{global} in the normal definitions, and local in \cs{fancypagestyle}.
6392 % The \cs{global} case is now considered a bug (or at least undesirable).
6393 %
6394 % If the value (argument 2) is not empty, a \cs{strut} will be added.
6395 % \changes{fancyhdr v5.2}{2025/02/07}{Inline \cs{if@nch@mpty}.}
6396 % \changes{fancyhdr v5.2}{2025/02/07}{Remove \cs{leavevmode}, because
6397 % the initialisation code also inserts a \cs{leavevmode}.}
6398 %
6399 % \begin{macrocode}
6400 \newcommand\f@nch@def[2]{%
6401 \def\temp@a{#2}\ifx\temp@a\@empty\f@nch@gbl\def#1{}%
6402 \else\f@nch@gbl\def#1{#2\strut}\fi}
6403 % \end{macrocode}
6404 % \end{macro}
6405 %
6406 % \changes{fancyhdr v4.0}{2019/03/17}{Added \texttt{headings} and
6407 % \texttt{myheadings} options.}
6408 % \changes{fancyhdr v5.2}{2025/01/15}{Use \cs{@ifundefined} instead of
6409 % \cs{f@nch@ifundefined}.}
6410 % Standard styles are redefined optionally. These definitions are
6411 % borrowed from the \PKGindex{nccfancyhdr}\pkg{nccfancyhdr} package
6412 % by by Alexander I. Rozhenko.
6413 %
6414 % \begin{macro}[internal]{\ps@myheadings}
6415 % The redefinition of the \texttt{myheadings} style is conditional.
6416 % We test the existence of the \cs{chapter} command and redefine the
6417 % style accordingly.
6418 %
6419 % \OPTindex{myheadings}\PSindex{myheadings}
6420 % \begin{macrocode}
6421 \DeclareOption{myheadings}{%
6422 \@ifundefined{chapter}{%
6423 % \end{macrocode}
6424 % An article-like class without chapters:
6425 % \begin{macrocode}
6426 \def\ps@myheadings{\ps@f@nch@fancyproto \let\@mkboth\@gobbletwo
6427 \fancyhf{}
6428 \fancyhead[LE,RO]{\thepage}%
6429 \fancyhead[RE]{\slshape\leftmark}%
6430 \fancyhead[LO]{\slshape\rightmark}%
6431 \let\sectionmark\@gobble
6432 \let\subsectionmark\@gobble
6433 }%
6434 }%
6435 % \end{macrocode}
6436 % A book/report-like class with chapters:
6437 % \begin{macrocode}
6438 {\def\ps@myheadings{\ps@f@nch@fancyproto \let\@mkboth\@gobbletwo
6439 \fancyhf{}
6440 \fancyhead[LE,RO]{\thepage}%
6441 \fancyhead[RE]{\slshape\leftmark}%
6442 \fancyhead[LO]{\slshape\rightmark}%
6443 \let\chaptermark\@gobble
6444 \let\sectionmark\@gobble
6445 }%
6446 }%
6447 }
6448 % \end{macrocode}
6449 % \end{macro}
6450 %
6451 % \begin{macro}[internal]{\ps@headings}
6452 % The redefinition of the \texttt{headings} style also differs for
6453 % book-like and article-like classes. It also differs for
6454 % one-side and two-side modes.
6455 % \changes{fancyhdr v4.0.3}{2022/05/18}{Changed definition of
6456 % \cs{@mkboth} from \cs{let}\cs{@mkboth}\cs{markboth} to
6457 % \cs{def}\Cmd{@mkboth\{\cs{protect}\cs{markboth}\}} so that it will pick up changes
6458 % to \cs{markboth}}
6459 % \changes{fancyhdr v5.2}{2025/01/15}{Use \cs{@ifundefined} instead of
6460 % \cs{f@nch@ifundefined}.}
6461 % \begin{macrocode}
6462 \DeclareOption{headings}{%
6463 \@ifundefined{chapter}{%
6464 \if@twoside
6465 % \end{macrocode}
6466 % An article in two-side mode:
6467 % \begin{macrocode}
6468 \def\ps@headings{\ps@f@nch@fancyproto \def\@mkboth{\protect\markboth}
6469 \fancyhf{}
6470 \fancyhead[LE,RO]{\thepage}%
6471 \fancyhead[RE]{\slshape\leftmark}%
6472 \fancyhead[LO]{\slshape\rightmark}%
6473 \def\sectionmark##1{%
6474 \markboth{\MakeUppercase{%
6475 \ifnum \c@secnumdepth >\z@ \thesection\quad \fi##1}}{}}%
6476 \def\subsectionmark##1{%
6477 \markright{%
6478 \ifnum \c@secnumdepth >\@ne \thesubsection\quad \fi##1}}%
6479 }%
6480 \else
6481 % \end{macrocode}
6482 % An article in one-side mode:
6483 % \begin{macrocode}
6484 \def\ps@headings{\ps@f@nch@fancyproto \def\@mkboth{\protect\markboth}
6485 \fancyhf{}
6486 \fancyhead[LE,RO]{\thepage}%
6487 \fancyhead[RE]{\slshape\leftmark}%
6488 \fancyhead[LO]{\slshape\rightmark}%
6489 \def\sectionmark##1{%
6490 \markright {\MakeUppercase{%
6491 \ifnum \c@secnumdepth >\z@ \thesection\quad \fi##1}}}%
6492 \let\subsectionmark\@gobble % Not needed but inserted for safety
6493 }%
6494 \fi
6495 }{\if@twoside
6496 % \end{macrocode}
6497 % A book in two-side mode:
6498 % \begin{macrocode}
6499 \def\ps@headings{\ps@f@nch@fancyproto \def\@mkboth{\protect\markboth}
6500 \fancyhf{}
6501 \fancyhead[LE,RO]{\thepage}%
6502 \fancyhead[RE]{\slshape\leftmark}%
6503 \fancyhead[LO]{\slshape\rightmark}%
6504 \def\chaptermark##1{%
6505 \markboth{\MakeUppercase{%
6506 \ifnum \c@secnumdepth >\m@ne \if@mainmatter
6507 \@chapapp\ \thechapter. \ \fi\fi##1}}{}}%
6508 \def\sectionmark##1{%
6509 \markright {\MakeUppercase{%
6510 \ifnum \c@secnumdepth >\z@ \thesection. \ \fi##1}}}%
6511 }%
6512 \else
6513 % \end{macrocode}
6514 % A book in one-side mode:
6515 % \begin{macrocode}
6516 \def\ps@headings{\ps@f@nch@fancyproto \def\@mkboth{\protect\markboth}
6517 \fancyhf{}
6518 \fancyhead[LE,RO]{\thepage}%
6519 \fancyhead[RE]{\slshape\leftmark}%
6520 \fancyhead[LO]{\slshape\rightmark}%
6521 \def\chaptermark##1{%
6522 \markright{\MakeUppercase{%
6523 \ifnum \c@secnumdepth >\m@ne \if@mainmatter
6524 \@chapapp\ \thechapter. \ \fi\fi##1}}}%
6525 \let\sectionmark\@gobble % Not needed but inserted for safety
6526 }%
6527 \fi
6528 }%
6529 }
6530 % \end{macrocode}
6531 % \end{macro}
6532 %
6533 % Process the options.
6534 % \changes{fancyhdr v4.0}{2019/03/15}{Process package options.}
6535 % \SpecialUsageIndex{\ProcessOptions}
6536 % \begin{macrocode}
6537 \ProcessOptions*
6538 % \end{macrocode}
6539 %
6540 % \changes{fancyhdr v5.0}{2024/05/08}{Removed \cs{f@nch@errmsg} and
6541 % \cs{f@nch@warning} and used \cs{PackageError} and \cs{PackageWarning} directly.}
6542 % \begin{macro}[internal]{\f@nch@forc}
6543 % Usage: \cs{f@nch@forc} \cs{var} \texttt{\{charstring\}\{body\}}.\\
6544 % Execute the body for each character in \texttt{charstring} bound
6545 % to \cs{var}.
6546 % This is similar to \LaTeX's \cs{@tfor}, but it expands the \texttt{charstring}.
6547 % \changes{fancyhdr v3.10}{2019/01/25}{Use \cs{newcommand} instead of \cs{def}.}
6548 % \changes{fancyhdr v4.0.2}{2021/05/29}{Make \cs{f@nch@rc} \cs{long}.}
6549 % \begin{macrocode}
6550 \newcommand{\f@nch@forc}[3]{\expandafter\f@nchf@rc\expandafter#1\expandafter{#2}{#3}}
6551 \newcommand{\f@nchf@rc}[3]{\def\temp@ty{#2}\ifx\@empty\temp@ty\else
6552 \f@nch@rc#1#2\f@nch@rc{#3}\fi}
6553 \long\def\f@nch@rc#1#2#3\f@nch@rc#4{\def#1{#2}#4\f@nchf@rc#1{#3}{#4}}
6554 % \end{macrocode}
6555 % \end{macro}
6556 % \begin{macro}[internal]{\f@nch@for}
6557 % Usage: \cs{f@nch@for}\cs{var}\texttt{\{list\}}\texttt{\{body\}} \\
6558 % Execute the body for each element of the list, bound to \cs{var}.
6559 % List elements are separated by commas. This is like \LaTeX's \cs{@for} but an empty
6560 % list is treated as a list with an empty element.
6561 %
6562 % \begin{macrocode}
6563 \newcommand{\f@nch@for}[3]{\edef\@fortmp{#2}%
6564 \expandafter\@forloop#2,\@nil,\@nil\@@#1{#3}}
6565 % \end{macrocode}
6566 % \end{macro}
6567 % \begin{macro}[internal]{\f@nch@default}
6568 % Usage: \cs{f@nch@default} \cs{var}\texttt{\{defaults\}\{argument\}} \\
6569 % Sets \cs{var} to the characters
6570 % from \texttt{defaults} appearing in \texttt{argument}, or to \texttt{defaults} if it would be
6571 % empty. All characters are lowercased first.
6572 %
6573 % \begin{macrocode}
6574 \newcommand\f@nch@default[3]{%
6575 \edef\temp@a{\lowercase{\edef\noexpand\temp@a{#3}}}\temp@a \def#1{}%
6576 \f@nch@forc\tmpf@ra{#2}%
6577 {\expandafter\f@nch@ifin\tmpf@ra\temp@a{\edef#1{#1\tmpf@ra}}{}}%
6578 \ifx\@empty#1\def#1{#2}\fi}
6579 % \end{macrocode}
6580 % \end{macro}
6581 %
6582 % \begin{macro}[internal]{\f@nch@ifin}
6583 % Usage: \cs{f@nch@ifin} \meta{char} \meta{set} \meta{truecase} \meta{falsecase} \\
6584 % If \meta{char} is in \meta{set}, then \meta{truecase} else \meta{falsecase}.
6585 % \begin{macrocode}
6586 \newcommand{\f@nch@ifin}[4]{%
6587 \edef\temp@a{#2}\def\temp@b##1#1##2\temp@b{\def\temp@b{##1}}%
6588 \expandafter\temp@b#2#1\temp@b\ifx\temp@a\temp@b #4\else #3\fi}
6589 % \end{macrocode}
6590 % \end{macro}
6591 % \begin{macro}{\fancyhead}
6592 % \changes{fancyhdr v3.9}{2016/10/12}{Let \cs{newcommand} do the
6593 % handling of the optional parameter.}
6594 % \begin{macro}{\fancyfoot}
6595 % \changes{fancyhdr v3.9}{2016/10/12}{Let \cs{newcommand} do the
6596 % handling of the optional parameter.}
6597 % \begin{macro}{\fancyhf}
6598 % \changes{fancyhdr v3.9}{2016/10/12}{Let \cs{newcommand} do the
6599 % handling of the optional parameter.}
6600 % These are the principal user macros. Pick up the parameters,
6601 % and supply an 'h' (\cs{fancyhead}) or 'f' (\cs{fancyfoot}).
6602 % \begin{macrocode}
6603 \newcommand{\fancyhead}[2][]{\f@nch@fancyhf\fancyhead h[#1]{#2}}%
6604 \newcommand{\fancyfoot}[2][]{\f@nch@fancyhf\fancyfoot f[#1]{#2}}%
6605 \newcommand{\fancyhf}[2][]{\f@nch@fancyhf\fancyhf {}[#1]{#2}}%
6606 % \end{macrocode}
6607 % \end{macro}
6608 % \end{macro}
6609 % \end{macro}
6610 %
6611 % \begin{macro}{\fancyheadoffset}
6612 % \changes{fancyhdr v3.9}{2016/10/12}{Let \cs{newcommand} do the
6613 % handling of the optional parameter.}
6614 % \begin{macro}{\fancyfootoffset}
6615 % \changes{fancyhdr v3.9}{2016/10/12}{Let \cs{newcommand} do the
6616 % handling of the optional parameter.}
6617 % \begin{macro}{\fancyhfoffset}
6618 % \changes{fancyhdr v3.9}{2016/10/12}{Let \cs{newcommand} do the
6619 % handling of the optional parameter.}
6620 % The commands for offsets.
6621 % Pick up the parameters,
6622 % and supply an 'h' (\cs{fancyheadoffset}) or 'f' (\cs{fancyfootoffset}).
6623 % \begin{macrocode}
6624 \newcommand{\fancyheadoffset}[2][]{\f@nch@fancyhfoffs\fancyheadoffset h[#1]{#2}}%
6625 \newcommand{\fancyfootoffset}[2][]{\f@nch@fancyhfoffs\fancyfootoffset f[#1]{#2}}%
6626 \newcommand{\fancyhfoffset}[2][]{\f@nch@fancyhfoffs\fancyhfoffset {}[#1]{#2}}%
6627 % \end{macrocode}
6628 % \end{macro}
6629 % \end{macro}
6630 % \end{macro}
6631 %
6632 % \begin{macro}[internal]{\f@nch@fancyhf@Echeck}
6633 % \changes{fancyhdr v4.1}{2022/09/06}{Implement \texttt{twoside} option.}
6634 % Macro for warning if `E' is used without `twoside' option.
6635 % \begin{macrocode}
6636 \def\f@nch@fancyhf@Echeck#1{%
6637 \if@twoside\else
6638 \iff@nch@twoside\else
6639 \if\f@nch@@eo e%
6640 \PackageWarning{fancyhdr} {\string#1's `E' option without twoside option is useless.\MessageBreak
6641 Please consider using the `twoside' option}%
6642 \fi\fi\fi
6643 }
6644 % \end{macrocode}
6645 % \end{macro}
6646 %
6647 % \begin{macro}[internal]{\f@nch@fancyhf}
6648 % \changes{fancyhdr v4.0.2}{2022/05/10}{Make \cs{f@nch@fancyhf} \cs{long}.}
6649 % \changes{fancyhdr v4.1}{2022/09/06}{Implement \texttt{twoside} option.}
6650 % This macro interprets the parameters for the headers and footers.\\
6651 % Parameters:\\
6652 % (1) The user command that was used (like \cs{fancyhead}). This is used
6653 % for errors/warnings.\\
6654 % (2) \texttt{h} (for \cs{fancyhead}), \texttt{f} (for \cs{fancyfoot}),
6655 % or \texttt{\{\}} (for \cs{fancyhf}).\\
6656 % (3) The optional parameter that was given to these commands (default \texttt{[]}).\\
6657 % (4) The required parameter that was given to these commands.\\
6658 % The header and footer fields are stored in command sequences with
6659 % names of the form: \cs{f@nch@}\meta{x}\meta{y}\meta{z} with \meta{x} from
6660 % \texttt{[eo]}, \meta{y} from \texttt{[lcr]} and \meta{z} from \texttt{[hf]}.
6661 %
6662 % \begin{macrocode}
6663 \long\def\f@nch@fancyhf#1#2[#3]#4{%
6664 \def\temp@c{}%
6665 \f@nch@forc\tmpf@ra{#3}%
6666 {\expandafter\f@nch@ifin\tmpf@ra{eolcrhf,EOLCRHF}%
6667 {}{\edef\temp@c{\temp@c\tmpf@ra}}}%
6668 \ifx\@empty\temp@c\else \PackageError{fancyhdr}{Illegal char `\temp@c' in
6669 \string#1 argument: [#3]}{}%
6670 \fi \f@nch@for\temp@c{#3}%
6671 {\f@nch@default\f@nch@@eo{eo}\temp@c
6672 \f@nch@fancyhf@Echeck{#1}%
6673 \f@nch@default\f@nch@@lcr{lcr}\temp@c
6674 \f@nch@default\f@nch@@hf{hf}{#2\temp@c}%
6675 \f@nch@forc\f@nch@eo\f@nch@@eo
6676 {\f@nch@forc\f@nch@lcr\f@nch@@lcr
6677 {\f@nch@forc\f@nch@hf\f@nch@@hf
6678 {\expandafter\f@nch@def\csname
6679 f@nch@\f@nch@eo\f@nch@lcr\f@nch@hf\endcsname {#4}}}}}}
6680 % \end{macrocode}
6681 % \end{macro}
6682 %
6683 % \begin{macro}[internal]{\f@nch@fancyhfoffs}
6684 % \changes{fancyhdr v4.0.2}{2021/03/27}{Change the offset length variables
6685 % \cs{f@nch@O@xyz} to \cs{f@nch@offset@xyz}}
6686 % \changes{fancyhdr v4.1}{2022/09/06}{Implement \texttt{twoside} option.}
6687 % This macro interprets the parameters for the header and footer
6688 % offsets.\\
6689 % Parameters:\\
6690 % (1) The user command that was used (like \cs{fancyheadoffset}). This is used
6691 % for errors/warnings.\\
6692 % (2) \texttt{h} (for \cs{fancyheadoffset}), \texttt{f} (for \cs{fancyfootoffset}),
6693 % or \texttt{\{\}} (for \cs{fancyhfoffset}).\\
6694 % (3) The optional parameter that was given to these commands (default \texttt{[]}).\\
6695 % (4) The required parameter that was given to these commands.\\
6696 % The header and footer offsets are stored in command sequences with
6697 % names of the form: \cs{f@nch@offset@}\meta{x}\meta{y}\meta{z} with \meta{x} from
6698 % \texttt{[eo]}, \meta{y} from \texttt{[lr]} and \meta{z} from \texttt{[hf]}.
6699 %
6700 % \begin{macrocode}
6701 \def\f@nch@fancyhfoffs#1#2[#3]#4{%
6702 \def\temp@c{}%
6703 \f@nch@forc\tmpf@ra{#3}%
6704 {\expandafter\f@nch@ifin\tmpf@ra{eolrhf,EOLRHF}%
6705 {}{\edef\temp@c{\temp@c\tmpf@ra}}}%
6706 \ifx\@empty\temp@c\else \PackageError{fancyhdr}{Illegal char `\temp@c' in
6707 \string#1 argument: [#3]}{}%
6708 \fi \f@nch@for\temp@c{#3}%
6709 {\f@nch@default\f@nch@@eo{eo}\temp@c
6710 \f@nch@fancyhf@Echeck{#1}%
6711 \f@nch@default\f@nch@@lcr{lr}\temp@c
6712 \f@nch@default\f@nch@@hf{hf}{#2\temp@c}%
6713 \f@nch@forc\f@nch@eo\f@nch@@eo
6714 {\f@nch@forc\f@nch@lcr\f@nch@@lcr
6715 {\f@nch@forc\f@nch@hf\f@nch@@hf
6716 {\expandafter\setlength\csname
6717 f@nch@offset@\f@nch@eo\f@nch@lcr\f@nch@hf\endcsname {#4}}}}}%
6718 \f@nch@setoffs}
6719 % \end{macrocode}
6720 % \end{macro}
6721 %
6722 % \begin{macro}{\fancyheadwidth, \fancyfootwidth, \fancyhfwidth}
6723 % The commands for field widths.
6724 % \changes{fancyhdr v5.0}{2025/01/01}{New commands \cs{fancyheadwidth},
6725 % \cs{fancyfootwidth} and \cs{fancyhfwidth}.}
6726 % \changes{fancyhdr v5.2}{2025/01/25}{Second optional parameter \meta{alignment}.}
6727 % \changes{fancyhdr v5.2}{2025/01/27}{Implement \texttt{*} version of
6728 % these commands.}
6729 % Pick up the parameters,
6730 % and supply an 'h' (\cs{fancyheadwidth}) or 'f' (\cs{fancyfootwidth}).
6731 % \begin{macrocode}
6732 \NewDocumentCommand {\fancyheadwidth}{ s O{} O{} m }
6733 {\f@nch@fancyhfwidth{#1}\fancyheadwidth h[#2][#3]{#4}}%
6734 \NewDocumentCommand {\fancyfootwidth}{ s O{} O{} m }
6735 {\f@nch@fancyhfwidth{#1}\fancyfootwidth f[#2][#3]{#4}}%
6736 \NewDocumentCommand {\fancyhfwidth} { s O{} O{} m }
6737 {\f@nch@fancyhfwidth{#1}\fancyhfwidth {}[#2][#3]{#4}}%
6738 % \end{macrocode}
6739 % \end{macro}
6740 %
6741 % \begin{macro}[internal]{\f@nch@fancyhfwidth}
6742 % This macro interprets the parameters for the header and footer field
6743 % widths.\\
6744 % Parameters:\\
6745 % (1) The optional \texttt{*} argument.\\
6746 % (2) The user command that was used (like \cs{fancyheadwidth}). This is used
6747 % for errors/warnings.\\
6748 % (3) \texttt{h} (for \cs{fancyheadwidth}), \texttt{f} (for \cs{fancyfootwidth}),
6749 % or \texttt{\{\}} (for \cs{fancyhfwidth}).\\
6750 % (4-5) The two optional parameters that were given to these commands
6751 % (default for each \texttt{[]}).\\
6752 % (6) The required parameter that was given to these commands.\\
6753 % The header and footer field widths are stored in command sequences with
6754 % names of the form: \cs{f@nch@width@}\meta{x}\meta{y}\meta{z} with \meta{x} from
6755 % \texttt{[eo]}, \meta{y} from \texttt{[lcr]} and \meta{z} from \texttt{[hf]}.
6756 % The header and footer alignments are stored (after defaults have
6757 % been applied) in command sequences with names of the form:
6758 % \cs{f@nch@align@}\meta{x}\meta{y}\meta{z} with \meta{x} from
6759 % \texttt{[eo]}, \meta{y} from \texttt{[lcr]} and \meta{z} from
6760 % \texttt{[hf]}.
6761 %
6762 % First we assign the \meta{width} argument to a temporary length
6763 % variable, to check if it is a legal \meta{length}.
6764 %
6765 % \begin{macrocode}
6766 \def\f@nch@fancyhfwidth#1#2#3[#4][#5]#6{%
6767 \setlength\@tempdima{#6}%
6768 \def\temp@c{}%
6769 \f@nch@forc\tmpf@ra{#4}%
6770 {\expandafter\f@nch@ifin\tmpf@ra{eolcrhf,EOLCRHF}%
6771 {}{\edef\temp@c{\temp@c\tmpf@ra}}}%
6772 \ifx\@empty\temp@c\else \PackageError{fancyhdr}{Illegal char `\temp@c' in
6773 \string#2 argument: [#4]}{}%
6774 \fi
6775 \f@nch@for\temp@c{#4}%
6776 {\f@nch@default\f@nch@@eo{eo}\temp@c
6777 \f@nch@fancyhf@Echeck{#2}%
6778 \f@nch@default\f@nch@@lcr{lcr}\temp@c
6779 \f@nch@default\f@nch@@hf{hf}{#3\temp@c}%
6780 \f@nch@forc\f@nch@eo\f@nch@@eo
6781 {\f@nch@forc\f@nch@lcr\f@nch@@lcr
6782 {\f@nch@forc\f@nch@hf\f@nch@@hf
6783 % \end{macrocode}
6784 % Then we store the \meta{width} in variables for all the specified
6785 % places. If the \texttt{*} form was given we use the calculated value,
6786 % otherwise the bare argument.
6787 % \begin{macrocode}
6788 {%
6789 \IfBooleanTF{#1}{%
6790 \expandafter\edef\csname
6791 f@nch@width@\f@nch@eo\f@nch@lcr\f@nch@hf\endcsname{\the\@tempdima}%
6792 }%
6793 {%
6794 \expandafter\def\csname
6795 f@nch@width@\f@nch@eo\f@nch@lcr\f@nch@hf\endcsname{#6}%
6796 }%
6797 % \end{macrocode}
6798 % Then we apply the defaults to the \meta{alignment} argument.
6799 % The defaults are:
6800 % \begin{itemize}
6801 % \item for the vertical alignment (v): \texttt{b} in a
6802 % header, and \texttt{t} in a footer. This is done by executing a
6803 % corresponding macro.
6804 % \item for the horizontal alignment (h): l, c, r: the same as the
6805 % field. Just copy the field letter.
6806 % \end{itemize}
6807 % If the optional parameter is empty, we leave it at these defaults,
6808 % otherwise we process the arguments with \cs{f@nchdrwdt@align}.
6809 % Finally we store the result in variables for the specified places.
6810 % \begin{macrocode}
6811 \csname f@nchdrwdt@align@v@\f@nch@hf\endcsname
6812 \edef\f@nch@align@@h{\f@nch@lcr}%
6813 \def\temp@a{#5}%
6814 \ifx\temp@a\@empty \else \f@nchdrwdt@align#5\@nil{#2}\fi
6815 \expandafter\edef\csname
6816 f@nch@align@\f@nch@eo\f@nch@lcr\f@nch@hf\endcsname
6817 {\f@nch@align@@v\f@nch@align@@h}}}}}}
6818 % \end{macrocode}
6819 % \end{macro}
6820 %
6821 % \begin{macro}[internal]{\f@nch@width@elh}
6822 % \begin{macro}[internal]{\f@nch@width@ech}
6823 % \begin{macro}[internal]{\f@nch@width@erh}
6824 % \begin{macro}[internal]{\f@nch@width@olh}
6825 % \begin{macro}[internal]{\f@nch@width@och}
6826 % \begin{macro}[internal]{\f@nch@width@orh}
6827 % \begin{macro}[internal]{\f@nch@width@elf}
6828 % \begin{macro}[internal]{\f@nch@width@ecf}
6829 % \begin{macro}[internal]{\f@nch@width@erf}
6830 % \begin{macro}[internal]{\f@nch@width@olf}
6831 % \begin{macro}[internal]{\f@nch@width@ocf}
6832 % \begin{macro}[internal]{\f@nch@width@orf}
6833 % Length parameters for the widths. These are stored as macros. They are
6834 % calculated as lengths when the header/footer is built.
6835 %
6836 % \begin{macrocode}
6837 \def\f@nch@width@elh{\headwidth}
6838 \def\f@nch@width@ech{\headwidth}
6839 \def\f@nch@width@erh{\headwidth}
6840 \def\f@nch@width@olh{\headwidth}
6841 \def\f@nch@width@och{\headwidth}
6842 \def\f@nch@width@orh{\headwidth}
6843 \def\f@nch@width@elf{\headwidth}
6844 \def\f@nch@width@ecf{\headwidth}
6845 \def\f@nch@width@erf{\headwidth}
6846 \def\f@nch@width@olf{\headwidth}
6847 \def\f@nch@width@ocf{\headwidth}
6848 \def\f@nch@width@orf{\headwidth}
6849 % \end{macrocode}
6850 % \end{macro}
6851 % \end{macro}
6852 % \end{macro}
6853 % \end{macro}
6854 % \end{macro}
6855 % \end{macro}
6856 % \end{macro}
6857 % \end{macro}
6858 % \end{macro}
6859 % \end{macro}
6860 % \end{macro}
6861 % \end{macro}
6862 %
6863 % \begin{macro}[internal]{\f@nch@align@elh}
6864 % \begin{macro}[internal]{\f@nch@align@ech}
6865 % \begin{macro}[internal]{\f@nch@align@erh}
6866 % \begin{macro}[internal]{\f@nch@align@olh}
6867 % \begin{macro}[internal]{\f@nch@align@och}
6868 % \begin{macro}[internal]{\f@nch@align@orh}
6869 % \begin{macro}[internal]{\f@nch@align@elf}
6870 % \begin{macro}[internal]{\f@nch@align@ecf}
6871 % \begin{macro}[internal]{\f@nch@align@erf}
6872 % \begin{macro}[internal]{\f@nch@align@olf}
6873 % \begin{macro}[internal]{\f@nch@align@ocf}
6874 % \begin{macro}[internal]{\f@nch@align@orf}
6875 %
6876 % Alignment parameters for the widths.
6877 %
6878 % \begin{macrocode}
6879 \def\f@nch@align@elh{bl}
6880 \def\f@nch@align@ech{bc}
6881 \def\f@nch@align@erh{br}
6882 \def\f@nch@align@olh{bl}
6883 \def\f@nch@align@och{bc}
6884 \def\f@nch@align@orh{br}
6885 \def\f@nch@align@elf{tl}
6886 \def\f@nch@align@ecf{tc}
6887 \def\f@nch@align@erf{tr}
6888 \def\f@nch@align@olf{tl}
6889 \def\f@nch@align@ocf{tc}
6890 \def\f@nch@align@orf{tr}
6891 % \end{macrocode}
6892 %
6893 % \end{macro}
6894 % \end{macro}
6895 % \end{macro}
6896 % \end{macro}
6897 % \end{macro}
6898 % \end{macro}
6899 % \end{macro}
6900 % \end{macro}
6901 % \end{macro}
6902 % \end{macro}
6903 % \end{macro}
6904 % \end{macro}
6905 %
6906 % \begin{macro}[internal]{\f@nchdrwdt@align@v@h, \f@nchdrwdt@align@v@f, \f@nchdrwdt@align}
6907 % \cs{f@nchdrwdt@align@v@h}: set v to \texttt{b}\\[1ex]
6908 % \cs{f@nchdrwdt@align@v@f}: set v to \texttt{t}\\[1ex]
6909 % \cs{f@nchdrwdt@align}\marg{vert}\marg{hor}\texttt{\cs{@nil}}\marg{originating command}\\[1ex]
6910 % The internal processing for \meta{alignment} parameter in \cs{fancyhfwidth},
6911 % etc.\\
6912 % ALGORITHM \cs{f@nchdrwdt@align}:\\
6913 % (v = vertical position; h = horizontal position)\\
6914 % These have been set to their defaults before calling us.\\
6915 % \textbf{IF} \texttt{\#1} in \texttt{\{T,t,c,b,B,-\}} \\
6916 % \textbf{THEN} \textbf{if} \texttt{\#1} $\ne$ `\texttt{-}' \textbf{then}
6917 % v := \texttt{\#1} \textbf{fi}\\
6918 % \hspace*{1em} \textbf{if} \texttt{\#2} is not empty \textbf{then} h := \texttt{\#2}
6919 % \textbf{fi}\\
6920 % \textbf{ELSE} (\texttt{\#1} not in \texttt{\{T,t,c,b,B,-\}} -- it must be
6921 % a horizontal alignment)\\
6922 % \hspace*{1em} h := \texttt{\#1}\\
6923 % \textbf{FI}\\
6924 % \textbf{if} h not in \texttt{\{l,c,r,j\}} \textbf{then} ERROR \textbf{fi}\\
6925 %
6926 % The result can be found in the variables \cs{f@nch@align@@v} and \cs{f@nch@align@@h}.
6927 % \begin{macrocode}
6928 \def\f@nchdrwdt@align@v@h{\def\f@nch@align@@v{b}}%
6929 \def\f@nchdrwdt@align@v@f{\def\f@nch@align@@v{t}}%
6930 \long\def\f@nchdrwdt@align#1#2\@nil#3{%
6931 \f@nch@ifin{#1}{TtcbB-}{%
6932 \f@nch@ifin{#1}{-}{}{\def\f@nch@align@@v{#1}}%
6933 \def\@tempa{#2}%
6934 \ifx\@tempa\@empty \else \def\f@nch@align@@h{#2}\fi
6935 }%
6936 {\def\f@nch@align@@h{#1}}%
6937 \expandafter\f@nch@ifin\expandafter{\f@nch@align@@h}{lcrj}{}%
6938 {\PackageError{fancyhdr}
6939 {\string#3: Illegal char `\f@nch@align@@h'\MessageBreak
6940 in alignment argument}{}}%
6941 }
6942 % \end{macrocode}
6943 % \end{macro}
6944 %
6945 % \begin{macro}{\lhead}
6946 % \changes{fancyhdr v3.9}{2016/10/12}{Let \cs{newcommand} do the
6947 % handling of the optional parameter.}
6948 % \begin{macro}{\chead}
6949 % \changes{fancyhdr v3.9}{2016/10/12}{Let \cs{newcommand} do the
6950 % handling of the optional parameter.}
6951 % \begin{macro}{\rhead}
6952 % \changes{fancyhdr v3.9}{2016/10/12}{Let \cs{newcommand} do the
6953 % handling of the optional parameter.}
6954 % \begin{macro}{\lfoot}
6955 % \changes{fancyhdr v3.9}{2016/10/12}{Let \cs{newcommand} do the
6956 % handling of the optional parameter.}
6957 % \begin{macro}{\cfoot}
6958 % \changes{fancyhdr v3.9}{2016/10/12}{Let \cs{newcommand} do the
6959 % handling of the optional parameter.}
6960 % \begin{macro}{\rfoot}
6961 % \changes{fancyhdr v3.9}{2016/10/12}{Let \cs{newcommand} do the
6962 % handling of the optional parameter.}
6963 % Fancyheadings version 1 commands. These are deprecated,
6964 % but they continue to work for compatibility reasons. They have an
6965 % optional parameter that is used as the value for even pages in a
6966 % two-sided document. If this is not given (or if the document is not
6967 % two-sided) the required parameter is used for both even and odd pages.
6968 % Therefore the default value for the optional parameter is the
6969 % required parameter. It is not possible to express this directly in
6970 % the definition. Therefore we use a trick. Both parameters are store
6971 % in a macro. For example for \cs{lhead} the parameter for even pages
6972 % is stored in \cs{f@nch@elh}, and the one for odd pages in
6973 % \cs{f@nch@olh}. For the others it is similar, just replace the
6974 % \texttt{l} with \texttt{c} or \texttt{r}, and the \texttt{h} with
6975 % \texttt{f}. In the body of the macro we first store the required
6976 % parameter in \cs{f@nch@olh}, and we use this macro as default for
6977 % the optional parameter. The optional parameter is then stored in
6978 % \cs{f@nch@elh}. The order of the assignments is therefore important.
6979 %
6980 % \begin{macrocode}
6981 \newcommand{\lhead}[2][\f@nch@olh]%
6982 {\f@nch@def\f@nch@olh{#2}\f@nch@def\f@nch@elh{#1}}
6983 \newcommand{\chead}[2][\f@nch@och]%
6984 {\f@nch@def\f@nch@och{#2}\f@nch@def\f@nch@ech{#1}}
6985 \newcommand{\rhead}[2][\f@nch@orh]%
6986 {\f@nch@def\f@nch@orh{#2}\f@nch@def\f@nch@erh{#1}}
6987 \newcommand{\lfoot}[2][\f@nch@olf]%
6988 {\f@nch@def\f@nch@olf{#2}\f@nch@def\f@nch@elf{#1}}
6989 \newcommand{\cfoot}[2][\f@nch@ocf]%
6990 {\f@nch@def\f@nch@ocf{#2}\f@nch@def\f@nch@ecf{#1}}
6991 \newcommand{\rfoot}[2][\f@nch@orf]%
6992 {\f@nch@def\f@nch@orf{#2}\f@nch@def\f@nch@erf{#1}}
6993 % \end{macrocode}
6994 % \end{macro}
6995 % \end{macro}
6996 % \end{macro}
6997 % \end{macro}
6998 % \end{macro}
6999 % \end{macro}
7000 %
7001 % \begin{macro}[internal]{\f@nch@headwidth}
7002 % \changes{fancyhdr v4.0.2}{2021/03/27}{Change the offset length variables
7003 % \cs{f@nch@O@xyz} to \cs{f@nch@offset@xyz}}
7004 % Length parameter to be used for \cs{headwidth}. We use this rather
7005 % than defining \cs{headwidth} as a length parameter directly to protect
7006 % ourselves to someone saying: \verb+\let\headwidth\textwidth+.
7007 % \begin{macrocode}
7008 \newlength{\f@nch@headwidth} \let\headwidth\f@nch@headwidth
7009 % \end{macrocode}
7010 % \end{macro}
7011 % \begin{macro}[internal]{\f@nch@offset@elh}
7012 % \begin{macro}[internal]{\f@nch@offset@erh}
7013 % \begin{macro}[internal]{\f@nch@offset@olh}
7014 % \begin{macro}[internal]{\f@nch@offset@orh}
7015 % \begin{macro}[internal]{\f@nch@offset@elf}
7016 % \begin{macro}[internal]{\f@nch@offset@erf}
7017 % \begin{macro}[internal]{\f@nch@offset@olf}
7018 % \begin{macro}[internal]{\f@nch@offset@orf}
7019 % Length parameters for the offsets.
7020 % \begin{macrocode}
7021 \newlength{\f@nch@offset@elh}
7022 \newlength{\f@nch@offset@erh}
7023 \newlength{\f@nch@offset@olh}
7024 \newlength{\f@nch@offset@orh}
7025 \newlength{\f@nch@offset@elf}
7026 \newlength{\f@nch@offset@erf}
7027 \newlength{\f@nch@offset@olf}
7028 \newlength{\f@nch@offset@orf}
7029 % \end{macrocode}
7030 % \end{macro}
7031 % \end{macro}
7032 % \end{macro}
7033 % \end{macro}
7034 % \end{macro}
7035 % \end{macro}
7036 % \end{macro}
7037 % \end{macro}
7038 %
7039 % \begin{macro}{\headrulewidth}
7040 % \begin{macro}{\footrulewidth}
7041 % \begin{macrocode}
7042 \newcommand{\headrulewidth}{0.4pt}
7043 \newcommand{\footrulewidth}{0pt}
7044 % \end{macrocode}
7045 % \end{macro}
7046 % \end{macro}
7047 %
7048 % \begin{macro}{\headruleskip}
7049 % Don't define \cs{headruleskip} if it is already defined.
7050 % \changes{fancyhdr v4.0}{2019/03/22}{Parameter \cs{headruleskip}.}
7051 % \changes{fancyhdr v5.2}{2025/01/15}{Use \cs{@ifundefined} instead of
7052 % \cs{f@nch@ifundefined}.}
7053 % \begin{macrocode}
7054 \@ifundefined{headruleskip}%
7055 {\newcommand{\headruleskip}{0pt}}{}
7056 % \end{macrocode}
7057 % \end{macro}
7058 %
7059 % \begin{macro}{\footruleskip}
7060 % Memoir also defines \cs{footruleskip}.
7061 % Don't define \cs{footruleskip} if it is already defined.
7062 % \changes{fancyhdr v5.2}{2025/01/15}{Use \cs{@ifundefined} instead of
7063 % \cs{f@nch@ifundefined}.}
7064 % \begin{macrocode}
7065 \@ifundefined{footruleskip}%
7066 {\newcommand{\footruleskip}{.3\normalbaselineskip}}{}
7067 % \end{macrocode}
7068 % \end{macro}
7069 %
7070 % \begin{macro}{\plainheadrulewidth}
7071 % \begin{macro}{\plainfootrulewidth}
7072 % Fancyplain stuff shouldn't be used anymore (rather
7073 % \texttt{\cs{fancypagestyle}\{plain\}} should be used), but we keep it for
7074 % compatibility reasons.
7075 %
7076 % \begin{macrocode}
7077 \newcommand{\plainheadrulewidth}{0pt}
7078 \newcommand{\plainfootrulewidth}{0pt}
7079 % \end{macrocode}
7080 % \end{macro}
7081 % \end{macro}
7082 %
7083 % \begin{macro}[internal]{\if@fancyplain}
7084 % Boolean for the implementation of \cs{fancyplain}
7085 % \begin{macrocode}
7086 \newif\if@fancyplain \@fancyplainfalse
7087 % \end{macrocode}
7088 % \end{macro}
7089 %
7090 % \begin{macro}{\fancyplain}
7091 % Deprecated macro
7092 % \begin{macrocode}
7093 \def\fancyplain#1#2{\if@fancyplain#1\else#2\fi}
7094 % \end{macrocode}
7095 % \end{macro}
7096 %
7097 % \begin{macro}{\headwidth}
7098 % Initialise \cs{headwidth} with a magic constant.
7099 % \begin{macrocode}
7100 \headwidth=-123456789sp
7101 % \end{macrocode}
7102 % \end{macro}
7103 %
7104 % \begin{macro}[internal]{\f@nch@raggedleft}
7105 % \begin{macro}[internal]{\f@nch@raggedright}
7106 % \begin{macro}[internal]{\f@nch@centering}
7107 % \begin{macro}[internal]{\f@nch@everypar}
7108 % \changes{fancyhdr v4.3}{2024/07/17}{Changed \cs{f@nch@everypar}. If the
7109 % LaTeX kernel has expl3, use \cs{tex\_everypar:D}, and reset \cs{par},
7110 % \cs{@@par} and \cs{endgraf} to their original \TeX{} definitions, so that
7111 % no paragraph hooks will intrude in \pkg{fancyhdr} code.}
7112 % \changes{fancyhdr v4.3.1}{2024/07/23}{Also reset \cs{everypar} to its
7113 % original \TeX{} value \cs{tex\_everypar:D} in \cs{f@nch@resetpar},
7114 % otherwise environments based on \cs{trivlist}
7115 % will not work properly in \pkg{fancyhdr} headers and footers.}
7116 % Save the standard definitions of \cs{raggedleft}, \cs{raggedright},
7117 % \cs{centering} and \cs{everypar} so that we can reset them when we are
7118 % typesetting the headers and footers. Some packages change these to
7119 % incompatible values.\\
7120 % \begin{macrocode}
7121 \let\f@nch@raggedleft\raggedleft
7122 \let\f@nch@raggedright\raggedright
7123 \let\f@nch@centering\centering
7124 \let\f@nch@everypar\everypar
7125 \ifdefined\ExplSyntaxOn
7126 \ExplSyntaxOn
7127 \providecommand\IfFormatAtLeastTF{\@ifl@t@r\fmtversion}
7128 \IfFormatAtLeastTF{2021-06-01}{
7129 % \end{macrocode}
7130 % \begin{macro}{\f@nch@saveclr@parhook, \f@nch@restore@parhook}
7131 % We disable paragraph hooks, so that no paragraph hooks will
7132 % intrude in \pkg{fancyhdr} code. \textbf{NOTE: This is a hack, and
7133 % should be replaced by cleaner code as soon as the \LaTeX{} kernel
7134 % provides the necessary commands.}
7135 % \changes{fancyhdr v4.5}{2024/11/29}{We use a less fragile way to
7136 % disable paragraph hooks, thereby partially reverting the solution in
7137 % version v4.3 and v4.3.1. This is less intruding in the hook system,
7138 % and especially it doesn't affect kernel hooks, only user provided
7139 % ones. We check the kernel version to see if it support paragraph hooks.}
7140 % \changes{fancyhdr v5.1}{2025/01/06}{A new way to disable the paragraph
7141 % hooks in headers and footers.}
7142 % \changes{fancyhdr v5.1.1}{2025/01/07}{Use low-level commands to reset
7143 % paragraph hooks to prevent LaTeX error when running with latex3
7144 % debugging.}
7145 % \changes{fancyhdr v5.2}{2025/01/14}{Use official interface to reset
7146 % the paragraph hooks.}
7147 % The way we do this now: Every hook consists of 4 global `variables':
7148 % \begin{itemize}
7149 % \item \cs{__hook \meta{name}}
7150 % \item \cs{__hook_toplevel \meta{name}}
7151 % \item \cs{__hook_next \meta{name}}
7152 % \item \cs{g__hook_\meta{name}_code_prop}
7153 % \end{itemize}
7154 % and there are 4 hooks (\texttt{para/before}, \texttt{para/begin},
7155 % \texttt{para/end}, and \texttt{para/after}). At the beginning of a
7156 % header/footer, i.e., before any init code and hooks, all these variables are
7157 % locally saved into variables with the same name, prefixed with
7158 % `\texttt{f@nch@}', and then clear the hook. At the end of the
7159 % header/footer they are globally restored to the saved value.
7160 % So we do only global assignments to them to avoid problems.
7161 % Save a (paragraph) hook locally and and clear it globally.
7162 % Restore it globally at the end of header/footer processing.
7163 % \begin{macrocode}
7164 \def\f@nch@saveclr@parhook #1{
7165 \expandafter\let\csname f@nch@__hook~#1\expandafter\endcsname
7166 \csname __hook~#1\endcsname
7167 \expandafter\let\csname f@nch@__hook_toplevel~#1\expandafter\endcsname
7168 \csname __hook_toplevel~#1\endcsname
7169 \expandafter\let\csname f@nch@__hook_next~#1\expandafter\endcsname
7170 \csname __hook_next~#1\endcsname
7171 \expandafter\let\csname f@nch@g__hook_#1_code_prop\expandafter\endcsname
7172 \csname g__hook_#1_code_prop\endcsname
7173 \RemoveFromHook{#1}[*]
7174 \ClearHookNext{#1}
7175 }
7176 \def\f@nch@restore@parhook #1{
7177 \global\expandafter\let\csname __hook~#1\expandafter\endcsname
7178 \csname f@nch@__hook~#1\endcsname
7179 \global\expandafter\let\csname __hook_toplevel~#1\expandafter\endcsname
7180 \csname f@nch@__hook_toplevel~#1\endcsname
7181 \global\expandafter\let\csname __hook_next~#1\expandafter\endcsname
7182 \csname f@nch@__hook_next~#1\endcsname
7183 \global\expandafter\let\csname g__hook_#1_code_prop\expandafter\endcsname
7184 \csname f@nch@g__hook_#1_code_prop\endcsname
7185 }
7186 \def\f@nch@resetpar{
7187 \f@nch@everypar{}
7188 \f@nch@saveclr@parhook{para/before}
7189 \f@nch@saveclr@parhook{para/begin}
7190 \f@nch@saveclr@parhook{para/end}
7191 \f@nch@saveclr@parhook{para/after}
7192 }
7193 \def\f@nch@restorepar{
7194 \f@nch@restore@parhook{para/before}
7195 \f@nch@restore@parhook{para/begin}
7196 \f@nch@restore@parhook{para/end}
7197 \f@nch@restore@parhook{para/after}
7198 }
7199 }{
7200 \def\f@nch@resetpar{
7201 \f@nch@everypar{}
7202 }
7203 \def\f@nch@restorepar{}
7204 }
7205 \ExplSyntaxOff
7206 \else
7207 \def\f@nch@resetpar{%
7208 \f@nch@everypar{}%
7209 }
7210 \def\f@nch@restorepar{}
7211 \fi
7212 % \end{macrocode}
7213 % \end{macro}
7214 % \end{macro}
7215 % \end{macro}
7216 % \end{macro}
7217 % \end{macro}
7218 %
7219 % \begin{macro}[internal]{\f@nch@noUppercase}
7220 % We want \cs{nouppercase} to work with the various evolutionary stages of
7221 % \cs{MakeUppercase}. The current version (2022/11/09) accepts an optional
7222 % argument with a language specification. Therefore we define a dummy macro
7223 % \cs{f@nch@noUppercase} which copies its mandatory argument, as a
7224 % replacement for \cs{MakeUppercase} while \cs{nouppercase} is active.
7225 % \begin{macrocode}
7226 \newcommand\f@nch@noUppercase[2][]{#2}
7227 % \end{macrocode}
7228 %
7229 % \begin{macro}[internal]{\f@nch@reset}
7230 % Command to reset various things in the headers: a.o. single spacing
7231 % (taken from setspace.sty) and the catcode of ^^M and
7232 % \cs{endlinechar} (so that epsf files
7233 % in the header work if a verbatim crosses a page boundary).
7234 % Also reset the catcodes that are changed in verbatim environments,
7235 % \cs{makeatother} and \cs{ExplSyntaxOn}. It also
7236 % defines a \cs{nouppercase} command that disables \cs{uppercase} and
7237 % \cs{MakeUppercase}. It can only be used in the headers and footers. Set
7238 % \cs{hsize} to \cs{headwidth} (this helps for multicol); reset
7239 % \bsbs, \cs{raggedleft}, \cs{raggedright} and \cs{centering} to
7240 % their default values (for \pkg{tabu}), and \cs{everypar} to empty.\\
7241 % The font is reset to \cs{normalfont}. Actually this is done in the
7242 % \LaTeX{} output routine, so we don't have to do it here.
7243 % \changes{fancyhdr v4.1}{2022/11/09}{Change \cs{nouppercase} to work with
7244 % new definition of \cs{MakeUppercase}.}
7245 % \changes{fancyhdr v4.2}{2024/04/19}{Reset catcodes to their default
7246 % values in order to facilitate \cs{input} in headers/footers when \texttt{verbatim}
7247 % is active. (Issue \# 8 \url{https://github.com/pietvo/fancyhdr/issues/8}.)}
7248 % \changes{fancyhdr v4.3}{2024/05/08}{Remove pre-NFSS stuff}
7249 % \changes{fancyhdr v4.3}{2024/07/17}{Replace \cs{f@nch@everypar} by \cs{f@nch@resetpar}.}
7250 % \changes{fancyhdr v5.2}{2025/01/15}{Use \cs{@ifundefined} instead of
7251 % \cs{f@nch@ifundefined}.}
7252 % \begin{macrocode}
7253 \def\f@nch@reset{\f@nch@resetpar\restorecr\endlinechar=13
7254 \catcode`\\=0\catcode`\{=1\catcode`\}=2\catcode`\$=3\catcode`\&=4
7255 \catcode`\#=6\catcode`\^=7\catcode`\_=8\catcode`\ =10\catcode`\@=11
7256 \catcode`\:=11\catcode`\~=13\catcode`\%=14
7257 \catcode0=15 %NULL
7258 \catcode9=10 %TAB
7259 \let\\\@normalcr \let\raggedleft\f@nch@raggedleft
7260 \let\raggedright\f@nch@raggedright \let\centering\f@nch@centering
7261 \def\baselinestretch{1}%
7262 \hsize=\headwidth
7263 \def\nouppercase##1{{%
7264 \let\uppercase\relax\let\MakeUppercase\f@nch@noUppercase
7265 \expandafter\let\csname MakeUppercase \endcsname\relax
7266 \expandafter\def\csname MakeUppercase\space\space\space\endcsname
7267 [####1]####2{####2}%
7268 ##1}}%
7269 \@ifundefined{@normalsize} {\normalsize} % for ucthesis.cls
7270 {\@normalsize}%
7271 }
7272 % \end{macrocode}
7273 % \end{macro}
7274 % \end{macro}
7275 %
7276 % \begin{macro}{\fancycenter}
7277 % \changes{fancyhdr v4.0}{2019/03/15}{Macro \cs{fancycenter} added}
7278 % \cs{fancycenter}\oarg{dist}\oarg{stretch}\marg{left-field}\marg{center-field}\marg{right-field}
7279 % \begin{macrocode}
7280 \newcommand*{\fancycenter}[1][1em]{%
7281 \@ifnextchar[{\f@nch@center{#1}}{\f@nch@center{#1}[3]}%
7282 }
7283 \def\f@nch@center#1[#2]#3#4#5{%
7284 % \end{macrocode}
7285 % At first, we execute the case when the \meta{center-field} is empty\footnote{%
7286 % This code is reused from the \PKGindex{nccfancyhdr}\pkg{nccfancyhdr} package by Alexander I. Rozhenko}:
7287 % \begin{macrocode}
7288 \def\@tempa{#4}\ifx\@tempa\@empty
7289 \hbox to\linewidth{\color@begingroup{#3}\hfil {#5}\color@endgroup}%
7290 \else
7291 % \end{macrocode}
7292 % All we need to do is to calculate skips inserted before and after
7293 % \meta{center-field}. We will calculate them in the \verb|\@tempskipa|
7294 % and \verb|\@tempskipb| registers. At first:
7295 % \begin{quote}
7296 % \verb|\@tempdima:=|\meta{dist};\\
7297 % \verb|\@tempdimb:=|\meta{dist}\verb|*|\meta{stretch};\\
7298 % \verb|\@tempdimc:=|\meta{dist}\verb|*|\meta{stretch}\verb|-|\meta{dist};\\
7299 % \verb|\@tempskipa:=\@tempskipb:=\@tempdimb + 1fil - \@tempdimc|;
7300 % \end{quote}
7301 % \begin{macrocode}
7302 \setlength\@tempdima{#1}%
7303 \setlength{\@tempdimb}{#2\@tempdima}%
7304 \@tempdimc \@tempdimb \advance\@tempdimc -\@tempdima
7305 \setlength\@tempskipa{\@tempdimb \@plus 1fil \@minus \@tempdimc}%
7306 \@tempskipb\@tempskipa
7307 % \end{macrocode}
7308 % At this point, the \cs{@tempskipa} and \cs{@tempskipb} registers
7309 % have the natural size \meta{dist}\verb|*|\meta{stretch},
7310 % unlimited stretchability, and the minimum size \meta{dist}.
7311 % Now we decrease the minimum size of \cs{@tempskipa} to zero if
7312 % the \meta{left-field} is empty:
7313 % \begin{macrocode}
7314 \def\@tempa{#3}\ifx\@tempa\@empty
7315 \addtolength\@tempskipa{\z@ \@minus \@tempdima}%
7316 \fi
7317 % \end{macrocode}
7318 % Do the same things with the \cs{@tempskipb} register if the
7319 % \meta{right-field} is empty:
7320 % \begin{macrocode}
7321 \def\@tempa{#5}\ifx\@tempa\@empty % empty right
7322 \addtolength\@tempskipb{\z@ \@minus \@tempdima}%
7323 \fi
7324 % \end{macrocode}
7325 % Finally, we correct the left and right glues taking into
7326 % account the difference between lengths of \meta{left-field}
7327 % and \meta{right-field}. We calculate which mark is shorter
7328 % and increase the natural size of the corresponding register
7329 % by the difference between their lengths.
7330 % \begin{macrocode}
7331 \settowidth{\@tempdimb}{#3}%
7332 \settowidth{\@tempdimc}{#5}%
7333 \ifdim\@tempdimb>\@tempdimc
7334 \advance\@tempdimb -\@tempdimc
7335 \addtolength\@tempskipb{\@tempdimb \@minus \@tempdimb}%
7336 \else
7337 \advance\@tempdimc -\@tempdimb
7338 \addtolength\@tempskipa{\@tempdimc \@minus \@tempdimc}%
7339 \fi
7340 % \end{macrocode}
7341 % The \cs{@tempskipa} and \cs{@tempskipb} have been calculated.
7342 % Put everything in the box.
7343 % \begin{macrocode}
7344 \hbox to\linewidth{\color@begingroup{#3}\hskip \@tempskipa
7345 {#4}\hskip \@tempskipb {#5}\color@endgroup}%
7346 \fi
7347 }
7348 % \end{macrocode}
7349 % \end{macro}
7350 %
7351 % \begin{macro}{\fancyheadinit}
7352 % This macro can be used to define initialisation code that will be run
7353 % before the construction of the header. It can for example set the
7354 % color or the font, or change \cs{headrulewidth} or \cs{headruleskip}.
7355 % It cannot make global changes, just changes for the header.
7356 % \begin{macro}[internal]{\f@nch@headinit}
7357 % Storage for the header initialisation code.
7358 % \begin{macrocode}
7359 \newcommand{\f@nch@headinit}{}
7360 \newcommand{\fancyheadinit}[1]{%
7361 \def\f@nch@headinit{#1}%
7362 }
7363 % \end{macrocode}
7364 % \end{macro}
7365 % \end{macro}
7366 %
7367 % \begin{macro}{\fancyfootinit}
7368 % This macro can be used to define initialisation code that will be run
7369 % before the construction of the footer. It can for example set the
7370 % color or the font, or change \cs{footrulewidth} or \cs{footruleskip}.
7371 % It cannot make global changes, just changes for the footer.
7372 % \begin{macro}[internal]{\f@nch@footinit}
7373 % Storage for the footer initialisation code.
7374 % \begin{macrocode}
7375 \newcommand{\f@nch@footinit}{}
7376 \newcommand{\fancyfootinit}[1]{%
7377 \def\f@nch@footinit{#1}%
7378 }
7379 % \end{macrocode}
7380 % \end{macro}
7381 % \end{macro}
7382 %
7383 % \begin{macro}{\fancyhfinit}
7384 % This macro sets both the header and the footer initialisation codes to
7385 % the same value.
7386 % \begin{macrocode}
7387 \newcommand{\fancyhfinit}[1]{%
7388 \def\f@nch@headinit{#1}%
7389 \def\f@nch@footinit{#1}%
7390 }
7391 % \end{macrocode}
7392 % \end{macro}
7393 %
7394 % \begin{hookdecl}{fancyhdr/before, fancyhdr/after, fancyhdr/head/begin,
7395 % fancyhdr/head/end, fancyhdr/foot/begin, fancyhdr/foot/end}
7396 % \changes{fancyhdr v4.5}{2024/12/05}{Hooks added}
7397 % Here we define the \pkg{fancyhdr} hooks. It will be conditional on
7398 % the presence of hook support in the \LaTeX{} kernel.
7399 % \begin{macrocode}
7400 \ifdefined\NewMirroredHookPair
7401 \NewMirroredHookPair{fancyhdr/before}{fancyhdr/after}
7402 \NewMirroredHookPair{fancyhdr/head/begin}{fancyhdr/head/end}
7403 \NewMirroredHookPair{fancyhdr/foot/begin}{fancyhdr/foot/end}
7404 \fi
7405 % \end{macrocode}
7406 % \end{hookdecl}
7407 %
7408 % \begin{macro}[internal]{\f@nch@height}
7409 % \changes{fancyhdr v5.0}{2021/02/20}{Length variable \cs{f@nch@height} added}
7410 % Length variable to store height of header/footer for use in \cs{fancyhdrsettoheight}
7411 % \begin{macrocode}
7412 \newlength\f@nch@height
7413 % \end{macrocode}
7414 % \end{macro}
7415 %
7416 % \begin{macro}[internal]{\f@nch@footalignment}
7417 % Length variable to store alignment length of \cs{fancyfootalign}
7418 % \begin{macrocode}
7419 \newlength\f@nch@footalignment
7420 % \end{macrocode}
7421 % \end{macro}
7422 % \begin{macro}[internal]{\iff@nch@footalign}
7423 % Boolean variable to store if a \meta{length} parameter was given to \cs{fancyfootalign}
7424 % \begin{macrocode}
7425 \newif\iff@nch@footalign\f@nch@footalignfalse
7426 % \end{macrocode}
7427 % \end{macro}
7428 % \begin{macro}{\fancyfootalign}
7429 % \changes{fancyhdr v5.0}{2024/05/13}{Macro \cs{fancyfootalign},
7430 % \cs{iff@nch@footalign} and length variable \cs{f@nch@footalignment} added}
7431 % This macro sets the distance between the bottom of the footer and the
7432 % bottom margin. The argument can be empty, or a \meta{length}.
7433 % \begin{macrocode}
7434 \newcommand{\fancyfootalign}[1]{%
7435 \def\temp@a{#1}%
7436 \ifx\temp@a\@empty
7437 \f@nch@footalignfalse
7438 \else
7439 \f@nch@footaligntrue
7440 \setlength\f@nch@footalignment{#1}%
7441 \fi
7442 }
7443 % \end{macrocode}
7444 % \end{macro}
7445 %
7446 % \begin{macro}{\fancyhdrsettoheight}
7447 % \changes{fancyhdr v5.0}{2021/02/20}{Macro \cs{fancyhdrsettoheight} added}
7448 % Macro to store the height of a header/footer in a length variable.\\
7449 % \cs{fancyhdrsettoheight}\marg{lengthvar}\marg{header/footer}\\
7450 % The second parameter can be \texttt{oddhead}, \texttt{evenhead},
7451 % \texttt{oddfoot}, or \texttt{evenfoot}.
7452 % \begin{macrocode}
7453 \newcommand\fancyhdrsettoheight[2]{%
7454 \expandafter\ifx\csname f@nch@#2\endcsname\fancyhdrsettoheight
7455 \else\PackageError{fancyhdr}{Unknown parameter #2 in \string\fancyhdrsettoheight}{}\fi
7456 \setbox\@tempboxa\hbox{{\f@nch@checkfalse\csname @#2\endcsname}}%
7457 \setlength{#1}\f@nch@height
7458 \setbox\@tempboxa\box\voidb@x
7459 }
7460 % \end{macrocode}
7461 % Define commands that specify the valid arguments for the second parameter.
7462 % \begin{macrocode}
7463 \let\f@nch@oddhead\fancyhdrsettoheight
7464 \let\f@nch@evenhead\fancyhdrsettoheight
7465 \let\f@nch@oddfoot\fancyhdrsettoheight
7466 \let\f@nch@evenfoot\fancyhdrsettoheight
7467 % \end{macrocode}
7468 % \end{macro}
7469 %
7470 % \begin{macro}[internal]{\f@nch@vbox}
7471 % Make a \cs{vbox} with the header or footer. Check whether there is
7472 % enough space and give a warning if not.
7473 % Use box 0 as a temp box and dimen 0 as temp dimen. This can be done,
7474 % because this code will always be used inside another box, and
7475 % therefore the changes are local.\\
7476 % Parameter 1 is \cs{headheight} or \cs{footskip}, respectively.\\
7477 % Parameter 2 is the contents of the box.
7478 %
7479 % \changes{fancyhdr v3.10}{2019/01/25}{Don't use \cs{global}\cs{setlength}.}
7480 % \changes{fancyhdr v3.10}{2019/01/26}{Use \cs{newcommand} instead of \cs{def}.}
7481 % \changes{fancyhdr v4.0}{2019/03/15}{Don't adjust the
7482 % \cs{headheight}/\cs{footskip}, except when the \texttt{compatV3} option is given.}
7483 % \changes{fancyhdr v4.0}{2019/03/15}{Don't check when the \texttt{nocheck} option is given.}
7484 % \changes{fancyhdr v4.0.2}{2021/02/11}{Shorten one sentence in the warning message.}
7485 % \changes{fancyhdr v4.0.2}{2021/02/11}{If the option \texttt{[nocheck]}
7486 % is given, just keep quiet and don't change the
7487 % \cs{headheight}/\cs{footskip} even if the \texttt{[compatV3]} option
7488 % is given.}
7489 % \changes{fancyhdr v5.0}{2021/02/20}{Set \cs{f@nch@height} to height of box}
7490 % \begin{macrocode}
7491 \newcommand\f@nch@vbox[2]{%
7492 \setbox0\vbox{#2}%
7493 \global\f@nch@height=\ht0
7494 \ifdim\ht0>#1\relax
7495 % \end{macrocode}
7496 % This is the part where the the header/footer is too tall for the vertical space.
7497 % If the \texttt{[nocheck]} package option is not given, we give a
7498 % warning message.
7499 % \begin{macrocode}
7500 \iff@nch@check
7501 \dimen0=#1\advance\dimen0-\ht0
7502 \PackageWarning{fancyhdr}{%
7503 \string#1 is too small (\the#1): \MessageBreak
7504 Make it at least \the\ht0, for example:\MessageBreak
7505 \string\setlength{\string#1}{\the\ht0}%
7506 % \end{macrocode}
7507 % If the \texttt{[compatV3]} option was given (and not
7508 % \texttt{[nocheck]}), we will also change the
7509 % \cs{headheight}/\cs{footskip} globally below, and announce this in the warning message.
7510 % \begin{macrocode}
7511 \iff@nch@compatViii .\MessageBreak
7512 We now make it that large for the rest of the document.\MessageBreak
7513 This may cause the page layout to be inconsistent, however
7514 \fi
7515 \ifx#1\headheight .\MessageBreak
7516 You might also make \topmargin smaller:\MessageBreak
7517 \string\addtolength{\string\topmargin}{\the\dimen0}%
7518 \fi
7519 \@gobble
7520 }%
7521 % \end{macrocode}
7522 % Here we do the actual global changing of the \cs{headheight}/\cs{footskip}.
7523 % \begin{macrocode}
7524 \iff@nch@compatViii
7525 \dimen0=#1\relax
7526 \global#1=\ht0\relax
7527 \ht0=\dimen0 %
7528 \else
7529 \ht0=#1\relax
7530 \fi
7531 % \end{macrocode}
7532 % However, if the \texttt{[nocheck]} options is given, we just make the
7533 % height of the header/footer equal to the reserved space, so that no
7534 % warning about ``Overfull vbox'' will be given. So we pretend that it
7535 % fits, and it is the user's responsibility to make sure no unwanted
7536 % effects take place.
7537 % \begin{macrocode}
7538 \else
7539 \ht0=#1\relax
7540 \fi
7541 \fi
7542 \box0}
7543 % \end{macrocode}
7544 % \end{macro}
7545 %
7546 % \begin{macro}[internal]{\f@nch@head}
7547 % \changes{fancyhdr v4.0}{2019/03/22}{Parameter \cs{headruleskip}.}
7548 % \changes{fancyhdr v4.0}{2019/03/25}{\cs{fancyheadinit} initialisation
7549 % code added and \cs{f@nch@reset} moved up.}
7550 % \changes{fancyhdr v4.0.2}{2022/05/09}{Added
7551 % \cs{leavevmode}\cs{ignorespaces} to each header/footer field.
7552 % The \cs{leavevmode} prevents a bug when a field starts with a
7553 % \cs{color} command. The \cs{ignorespaces} skips initial spaces in
7554 % the parameter, as is usual in a \cs{parbox}, for backwards compatibility.}
7555 % \changes{fancyhdr v4.5}{2024/12/05}{Hooks added}
7556 % \changes{fancyhdr v5.0}{2025/01/01}{Support for \cs{fancyheadwidth},
7557 % \cs{fancyfootwidth} and \cs{fancyhfwidth}.}
7558 % \changes{fancyhdr v5.1}{2025/01/06}{Add paragraph hook restore code
7559 % (\cs{f@nch@restorepar}).}
7560 % \changes{fancyhdr v5.2}{2025/01/25}{Implement \cs{fancyhfwidth} etc.
7561 % \meta{alignment} option.}
7562 % Put together a header (\cs{f@nch@head}) or footer (\cs{f@nch@foot})
7563 % given the left, center and right text and their widths,
7564 % fillers at left and right and a rule. The \cs{xlap} commands put
7565 % the text into an hbox of zero size, so overlapping text does not
7566 % generate an errormessage.\\ These macros have 8 parameters:\\
7567 % 1. LEFTSIDE BEARING. This determines at which side the header will stick
7568 % out. When \cs{fancyhfoffset} is used this calculates \cs{headwidth},
7569 % otherwise it is \cs{hss} or \cs{relax} (after expansion). \\
7570 % 2. \cs{f@nch@olh}, \cs{f@nch@elh}, \cs{f@nch@olf} or \cs{f@nch@elf}.
7571 % This is the left component. \\
7572 % 3. \cs{f@nch@och}, \cs{f@nch@ech}, \cs{f@nch@ocf} or \cs{f@nch@ecf}.
7573 % This is the center component. \\
7574 % 4. \cs{f@nch@orh}, \cs{f@nch@erh}, \cs{f@nch@orf} or \cs{f@nch@erf}.
7575 % This is the right component. \\
7576 % 5. RIGHTSIDE BEARING. This is always \cs{relax} or \cs{hss}
7577 % (after expansion).\\
7578 % 6. Even (\texttt{e}) or odd (\texttt{o}).
7579 %
7580 % Before constructing the header or footer, the environment is reset to
7581 % a known state, the appropriate hooks (\texttt{fancyhdr/before} and
7582 % \TTindex{fancyhdr/before}%
7583 % \TTindex{fancyhdr/head/begin}\TTindex{fancyhdr/foot/begin}%
7584 % \texttt{fancyhdr/head/begin} or \texttt{fancyhdr/foot/begin}) are
7585 % run, and then the corresponding initialisation code as given in
7586 % \cs{fancyheadinit} or \cs{fancyfootinit}, respectively, is run.\\
7587 % After constructing the header or footer, the hooks for the end
7588 % (\texttt{fancyhdr/head/end} or \texttt{fancyhdr/foot/end} and
7589 % \TTindex{fancyhdr/head/end}\TTindex{fancyhdr/foot/end}%
7590 % \TTindex{fancyhdr/after}%
7591 % \texttt{fancyhdr/after}) are run.
7592 % \begin{macrocode}
7593 \newcommand\f@nch@head[6]{%
7594 \f@nch@reset
7595 \ifdefined\UseHook\UseHook{fancyhdr/before}\UseHook{fancyhdr/head/begin}\fi
7596 \f@nch@headinit\relax
7597 #1%
7598 \hbox to\headwidth{%
7599 \f@nch@vbox\headheight{%
7600 \f@nch@hfbox{#2}{#3}{#4}{#6}{h}%
7601 \vskip\headruleskip\relax
7602 \headrule
7603 }%
7604 }%
7605 #5%
7606 \ifdefined\UseHook\UseHook{fancyhdr/head/end}\UseHook{fancyhdr/after}\fi
7607 \f@nch@restorepar
7608 }
7609 % \end{macrocode}
7610 %
7611 % \begin{macro}[internal]{\f@nch@foot}
7612 % \changes{fancyhdr v3.10}{2019/01/26}{Put \cs{footrule} in a \cs{vbox}
7613 % to accommodate for flexible footrules.}
7614 % \changes{fancyhdr v3.10}{2019/01/28}{Use \cs{unvbox} on the footrule \cs{vbox}
7615 % to preserve vertical spacing.}
7616 % \changes{fancyhdr v3.10}{2019/01/28}{Move \cs{footruleskip} outside of the \cs{footrule}
7617 % definition.}
7618 % \changes{fancyhdr v4.0}{2019/03/25}{\cs{fancyfootinit} initialisation
7619 % code added and \cs{f@nch@reset} moved up.}
7620 % \changes{fancyhdr v4.0.2}{2022/05/09}{Added
7621 % \cs{leavevmode}\cs{ignorespaces} to each header/footer field.
7622 % The \cs{leavevmode} prevents a bug when a field starts with a
7623 % \cs{color} command. The \cs{ignorespaces} skips initial spaces in
7624 % the parameter, as is usual in a \cs{parbox}, for backwards compatibility.}
7625 % \changes{fancyhdr v4.5}{2024/12/05}{Hooks added}
7626 % \changes{fancyhdr v5.0}{2025/01/01}{Support for \cs{fancyheadwidth},
7627 % \cs{fancyfootwidth} and \cs{fancyhfwidth}.}
7628 % \changes{fancyhdr v5.1}{2025/01/06}{Add paragraph hook restore code
7629 % (\cs{f@nch@restorepar}).}
7630 % \changes{fancyhdr v5.2}{2025/01/25}{Implement \cs{fancyhfwidth} etc.
7631 % \meta{alignment} option.}
7632 % We put the \cs{footrule} in a \cs{vbox} to accommodate for flexible
7633 % footrules (e.g., using \cs{hrulefill}), so that the \cs{headwidth} will
7634 % be used as the line width. But to preserve the vertical spacing we
7635 % then \cs{unvbox} this box.
7636 %
7637 % \begin{macrocode}
7638 \newcommand\f@nch@foot[6]{%
7639 \f@nch@reset
7640 \ifdefined\UseHook\UseHook{fancyhdr/before}\UseHook{fancyhdr/foot/begin}\fi
7641 \f@nch@footinit\relax
7642 #1%
7643 \hbox to\headwidth{%
7644 \f@nch@vbox\footskip{%
7645 \setbox0=\vbox{\footrule}\unvbox0
7646 \vskip\footruleskip
7647 \f@nch@hfbox{#2}{#3}{#4}{#6}{f}%
7648 % \end{macrocode}
7649 % \changes{fancyhdr v5.0}{2024/05/13}{\cs{vskip}\meta{length}
7650 % added if \cs{fancyfootalign}\protect\marg{length} was given.}
7651 % Add vertical space if \cs{fancyfootalign}\marg{length} has been given.
7652 % \begin{macrocode}
7653 \iff@nch@footalign \vskip\f@nch@footalignment \fi
7654 }%
7655 }%
7656 #5%
7657 \ifdefined\UseHook\UseHook{fancyhdr/foot/end}\UseHook{fancyhdr/after}\fi
7658 \f@nch@restorepar
7659 }
7660 % \end{macrocode}
7661 % \end{macro}
7662 % \end{macro}
7663 %
7664 % \begin{macro}[internal]{\f@nch@widthL, \f@nch@widthC, \f@nch@widthR}
7665 % Length variables to store the field widths during construction of the
7666 % header/footer.
7667 % \begin{macrocode}
7668 \newlength\f@nch@widthL
7669 \newlength\f@nch@widthC
7670 \newlength\f@nch@widthR
7671 % \end{macrocode}
7672 %
7673 % \end{macro}
7674 % \begin{macro}[internal]{\f@nch@hfbox}
7675 % This macro constructs the box with the header or footer. It has 5 parameters:\\
7676 % 1. Left field\\
7677 % 2. Center field\\
7678 % 3. Right field\\
7679 % 4. Even (\texttt{e}) or odd (\texttt{o}).\\
7680 % 5. Header (\texttt{h}) or footer (\texttt{f}).
7681 %
7682 % Algorithm:\\
7683 % First we store the field widths in length variables.\\
7684 % If the sum of the field widths > \cs{headwidth}: the center field is
7685 % centered in the header/footer, and the left and right fields are put
7686 % in an \cs{\meta{x}lap} to prevent error messages about overlapping.\\
7687 % Otherwise, if there is no overlap between the fields, also put the
7688 % center field centered in the header/footer. This is done by the macro
7689 % \cs{f@nch@hfbox@center}\\
7690 % Otherwise (there is enough space, but centering would cause overlap):\\
7691 % put the center field centered between the left and right field, i.e.,
7692 % with equal gaps on both sides. This is done by the macro
7693 % \cs{f@nch@hfbox@fit}.
7694 % \changes{fancyhdr v5.2}{2025/01/25}{Implement \cs{fancyhfwidth} etc.
7695 % \meta{alignment} option.}
7696 %
7697 % \begin{macrocode}
7698 \newcommand\f@nch@hfbox[5]{%
7699 \setlength\f@nch@widthL{\csname f@nch@width@#4l#5\endcsname}%
7700 \setlength\f@nch@widthC{\csname f@nch@width@#4c#5\endcsname}%
7701 \setlength\f@nch@widthR{\csname f@nch@width@#4r#5\endcsname}%
7702 \let\@tempa\f@nch@hfbox@center
7703 \ifdim \dimexpr \f@nch@widthL+\f@nch@widthC+\f@nch@widthR>\headwidth
7704 \else
7705 \ifdim \dimexpr \f@nch@widthL+0.5\f@nch@widthC>0.5\headwidth
7706 \let \@tempa\f@nch@hfbox@fit
7707 \fi
7708 \ifdim \dimexpr \f@nch@widthR+0.5\f@nch@widthC>0.5\headwidth
7709 \let \@tempa\f@nch@hfbox@fit
7710 \fi
7711 \fi
7712 \@tempa{#1}{#2}{#3}#4#5%
7713 }
7714 % \end{macrocode}
7715 % \end{macro}
7716 %
7717 % \begin{macro}[internal]{\f@nch@hfbox@center}
7718 % This macro constructs the box with the header or footer. This is the
7719 % version that centers the center field in the total header/footer.
7720 % It has 4 parameters:\\
7721 % 1. Left field\\
7722 % 2. Center field\\
7723 % 3. Right field\\
7724 % 4. Even (\texttt{e}) or odd (\texttt{o}).\\
7725 % 5. Header (\texttt{h}) or footer (\texttt{f}).
7726 % \changes{fancyhdr v5.2}{2025/01/25}{Implement \cs{fancyhfwidth} etc.
7727 % \meta{alignment} option.}
7728 % \begin{macrocode}
7729 \newcommand\f@nch@hfbox@center[5]{%
7730 \hbox to \headwidth{%
7731 \rlap{\f@nch@parbox{#1}\f@nch@widthL{#4}l{#5}}%
7732 \hfill
7733 \f@nch@parbox{#2}\f@nch@widthC{#4}c{#5}%
7734 \hfill
7735 \llap{\f@nch@parbox{#3}\f@nch@widthR{#4}r{#5}}%
7736 }%
7737 }
7738 % \end{macrocode}
7739 % \end{macro}
7740 % \begin{macro}[internal]{\f@nch@hfbox@fit}
7741 % This macro constructs the box with the header or footer. This is the
7742 % version that centers the center field between the left and right fields.
7743 % It has 4 parameters:\\
7744 % 1. Left field\\
7745 % 2. Center field\\
7746 % 3. Right field\\
7747 % 4. Even (\texttt{e}) or odd (\texttt{o}).\\
7748 % 5. Header (\texttt{h}) or footer (\texttt{f}).
7749 % \changes{fancyhdr v5.2}{2025/01/25}{Implement \cs{fancyhfwidth} etc.
7750 % \meta{alignment} option.}
7751 % \begin{macrocode}
7752 \newcommand\f@nch@hfbox@fit[5]{%
7753 \hbox to \headwidth{%
7754 \f@nch@parbox{#1}\f@nch@widthL{#4}l{#5}%
7755 \hfill
7756 \f@nch@parbox{#2}\f@nch@widthC{#4}c{#5}%
7757 \hfill
7758 \f@nch@parbox{#3}\f@nch@widthR{#4}r{#5}%
7759 }%
7760 }%
7761 % \end{macrocode}
7762 % \end{macro}
7763 %
7764 % \begin{macro}[internal]{\f@nch@parbox}
7765 % This macro constructs one \cs{parbox} in the header or footer.
7766 % It has 4 parameters:\\
7767 % 1. The contents\\
7768 % 2. The width for the \cs{parbox}.\\
7769 % 3. Even (\texttt{e}) or odd (\texttt{o}).\\
7770 % 4. Left (\texttt{l}), center (\texttt{c}) or right (\texttt{r}).\\
7771 % 5. Header (\texttt{h}) or footer (\texttt{f}).\\
7772 % Result: the proper \cs{parbox}\\[1ex]
7773 % First we get (with \Cmd{csname}) the proper alignment parameter. Then we
7774 % expand this so that \cs{f@nch@parbox@align} gets the two alignment letters
7775 % as separate arguments. Then \cs{f@nch@parbox@align} is called to set
7776 % up the alignment variables. After that we construct the \cs{parbox}
7777 % with the calculated variables.
7778 % \begin{macrocode}
7779 \newcommand\f@nch@parbox[5]{%
7780 \expandafter\expandafter\expandafter\f@nch@parbox@align
7781 \csname f@nch@align@#3#4#5\endcsname
7782 \parbox[\f@nch@align@@v]{#2}%
7783 {%
7784 \f@nch@align@@pre
7785 \f@nch@align@@h\leavevmode\ignorespaces#1%
7786 \f@nch@align@@post
7787 }%
7788 }
7789 % \end{macrocode}
7790 % \end{macro}
7791 %
7792 % \begin{macro}[internal]{\f@nch@parbox@align}
7793 % The macro \cs{f@nch@parbox@align} sets the alignment variables for \cs{f@nch@parbox}.
7794 % It has 2 parameters, the two letters for the vertical and horizontal
7795 % alignment, with the defaults applied.\\
7796 % 1. Vertical (\texttt{T, t, c, b, B}).\\
7797 % 2. Horizontal (\texttt{l, c, r, j}).\\
7798 % Result variables:
7799 % \begin{description}
7800 % \item[\cs{f@nch@align@@v}] The vertical alignment for the \cs{parbox}:
7801 % \texttt{t}, \texttt{c} or \texttt{b}.
7802 % \item[\cs{f@nch@align@@h}] The horizontal alignment for the
7803 % \cs{parbox}: \cs{raggedright}, \cs{centering}, \cs{raggedleft} or
7804 % empty for \texttt{l, c, r, j}, respectively.
7805 % \item[\cs{f@nch@align@@pre}] code before the contents of the
7806 % \cs{parbox}: \Cmd{vspace\{0pt\}} for \texttt{T} alignment, otherwise empty.
7807 % \item[\cs{f@nch@align@@post}] code after the contents of the
7808 % \cs{parbox}: \Cmd{vspace\{0pt\}} for \texttt{B} alignment, otherwise empty.
7809 % \end{description}
7810 % First we set the defaults for \cs{f@nch@align@@pre} and
7811 % \cs{f@nch@align@@post} (empty). Then we call the proper macros for the
7812 % alignment parameters.
7813 % \begin{macrocode}
7814 \newcommand\f@nch@parbox@align[2]{%
7815 \def\f@nch@align@@pre{}%
7816 \def\f@nch@align@@post{}%
7817 \csname f@nch@parbox@align@v#1\endcsname
7818 \csname f@nch@parbox@align@h#2\endcsname
7819 }
7820 % \end{macrocode}
7821 % \end{macro}
7822 %
7823 % \begin{macro}[internal]{\f@nch@parbox@align@vT,
7824 % \f@nch@parbox@align@vt, \f@nch@parbox@align@vc, \f@nch@parbox@align@vb, \f@nch@parbox@align@vB, \f@nch@parbox@align@hl, \f@nch@parbox@align@hc, \f@nch@parbox@align@hr, \f@nch@parbox@align@hj}
7825 %
7826 % The macro \cs{f@nch@parbox@align@\meta{v$|$h}\meta{x}} sets the variables for the
7827 % vertical or horizontal alignment option \texttt{\meta{x}}.
7828 % \begin{macrocode}
7829 \def\f@nch@parbox@align@vT{\def\f@nch@align@@v{t}\def\f@nch@align@@pre{\vspace{0pt}}}
7830 \def\f@nch@parbox@align@vt{\def\f@nch@align@@v{t}}
7831 \def\f@nch@parbox@align@vc{\def\f@nch@align@@v{c}}
7832 \def\f@nch@parbox@align@vb{\def\f@nch@align@@v{b}}
7833 \def\f@nch@parbox@align@vB{\def\f@nch@align@@v{b}\def\f@nch@align@@post{\vspace{0pt}}}
7834 \def\f@nch@parbox@align@hl{\def\f@nch@align@@h{\raggedright}}
7835 \def\f@nch@parbox@align@hc{\def\f@nch@align@@h{\centering}}
7836 \def\f@nch@parbox@align@hr{\def\f@nch@align@@h{\raggedleft}}
7837 \def\f@nch@parbox@align@hj{\def\f@nch@align@@h{}}
7838 % \end{macrocode}
7839 % \end{macro}
7840 %
7841 % \changes{fancyhdr v5.2}{2025/01/28}{Remove fallback definition of \cs{MakeUppercase}.}
7842 %
7843 % \begin{macro}[internal]{\@chapapp}
7844 % Define \cs{@chapapp} for classes that don't have it, e.g., amsbook
7845 % \changes{fancyhdr v5.2}{2025/01/15}{Use \cs{@ifundefined} instead of
7846 % \cs{f@nch@ifundefined}.}
7847 % \begin{macrocode}
7848 \@ifundefined{@chapapp}{\let\@chapapp\chaptername}{}%
7849 % \end{macrocode}
7850 % \end{macro}
7851 % \begin{macro}[internal]{\f@nch@initialise}
7852 % \changes{fancyhdr v4.0}{2019/03/21}{Put all the initialisation code in
7853 % \cs{f@nch@initialise}}
7854 % This macro initialises the headers and footers and \cs{chaptermark}
7855 % and/or \Cmd{[sub]sectionmark} for page style \texttt{fancy}
7856 % \begin{macrocode}
7857 \def\f@nch@initialise{%
7858 % \end{macrocode}
7859 %
7860 % \begin{macro}{\chaptermark}
7861 % \begin{macro}{\sectionmark}
7862 % \begin{macro}{\subsectionmark}
7863 % Standard definitions for \cs{chaptermark}, \cs{sectionmark} and \cs{subsectionmark}.
7864 % \changes{fancyhdr v5.2}{2025/01/15}{Use \cs{@ifundefined} instead of
7865 % \cs{f@nch@ifundefined}.}
7866 %
7867 % \begin{macrocode}
7868 \@ifundefined{chapter}%
7869 {\def\sectionmark##1{\markboth{\MakeUppercase{\ifnum \c@secnumdepth>\z@
7870 \thesection\hskip 1em\relax
7871 \fi ##1}}{}}%
7872 \def\subsectionmark##1{\markright {\ifnum \c@secnumdepth >\@ne
7873 \thesubsection\hskip 1em\relax \fi ##1}}}%
7874 {\def\chaptermark##1{\markboth {\MakeUppercase{\ifnum
7875 \c@secnumdepth>\m@ne \@chapapp\ \thechapter. \ \fi ##1}}{}}%
7876 \def\sectionmark##1{\markright{\MakeUppercase{\ifnum \c@secnumdepth >\z@
7877 \thesection. \ \fi ##1}}}%
7878 }%
7879 % \end{macrocode}
7880 % \end{macro}
7881 % \end{macro}
7882 % \end{macro}
7883 %
7884 % \begin{macro}{\headrule}
7885 % \begin{macrocode}
7886 \def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
7887 \hrule\@height\headrulewidth\@width\headwidth
7888 \vskip-\headrulewidth}}%
7889 % \end{macrocode}
7890 % \end{macro}
7891 %
7892 % \begin{macro}{\footrule}
7893 % \changes{fancyhdr v3.10}{2019/01/28}{Move \cs{footruleskip} outside of the \cs{footrule}
7894 % definition and remove useless \cs{vskip} at the top.}
7895 % \begin{macrocode}
7896 \def\footrule{{\if@fancyplain\let\footrulewidth\plainfootrulewidth\fi
7897 \hrule\@width\headwidth\@height\footrulewidth}}%
7898 % \end{macrocode}
7899 % \end{macro}
7900 %
7901 % Default values for \cs{headrulewidth}, \cs{footrulewidth},
7902 % \cs{headruleskip} and \cs{footruleskip}.
7903 % \begin{macrocode}
7904 \def\headrulewidth{0.4pt}%
7905 \def\footrulewidth{0pt}%
7906 \def\headruleskip{0pt}%
7907 \def\footruleskip{0.3\normalbaselineskip}%
7908 % \end{macrocode}
7909 % Initialisation of the head and foot text.
7910 %
7911 % The default values still contain \cs{fancyplain} for compatibility:
7912 % left head empty on ``plain'' pages, \cs{rightmark} on even, \cs{leftmark} on odd pages;
7913 % right head empty on ``plain'' pages, \cs{leftmark} on even, \cs{rightmark} on odd pages.
7914 % \begin{macrocode}
7915 \fancyhf{}%
7916 \if@twoside
7917 \fancyhead[el,or]{\fancyplain{}{\slshape\rightmark}}%
7918 \fancyhead[er,ol]{\fancyplain{}{\slshape\leftmark}}%
7919 \else
7920 \fancyhead[l]{\fancyplain{}{\slshape\rightmark}}%
7921 \fancyhead[r]{\fancyplain{}{\slshape\leftmark}}%
7922 \fi
7923 \fancyfoot[c]{\rmfamily\thepage}% page number
7924 }
7925 % \end{macrocode}
7926 % Call the initialisation
7927 % \begin{macrocode}
7928 \f@nch@initialise
7929 % \end{macrocode}
7930 % \end{macro}
7931 %
7932 % \begin{macro}[internal]{\ps@f@nch@fancyproto}
7933 % \cs{ps@f@nch@fancyproto} is the
7934 % initial value for page style \texttt{fancy}. The real page style
7935 % is \cs{ps@f@nch@fancycore} but \cs{ps@f@nch@fancyproto} for the first use
7936 % of \Cmd{pagestyle\{fancy\}} or any of its derivatives. It
7937 % initialises \cs{headwidth}, and then resets itself to
7938 % \cs{ps@f@nch@fancycore}. For backwards compatibility it still
7939 % contains \cs{@fancyplainfalse}.
7940 % The reason we have \cs{ps@f@nch@fancyproto} is so that page style
7941 % \texttt{fancy} can be redefined.
7942 % \changes{fancyhdr v4.0}{2019/03/21}{Reorganise \cs{ps@fancy}}
7943 % \begin{macrocode}
7944 \def\ps@f@nch@fancyproto{%
7945 % \end{macrocode}
7946 % Initialise \cs{headwidth} if the user didn't. If \cs{headwidth} ${}< 0$,
7947 % then the user did not initialise it, or they just added something to
7948 % it in the expectation that
7949 % it was initialised to \cs{textwidth}. We compensate this now. This loses if
7950 % the user intended to multiply it by a factor. But that case is more
7951 % likely done by saying something like \verb+\setlength{\headwidth}{1.2\textwidth}+.
7952 % The documentation advises to change \cs{headwidth} after the first call to
7953 % \verb+\pagestyle{fancy}+. This code is just to catch the most common cases were
7954 % that is not the case.
7955 % \begin{macrocode}
7956 \ifdim\headwidth<0sp
7957 \global\advance\headwidth123456789sp\global\advance\headwidth\textwidth
7958 \fi
7959 % \end{macrocode}
7960 % Now we reset \cs{ps@f@nch@fancyproto} to \cs{ps@f@nch@fancycore} with \cs{@fancyplainfalse}
7961 % and call that version.
7962 % \begin{macrocode}
7963 \gdef\ps@f@nch@fancyproto{\@fancyplainfalse\ps@f@nch@fancycore}%
7964 \@fancyplainfalse\ps@f@nch@fancycore
7965 }%
7966 % \end{macrocode}
7967 % Let the system know this is a \pkg{fancyhdr} page style.
7968 % \begin{macrocode}
7969 \@namedef{f@nch@ps@f@nch@fancyproto-is-fancyhdr}{}
7970 % \end{macrocode}
7971 % \end{macro}
7972 % \begin{macro}[internal]{\ps@fancy}
7973 % Define \cs{ps@fancy} just to call \cs{ps@f@nch@fancyproto}.
7974 % \begin{macrocode}
7975 \def\ps@fancy{\ps@f@nch@fancyproto}
7976 \@namedef{f@nch@ps@fancy-is-fancyhdr}{}
7977 % \end{macrocode}
7978 % \end{macro}
7979 %
7980 % \begin{macro}[internal]{\ps@fancyplain}
7981 % The page style \texttt{fancyplain} (deprecated).
7982 % After initializing by calling \cs{ps@f@nch@fancyproto} it sets page style
7983 % \texttt{plain} to our version \cs{ps@plain@fancy}, which just sets
7984 % \cs{@fancyplaintrue} and then calls the page style fancy implementation.
7985 %
7986 % \begin{macrocode}
7987 \def\ps@fancyplain{\ps@f@nch@fancyproto \let\ps@plain\ps@plain@fancy}
7988 \def\ps@plain@fancy{\@fancyplaintrue\ps@f@nch@fancycore}
7989 % \end{macrocode}
7990 % \end{macro}
7991 %
7992 % \begin{macro}[internal]{\f@nch@ps@empty}
7993 % Save the definition of \cs{ps@empty} (page style \texttt{empty}).
7994 % \changes{fancyhdr v4.0}{2019/03/21}{Rename \cs{ps@@empty} to \cs{f@nch@ps@empty}}
7995 %
7996 % \begin{macrocode}
7997 \let\f@nch@ps@empty\ps@empty
7998 % \end{macrocode}
7999 % \end{macro}
8000 %
8001 % \begin{macro}[internal]{\ps@f@nch@fancycore}
8002 % \changes{fancyhdr v4.0}{2019/03/21}{Rename \cs{ps@@fancy} to \cs{ps@f@nch@fancycore}}
8003 % \changes{fancyhdr v4.1}{2022/09/06}{Implement \texttt{twoside} option.}
8004 % \changes{fancyhdr v5.0}{2025/01/01}{Support for \cs{fancyheadwidth},
8005 % \cs{fancyfootwidth} and \cs{fancyhfwidth}.}
8006 % \changes{fancyhdr v5.2}{2025/01/25}{Implement \cs{fancyhfwidth} etc.
8007 % \meta{alignment} option.}
8008 % The actual implementation of page style \texttt{fancy}. For amsbook/amsart, which do
8009 % strange things with \cs{topskip}, we start with \cs{f@nch@ps@empty}. We
8010 % construct the even and odd headers and footers from all the parts that
8011 % we have collected.
8012 % \begin{macrocode}
8013 \def\ps@f@nch@fancycore{%
8014 \f@nch@ps@empty
8015 \def\@mkboth{\protect\markboth}%
8016 \def\f@nch@oddhead{\f@nch@head\f@nch@Oolh\f@nch@olh\f@nch@och\f@nch@orh\f@nch@Oorh{o}}%
8017 \def\@oddhead{%
8018 \iff@nch@twoside
8019 \ifodd\c@page
8020 \f@nch@oddhead
8021 \else
8022 \@evenhead
8023 \fi
8024 \else
8025 \f@nch@oddhead
8026 \fi
8027 }
8028 \def\f@nch@oddfoot{\f@nch@foot\f@nch@Oolf\f@nch@olf\f@nch@ocf\f@nch@orf\f@nch@Oorf{o}}%
8029 \def\@oddfoot{%
8030 \iff@nch@twoside
8031 \ifodd\c@page
8032 \f@nch@oddfoot
8033 \else
8034 \@evenfoot
8035 \fi
8036 \else
8037 \f@nch@oddfoot
8038 \fi
8039 }
8040 \def\@evenhead{\f@nch@head\f@nch@Oelh\f@nch@elh\f@nch@ech\f@nch@erh\f@nch@Oerh{e}}%
8041 \def\@evenfoot{\f@nch@foot\f@nch@Oelf\f@nch@elf\f@nch@ecf\f@nch@erf\f@nch@Oerf{e}}%
8042 }
8043 % \end{macrocode}
8044 % \end{macro}
8045 %
8046 % \begin{macro}[internal]{\f@nch@Oolh}
8047 % \begin{macro}[internal]{\f@nch@Oorh}
8048 % \begin{macro}[internal]{\f@nch@Oelh}
8049 % \begin{macro}[internal]{\f@nch@Oerh}
8050 % \begin{macro}[internal]{\f@nch@Oolf}
8051 % \begin{macro}[internal]{\f@nch@Oorf}
8052 % \begin{macro}[internal]{\f@nch@Oelf}
8053 % \begin{macro}[internal]{\f@nch@Oerf}
8054 % Default definitions for compatibility mode: These cause the
8055 % header/footer to take the defined \cs{headwidth} as its width and if
8056 % required to shift it in the direction of the marginpar area.
8057 %
8058 % \begin{macrocode}
8059 \def\f@nch@Oolh{\if@reversemargin\hss\else\relax\fi}
8060 \def\f@nch@Oorh{\if@reversemargin\relax\else\hss\fi}
8061 \let\f@nch@Oelh\f@nch@Oorh
8062 \let\f@nch@Oerh\f@nch@Oolh
8063 \let\f@nch@Oolf\f@nch@Oolh
8064 \let\f@nch@Oorf\f@nch@Oorh
8065 \let\f@nch@Oelf\f@nch@Oelh
8066 \let\f@nch@Oerf\f@nch@Oerh
8067 % \end{macrocode}
8068 % \end{macro}
8069 % \end{macro}
8070 % \end{macro}
8071 % \end{macro}
8072 % \end{macro}
8073 % \end{macro}
8074 % \end{macro}
8075 % \end{macro}
8076 %
8077 % \begin{macro}[internal]{\f@nch@offsolh}
8078 % \begin{macro}[internal]{\f@nch@offselh}
8079 % \changes{fancyhdr v5.0}{2021/03/27}{Change the offset length variables
8080 % \cs{f@nch@O@xyz} to \cs{f@nch@offset@xyz}}
8081 % New definitions for the use of \cs{fancyhfoffset},
8082 % \cs{fancyheadoffset}, \cs{fancyfootoffset}. These calculate the
8083 % \cs{headwidth} from \cs{textwidth} and the specified offsets.\\
8084 % First for the header.
8085 %
8086 % \begin{macrocode}
8087 \def\f@nch@offsolh{\headwidth=\textwidth\advance\headwidth\f@nch@offset@olh
8088 \advance\headwidth\f@nch@offset@orh\hskip-\f@nch@offset@olh}
8089 \def\f@nch@offselh{\headwidth=\textwidth\advance\headwidth\f@nch@offset@elh
8090 \advance\headwidth\f@nch@offset@erh\hskip-\f@nch@offset@elh}
8091 % \end{macrocode}
8092 % \end{macro}
8093 % \end{macro}
8094 %
8095 % \begin{macro}[internal]{\f@nch@offsolf}
8096 % \begin{macro}[internal]{\f@nch@offself}
8097 % The same for the footer.
8098 %
8099 % \begin{macrocode}
8100 \def\f@nch@offsolf{\headwidth=\textwidth\advance\headwidth\f@nch@offset@olf
8101 \advance\headwidth\f@nch@offset@orf\hskip-\f@nch@offset@olf}
8102 \def\f@nch@offself{\headwidth=\textwidth\advance\headwidth\f@nch@offset@elf
8103 \advance\headwidth\f@nch@offset@erf\hskip-\f@nch@offset@elf}
8104 % \end{macrocode}
8105 % \end{macro}
8106 % \end{macro}
8107 %
8108 % \begin{macro}[internal]{\f@nch@setoffs}
8109 % \changes{fancyhdr v5.0}{2021/03/27}{Use \cs{def} instead of \cs{let}
8110 % to make it easier to pick up these macros for \cs{fancypagestyle*}}
8111 % Set the offset parts to be used in the construction of the headers and
8112 % footers. Depending on \cs{f@nch@gbl} it will be done globally (for
8113 % page style \texttt{fancy}) in \texttt{compatV3} mode)
8114 % or locally (for \cs{fancypagestyle}).
8115 % The macros \Cmd{f@nch@Oxyz} tell what should be done at the various
8116 % ends of the headers/footers. They are done with \cs{def} rather than
8117 % \cs{let} so they are easier to pick up for \cs{fancypagestyle*}.
8118 %
8119 % Just in case \verb+\let\headwidth\textwidth+ was used, we reset
8120 % \cs{headwidth} to the length parameter that it should be.
8121 % \begin{macrocode}
8122 \def\f@nch@setoffs{%
8123 \f@nch@gbl\let\headwidth\f@nch@headwidth
8124 \f@nch@gbl\def\f@nch@Oolh{\f@nch@offsolh}%
8125 \f@nch@gbl\def\f@nch@Oelh{\f@nch@offselh}%
8126 \f@nch@gbl\def\f@nch@Oorh{\hss}%
8127 \f@nch@gbl\def\f@nch@Oerh{\hss}%
8128 \f@nch@gbl\def\f@nch@Oolf{\f@nch@offsolf}%
8129 \f@nch@gbl\def\f@nch@Oelf{\f@nch@offself}%
8130 \f@nch@gbl\def\f@nch@Oorf{\hss}%
8131 \f@nch@gbl\def\f@nch@Oerf{\hss}%
8132 }
8133 % \end{macrocode}
8134 % \end{macro}
8135 %
8136 % \begin{macro}[internal]{\iff@nch@footnote}
8137 % \begin{macro}[internal]{\@makecol}
8138 % \changes{fancyhdr v5.0}{2021/03/27}{Change the internal variables
8139 % \cs{topfloat} and \cs{botfloat} to localised ones \cs{f@nch@topfloat}
8140 % and \cs{f@nch@botfloat}.}
8141 % Redefine \cs{@makecol} so that we can capture if there are
8142 % top/bottom floats, footnotes or if we are on a float page. Because
8143 % of a clash with the \PKGindex{footmisc}\pkg{footmisc} package we do this at
8144 % \verb+\begin{document}+.\\
8145 % We need a boolean \cs{iff@nch@footnote} to capture if there was a footnote.
8146 %
8147 % \begin{macrocode}
8148 \newif\iff@nch@footnote
8149 \AtBeginDocument{%
8150 \let\latex@makecol\@makecol
8151 \def\@makecol{\ifvoid\footins\f@nch@footnotefalse\else\f@nch@footnotetrue\fi
8152 \let\f@nch@topfloat\@toplist\let\f@nch@botfloat\@botlist\latex@makecol}%
8153 }
8154 % \end{macrocode}
8155 % \end{macro}
8156 % \end{macro}
8157 %
8158 % \begin{macro}{\iftopfloat}
8159 % \begin{macro}{\ifbotfloat}
8160 % \begin{macro}{\iffloatpage}
8161 % \begin{macro}{\iffootnote}
8162 % These can be used in a header/footer field to make them conditional on
8163 % the presence of floats and/or footnotes.
8164 % \changes{fancyhdr v5.0}{2024/05/08}{Replace \cs{empty} with \cs{@empty}}
8165 % \begin{macrocode}
8166 \newcommand\iftopfloat[2]{\ifx\f@nch@topfloat\@empty #2\else #1\fi}%
8167 \newcommand\ifbotfloat[2]{\ifx\f@nch@botfloat\@empty #2\else #1\fi}%
8168 \newcommand\iffloatpage[2]{\if@fcolmade #1\else #2\fi}%
8169 \newcommand\iffootnote[2]{\iff@nch@footnote #1\else #2\fi}%
8170 % \end{macrocode}
8171 % \end{macro}
8172 % \end{macro}
8173 % \end{macro}
8174 % \end{macro}
8175 %
8176 % \changes{fancyhdr v5.0}{2021/02/16}{Define \cs{newtoks}\cs{@temptokenb}}
8177 % \begin{macro}[internal]{\@temptokenb}
8178 % A token register to collect information for \cs{fancypagestyle*}. The
8179 % definition is conditional on the non-existence of it.
8180 % \begin{macrocode}
8181 \ifx\@temptokenb\undefined \csname newtoks\endcsname\@temptokenb\fi
8182 % \end{macrocode}
8183 % \end{macro}
8184 %
8185 % \changes{fancyhdr v5.0}{2021/02/17}{Define \cs{iff@nch@pagestyle@star}
8186 % to record if \cs{fancypagestyle*} is used.}
8187 % \begin{macro}[internal]{\iff@nch@pagestyle@star}
8188 % A conditional to record if \cs{fancypagestyle*} is used.
8189 % \begin{macrocode}
8190 \newif\iff@nch@pagestyle@star
8191 % \end{macrocode}
8192 % \end{macro}
8193 %
8194 % \begin{macro}{\fancypagestyle}
8195 % Define a new page style. With \texttt{*} define a ``closed'' page
8196 % style, otherwise an ``open'' one.
8197 % \changes{fancyhdr v5.0}{2021/02/17}{Add \cs{fancypagestyle*}}
8198 % \begin{macrocode}
8199 \newcommand\fancypagestyle{%
8200 \@ifstar{\f@nch@pagestyle@startrue\f@nch@pagestyle}%
8201 {\f@nch@pagestyle@starfalse\f@nch@pagestyle}%
8202 }
8203 % \end{macrocode}
8204 % \end{macro}
8205 % \begin{macro}[internal]{\f@nch@pagestyle}
8206 % Internal macro for \cs{fancypagestyle}. The optional second argument is the base page style.
8207 % It defaults to \cs{ps@f@nch@fancyproto}.
8208 % \changes{fancyhdr v4.0}{2019/03/21}{Added optional base style argument.}
8209 % \begin{macrocode}
8210 \newcommand\f@nch@pagestyle[1]{%
8211 \@ifnextchar[{\f@nch@@pagestyle{#1}}{\f@nch@@pagestyle{#1}[f@nch@fancyproto]}%
8212 }
8213 % \end{macrocode}
8214 % \end{macro}
8215 % \begin{macro}[internal]{\f@nch@@pagestyle}
8216 % The actual code for \cs{fancypagestyle}. Build the page style body.
8217 % Declare it as a fancyhdr-based page style.
8218 % \changes{fancyhdr v4.0}{2019/09/05}{Make the definition of \cs{f@nch@pagestyle} \cs{long}.}
8219 % \changes{fancyhdr v5.0}{2021/02/17}{Add \cs{fancypagestyle*}}
8220 % \changes{fancyhdr v5.2}{2025/01/15}{Use \cs{@ifundefined} instead of
8221 % \cs{f@nch@ifundefined}.}
8222 % \begin{macrocode}
8223 \long\def\f@nch@@pagestyle#1[#2]#3{%
8224 \@ifundefined{ps@#2}{%
8225 \PackageError{fancyhdr}{\string\fancypagestyle: Unknown base page style `#2'}{}%
8226 }{%
8227 \@ifundefined{f@nch@ps@#2-is-fancyhdr}{%
8228 \PackageError{fancyhdr}{\string\fancypagestyle: Base page style `#2' is not fancyhdr-based}{}%
8229 }%
8230 {%
8231 % \end{macrocode}
8232 % First put necessary definitions in \cs{@temptokenb}, if required
8233 % (\cs{fancypagestyle*}) by calling \cs{f@nch@pagestyle@setup}.
8234 % Then define the page style by expanding \cs{the}\cs{@temptokenb} and
8235 % adding the base style and our definitions.
8236 % \begin{macrocode}
8237 \f@nch@pagestyle@setup
8238 \def\temp@b{\@namedef{ps@#1}}%
8239 \expandafter\temp@b\expandafter{\the\@temptokenb
8240 \let\f@nch@gbl\relax\@nameuse{ps@#2}#3\relax}%
8241 \@namedef{f@nch@ps@#1-is-fancyhdr}{}%
8242 }%
8243 }%
8244 }
8245 % \end{macrocode}
8246 % \end{macro}
8247 %
8248 % \begin{macro}[internal]{\f@nch@pagestyle@setup}
8249 % Internal macro for \cs{fancypagestyle}. Setup \cs{@temptokenb}:\\
8250 % For \cs{fancypagestyle*} collect relevant macro definitions in \cs{@temptokenb}.\\
8251 % For \cs{fancypagestyle} make \cs{@temptokenb} empty.
8252 % \changes{fancyhdr v5.0}{2021/02/17}{Add \cs{f@nch@pagestyle@setup}
8253 % macro for \cs{fancypagestyle*}}
8254 % \changes{fancyhdr v5.0}{2021/03/27}{Also save the offset length variables
8255 % \cs{f@nch@offset@xyz} with \cs{setlength}}
8256 % \changes{fancyhdr v5.0}{2022/01/24}{Replace \cs{myname} with \cs{temp@a}}
8257 % \changes{fancyhdr v5.0}{2025/01/02}{Implement \cs{fancyhfwidth} etc.,
8258 % store \meta{width}.}
8259 % \changes{fancyhdr v5.2}{2025/01/27}{Implement \cs{fancyhfwidth} etc.,
8260 % store \meta{alignment}.}
8261 % \begin{macrocode}
8262 \newcommand\f@nch@pagestyle@setup{%
8263 \iff@nch@pagestyle@star
8264 % \end{macrocode}
8265 % For \cs{fancypagestyle*}, first save value of \cs{iff@nch@check}
8266 % (the \texttt{[nocheck]} option).
8267 % \begin{macrocode}
8268 \iff@nch@check\@temptokenb={\f@nch@checktrue}\else\@temptokenb={\f@nch@checkfalse}\fi
8269 % \end{macrocode}
8270 % Save values of all relevant macros (50 in total):\\
8271 % headers and footers (12), header and footer widths (12),
8272 % header and footer alignments (12),
8273 % header and footer offsets (8), header and footer inits (2),
8274 % \cs{headrule} and \cs{footrule} and \texttt{...width} (4)
8275 % \begin{macrocode}
8276 \@tfor\temp@a:=
8277 \f@nch@olh\f@nch@och\f@nch@orh\f@nch@elh\f@nch@ech\f@nch@erh
8278 \f@nch@olf\f@nch@ocf\f@nch@orf\f@nch@elf\f@nch@ecf\f@nch@erf
8279 \f@nch@width@elh\f@nch@width@ech\f@nch@width@erh\f@nch@width@olh
8280 \f@nch@width@och\f@nch@width@orh\f@nch@width@elf\f@nch@width@ecf
8281 \f@nch@width@erf\f@nch@width@olf\f@nch@width@ocf\f@nch@width@orf
8282 \f@nch@align@elh\f@nch@align@ech\f@nch@align@erh\f@nch@align@olh
8283 \f@nch@align@och\f@nch@align@orh\f@nch@align@elf\f@nch@align@ecf
8284 \f@nch@align@erf\f@nch@align@olf\f@nch@align@ocf\f@nch@align@orf
8285 \f@nch@Oolh\f@nch@Oorh\f@nch@Oelh\f@nch@Oerh
8286 \f@nch@Oolf\f@nch@Oorf\f@nch@Oelf\f@nch@Oerf
8287 \f@nch@headinit\f@nch@footinit
8288 \headrule\headrulewidth\footrule\footrulewidth
8289 \do {%
8290 % \end{macrocode}
8291 % First get the body of the macro.
8292 % Next put it in a \cs{def}\meta{\cs{macro}}\texttt{\{}\meta{body of \cs{macro}}\texttt{\}}.
8293 % \begin{macrocode}
8294 \toks@=\expandafter\expandafter\expandafter{\temp@a}%
8295 \toks@=\expandafter\expandafter\expandafter{%
8296 \expandafter\expandafter\expandafter\def
8297 \expandafter\expandafter\temp@a\expandafter{\the\toks@}}%
8298 % \end{macrocode}
8299 % Set up a macro to append \cs{toks@} to \cs{@temptokenb} and then execute it.
8300 % \begin{macrocode}
8301 \edef\temp@b{\@temptokenb={\the\@temptokenb\the\toks@}}%
8302 \temp@b
8303 }%
8304 % \end{macrocode}
8305 % Now pick up the offset length variables in a similar way, but with
8306 % \cs{setlength} rather than \cs{def}.
8307 % \begin{macrocode}
8308 \@tfor\temp@a:=
8309 \f@nch@offset@olh\f@nch@offset@orh\f@nch@offset@elh\f@nch@offset@erh
8310 \f@nch@offset@olf\f@nch@offset@orf\f@nch@offset@elf\f@nch@offset@erf
8311 \do {%
8312 \toks@=\expandafter\expandafter\expandafter{\expandafter\the\temp@a}%
8313 \toks@=\expandafter\expandafter\expandafter{%
8314 \expandafter\expandafter\expandafter\setlength
8315 \expandafter\expandafter\temp@a\expandafter{\the\toks@}}%
8316 % \end{macrocode}
8317 % Set up a macro to append \cs{toks@} to \cs{@temptokenb} and then execute it.
8318 % \begin{macrocode}
8319 \edef\temp@b{\@temptokenb={\the\@temptokenb\the\toks@}}%
8320 \temp@b
8321 }%
8322 \else
8323 % \end{macrocode}
8324 % For \cs{fancypagestyle} without \texttt{*}, set \cs{@temptokenb} empty.
8325 % \begin{macrocode}
8326 \@temptokenb={}%
8327 \fi
8328 }
8329 % \end{macrocode}
8330 % \end{macro}
8331 % \begin{macro}{\fancypagestyleassign}
8332 % \changes{fancyhdr v5.0}{2024/12/25}{Macro \cs{fancypagestyleassign} added}
8333 % \changes{fancyhdr v5.2}{2025/01/15}{Use \cs{@ifundefined} instead of
8334 % \cs{f@nch@ifundefined}.}
8335 % \begin{syntax}
8336 % \cs{fancypagestyleassign}\marg{ps1}\marg{ps2}
8337 % \end{syntax}
8338 % Assigns page style \meta{ps2} to \meta{ps1}. This causes
8339 % \meta{ps1} to be an exact copy of \meta{ps2}, but completely
8340 % independent of \meta{ps2}. We do the equivalent of a \cs{let}
8341 % command, like \cs{let}\cs{ps@\meta{ps1}}\cs{ps@\meta{ps2}}.
8342 % \begin{macrocode}
8343 \newcommand\fancypagestyleassign[2]{%
8344 \@ifundefined{ps@#2}{%
8345 \PackageError{fancyhdr}{\string\fancypagestyleassign: Unknown page style `#2'}{}%
8346 }{%
8347 \expandafter\let
8348 \csname ps@#1\expandafter\endcsname
8349 \csname ps@#2\endcsname
8350 % \end{macrocode}
8351 % If \meta{ps2} is fancyhdr-based, \meta{ps1} will also be
8352 % fancyhdr-based, otherwise it is not.
8353 % \changes{fancyhdr v5.2}{2025/01/27}{Remove \Cmd{PackageNote}.}
8354 % \begin{macrocode}
8355 \@ifundefined{f@nch@ps@#2-is-fancyhdr}{%
8356 \expandafter\let\csname f@nch@ps@#1-is-fancyhdr\endcsname\@undefined
8357 }{%
8358 \@namedef{f@nch@ps@#1-is-fancyhdr}{}%
8359 }%
8360 }%
8361 }
8362 % \end{macrocode}
8363 % \end{macro}
8364 %
8365 % \begin{macro}[internal]{\ps@fancydefault}
8366 % \changes{fancyhdr v4.0}{2019/03/21}{Added \cs{ps@fancydefault}}
8367 % \changes{fancyhdr v5.0}{2021/04/11}{Defined \cs{ps@fancydefault} with
8368 % \cs{fancypagestyle*}}
8369 % This is page style \texttt{fancydefault}. It is in fact page style
8370 % \texttt{fancy} with all the defaults embedded, including the relevant
8371 % definitions of \cs{chaptermark} and \Cmd{[sub]sectionmark}. This is in
8372 % contrast with page style \texttt{fancy} that gets all its settings
8373 % from the environment. It is defined with \cs{fancypagestyle*}.
8374 % \begin{macrocode}
8375 \fancypagestyle*{fancydefault}{\f@nch@initialise}
8376 % \end{macrocode}
8377 % \end{macro}
8378 %
8379 % \begin{macro}{\fancyhdrbox}
8380 % \changes{fancyhdr v5.0}{2024/12/16}{Macro \cs{fancyhdrbox} added}
8381 % \cs{fancyhdrbox}\oarg{alignment}\oarg{width}\marg{lines separated by \cmd{\\}}\\[1ex]
8382 % This command creates a \cs{halign} inside a vertical box (\cs{vbox} or \cs{vtop}).
8383 %
8384 % We need some variables, but these don't have to be declared. They are
8385 % characterised by \texttt{@@} in their name.
8386 % \begin{description}[leftmargin=4cm]
8387 % \item[\cs{f@nchdrbox@@v}] -- vertical alignment (\texttt{T},
8388 % \texttt{t}, \texttt{c}, \texttt{b}, \texttt{B})
8389 % \item[\cs{f@nchdrbox@@h}] -- horizontal alignment (\texttt{l}, \texttt{c}, \texttt{r})
8390 % \item[\cs{f@nchdrbox@@pre}] -- code to be inserted before the
8391 % first row, a `topstrut' or \Cmd{vspace\{0pt\}}
8392 % \item[\cs{f@nchdrbox@@postx}] -- code to be executed at the end of the
8393 % last row, possibly a `botstrut'
8394 % \item[\cs{f@nchdrbox@@posty}] -- code to be executed after the
8395 % \cs{halign}, possibly a \Cmd{vspace\{0pt\}}
8396 % \item[\cs{f@nchdrbox@@crstrut}] -- a `strut' to be inserted at
8397 % each \cmd{\\} in the \cs{halign}
8398 % \item[\cs{f@nchdrbox@@halignto}] -- This is either empty, if no
8399 % \meta{width} argument is given,
8400 % or `\texttt{to~\meta{width}}' if
8401 % it is given.
8402 % \end{description}
8403 % A `strut' is a \TeX{} construct to keep the baselines of the lines in
8404 % a text on a fixed distance. It normally is an invisible rule of \texttt{width}
8405 % \texttt{0pt}, \texttt{height} \texttt{0.7\cs{baselineskip}} and \texttt{depth}
8406 % \texttt{0.3\cs{baselineskip}}. Therefore the struts are
8407 % dependent of the font of the text. But for the \cs{fancyhdrbox} alignments
8408 % \texttt{T} and \texttt{B} we need special `topstrut' (which only has
8409 % the \texttt{height}) part, or a `botstrut' (which only has the
8410 % \texttt{depth}) part. For example with the \texttt{T} alignment, there
8411 % should be no strut on the first line, because then we don't want the extra
8412 % space above this line. We use instead a \cmd{vspace\{0pt\}}.
8413 % But we need the \texttt{depth} part
8414 % because we want the extra space below the line. Similar for the
8415 % \texttt{B} alignment, but then in the opposite direction.
8416 % \begin{macro}[internal]{\f@nchdrbox@topstrut, \f@nchdrbox@botstrut}
8417 % \begin{macrocode}
8418 \def\f@nchdrbox@topstrut{\vrule height\ht\strutbox width\z@}
8419 \def\f@nchdrbox@botstrut{\vrule depth\dp\strutbox width\z@}
8420 % \end{macrocode}
8421 % \end{macro}
8422 % \begin{macro}[internal]{\f@nchdrbox@nostrut}
8423 % At each \cmd{\\} \cs{f@nchdrbox@@crstrut} will be inserted. It will be a normal \cs{strut}, except
8424 % in the first row when the alignment is \texttt{T}; then it will be a
8425 % `botstrut', and moreover, we will insert a \Cmd{vspace\{0pt\}} at the
8426 % top of the box. The macro \cs{f@nchdrbox@nostrut} will set this up.
8427 % The assignment to \cs{f@nchdrbox@@crstrut} will be local to the
8428 % \cs{halign} cell, so after the \cmd{\\} it will be reset to the default.
8429 % \begin{macrocode}
8430 \def\f@nchdrbox@nostrut{\noalign{\vspace{0pt}}\let\f@nchdrbox@@crstrut\f@nchdrbox@botstrut}
8431 % \end{macrocode}
8432 % \end{macro}
8433 % ^^A\begin{macro}{\fancyhdrbox}
8434 % Now we start the only user command in the part: \cs{fancyhdrbox}.
8435 % The code is run in a group so that changes to variables are local.
8436 % This is necessary in case we use nested \cs{fancyhdrbox}es.
8437 %
8438 % First we set the variables \cs{f@nchdrbox@@pre},
8439 % \cs{f@nchdrbox@topstrut}, \cs{f@nchdrbox@@posty}, and
8440 % \cs{f@nchdrbox@@crstrut} to their default values. Then we test if
8441 % the second optional argument (\meta{width}) was given, and if so,
8442 % record this in \cs{f@nchdrbox@@halignto}. We put the \meta{width}
8443 % value in a length variable with \cs{setlength} so that we can
8444 % support \pkg{calc}-style values.
8445 %
8446 % And then we check if the first optional argument \meta{alignment} is
8447 % empty. In that case we use \texttt{cl} instead.
8448 % \begin{macrocode}
8449 \NewDocumentCommand{\fancyhdrbox}{ O{cl} o m }{%
8450 \begingroup
8451 \let\f@nchdrbox@@pre\f@nchdrbox@topstrut
8452 \let\f@nchdrbox@@postx\f@nchdrbox@botstrut
8453 \let\f@nchdrbox@@posty\relax
8454 \let\f@nchdrbox@@crstrut\strut
8455 \IfNoValueTF{#2}%
8456 {\let\f@nchdrbox@@halignto\@empty}%
8457 {\setlength\@tempdima{#2}%
8458 \def\f@nchdrbox@@halignto{to\@tempdima}}%
8459 \def\@tempa{#1}%
8460 \ifx\@tempa\@empty
8461 \f@nchdrbox@align cl\@nil{#3}%
8462 \else
8463 \f@nchdrbox@align #1\@nil{#3}%
8464 \fi
8465 \endgroup
8466 }
8467 % \end{macrocode}
8468 % ^^A\end{macro}
8469 %
8470 % \begin{macro}[internal]{\f@nchdrbox@cr, \@f@nchdrbox@xcr,
8471 % \@f@nchdrbox@argc, \@f@nchdrbox@xargc, \@f@nchdrbox@yargc}
8472 % This is the definition for \cmd{\\} inside \cs{fancyhdrbox},
8473 % \cmd{\\*} does nothing special here, but we accept it anyway.
8474 % The code is mostly copied from the \env{tabular} code from the
8475 % \LaTeX{} kernel, but simplified, and the names of the macros are
8476 % changed so that we don't rely on internals in the \LaTeX{} kernel that
8477 % may change. The trick with the \verb|\ifnum0=`|
8478 % allows to get unbalanced braces in a macro.
8479 % \begin{macrocode}
8480 \protected\def\f@nchdrbox@cr{%
8481 {\ifnum0=`}\fi\@ifstar\@f@nchdrbox@xcr\@f@nchdrbox@xcr}
8482
8483 \def\@f@nchdrbox@xcr{%
8484 \unskip\f@nchdrbox@@crstrut
8485 \@ifnextchar[\@f@nchdrbox@argc{\ifnum0=`{\fi}\cr}%
8486 }
8487
8488 \def\@f@nchdrbox@argc[#1]{%
8489 \ifnum0=`{\fi}%
8490 \ifdim #1>\z@
8491 \unskip\@f@nchdrbox@xargc{#1}%
8492 \else
8493 \@f@nchdrbox@yargc{#1}%
8494 \fi}
8495
8496 \def\@f@nchdrbox@xargc#1{\@tempdima #1\advance\@tempdima \dp \strutbox
8497 \vrule \@height\z@ \@depth\@tempdima \@width\z@ \cr}
8498
8499 \def\@f@nchdrbox@yargc#1{\cr\noalign{\setlength\@tempdima{#1}\vskip\@tempdima}}
8500 % \end{macrocode}
8501 % \end{macro}
8502 % \begin{macro}[internal]{\f@nchdrbox@T, \f@nchdrbox@t, \f@nchdrbox@c, \f@nchdrbox@b, \f@nchdrbox@B}
8503 % Processing for the vertical alignment options \texttt{T},
8504 % \texttt{t}, \texttt{c}, \texttt{b}, \texttt{B}.
8505 %
8506 % \begin{description}
8507 % \item[\texttt{T}] set \cs{f@nchdrbox@@pre} to `nostrut' and execute
8508 % the \texttt{t} code
8509 % \item[\texttt{t}] set vertical alignment to \texttt{t} and
8510 % horizontal to \texttt{l}
8511 % \item[\texttt{c}] set both vertical and horizontal alignment to \texttt{c}
8512 % \item[\texttt{b}] set vertical alignment to \texttt{b} and
8513 % horizontal to \texttt{l}
8514 % \item[\texttt{B}] set \cs{f@nchdrbox@@postx} to do nothing and
8515 % \cs{f@nchdrbox@@posty} to \Cmd{vspace\{0pt\}} and
8516 % execute the \texttt{b} code
8517 % \end{description}
8518 % The horizontal alignments are defaults, they may be changed by
8519 % processing the horizontal argument, if present.
8520 % \begin{macrocode}
8521 \def\f@nchdrbox@T{\let\f@nchdrbox@@pre\f@nchdrbox@nostrut
8522 \f@nchdrbox@t}
8523 \def\f@nchdrbox@t{\def\f@nchdrbox@@v{t}\def\f@nchdrbox@@h{l}}
8524 \def\f@nchdrbox@c{\def\f@nchdrbox@@v{c}\def\f@nchdrbox@@h{c}}
8525 \def\f@nchdrbox@b{\def\f@nchdrbox@@v{b}\def\f@nchdrbox@@h{l}}
8526 \def\f@nchdrbox@B{\let\f@nchdrbox@@postx\relax
8527 \def\f@nchdrbox@@posty{\vspace{0pt}}%
8528 \f@nchdrbox@b}
8529 % \end{macrocode}
8530 % \end{macro}
8531 %
8532 % \begin{macro}[internal]{\f@nchdrbox@align}
8533 % \changes{fancyhdr v5.2}{2025/01/23}{Check for legal alignment
8534 % argument added.}
8535 % \cs{f@nchdrbox@align}\marg{vert}\marg{hor}\texttt{\cs{@nil}}\marg{lines}\\[1ex]
8536 % The internal processing for the \cs{halign} in a vertical box.\\
8537 % ALGORITHM \cs{f@nchdrbox@align}:\\
8538 % (v = vertical position; h = horizontal position)\\
8539 % \textbf{IF} \texttt{\#1} in \texttt{\{T,t,c,b,B\}} \\
8540 % \textbf{THEN} v := \texttt{\#1}; h := (\textbf{if} \texttt{\#1} == \texttt{c} \textbf{then} \texttt{c} \textbf{else} \texttt{l} \textbf{fi}) (coded in \cs{f@nchdrbox@\meta{\#1}})\\
8541 % \hspace*{1em} (The h value is the default in case \texttt{\#2} is empty)\\
8542 % \hspace*{1em} \textbf{if} \texttt{\#2} is not empty \textbf{then} h := \texttt{\#2} \textbf{fi}\\
8543 % \textbf{ELSE} (\texttt{\#1} not in \texttt{\{T,t,c,b,B\}} -- it must be
8544 % a horizontal alignment)\\
8545 % \hspace*{1em} v := \texttt{c}\\
8546 % \hspace*{1em} h := \texttt{\#1}\\
8547 % \textbf{FI}\\
8548 % \textbf{if} h not in \texttt{\{l,c,r\}} \textbf{then} ERROR \textbf{fi}\\
8549 % Set the \cs{halign} in a \cs{vtop} (for \texttt{T/t} alignment) or
8550 % \cs{vbox} (for others). This box is put into \cs{box0} because we have
8551 % to change it for the vertical alignment \texttt{c}. For the others it
8552 % isn't necessary, but it just makes the code easier to do it anyway.
8553 % We also insert the \cs{f@nchdrbox@@pre},
8554 % \cs{f@nchdrbox@@postx} and \cs{f@nchdrbox@@posty} variables in the
8555 % proper places. The rest of the code is roughly based on the
8556 % \env{tabular} code in the \LaTeX{} kernel.
8557 % \begin{macrocode}
8558 \long\def\f@nchdrbox@align#1#2\@nil#3{%
8559 \f@nch@ifin{#1}{TtcbB}{%
8560 \@nameuse{f@nchdrbox@#1}%
8561 \def\@tempa{#2}%
8562 \ifx\@tempa\@empty\else \def\f@nchdrbox@@h{#2}\fi
8563 }%
8564 {\def\f@nchdrbox@@v{c}\def\f@nchdrbox@@h{#1}}%
8565 \expandafter\f@nch@ifin\expandafter{\f@nchdrbox@@h}{lcr}{}%
8566 {\PackageError{fancyhdr}{\string\fancyhdrbox: Illegal char `\f@nchdrbox@@h'\MessageBreak
8567 in alignment argument}{}}%
8568 \let\\\f@nchdrbox@cr
8569 \setbox0=\if \f@nchdrbox@@v t\vtop
8570 \else \vbox
8571 \fi
8572 {%
8573 \ialign \f@nchdrbox@@halignto
8574 \bgroup \relax
8575 {\if \f@nchdrbox@@h l\hskip 1sp\else \hfil \fi
8576 \ignorespaces ##\unskip
8577 \if\f@nchdrbox@@h r\else \hfil \fi
8578 }%
8579 \tabskip\z@skip \cr
8580 \f@nchdrbox@@pre
8581 #3\unskip \f@nchdrbox@@postx
8582 \crcr
8583 \egroup
8584 \f@nchdrbox@@posty
8585 }%
8586 % \end{macrocode}
8587 % If the vertical alignment is \texttt{c}, we calculate the
8588 % total height + depth of the resulting \cs{box0} and then set
8589 % the depth and height of this box each to half of this value. This way
8590 % the box will be vertically centered. We don't use \cs{vcenter} for
8591 % this, because it centers the box on the \emph{math axis}, which
8592 % doesn't make sense here, and sometimes gives a different vertical
8593 % positioning (not exactly centered).
8594 % \begin{macrocode}
8595 \if\f@nchdrbox@@v c\@tempdima=\ht0\advance\@tempdima\dp0%
8596 \ht0=0.5\@tempdima\dp0=0.5\@tempdima\fi
8597 % \end{macrocode}
8598 % Finally we put the box in horizontal mode in the running text.
8599 % \begin{macrocode}
8600 \leavevmode \box0
8601 }
8602 % \end{macrocode}
8603 % \end{macro}
8604 %
8605 % \end{macro}
8606 %
8607 % \smallskip
8608 % \changes{fancyhdr v4.1}{202/09/16}{Support for class \pkg{newlfm}.}
8609 % The (really outdated) document class \pkg{newlfm} uses some internal
8610 % \pkg{fancyhdr} commands that have gotten new names. So here we check if
8611 % that class is loaded and then we redefine the affected \pkg{newlfm} macros.
8612 % We have to do some of the redefinitions in \cs{AtBeginDocument}, as
8613 % \pkg{fancyhdr} is loaded before the affected macros are defined. Also
8614 % the macro \cs{@zfancyhead} is only called once, with wrong (outdated)
8615 % parameters, so instead of changing the call of the macro, we substitute the
8616 % right parameters inline.
8617 % \begin{macrocode}
8618 \@ifclassloaded{newlfm}
8619 {
8620 \let\ps@@empty\f@nch@ps@empty
8621 \AtBeginDocument{%
8622 \renewcommand{\@zfancyhead}[5]{\relax\hbox to\headwidth{\f@nch@reset
8623 \@zfancyvbox\headheight{\hbox
8624 {\rlap{\parbox[b]{\headwidth}{\raggedright\f@nch@olh}}\hfill
8625 \parbox[b]{\headwidth}{\centering\f@nch@olh}\hfill
8626 \llap{\parbox[b]{\headwidth}{\raggedleft\f@nch@orh}}}%
8627 \zheadrule}}\relax}%
8628 }
8629 }
8630 {}
8631 % \end{macrocode}
8632 %</fancyhdr>
8633 %
8634 % \section{\pkg{extramarks.sty}}
8635 % \setlength\parindent{0pt}
8636 %<*extramarks>
8637 %
8638 % This package gives you extra marks, that you can define, set and use
8639 % in your page headers and footers. It is based on the new \LaTeX{}
8640 % marks mechanism as introduced in the 2022/06/01 \LaTeX{} release. If
8641 % your \LaTeX{} implementation is older it will fallback to
8642 % \pkg{extramarks} version 4.
8643 %
8644 % \changes{extramarks v5.0}{2024/05/14}{New implementation with
8645 % independent marks, and fallback option to earlier version 4.}
8646 % Provide a rollback to earlier version.
8647 % \changes{extramarks v5.2}{2025/01/15}{Assume \cs{DeclareRelease} is
8648 % present (\LaTeX{} version at lease 2018-04-01).}
8649 % \begin{macrocode}
8650 \DeclareRelease{v4}{2024/11/30}{extramarks-v4.sty}
8651 \DeclareCurrentRelease{v5}{2025/02/07}
8652 \@ifundefined{NewMarkClass}
8653 {\PackageWarningNoLine{extramarks}{%
8654 **************************************************\MessageBreak
8655 Your LaTeX installation is too old for extramarks version 5.\MessageBreak
8656 We will fallback to extramarks version 4 now.\MessageBreak
8657 Please note that some commands will not be available,\MessageBreak
8658 and that the functionality may be slightly different.\MessageBreak
8659 You are advised to update your LaTeX installation.\MessageBreak
8660 **************************************************}
8661 \RequirePackage{extramarks-v4}\endinput}{}
8662 % \end{macrocode}
8663 % \changes{extramarks v5.0}{2024/11/30}{Check if \pkg{extramarks}
8664 % version 5 is not used with a too old version of \pkg{multicol}.}
8665 % \changes{extramarks v5.1}{2025/01/04}{Bug fix: use \cs{IfPackageLoadedT}.}
8666 % We also do a sanity check for the package \PKGindex{multicol}\pkg{multicol}. If it is
8667 % too old it will not work correctly with the new \pkg{extramarks}. In that
8668 % case \pkg{extramarks-v4} should be used instead. So in that case
8669 % we give a warning and then load package \pkg{extramarks-v4}.
8670 % First \cs{extramarks} must be made undefined, otherwise loading
8671 % \pkg{extramarks-v4} will give an error.
8672 % \begin{macrocode}
8673 \AtBeginDocument{%
8674 \IfPackageLoadedT{multicol}%
8675 {\IfPackageAtLeastF{multicol}{2024-11-21}{%
8676 \PackageWarningNoLine{extramarks}{%
8677 You are using package `extramarks' with a version\MessageBreak
8678 of `multicol' that is too old. The new version\MessageBreak
8679 of `multicol' will be released on June 1, 2025.\MessageBreak
8680 We will fallback to extramarks version 4 now.}%
8681 \let\extramarks\undefined
8682 \RequirePackage{extramarks-v4}
8683 }%
8684 }%
8685 }
8686 % \end{macrocode}
8687 %
8688 % \changes{extramarks v1.99e}{2000/10/11}{Added a few \% marks to get rid
8689 % of unwanted spaces, and \cs{endinput}. \\
8690 % Added LPPL license clause.}
8691 % \changes{extramarks v2.0beta}{2002/03/12}{Adapted for the new
8692 % implementation of marks in \LaTeX{} to solve bug latex/3203. \\
8693 % Added symmetric commands \cs{firstrightmark}, \cs{lastleftmark}, \cs{firstleftxmark},
8694 % \cs{firstrightxmark}, \cs{lastrightxmark}, \cs{lastleftxmark}, \cs{topleftxmark} and
8695 % \cs{toprightxmark}.}
8696 % \changes{extramarks v2.0x=fancyhdr v 2.0}{2004/03/03}{version 2.0 Release.}
8697 % \changes{extramarks v2.1}{2016/08/27}{Added a \cs{ProvidesPackage} line.\\
8698 % Updated contact information.}
8699 % \changes{extramarks v3.9}{2016/10/12}{Unify version number with \pkg{fancyhdr.sty}.}
8700 %
8701 % \begin{macro}[internal]{\@mkboth}
8702 % Initialization of \cs{@mkboth}, so that it will pick up changes to
8703 % \cs{markboth}
8704 % \changes{extramarks v4.0.3}{2022/05/18}{Initialize definition of
8705 % \cs{@mkboth} to \cs{def}\Cmd{@mkboth\{\cs{protect}\cs{markboth}\}}
8706 % if it wasn't equal to \cs{@gobbletwo} so that it will pick up
8707 % changes to \cs{markboth}}
8708 % \begin{macrocode}
8709 \ifx\@mkboth\@gobbletwo\else\def\@mkboth{\protect\markboth}\fi
8710 % \end{macrocode}
8711 % \end{macro}
8712 %
8713 % \begin{variable}{extramarks-left, extramarks-right}
8714 % \begin{syntax}
8715 % \texttt{extramarks-left}\\
8716 % \texttt{extramarks-right}
8717 % \end{syntax}
8718 % We need two mark classes. We call them \texttt{extramarks-left} and \texttt{extramarks-right}.
8719 % \begin{macrocode}
8720 \NewMarkClass{extramarks-left}
8721 \NewMarkClass{extramarks-right}
8722 % \end{macrocode}
8723 % \end{variable}
8724 %
8725 % \begin{macro}{\extramarks}
8726 % This command is used to define the extra marks.
8727 % \begin{macrocode}
8728 \newcommand\extramarks[2]{%
8729 \InsertMark{extramarks-left}{#1}%
8730 \InsertMark{extramarks-right}{#2}}
8731 % \end{macrocode}
8732 % \end{macro}
8733 %
8734 % \begin{macro}{\extramarksleft,\extramarksright}
8735 % These commands can be used to set the two marks independently. These
8736 % are only available in \pkg{extramarks} version 4.5 or later.
8737 % \begin{macrocode}
8738 \newcommand\extramarksleft[1]{%
8739 \InsertMark{extramarks-left}{#1}}
8740 \newcommand\extramarksright[1]{%
8741 \InsertMark{extramarks-right}{#1}}
8742 % \end{macrocode}
8743 % \end{macro}
8744 %
8745 % \begin{macro}{\firstleftmark}
8746 % \begin{macro}{\lastrightmark}
8747 % \begin{macro}{\firstrightmark}
8748 % \begin{macro}{\lastleftmark}
8749 % The new marks to be used in the headers and/or footers (based on the standard marks info).
8750 % \begin{macrocode}
8751 \newcommand\firstleftmark{\FirstMark{2e-left}}
8752 \newcommand\lastrightmark{\LastMark{2e-right}}
8753 % \end{macrocode}
8754 % We first define the following commands with \cs{newcommand} to detect
8755 % possible name clashes; then we redefine them with \cs{let}.
8756 % \begin{macrocode}
8757 \newcommand\firstrightmark{\rightmark}
8758 \let\firstrightmark \rightmark
8759 \newcommand\lastleftmark{\leftmark}
8760 \let\lastleftmark \leftmark
8761 % \end{macrocode}
8762 % \end{macro}
8763 % \end{macro}
8764 % \end{macro}
8765 % \end{macro}
8766 %
8767 % \begin{macro}{\firstleftxmark}
8768 % \begin{macro}{\firstrightxmark}
8769 % \begin{macro}{\topleftxmark}
8770 % \begin{macro}{\toprightxmark}
8771 % \begin{macro}{\lastleftxmark}
8772 % \begin{macro}{\lastrightxmark}
8773 % \begin{macro}{\firstxmark}
8774 % \begin{macro}{\lastxmark}
8775 % \begin{macro}{\topxmark}
8776 % The new extra marks.
8777 % \begin{macrocode}
8778 \newcommand\firstleftxmark{\FirstMark{extramarks-left}}
8779 \newcommand\lastrightxmark{\LastMark{extramarks-right}}
8780 \newcommand\firstrightxmark{\FirstMark{extramarks-right}}
8781 \newcommand\topleftxmark{\TopMark{extramarks-left}}
8782 \newcommand\toprightxmark{\TopMark{extramarks-right}}
8783 \newcommand\lastleftxmark{\LastMark{extramarks-left}}
8784 % \end{macrocode}
8785 % We first define the following commands with \cs{newcommand} to detect
8786 % possible name clashes; then we redefine them with \cs{let}.
8787 % \begin{macrocode}
8788 \newcommand\firstxmark{\firstleftxmark}
8789 \let\firstxmark\firstleftxmark
8790 \newcommand\lastxmark{\lastrightxmark}
8791 \let\lastxmark\lastrightxmark
8792 \newcommand\topxmark{\topleftxmark}
8793 \let\topxmark\topleftxmark
8794 % \end{macrocode}
8795 % \end{macro}
8796 % \end{macro}
8797 % \end{macro}
8798 % \end{macro}
8799 % \end{macro}
8800 % \end{macro}
8801 % \end{macro}
8802 % \end{macro}
8803 % \end{macro}
8804 %
8805 %</extramarks>
8806 %
8807 % \section{\pkg{extramarks-v4.sty}}
8808 %
8809 %<*extramarks-v4>
8810 %
8811 % \changes{extramarks v1.99e}{2000/10/11}{Added a few \% marks to get rid
8812 % of unwanted spaces, and \cs{endinput}. \\
8813 % Added LPPL license clause.}
8814 % \changes{extramarks v2.0beta}{2002/03/12}{Adapted for the new
8815 % implementation of marks in \LaTeX{} to solve bug latex/3203. \\
8816 % Added symmetric commands \cs{firstrightmark}, \cs{lastleftmark}, \cs{firstleftxmark},
8817 % \cs{firstrightxmark}, \cs{lastrightxmark}, \cs{lastleftxmark}, \cs{topleftxmark} and
8818 % \cs{toprightxmark}.}
8819 % \changes{extramarks v2.0x=fancyhdr v 2.0}{2004/03/03}{version 2.0 Release.}
8820 % \changes{extramarks v2.1}{2016/08/27}{Added a \cs{ProvidesPackage} line.\\
8821 % Updated contact information.}
8822 % \changes{extramarks v3.9}{2016/10/12}{Unify version number with \pkg{fancyhdr.sty}.}
8823 %
8824 % \changes{extramarks v3.9a}{2017/06/30}{Restore \cs{newtoks}\cs{@temptokenb}}
8825 % \changes{extramarks v5.0}{2021/02/16}{Make \cs{newtoks}\cs{@temptokenb} conditional}
8826 % \begin{variable}[internal]{\@temptokenb}
8827 % A token register to store some marks information
8828 % \begin{macrocode}
8829 \ifx\@temptokenb\undefined \csname newtoks\endcsname\@temptokenb\fi
8830 % \end{macrocode}
8831 % \end{variable}
8832 %
8833 % \begin{macro}[internal]{\unrestored@protected@xdef}
8834 % Define this macro just in case it isn't defined (should be part of \LaTeX).
8835 % \begin{macrocode}
8836 \providecommand\unrestored@protected@xdef{%
8837 \let\protect\@unexpandable@protect \xdef}
8838 % \end{macrocode}
8839 % \end{macro}
8840 %
8841 % \begin{macro}[internal]{\markboth}
8842 % Our own definition of \cs{markboth}, mainly because \cs{@markboth}
8843 % gets more parameters.
8844 % \changes{extramarks v4.4}{2024/11/20}{Add setting the new style marks
8845 % for \cs{leftmark} (\texttt{2e-left}) and \cs{rightmark}
8846 % (\texttt{2e-right} and \texttt{2e-right-nonempty}). We do this only if
8847 % the new marks are defined in the \LaTeX{} kernel.}
8848 % First the definition for modern \LaTeX{} distributions.
8849 % \begin{macrocode}
8850 \ifdefined\ExplSyntaxOn
8851 \ExplSyntaxOn
8852 \DeclareRobustCommand*\markboth[2]{%
8853 \begingroup
8854 \let\label\relax \let\index\relax \let\glossary\relax
8855 \expandafter\@markboth\@themark{#1}{#2}%
8856 \@temptokena \expandafter{\@themark}%
8857 \ifdefined\mark_insert:nn
8858 % 3 new lines to set the new marks
8859 \mark_insert:nn{2e-left}{#1}
8860 \mark_insert:nn{2e-right}{#2}
8861 \tl_if_empty:nF{#2}{ \mark_insert:nn{2e-right-nonempty}{#2} }
8862 \fi
8863 \mark{\the\@temptokena}%
8864 \endgroup
8865 \if@nobreak\ifvmode\nobreak\fi\fi}
8866 \ExplSyntaxOff
8867 % \end{macrocode}
8868 % If we are with a pre-\LaTeX3 kernel, we use the definition from an
8869 % older version of \pkg{extramarks}.
8870 % \begin{macrocode}
8871 \else
8872 \def\markboth#1#2{%
8873 \begingroup
8874 \let\label\relax \let\index\relax \let\glossary\relax
8875 \expandafter\@markboth\@themark{#1}{#2}%
8876 \@temptokena \expandafter{\@themark}%
8877 \mark{\the\@temptokena}%
8878 \endgroup
8879 \if@nobreak\ifvmode\nobreak\fi\fi}
8880 \fi
8881 % \end{macrocode}
8882 % \end{macro}
8883 % \begin{macro}[internal]{\@mkboth}
8884 % Initialization of \cs{@mkboth}, so that it will pick up changes to
8885 % \cs{markboth}
8886 % \changes{extramarks v4.0.3}{2022/05/18}{Initialize definition of
8887 % \cs{@mkboth} to \cs{def}\Cmd{@mkboth\{\cs{protect}\cs{markboth}\}}
8888 % if it wasn't equal to \cs{@gobbletwo} so that it will pick up
8889 % changes to \cs{markboth}}
8890 % \begin{macrocode}
8891 \ifx\@mkboth\@gobbletwo\else\def\@mkboth{\protect\markboth}\fi
8892 % \end{macrocode}
8893 % \end{macro}
8894 % \begin{macro}[internal]{\markright}
8895 % We use the standard definition of \cs{markright}. No use to duplicate here.
8896 % \end{macro}
8897 %
8898 % \begin{macro}[internal]{\@markboth}
8899 % Note: put \texttt{\#3\#4} in toks register.
8900 % \begin{macrocode}
8901 \def\@markboth#1#2#3#4#5#6{\@temptokena{{#3}{#4}}%
8902 \unrestored@protected@xdef\@themark{{#5}{#6}\the\@temptokena}}
8903 % \end{macrocode}
8904 % \end{macro}
8905 %
8906 % \begin{macro}[internal]{\@markright}
8907 % Note: put \texttt{\#1} and \texttt{\#3\#4} in toks registers.
8908 % Maybe I can get rid of the extra \cs{@temptokenb} by doing the expansion
8909 % of \texttt{\#5} to a temp separately. But then, nowadays registers
8910 % are plenty.
8911 % \begin{macrocode}
8912 \def\@markright#1#2#3#4#5{\@temptokena{#1}\@temptokenb{{#3}{#4}}%
8913 \unrestored@protected@xdef\@themark{{\the\@temptokena}{#5}\the\@temptokenb}}
8914 % \end{macrocode}
8915 % \end{macro}
8916
8917 % \begin{macro}[internal]{\@leftmark}
8918 % \begin{macro}[internal]{\@rightmark}
8919 % Internal macros to get the standard marks.
8920 % \begin{macrocode}
8921 \def\@leftmark#1#2#3#4{#1}
8922 \def\@rightmark#1#2#3#4{#2}
8923 % \end{macrocode}
8924 % \end{macro}
8925 % \end{macro}
8926 % \changes{extramarks-v4 v4.5}{2024/11/28}{Don't redefine \cs{leftmark}
8927 % and \cs{rightmark} in \LaTeX{} kernel 2025-06-01 and later.}
8928 %
8929 % \begin{macro}[internal]{\leftmark}
8930 % \begin{macro}[internal]{\rightmark}
8931 % \begin{macro}{\firstleftmark}
8932 % \begin{macro}{\lastrightmark}
8933 % \begin{macro}{\firstrightmark}
8934 % \begin{macro}{\lastleftmark}
8935 % The standard marks + the new ones (based on the standard marks info).
8936 % We provide \cs{IfFormatAtLeastTF} in case we have a rather old \LaTeX{}
8937 % format (in which case the test will always be false).
8938 % If the \LaTeX{} format is 2025-06-01 or later, \cs{leftmark} and
8939 % \cs{rightmark} have definitions based upon the new marks, so we should
8940 % not redefine these even in the \pkg{extramarks-v4} mode.
8941 % \begin{macrocode}
8942 \providecommand\IfFormatAtLeastTF{\@ifl@t@r\fmtversion}
8943 \IfFormatAtLeastTF{2025-06-01}{}{%
8944 \def\leftmark{\expandafter\@leftmark
8945 \botmark\@empty\@empty\@empty\@empty}
8946 \def\rightmark{\expandafter\@rightmark
8947 \firstmark\@empty\@empty\@empty\@empty}
8948 }
8949 \def\firstleftmark{\expandafter\@leftmark
8950 \firstmark\@empty\@empty\@empty\@empty}
8951 \def\lastrightmark{\expandafter\@rightmark
8952 \botmark\@empty\@empty\@empty\@empty}
8953 \let\firstrightmark \rightmark
8954 \let\lastleftmark \leftmark
8955 % \end{macrocode}
8956 % \end{macro}
8957 % \end{macro}
8958 % \end{macro}
8959 % \end{macro}
8960 % \end{macro}
8961 % \end{macro}
8962
8963 % \begin{macro}[internal]{\@themark}
8964 % This is where the marks information is stored.
8965 % \begin{macrocode}
8966 \def\@themark{{}{}{}{}}
8967 % \end{macrocode}
8968 % \end{macro}
8969
8970 % \begin{macro}{\extramarks}
8971 % This command is used to define the extra marks.
8972 % \begin{macrocode}
8973 \newcommand\extramarks[2]{%
8974 \begingroup
8975 \let\label\relax \let\index\relax \let\glossary\relax
8976 \expandafter\@markextra\@themark{#1}{#2}%
8977 \@temptokena \expandafter{\@themark}%
8978 \mark{\the\@temptokena}%
8979 \endgroup
8980 \if@nobreak\ifvmode\nobreak\fi\fi}
8981 % \end{macrocode}
8982 % \end{macro}
8983 %
8984 % \begin{macro}[internal]{\@markextra}
8985 % Internal macro to store the extra marks in the marks storage.\\
8986 % Note: Put \texttt{\#1\#2} in toks register.
8987 % \begin{macrocode}
8988 \def\@markextra#1#2#3#4#5#6{\@temptokena {{#1}{#2}}%
8989 \unrestored@protected@xdef\@themark{\the\@temptokena{#5}{#6}}}
8990 % \end{macrocode}
8991 % \end{macro}
8992 % \changes{extramarks-v4 v4.5}{2024/11/30}{Add commands
8993 % \cs{extramarksleft} and \cs{extramarksright} for compatibility with
8994 % \pkg{extramarks} version 5.}
8995 % \begin{macro}{\extramarksleft}
8996 % This command is used to define the left extra mark.
8997 % As this is not independent from the other marks, it is not perfect.
8998 % \begin{macrocode}
8999 \def\extramarksleft#1{%
9000 \begingroup
9001 \let\label\relax \let\index\relax \let\glossary\relax
9002 \expandafter\@markextraleft\@themark{#1}%
9003 \@temptokena \expandafter{\@themark}%
9004 \mark{\the\@temptokena}%
9005 \endgroup
9006 \if@nobreak\ifvmode\nobreak\fi\fi}
9007 % \end{macrocode}
9008 % \end{macro}
9009 % \begin{macro}[internal]{\@extramarksleft}
9010 % Internal macro to store the left mark in the marks storage.\\
9011 % Note: Put \texttt{\#1\#2} and \texttt{\#4}in toks registers.
9012 % \begin{macrocode}
9013 \def\@markextraleft#1#2#3#4#5{\@temptokena {{#1}{#2}}%
9014 \@temptokenb {{#4}}%
9015 \unrestored@protected@xdef\@themark{\the\@temptokena{#5}\the\@temptokenb}}
9016 % \end{macrocode}
9017 % \end{macro}
9018 % \begin{macro}{\extramarksright}
9019 % This command is used to define the right extra mark.
9020 % As this is not independent from the other marks, it is not perfect.
9021 % \begin{macrocode}
9022 \def\extramarksright#1{%
9023 \begingroup
9024 \let\label\relax \let\index\relax \let\glossary\relax
9025 \expandafter\@markextraright\@themark{#1}%
9026 \@temptokena \expandafter{\@themark}%
9027 \mark{\the\@temptokena}%
9028 \endgroup
9029 \if@nobreak\ifvmode\nobreak\fi\fi}
9030 % \end{macrocode}
9031 % \end{macro}
9032 % \begin{macro}[internal]{\@extramarksright}
9033 % Internal macro to store the right mark in the marks storage.\\
9034 % Note: Put \texttt{\#1\#2\#3} in toks register.
9035 % \begin{macrocode}
9036 \def\@markextraright#1#2#3#4#5{\@temptokena {{#1}{#2}{#3}}%
9037 \unrestored@protected@xdef\@themark{\the\@temptokena{#5}}}
9038 % \end{macrocode}
9039 % \end{macro}
9040 %
9041 % \begin{macro}{\firstleftxmark}
9042 % \begin{macro}{\firstrightxmark}
9043 % \begin{macro}{\topleftxmark}
9044 % \begin{macro}{\toprightxmark}
9045 % \begin{macro}{\lastleftxmark}
9046 % \begin{macro}{\lastrightxmark}
9047 % \begin{macro}{\firstxmark}
9048 % \begin{macro}{\lastxmark}
9049 % \begin{macro}{\topxmark}
9050 % The new extra marks.
9051 % \begin{macrocode}
9052 \def\firstleftxmark{\expandafter\@leftxmark
9053 \firstmark\@empty\@empty\@empty\@empty}
9054 \def\firstrightxmark{\expandafter\@rightxmark
9055 \firstmark\@empty\@empty\@empty\@empty}
9056 \def\topleftxmark{\expandafter\@leftxmark
9057 \topmark\@empty\@empty\@empty\@empty}
9058 \def\toprightxmark{\expandafter\@rightxmark
9059 \topmark\@empty\@empty\@empty\@empty}
9060 \def\lastleftxmark{\expandafter\@leftxmark
9061 \botmark\@empty\@empty\@empty\@empty}
9062 \def\lastrightxmark{\expandafter\@rightxmark
9063 \botmark\@empty\@empty\@empty\@empty}
9064 \let\firstxmark\firstleftxmark
9065 \let\lastxmark\lastrightxmark
9066 \let\topxmark\topleftxmark
9067 % \end{macrocode}
9068 % \end{macro}
9069 % \end{macro}
9070 % \end{macro}
9071 % \end{macro}
9072 % \end{macro}
9073 % \end{macro}
9074 % \end{macro}
9075 % \end{macro}
9076 % \end{macro}
9077 %
9078 % \begin{macro}[internal]{\@tleftxmark}
9079 % \begin{macro}[internal]{\@rightxmark}
9080 % Internal macros to extract the extra marks out of the marks storage.
9081 % \begin{macrocode}
9082 \def\@leftxmark#1#2#3#4{#3}
9083 \def\@rightxmark#1#2#3#4{#4}
9084 % \end{macrocode}
9085 % \end{macro}
9086 % \end{macro}
9087 %
9088 %</extramarks-v4>
9089 %
9090 % \section{\pkg{fancyheadings.sty}}
9091 %
9092 % Fancyheadings.sty was the original style file (as they were called
9093 % then) to implement fancy headers and footers in \LaTeX. This was in the time
9094 % when MSDOS was stil quite a dominant ``Operating System''. It had a
9095 % nasty property (amongst others): filenames consisted of at most 8
9096 % characters + a 3 character extension. This meant that the name
9097 % '\pkg{fancyheadings.sty}' was internally truncated in MSDOS to
9098 % '\pkg{fancyhea.sty}', although it was perfectly OK to say
9099 % '\pkg{fancyheadings}' in \LaTeX. However, some people started to write also
9100 % '\pkg{fancyhea}' in \LaTeX{} documents, which made them unportable to for
9101 % example Unix systems, unless there a copy or link was made to
9102 % '\pkg{fancyhea.sty}'. I found this so annoying that I decided to rename the
9103 % package to '\pkg{fancyhdr.sty}'. This package has evolved to a version that
9104 % is incompatible with the original '\pkg{fancyheadings}'. \pkg{Fancyheadings}
9105 % should no longer be used, therefore this package is provided that
9106 % issues a clear warning and then switches to \pkg{fancyhdr}.
9107 %
9108 %
9109 %<*fancyheadings>
9110 % \begin{macrocode}
9111 \PackageWarningNoLine{fancyheadings}{%
9112 Please stop using fancyheadings!\MessageBreak
9113 Use fancyhdr instead.\MessageBreak
9114 We will call fancyhdr with the very same\MessageBreak
9115 options you passed to fancyheadings.\MessageBreak
9116 \MessageBreak
9117 fancyhdr is 99 percent compatible with\MessageBreak
9118 fancyheadings. The only incompatibility is\MessageBreak
9119 that \protect\headrulewidth\space and \protect\footrulewidth\space
9120 and\MessageBreak
9121 their \protect\plain... versions are no longer length\MessageBreak
9122 parameters, but normal macros (to be changed\MessageBreak
9123 with \protect\renewcommand\space rather than \protect\setlength).}
9124 \RequirePackage{fancyhdr}
9125 % \end{macrocode}
9126 %</fancyheadings>
9127 % \end{implementation}
9128 %
9129 % \Finale
9130 \endinput