summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/novel/novel-HeadFootStyles.sty
blob: f55f864c311099c0a8c98af178ccfb15d755731f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
%%
%% 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/11/17 v1.46 LaTeX file (header and footer layouts and styles)]
%% 



%% File `novel-LayoutSettings.sty' reserved space for header/footer,
%% but did not place anything there. In this file, `fancyhdr' syntax
%% defines the layout. The layout are not activated until
%% \AtEndPreamble, and only if the user did not already define the layout
%% in the Preamble.

%% Note that `style' sometimes means `layout`.



%% INITIALIZE FANCYHDR
%% -----------------------------------------------------------------------------
%% Before now now, space was reserved for header/footer.
% Start by loading package `fancyhdr' and blanking everything:
%
\newtoggle{@inheadfoot} % true in header or footer
%
\RequirePackage{fancyhdr}
  \renewcommand\headrulewidth{0pt}
  \renewcommand\footrulewidth{0pt}
  \fancyhead[LO,RE,LE,RO,CE,CO]{}
  \fancyfoot[LO,RE,LE,RO,CE,CO]{}
% \SetLooseHead looseness factor (fontspec LetterSpace) 0=tight, 50=default
\gdef\SetLooseHead#1{
  \gdef\@@loosehead{#1}
  \FPdiv{\@loosehead}{\@@loosehead}{10} % change in method of using fontspec with microtype
  \FPmin{\@looseheadnum}{\@loosehead}{50} % Don't want numbers too loose.
  \FPdiv{\@looseheadword}{\@loosehead}{30} % new in v. 1.40.3.
  \FPadd{\@looseheadword}{\@looseheadword}{1}
}
\SetLooseHead{50}
% Create flags to know if \fancyhead and \fancyfoot have been defined by user,
%   somewhere in the Preamble. If not, then pre-defined layout 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 it requests only the page
% number, decide what to do based on this command and whether footer is used:
\newif \if@thispagestyleset \@thispagestylesetfalse
%
%% See AtBeginShipout routine in novel.cls.
%
\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.


