1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
%%
%% This is file `novel-HeadFootStyles.sty', part of class `novel'.
%% Copyright 2017 Robert Allgeyer.
%%
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%%
\ProvidesFile{novel-HeadFootStyles.sty}%
[2017/03/21 v1.0.9 LaTeX file (header and footer styles)]
%%
%% File `novel-LayoutSettings.sty' reserved space for header/footer,
%% but did not place anything there. In this file, `fancyhdr' syntax
%% defines the standard styles. These styles are not activated until
%% \AtEndPreamble, and only if the user did not already define the styles
%% in the Preamble.
% @isVerso true = even page, false = odd page. Only accurate during shipout.
% Not to be used in commands that are inserted in main text!
\newif \if@isVerso \@isVersofalse
\def\check@IsVerso{%
\def\my@PageNum{\arabic{page}}%
\FPdiv{\my@HalfPageNum}{\my@PageNum}{2}%
\FPifint{\my@HalfPageNum}%
\global\@isVersotrue%
\else%
\global\@isVersofalse%
\fi%
}
%
\newtoggle{@inheadfoot} % true in header or footer
%%
%% INITIALIZE FANCYHDR
%% -----------------------------------------------------------------------------
%% Before now now, space was reserved for header/footer.
% Start by loading package `fancyhdr' and blanking everything:
\RequirePackage{fancyhdr}
\renewcommand\headrulewidth{0pt}
\renewcommand\footrulewidth{0pt}
\fancyhead[LO,RE,LE,RO,CE,CO]{}
\fancyfoot[LO,RE,LE,RO,CE,CO]{}
% \textls looseness factor (microtype) 0=tight, 50=default
\gdef\SetLooseHead#1{
\gdef\@loosehead{#1}
\FPmin{\@looseheadnum}{\@loosehead}{50} % Don't want numbers too loose.
}
\SetLooseHead{50}
% Create flags to know if \fancyhead and \fancyfoot have been defined by user,
% somewhere in the Preamble. If not, then pre-defined styles based on trimsize
% will be applied \AtEndPreamble.
\LetLtxMacro{\@tempFancyhead}{\fancyhead} % from package `letltxmacro'
\renewcommand\fancyhead[2][]{%
\@styledHeadertrue%
\@tempFancyhead[#1]{\toggletrue{@inheadfoot}{\normalsize#2}}%
}
%
\LetLtxMacro{\@tempFancyfoot}{\fancyfoot}
\renewcommand\fancyfoot[2][]{%
\@styledFootertrue%
\FPsub{\@footraise}{\@footjump}{1}%
\FPmul{\@footraise}{-\@footraise}{\Current@BaselineSkipNum}%
\@tempFancyfoot[#1]{%
\toggletrue{@inheadfoot}%
\stake\smash{\raisebox{\@footraise pt}{{\normalsize#2}}}%
}%
}
%
\LetLtxMacro{\@myTempTPS}{\thispagestyle}
% Re-define \thispagestyle based on layout. When style requests only the page
% number, decide what to do based on this command and whether footer is used:
\newif \if@thispagestyleset \@thispagestylesetfalse
\AtBeginShipout{\global\@thispagestylesetfalse}
%
\gdef\thispagestyle#1{%
\global\@thispagestylesettrue%
\gdef\@pagestyleOK{false}%
\ifthenelse{\equal{#1}{fancy}}{%
\gdef\@pagestyleOK{true}%
\@myTempTPS{fancy}%
}{}%
\ifthenelse{\equal{#1}{empty}}{%
\gdef\@pagestyleOK{true}%
\@myTempTPS{empty}%
}{}%
\ifthenelse{\equal{#1}{plain}\OR\equal{#1}{fancyplain}\OR\equal{#1}{footer}}{%
\gdef\@pagestyleOK{true}%
\if@gotFooter \@myTempTPS{fancyplain}%
\else \@myTempTPS{empty}%
\fi%
}{}%
\ifthenelse{\equal{#1}{forcenumber}}{%
\gdef\@pagestyleOK{true}%
\if@gotFooter \@myTempTPS{fancyplain}%
\else \@myTempTPS{fancynumber}%
\fi%
}{}%
%
\ifthenelse{\equal{#1}{dropfolioinside}% after \clearpage
\OR \equal{#1}{dropfolio} \OR \equal{#1}{dropfoliolater}}{% compatibility
\gdef\@pagestyleOK{true}%
\if@gotFooter%
\@myTempTPS{fancyplain}%
\else%
\global\@addCTlinefalse%
\@myTempTPS{empty}%
\@dropfolioinside
\fi%
}{}%
% With `dropfoliobeneath` only a footer is used, if present. If no footer,
% then the styled page number is centered at one baselineskip beneath the
% ordinary bottom of the textblock. Thus, the number intrudes into the
% bottom margin. This is OK if the bottom margin is wider than minimum.
% Whether the margin is wide enough, is for the user to determine, because
% the document class does not know the printer's limitations.
\ifthenelse{\equal{#1}{dropfoliobeneath}}{% after \clearpage
\gdef\@pagestyleOK{true}%
\if@gotFooter%
\@myTempTPS{fancyplain}%
\else%
\@myTempTPS{empty}%
\@dropfoliobeneath
\fi%
}{}%
%%
\ifthenelse{\equal{\@pagestyleOK}{true}}{}{%
\ClassWarning{novel}{^^JPage \pagenumberstyle\space has %
\string\thispagestyle{}^^J%
but its argument is not defined. Default substituted. Better fix that.^^J}%
}%
}
%
%% End initialize fancyhdr.
%% ACTIVATE HEADER/FOOTER STYLES AT BEGIN DOCUMENT
%% -----------------------------------------------------------------------------
%
\gdef\@activateHeadFootStyles{ % called \AtBeginDocument by novel.cls
% Pre-configured header/footer styles, unless user over-rode them:
% \versoheadtext is initialized to \theauthor
% \rectoheadtext is initialized to \thetitle
\@ifundefined{versoheadtext}{
\NewVersoHeadText{\smcp{\StrSubstitute{\theauthor}{\space}{~}}}
}{}
\@ifundefined{rectoheadtext}{
\NewRectoHeadText{\smcp{\StrSubstitute{\thetitle}{\space}{~}}}
}{}
%
% ----------------------------------------------------------------------------
% IF YOU ARE WRITING YOUR OWN HEADER/FOOTER STYLE:
% Look here for the pre-defined styles, for use as models.
% Note that if you write \fancyhead or \fancyfoot in the Preamble,
% that sets the \@styledHeader flag, so these codes do not over-ride yours.
\ifthenelse{\equal{\my@HeadFootStyle}{1}}{ % default
\if@styledHeader\else
\fancyhead[LE]{\makebox[2.5em][l]{%
{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}\my@VersoEmblem%
}
\fancyhead[RO]{\my@RectoEmblem\makebox[2.5em][r]{%
{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}%
}
\fancyhead[CE]{{\headfont\textls[\@loosehead]{\versoheadtext}}}
\fancyhead[CO]{{\headfont\textls[\@loosehead]{\rectoheadtext}}}
\fi
}{}
%
\ifthenelse{\equal{\my@HeadFootStyle}{2}}{
\if@styledFooter\else
\fancyfoot[LE]{\makebox[2.5em][l]{%
{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}\my@VersoEmblem%
}
\fancyfoot[RO]{\my@RectoEmblem\makebox[2.5em][r]{%
{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}%
}
\fi
}{}
%
\ifthenelse{\equal{\my@HeadFootStyle}{3}}{
\if@styledFooter\else
\fancyfoot[CO,CE]{{%
\headfont\textls[\@looseheadnum]{\pagenumberstyle}}%
}
\fi
}{}
%
\ifthenelse{\equal{\my@HeadFootStyle}{4}}{
\if@styledHeader\else
\fancyhead[LE]{\makebox[2.5em][l]{%
{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}%
\my@VersoEmblem\hspace{1em}%
{\headfont\textls[\@loosehead]{\versoheadtext}}%
}
\fancyhead[RO]{{\headfont\textls[\@loosehead]{\rectoheadtext}}%
\hspace{1em}\my@RectoEmblem\makebox[2.5em][r]{{%
\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}%
}
\fi
}{}
%
\ifthenelse{\equal{\my@HeadFootStyle}{5}}{
\if@styledHeader\else
\fancyhead[CE]{{\headfont\textls[\@loosehead]{\versoheadtext}}}
\fancyhead[CO]{{\headfont\textls[\@loosehead]{\rectoheadtext}}}
\fi
\if@styledFooter\else
\fancyfoot[CO,CE]{%
{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}%
}
\fi
}{}
%
\ifthenelse{\equal{\my@HeadFootStyle}{6}}{
\if@styledHeader\else
\fancyhead[LE]{\makebox[2.5em][l]{%
{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}\my@VersoEmblem%
}
\fancyhead[RO]{\my@RectoEmblem\makebox[2.5em][r]{%
{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}%
}
\fancyhead[RE]{{\headfont\textls[\@loosehead]{\versoheadtext}}}
\fancyhead[LO]{{\headfont\textls[\@loosehead]{\rectoheadtext}}}
\fi
}{}
%
% END PRE-DEFINED STYLES.
% ----------------------------------------------------------------------------
%
% Substitute for \thispagestyle{plain}
\fancypagestyle{fancyplain}{ % if has footer
\renewcommand\headrulewidth{0pt}
\renewcommand\footrulewidth{0pt}
\fancyhead[LO,RE,LE,RO,CE,CO]{}
\fancyfoot[LO,RE,LE,RO,CE,CO]{}
\fancyfoot[CO,CE]{{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}
}
% Not a user command, use plain or fancyplain:
\fancypagestyle{fancynumber}{ % if has header but not footer
\renewcommand\headrulewidth{0pt}
\renewcommand\footrulewidth{0pt}
\fancyhead[LO,RE,LE,RO,CE,CO]{}
\fancyhead[LE]{\makebox[2.5em][l]{%
{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}\my@VersoEmblem%
}
\fancyhead[RO]{\my@RectoEmblem\makebox[2.5em][r]{%
{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}%
}
\fancyfoot[LO,RE,LE,RO,CE,CO]{}
}
% Now put `fancyhdr' to work:
\pagestyle{fancy} % default unless over-ridden by \thispagestyle{}
%
} % end \@activateHeadFootStyles
%
%% end initialize fancyhdr
%% DROPFOLIO
%% -----------------------------------------------------------------------------
\newlength\temp@pgnumwidth
\newlength\temp@pgnumraise
%
% \@dropfolioinside reduces the textblock height by one lineskip. At the bottom,
% where the last line would have been, the styled page number is centered.
\newcommand\@dropfolioinside{%
\enlargethispage{-\nbs}%
\setlength\temp@pgnumwidth{%
\widthof{{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}}%
\if@offcenterTrim%
\setlength\temp@pgnumraise{%
\New@BottomMargin+\New@MediaHeight-\New@TrimHeight}%
\else%
\setlength\temp@pgnumraise{%
\New@BottomMargin+0.5\New@MediaHeight-0.5\New@TrimHeight}%
\fi%
\check@IsVerso%
\if@isVerso%
\AddToShipoutPicture*{\@getPageXY\AtPageLowerLeft{%
\hspace{\dimexpr\Trim@Lx+\New@OutsideMargin+0.5\textwidth-0.5\temp@pgnumwidth}\raisebox{%
\temp@pgnumraise}{{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}}}%
\else%
\AddToShipoutPicture*{\@getPageXY\AtPageLowerLeft{%
\hspace{\dimexpr\Trim@Lx+\New@InsideMargin-0.5\temp@pgnumwidth}%
\charscale[1,0.5\textwidth,\temp@pgnumraise]{%
{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}}}%
\fi%
} % end \@dropfolioinside
%
\let\dropfolionow\relax % compatibility with earlier version.
%
% \@dropfoliobeneath does not change the textblock height. The styled page
% number is centered where an extra line would be, within the bottom margin.
\newcommand\@dropfoliobeneath{%
\setlength\temp@pgnumwidth{%
\widthof{{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}}%
\if@offcenterTrim%
\setlength\temp@pgnumraise{%
\New@BottomMargin-\nbs+\New@MediaHeight-\New@TrimHeight}%
\else%
\setlength\temp@pgnumraise{%
\New@BottomMargin-\nbs+0.5\New@MediaHeight-0.5\New@TrimHeight}%
\fi%
\check@IsVerso%
\if@isVerso%
\AddToShipoutPicture*{\@getPageXY\AtPageLowerLeft{%
\hspace{\dimexpr\Trim@Lx+\New@OutsideMargin-0.5\temp@pgnumwidth}\raisebox{%
\temp@pgnumraise}{{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}}}%
\else%
\AddToShipoutPicture*{\@getPageXY\AtPageLowerLeft{%
\hspace{\dimexpr\Trim@Lx+\New@InsideMargin-0.5\temp@pgnumwidth}%
\charscale[1,0.5\textwidth,\temp@pgnumraise]{%
{\headfont\textls[\@looseheadnum]{\pagenumberstyle}}}}}%
\fi%
} % end \@dropfoliobeneath
%%
%
% Content of header text (if present) can be changed at any time within
% the body, using the following commands. If not used, then
% Verso is initialized to \theauthor and Recto is initialized to \thetitle
% AtBeginDocument, with adjustments to interword spacing.
% If you wish, you may write the commands with empty arguments, in which case
% the header still appears with page number (if present), but no text.
%
\newlength\@mykem
%
\gdef\NewVersoHeadText#1{
\FPdiv{\@myk}{\@loosehead}{500}
\setlength\@mykem{\@myk em}
\gdef\versoheadtext{\gdef~{\kern\@mykem\space}#1\gdef~{\nobreakspace {}}}
}
\let\SetVersoHeadText\NewVersoHeadText\relax % for convenience
\let\RenewVersoHeadText\NewVersoHeadText\relax % for convenience
%
\gdef\NewRectoHeadText#1{
\FPdiv{\@myk}{\@loosehead}{500}
\setlength\@mykem{\@myk em}
\gdef\rectoheadtext{\gdef~{\kern\@mykem\space}#1\gdef~{\nobreakspace {}}}
}
\let\SetRectoHeadText\NewRectoHeadText\relax % for convenience
\let\RenewRectoHeadText\NewRectoHeadText\relax % for convenience
%
%%
%
%% End of file `novel-HeadFootStyles.sty'
|