1 | % fancyhdr.sty version 1.99d
|
---|
2 | % Fancy headers and footers for LaTeX.
|
---|
3 | % Piet van Oostrum, Dept of Computer Science, University of Utrecht
|
---|
4 | % Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands
|
---|
5 | % Telephone: +31 30 2532180. Email: piet@cs.ruu.nl
|
---|
6 | % ========================================================================
|
---|
7 | % LICENCE: This is free software. You are allowed to use and distribute
|
---|
8 | % this software in any way you like. You are also allowed to make modified
|
---|
9 | % versions of it, but you can distribute a modified version only if you
|
---|
10 | % clearly indicate that it is a modified version and the person(s) who
|
---|
11 | % modified it. This indication should be in a prominent place, e.g. in the
|
---|
12 | % top of the file. If possible a contact address, preferably by email,
|
---|
13 | % should be given for these persons. If that is feasible the modifications
|
---|
14 | % should be indicated in the source code.
|
---|
15 | % ========================================================================
|
---|
16 | % MODIFICATION HISTORY:
|
---|
17 | % Sep 16, 1994
|
---|
18 | % version 1.4: Correction for use with \reversemargin
|
---|
19 | % Sep 29, 1994:
|
---|
20 | % version 1.5: Added the \iftopfloat, \ifbotfloat and \iffloatpage commands
|
---|
21 | % Oct 4, 1994:
|
---|
22 | % version 1.6: Reset single spacing in headers/footers for use with
|
---|
23 | % setspace.sty or doublespace.sty
|
---|
24 | % Oct 4, 1994:
|
---|
25 | % version 1.7: changed \let\@mkboth\markboth to
|
---|
26 | % \def\@mkboth{\protect\markboth} to make it more robust
|
---|
27 | % Dec 5, 1994:
|
---|
28 | % version 1.8: corrections for amsbook/amsart: define \@chapapp and (more
|
---|
29 | % importantly) use the \chapter/sectionmark definitions from ps@headings if
|
---|
30 | % they exist (which should be true for all standard classes).
|
---|
31 | % May 31, 1995:
|
---|
32 | % version 1.9: The proposed \renewcommand{\headrulewidth}{\iffloatpage...
|
---|
33 | % construction in the doc did not work properly with the fancyplain style.
|
---|
34 | % June 1, 1995:
|
---|
35 | % version 1.91: The definition of \@mkboth wasn't restored on subsequent
|
---|
36 | % \pagestyle{fancy}'s.
|
---|
37 | % June 1, 1995:
|
---|
38 | % version 1.92: The sequence \pagestyle{fancyplain} \pagestyle{plain}
|
---|
39 | % \pagestyle{fancy} would erroneously select the plain version.
|
---|
40 | % June 1, 1995:
|
---|
41 | % version 1.93: \fancypagestyle command added.
|
---|
42 | % Dec 11, 1995:
|
---|
43 | % version 1.94: suggested by Conrad Hughes <chughes@maths.tcd.ie>
|
---|
44 | % CJCH, Dec 11, 1995: added \footruleskip to allow control over footrule
|
---|
45 | % position (old hardcoded value of .3\normalbaselineskip is far too high
|
---|
46 | % when used with very small footer fonts).
|
---|
47 | % Jan 31, 1996:
|
---|
48 | % version 1.95: call \@normalsize in the reset code if that is defined,
|
---|
49 | % otherwise \normalsize.
|
---|
50 | % this is to solve a problem with ucthesis.cls, as this doesn't
|
---|
51 | % define \@currsize. Unfortunately for latex209 calling \normalsize doesn't
|
---|
52 | % work as this is optimized to do very little, so there \@normalsize should
|
---|
53 | % be called. Hopefully this code works for all versions of LaTeX known to
|
---|
54 | % mankind.
|
---|
55 | % April 25, 1996:
|
---|
56 | % version 1.96: initialize \headwidth to a magic (negative) value to catch
|
---|
57 | % most common cases that people change it before calling \pagestyle{fancy}.
|
---|
58 | % Note it can't be initialized when reading in this file, because
|
---|
59 | % \textwidth could be changed afterwards. This is quite probable.
|
---|
60 | % We also switch to \MakeUppercase rather than \uppercase and introduce a
|
---|
61 | % \nouppercase command for use in headers. and footers.
|
---|
62 | % May 3, 1996:
|
---|
63 | % version 1.97: Two changes:
|
---|
64 | % 1. Undo the change in version 1.8 (using the pagestyle{headings} defaults
|
---|
65 | % for the chapter and section marks. The current version of amsbook and
|
---|
66 | % amsart classes don't seem to need them anymore. Moreover the standard
|
---|
67 | % latex classes don't use \markboth if twoside isn't selected, and this is
|
---|
68 | % confusing as \leftmark doesn't work as expected.
|
---|
69 | % 2. include a call to \ps@empty in ps@@fancy. This is to solve a problem
|
---|
70 | % in the amsbook and amsart classes, that make global changes to \topskip,
|
---|
71 | % which are reset in \ps@empty. Hopefully this doesn't break other things.
|
---|
72 | % May 7, 1996:
|
---|
73 | % version 1.98:
|
---|
74 | % Added % after the line \def\nouppercase
|
---|
75 | % May 7, 1996:
|
---|
76 | % version 1.99: This is the alpha version of fancyhdr 2.0
|
---|
77 | % Introduced the new commands \fancyhead, \fancyfoot, and \fancyhf.
|
---|
78 | % Changed \headrulewidth, \footrulewidth, \footruleskip to
|
---|
79 | % macros rather than length parameters, In this way they can be
|
---|
80 | % conditionalized and they don't consume length registers. There is no need
|
---|
81 | % to have them as length registers unless you want to do calculations with
|
---|
82 | % them, which is unlikely. Note that this may make some uses of them
|
---|
83 | % incompatible (i.e. if you have a file that uses \setlength or \xxxx=)
|
---|
84 | % May 10, 1996:
|
---|
85 | % version 1.99a:
|
---|
86 | % Added a few more % signs
|
---|
87 | % May 10, 1996:
|
---|
88 | % version 1.99b:
|
---|
89 | % Changed the syntax of \f@nfor to be resistent to catcode changes of :=
|
---|
90 | % Removed the [1] from the defs of \lhead etc. because the parameter is
|
---|
91 | % consumed by the \@[xy]lhead etc. macros.
|
---|
92 | % June 24, 1997:
|
---|
93 | % version 1.99c:
|
---|
94 | % corrected \nouppercase to also include the protected form of \MakeUppercase
|
---|
95 | % \global added to manipulation of \headwidth.
|
---|
96 | % \iffootnote command added.
|
---|
97 | % Some comments added about \@fancyhead and \@fancyfoot.
|
---|
98 | % Aug 24, 1998
|
---|
99 | % version 1.99d
|
---|
100 | % Changed the default \ps@empty to \ps@@empty in order to allow
|
---|
101 | % \fancypagestyle{empty} redefinition.
|
---|
102 |
|
---|
103 | \let\fancy@def\gdef
|
---|
104 |
|
---|
105 | \def\if@mpty#1#2#3{\def\temp@ty{#1}\ifx\@empty\temp@ty #2\else#3\fi}
|
---|
106 |
|
---|
107 | % Usage: \@forc \var{charstring}{command to be executed for each char}
|
---|
108 | % This is similar to LaTeX's \@tfor, but expands the charstring.
|
---|
109 |
|
---|
110 | \def\@forc#1#2#3{\expandafter\f@rc\expandafter#1\expandafter{#2}{#3}}
|
---|
111 | \def\f@rc#1#2#3{\def\temp@ty{#2}\ifx\@empty\temp@ty\else
|
---|
112 | \f@@rc#1#2\f@@rc{#3}\fi}
|
---|
113 | \def\f@@rc#1#2#3\f@@rc#4{\def#1{#2}#4\f@rc#1{#3}{#4}}
|
---|
114 |
|
---|
115 | % Usage: \f@nfor\name:=list\do{body}
|
---|
116 | % Like LaTeX's \@for but an empty list is treated as a list with an empty
|
---|
117 | % element
|
---|
118 |
|
---|
119 | \newcommand{\f@nfor}[3]{\edef\@fortmp{#2}%
|
---|
120 | \expandafter\@forloop#2,\@nil,\@nil\@@#1{#3}}
|
---|
121 |
|
---|
122 | % Usage: \def@ult \cs{defaults}{argument}
|
---|
123 | % sets \cs to the characters from defaults appearing in argument
|
---|
124 | % or defaults if it would be empty. All characters are lowercased.
|
---|
125 |
|
---|
126 | \newcommand\def@ult[3]{%
|
---|
127 | \edef\temp@a{\lowercase{\edef\noexpand\temp@a{#3}}}\temp@a
|
---|
128 | \def#1{}%
|
---|
129 | \@forc\tmpf@ra{#2}%
|
---|
130 | {\expandafter\if@in\tmpf@ra\temp@a{\edef#1{#1\tmpf@ra}}{}}%
|
---|
131 | \ifx\@empty#1\def#1{#2}\fi}
|
---|
132 | %
|
---|
133 | % \if@in <char><set><truecase><falsecase>
|
---|
134 | %
|
---|
135 | \newcommand{\if@in}[4]{%
|
---|
136 | \edef\temp@a{#2}\def\temp@b##1#1##2\temp@b{\def\temp@b{##1}}%
|
---|
137 | \expandafter\temp@b#2#1\temp@b\ifx\temp@a\temp@b #4\else #3\fi}
|
---|
138 |
|
---|
139 | \newcommand{\fancyhead}{\@ifnextchar[{\f@ncyhf h}{\f@ncyhf h[]}}
|
---|
140 | \newcommand{\fancyfoot}{\@ifnextchar[{\f@ncyhf f}{\f@ncyhf f[]}}
|
---|
141 | \newcommand{\fancyhf}{\@ifnextchar[{\f@ncyhf {}}{\f@ncyhf {}[]}}
|
---|
142 |
|
---|
143 | % The header and footer fields are stored in command sequences with
|
---|
144 | % names of the form: \f@ncy<x><y><z> with <x> for [eo], <y> form [lcr]
|
---|
145 | % and <z> from [hf].
|
---|
146 |
|
---|
147 | \def\f@ncyhf#1[#2]#3{%
|
---|
148 | \def\temp@c{}%
|
---|
149 | \@forc\tmpf@ra{#2}%
|
---|
150 | {\expandafter\if@in\tmpf@ra{eolcrhf,EOLCRHF}%
|
---|
151 | {}{\edef\temp@c{\temp@c\tmpf@ra}}}%
|
---|
152 | \ifx\@empty\temp@c\else
|
---|
153 | \ifx\PackageError\undefined
|
---|
154 | \errmessage{Illegal char `\temp@c' in fancyhdr argument:
|
---|
155 | [#2]}\else
|
---|
156 | \PackageError{Fancyhdr}{Illegal char `\temp@c' in fancyhdr argument:
|
---|
157 | [#2]}{}\fi
|
---|
158 | \fi
|
---|
159 | \f@nfor\temp@c{#2}%
|
---|
160 | {\def@ult\f@@@eo{eo}\temp@c
|
---|
161 | \def@ult\f@@@lcr{lcr}\temp@c
|
---|
162 | \def@ult\f@@@hf{hf}{#1\temp@c}%
|
---|
163 | \@forc\f@@eo\f@@@eo
|
---|
164 | {\@forc\f@@lcr\f@@@lcr
|
---|
165 | {\@forc\f@@hf\f@@@hf
|
---|
166 | {\expandafter\fancy@def\csname
|
---|
167 | f@ncy\f@@eo\f@@lcr\f@@hf\endcsname
|
---|
168 | {#3}}}}}}
|
---|
169 |
|
---|
170 | % Fancyheadings version 1 commands. These are more or less deprecated,
|
---|
171 | % but they continue to work.
|
---|
172 |
|
---|
173 | \newcommand{\lhead}{\@ifnextchar[{\@xlhead}{\@ylhead}}
|
---|
174 | \def\@xlhead[#1]#2{\fancy@def\f@ncyelh{#1}\fancy@def\f@ncyolh{#2}}
|
---|
175 | \def\@ylhead#1{\fancy@def\f@ncyelh{#1}\fancy@def\f@ncyolh{#1}}
|
---|
176 |
|
---|
177 | \newcommand{\chead}{\@ifnextchar[{\@xchead}{\@ychead}}
|
---|
178 | \def\@xchead[#1]#2{\fancy@def\f@ncyech{#1}\fancy@def\f@ncyoch{#2}}
|
---|
179 | \def\@ychead#1{\fancy@def\f@ncyech{#1}\fancy@def\f@ncyoch{#1}}
|
---|
180 |
|
---|
181 | \newcommand{\rhead}{\@ifnextchar[{\@xrhead}{\@yrhead}}
|
---|
182 | \def\@xrhead[#1]#2{\fancy@def\f@ncyerh{#1}\fancy@def\f@ncyorh{#2}}
|
---|
183 | \def\@yrhead#1{\fancy@def\f@ncyerh{#1}\fancy@def\f@ncyorh{#1}}
|
---|
184 |
|
---|
185 | \newcommand{\lfoot}{\@ifnextchar[{\@xlfoot}{\@ylfoot}}
|
---|
186 | \def\@xlfoot[#1]#2{\fancy@def\f@ncyelf{#1}\fancy@def\f@ncyolf{#2}}
|
---|
187 | \def\@ylfoot#1{\fancy@def\f@ncyelf{#1}\fancy@def\f@ncyolf{#1}}
|
---|
188 |
|
---|
189 | \newcommand{\cfoot}{\@ifnextchar[{\@xcfoot}{\@ycfoot}}
|
---|
190 | \def\@xcfoot[#1]#2{\fancy@def\f@ncyecf{#1}\fancy@def\f@ncyocf{#2}}
|
---|
191 | \def\@ycfoot#1{\fancy@def\f@ncyecf{#1}\fancy@def\f@ncyocf{#1}}
|
---|
192 |
|
---|
193 | \newcommand{\rfoot}{\@ifnextchar[{\@xrfoot}{\@yrfoot}}
|
---|
194 | \def\@xrfoot[#1]#2{\fancy@def\f@ncyerf{#1}\fancy@def\f@ncyorf{#2}}
|
---|
195 | \def\@yrfoot#1{\fancy@def\f@ncyerf{#1}\fancy@def\f@ncyorf{#1}}
|
---|
196 |
|
---|
197 | \newdimen\headwidth
|
---|
198 | \newcommand{\headrulewidth}{0.4pt}
|
---|
199 | \newcommand{\footrulewidth}{\z@skip}
|
---|
200 | \newcommand{\footruleskip}{.3\normalbaselineskip}
|
---|
201 |
|
---|
202 | % Fancyplain stuff shouldn't be used anymore (rather
|
---|
203 | % \fancypagestyle{plain} should be used), but it must be present for
|
---|
204 | % compatibility reasons.
|
---|
205 |
|
---|
206 | \newcommand{\plainheadrulewidth}{\z@skip}
|
---|
207 | \newcommand{\plainfootrulewidth}{\z@skip}
|
---|
208 | \newif\if@fancyplain \@fancyplainfalse
|
---|
209 | \def\fancyplain#1#2{\if@fancyplain#1\else#2\fi}
|
---|
210 |
|
---|
211 | \headwidth=-123456789sp %magic constant
|
---|
212 |
|
---|
213 | % Command to reset various things in the headers:
|
---|
214 | % a.o. single spacing (taken from setspace.sty)
|
---|
215 | % and the catcode of ^^M (so that epsf files in the header work if a
|
---|
216 | % verbatim crosses a page boundary)
|
---|
217 | % It also defines a \nouppercase command that disables \uppercase and
|
---|
218 | % \Makeuppercase. It can only be used in the headers and footers.
|
---|
219 | \def\fancy@reset{\restorecr
|
---|
220 | \def\baselinestretch{1}%
|
---|
221 | \def\nouppercase##1{{\let\uppercase\relax\let\MakeUppercase\relax
|
---|
222 | \expandafter\let\csname MakeUppercase \endcsname\relax##1}}%
|
---|
223 | \ifx\undefined\@newbaseline% NFSS not present; 2.09 or 2e
|
---|
224 | \ifx\@normalsize\undefined \normalsize % for ucthesis.cls
|
---|
225 | \else \@normalsize \fi
|
---|
226 | \else% NFSS (2.09) present
|
---|
227 | \@newbaseline%
|
---|
228 | \fi}
|
---|
229 |
|
---|
230 | % Initialization of the head and foot text.
|
---|
231 |
|
---|
232 | % The default values still contain \fancyplain for compatibility.
|
---|
233 | \fancyhf{} % clear all
|
---|
234 | % lefthead empty on ``plain'' pages, \rightmark on even, \leftmark on odd pages
|
---|
235 | % evenhead empty on ``plain'' pages, \leftmark on even, \rightmark on odd pages
|
---|
236 | \fancyhead[el,or]{\fancyplain{}{\sl\rightmark}}
|
---|
237 | \fancyhead[er,ol]{\fancyplain{}{\sl\leftmark}}
|
---|
238 | \fancyfoot[c]{\rm\thepage} % page number
|
---|
239 |
|
---|
240 | % Put together a header or footer given the left, center and
|
---|
241 | % right text, fillers at left and right and a rule.
|
---|
242 | % The \lap commands put the text into an hbox of zero size,
|
---|
243 | % so overlapping text does not generate an errormessage.
|
---|
244 | % These macros have 5 parameters:
|
---|
245 | % 1. \@lodd or \@rodd % This determines at which side the header will stick
|
---|
246 | % out.
|
---|
247 | % 2. \f@ncyolh, \f@ncyelh, \f@ncyolf or \f@ncyelf. This is the left component.
|
---|
248 | % 3. \f@ncyoch, \f@ncyech, \f@ncyocf or \f@ncyecf. This is the middle comp.
|
---|
249 | % 4. \f@ncyorh, \f@ncyerh, \f@ncyorf or \f@ncyerf. This is the right component.
|
---|
250 | % 5. \@lodd or \@rodd % This determines at which side the header will stick
|
---|
251 | % out. This is the reverse of parameter nr. 1. One of them is always
|
---|
252 | % \relax and the other one is \hss (after expansion).
|
---|
253 |
|
---|
254 | \def\@fancyhead#1#2#3#4#5{#1\hbox to\headwidth{\fancy@reset\vbox{\hbox
|
---|
255 | {\rlap{\parbox[b]{\headwidth}{\raggedright#2\strut}}\hfill
|
---|
256 | \parbox[b]{\headwidth}{\centering#3\strut}\hfill
|
---|
257 | \llap{\parbox[b]{\headwidth}{\raggedleft#4\strut}}}\headrule}}#5}
|
---|
258 |
|
---|
259 | \def\@fancyfoot#1#2#3#4#5{#1\hbox to\headwidth{\fancy@reset\vbox{\footrule
|
---|
260 | \hbox{\rlap{\parbox[t]{\headwidth}{\raggedright#2\strut}}\hfill
|
---|
261 | \parbox[t]{\headwidth}{\centering#3\strut}\hfill
|
---|
262 | \llap{\parbox[t]{\headwidth}{\raggedleft#4\strut}}}}}#5}
|
---|
263 |
|
---|
264 | \def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
|
---|
265 | \hrule\@height\headrulewidth\@width\headwidth \vskip-\headrulewidth}}
|
---|
266 |
|
---|
267 | \def\footrule{{\if@fancyplain\let\footrulewidth\plainfootrulewidth\fi
|
---|
268 | \vskip-\footruleskip\vskip-\footrulewidth
|
---|
269 | \hrule\@width\headwidth\@height\footrulewidth\vskip\footruleskip}}
|
---|
270 |
|
---|
271 | \def\ps@fancy{%
|
---|
272 | \@ifundefined{@chapapp}{\let\@chapapp\chaptername}{}%for amsbook
|
---|
273 | %
|
---|
274 | % Define \MakeUppercase for old LaTeXen.
|
---|
275 | % Note: we used \def rather than \let, so that \let\uppercase\relax (from
|
---|
276 | % the version 1 documentation) will still work.
|
---|
277 | %
|
---|
278 | \@ifundefined{MakeUppercase}{\def\MakeUppercase{\uppercase}}{}%
|
---|
279 | \@ifundefined{chapter}{\def\sectionmark##1{\markboth
|
---|
280 | {\MakeUppercase{\ifnum \c@secnumdepth>\z@
|
---|
281 | \thesection\hskip 1em\relax \fi ##1}}{}}%
|
---|
282 | \def\subsectionmark##1{\markright {\ifnum \c@secnumdepth >\@ne
|
---|
283 | \thesubsection\hskip 1em\relax \fi ##1}}}%
|
---|
284 | {\def\chaptermark##1{\markboth {\MakeUppercase{\ifnum \c@secnumdepth>\m@ne
|
---|
285 | \@chapapp\ \thechapter. \ \fi ##1}}{}}%
|
---|
286 | \def\sectionmark##1{\markright{\MakeUppercase{\ifnum \c@secnumdepth >\z@
|
---|
287 | \thesection. \ \fi ##1}}}}%
|
---|
288 | %\csname ps@headings\endcsname % use \ps@headings defaults if they exist
|
---|
289 | \ps@@fancy
|
---|
290 | \gdef\ps@fancy{\@fancyplainfalse\ps@@fancy}%
|
---|
291 | % Initialize \headwidth if the user didn't
|
---|
292 | %
|
---|
293 | \ifdim\headwidth<0sp
|
---|
294 | %
|
---|
295 | % This catches the case that \headwidth hasn't been initialized and the
|
---|
296 | % case that the user added something to \headwidth in the expectation that
|
---|
297 | % it was initialized to \textwidth. We compensate this now. This loses if
|
---|
298 | % the user intended to multiply it by a factor. But that case is more
|
---|
299 | % likely done by saying something like \headwidth=1.2\textwidth.
|
---|
300 | % The doc says you have to change \headwidth after the first call to
|
---|
301 | % \pagestyle{fancy}. This code is just to catch the most common cases were
|
---|
302 | % that requirement is violated.
|
---|
303 | %
|
---|
304 | \global\advance\headwidth123456789sp\global\advance\headwidth\textwidth
|
---|
305 | \fi}
|
---|
306 | \def\ps@fancyplain{\ps@fancy \let\ps@plain\ps@plain@fancy}
|
---|
307 | \def\ps@plain@fancy{\@fancyplaintrue\ps@@fancy}
|
---|
308 | \let\ps@@empty\ps@empty
|
---|
309 | \def\ps@@fancy{%
|
---|
310 | \ps@@empty % This is for amsbook/amsart, which do strange things with \topskip
|
---|
311 | \def\@mkboth{\protect\markboth}%
|
---|
312 | \def\@oddhead{\@fancyhead\@lodd\f@ncyolh\f@ncyoch\f@ncyorh\@rodd}%
|
---|
313 | \def\@oddfoot{\@fancyfoot\@lodd\f@ncyolf\f@ncyocf\f@ncyorf\@rodd}%
|
---|
314 | \def\@evenhead{\@fancyhead\@rodd\f@ncyelh\f@ncyech\f@ncyerh\@lodd}%
|
---|
315 | \def\@evenfoot{\@fancyfoot\@rodd\f@ncyelf\f@ncyecf\f@ncyerf\@lodd}%
|
---|
316 | }
|
---|
317 | \def\@lodd{\if@reversemargin\hss\else\relax\fi}
|
---|
318 | \def\@rodd{\if@reversemargin\relax\else\hss\fi}
|
---|
319 |
|
---|
320 | \newif\iffootnote
|
---|
321 | \let\latex@makecol\@makecol
|
---|
322 | \def\@makecol{\ifvoid\footins\footnotetrue\else\footnotefalse\fi
|
---|
323 | \let\topfloat\@toplist\let\botfloat\@botlist\latex@makecol}
|
---|
324 | \def\iftopfloat#1#2{\ifx\topfloat\empty #2\else #1\fi}
|
---|
325 | \def\ifbotfloat#1#2{\ifx\botfloat\empty #2\else #1\fi}
|
---|
326 | \def\iffloatpage#1#2{\if@fcolmade #1\else #2\fi}
|
---|
327 |
|
---|
328 | \newcommand{\fancypagestyle}[2]{%
|
---|
329 | \@namedef{ps@#1}{\let\fancy@def\def#2\relax\ps@fancy}}
|
---|