%% See AtBeginDocument routine in novel.cls:
%% -----------------------------------------------------------------------------
\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{\theauthor} % revised in v. 1.40.3
  }{}
  \@ifundefined{rectoheadtext}{
    \NewRectoHeadText{\thetitle} % revised in v. 1.40.3
  }{}
  %
  % ----------------------------------------------------------------------------
  % IF YOU ARE WRITING YOUR OWN HEADER/FOOTER LAYOUT:
  % Look here for the pre-defined layouts, 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{\addfontfeature{LetterSpace=\@looseheadnum}\pagenumberstyle}}}\my@VersoEmblem%
      }
      \fancyhead[RO]{\my@RectoEmblem\makebox[2.5em][r]{%
        {\headfont{\addfontfeature{LetterSpace=\@looseheadnum}\pagenumberstyle}}}%
      }
      \fancyhead[CE]{{\headfont{\addfontfeature{LetterSpace=\@loosehead}\versoheadtext}}}
      \fancyhead[CO]{{\headfont{\addfontfeature{LetterSpace=\@loosehead}\rectoheadtext}}}
    \fi
  }{}
  %
  \ifthenelse{\equal{\my@HeadFootStyle}{2}}{
    \if@styledFooter\else
      \fancyfoot[LE]{\makebox[2.5em][l]{%
        {\headfont{\addfontfeature{LetterSpace=\@looseheadnum}\pagenumberstyle}}}\my@VersoEmblem%
      }
      \fancyfoot[RO]{\my@RectoEmblem\makebox[2.5em][r]{%
        {\headfont{\addfontfeature{LetterSpace=\@loosehead}\pagenumberstyle}}}%
      }
    \fi
  }{}
  %
  \ifthenelse{\equal{\my@HeadFootStyle}{3}}{
    \if@styledFooter\else
      \fancyfoot[CO,CE]{%
        {\headfont{\addfontfeature{LetterSpace=\@looseheadnum}\pagenumberstyle}}%
      }
    \fi
  }{}
  %
  \ifthenelse{\equal{\my@HeadFootStyle}{4}}{
    \if@styledHeader\else
      \fancyhead[LE]{\makebox[2.5em][l]{%
        {\headfont{\addfontfeature{LetterSpace=\@looseheadnum}\pagenumberstyle}}}%
        \my@VersoEmblem\hspace{1em}%
        {\headfont{\addfontfeature{LetterSpace=\@loosehead}\versoheadtext}}%
      }
      \fancyhead[RO]{{\headfont{\addfontfeature{LetterSpace=\@loosehead}\rectoheadtext}}%
        \hspace{1em}\my@RectoEmblem\makebox[2.5em][r]{{%
          \headfont{\addfontfeature{LetterSpace=\@looseheadnum}\pagenumberstyle}}}%
      }
    \fi
  }{}
  %
  \ifthenelse{\equal{\my@HeadFootStyle}{5}}{
    \if@styledHeader\else
        \fancyhead[CE]{{\headfont{\addfontfeature{LetterSpace=\@loosehead}\versoheadtext}}}
        \fancyhead[CO]{{\headfont{\addfontfeature{LetterSpace=\@loosehead}\rectoheadtext}}}
    \fi
    \if@styledFooter\else
      \fancyfoot[CO,CE]{%
        {\headfont{\addfontfeature{LetterSpace=\@looseheadnum}\pagenumberstyle}}%
      }
    \fi
  }{}
  %
  \ifthenelse{\equal{\my@HeadFootStyle}{6}}{
    \if@styledHeader\else
      \fancyhead[LE]{\makebox[2.5em][l]{%
        {\headfont{\addfontfeature{LetterSpace=\@looseheadnum}\pagenumberstyle}}}\my@VersoEmblem%
      }
      \fancyhead[RO]{\my@RectoEmblem\makebox[2.5em][r]{%
        {\headfont{\addfontfeature{LetterSpace=\@looseheadnum}\pagenumberstyle}}}%
      }
      \fancyhead[RE]{{\headfont{\addfontfeature{LetterSpace=\@loosehead}\versoheadtext}}}
      \fancyhead[LO]{{\headfont{\addfontfeature{LetterSpace=\@loosehead}\rectoheadtext}}}
    \fi
  }{}
  %
  %
  % END PRE-DEFINED LAYOUTS AND 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{\addfontfeature{LetterSpace=\@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{\addfontfeature{LetterSpace=\@looseheadnum}\pagenumberstyle}}}\my@VersoEmblem%
    }
    \fancyhead[RO]{\my@RectoEmblem\makebox[2.5em][r]{%
      {\headfont{\addfontfeature{LetterSpace=\@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{\addfontfeature{LetterSpace=\@looseheadnum}\pagenumberstyle}}}}%
  \if@offcenterTrim%
    \setlength\temp@pgnumraise{%
      \dimexpr\New@BottomMargin+\New@MediaHeight-\New@TrimHeight}%
    \global\temp@pgnumraise=\temp@pgnumraise%
  \else%
    \setlength\temp@pgnumraise{%
      \dimexpr\New@BottomMargin+0.5\New@MediaHeight-0.5\New@TrimHeight}%
    \global\temp@pgnumraise=\temp@pgnumraise%
  \fi%
  %%%%%
  \ifodd\c@page%
    \AddToShipoutPicture*{\@getPageXY\AtPageLowerLeft{%
     \hspace{\dimexpr\Trim@Lx+\New@InsideMargin-0.5\temp@pgnumwidth}%
      \charscale[1,0.5\textwidth,\temp@pgnumraise]{%
       {\headfont{\addfontfeature{LetterSpace=\@looseheadnum}\pagenumberstyle}}}}}%
  \else%
    \AddToShipoutPicture*{\@getPageXY\AtPageLowerLeft{%
     \hspace{\dimexpr\Trim@Lx+\New@OutsideMargin+0.5\textwidth-0.5\temp@pgnumwidth}\raisebox{%
      \temp@pgnumraise}{{\headfont{\addfontfeature{LetterSpace=\@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{\addfontfeature{LetterSpace=\@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%
  \AddToShipoutPicture*{\@getPageXY\AtPageLowerLeft{%
    \ifodd\c@page%
      \hspace{\dimexpr\Trim@Lx+\New@InsideMargin-0.5\temp@pgnumwidth}%
    \else%
      \hspace{\dimexpr\Trim@Lx+\New@OutsideMargin-0.5\temp@pgnumwidth}%
    \fi%
    \charscale[1,0.5\textwidth,\temp@pgnumraise]{%
      {\headfont{\addfontfeature{LetterSpace=\@looseheadnum}\pagenumberstyle}}}%
    }%
  }%
} % 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{#1}
}
\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{#1}
}
\let\SetRectoHeadText\NewRectoHeadText\relax % for convenience
\let\RenewRectoHeadText\NewRectoHeadText\relax % for convenience
%
%%



%
%% End of file `novel-HeadFootStyles.sty'