summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/novel/lualatex/novel-Footnotes.sty
blob: 83aa2558dfcc0e65992314f9e1ace94e35b1385f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
%% This is file `novel-Footnotes.sty', part of `novel' document class.
%% Copyright 2017-2023 Robert Allgeyer.
%%
%% 
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, version 1.3c only.
%%
\ProvidesFile{novel-Footnotes.sty}%
[2023/03/25 v1.81b LaTeX file (commands for footnotes and endnotes)]
%%



%% Markers (superscript, subscripts):
\newtoggle{@usesymbolmark} % true when footnote markers are symbolic
\newtoggle{@realmarker} % true when OT features sups, sinf, subs requested
%


%% superscripts and subscripts
\let\subs\relax
\let\sups\relax
\let\textsuperscript\relax
\let\textsubscript\relax
% Perhaps superscripts and subscripts (scientific) are in the font, or not.
% Problem: The best fonts have these characters at size/weight designed
%   to mingle with normal size. But many fonts merely scaled characters,
%   which will be too light at the small size.
% The unstarred version of these commands use the Open Type features when
%   they are present, then faking (auto scale/raise) if features not present. 
% The starred version just fakes, without regard for features.
% 

% Note that the effect of these commands continues, not just one-shot:
\gdef\realmarker{\global\toggletrue{@realmarker}} % anywhere in text
\gdef\fakemarker{\global\togglefalse{@realmarker}} % anywhere in text
\newlength\@hoAhl % height of Ahl, locally measured and set when needed
%%
\ExplSyntaxOn
%
\DeclareDocumentCommand \sups { m } {%
  \iftoggle{@realmarker}{%
    \fontspec_if_feature:nTF {sups}{%
      \ifvmode\else\unskip\fi%
      {\addfontfeature{VerticalPosition=Superior}\smash{#1}}%
    }{%
      \setlength\@hoAhl{\heightof{Ahl}}% local
      \ifvmode\else\unskip\fi\charscale[0.7,0pt,0.5\@hoAhl]{#1}%
    }%
  }{%
    \setlength\@hoAhl{\heightof{Ahl}}% local
    \ifvmode\else\unskip\fi%
    {\addfontfeature{Numbers=Lining}\charscale[0.7,0pt,0.5\@hoAhl]{#1}}%
  }%
}% end \sups
%
\DeclareDocumentCommand \subs { m } {%
  \iftoggle{@realmarker}{%
    \fontspec_if_feature:nTF {sinf}{%
      \ifvmode\else\unskip\fi%
      {\addfontfeature{VerticalPosition=ScientificInferior}\smash{#1}}%
    }{%
      \fontspec_if_feature:nTF {subs}{%
        \ifvmode\else\unskip\fi%
        {\addfontfeature{VerticalPosition=Inferior}\smash{#1}}%
      }{%
        \setlength\@hoAhl{\heightof{Ahl}}% local
        \ifvmode\else\unskip\fi\charscale[0.7,0pt,-0.2\@hoAhl]{#1}%
      }%
    }%
  }{%
    \setlength\@hoAhl{\heightof{Ahl}}% local
    \ifvmode\else\unskip\fi%
    {\addfontfeature{Numbers=Lining}\charscale[0.7,0pt,-0.2\@hoAhl]{#1}}%
  }%
}% end \subs
%
\cs_new_eq:NN \textsuperscript \sups
\cs_new_eq:NN \textsubscript \subs
\ExplSyntaxOff
%%



% \SetMarkerStyle does two things.
% Option real: OT features sups, sinf, subs requested. Fake if not available.
% Option fake: Always fake OT features sups, sinf, subs.
% Mandatory: asterisk, dagger, number. Pertains to footnote markers only.
% No matter real or fake, the asterisk symbol is always real, and the
%   dagger, dbldagger, and section (when used as footnote markers)
%   are always partially faked.
\newcommand\SetMarkerStyle[2][real]{
  \def\@goodfnm{no}
  \ifthenelse{\equal{#2}{asterisk}}{%
    \def\@goodfnm{yes}\global\toggletrue{@usesymbolmark}%
    \gdef\@myfnsymbols{*}}{}
  \ifthenelse{\equal{#2}{dagger}}{%
    \def\@goodfnm{yes}\global\toggletrue{@usesymbolmark}%
    \gdef\@myfnsymbols{†}}{}
  \ifthenelse{\equal{#2}{number}}{%
    \def\@goodfnm{yes}\global\togglefalse{@usesymbolmark}}{}
  \def\@goodfnk{no}
  \ifthenelse{\equal{#1}{real}\OR\equal{#1}{}}{%
    \def\@goodfnk{yes}\global\toggletrue{@realmarker}}{}
  \ifthenelse{\equal{#1}{fake}}{%
    \def\@goodfnk{yes}\global\togglefalse{@realmarker}}{}
  \ifthenelse{\equal{\@goodfnm}{no}\OR\equal{\@goodfnk}{no}}{%
    \ClassError{novel}{Bad choice for \string\SetMarkers}%
    {Optional: real, fake. Required: asterisk, dagger, number.}%
  }{}
}
\LetLtxMacro{\SetMarkers}{\SetMarkerStyle} % backward compatibilty pre-v1.40.3.
%
\SetMarkerStyle[real]{asterisk} % default
%%



%% FOOTNOTES
%% ----------------------------------------------------------------------------
% In `novel' class, you may place footnotes at the botom of the textblock.
% The markers may be symbolic (default begins with asterisk), or
% set so that the asterisk is not used, or the markers may be numbers,
% If symbolic, they will be automatically reset by ChapterStart.
% You can manually reset them at any time.
% You can also make a non-marked footnote, which does not increment the count.


% Lengths used to tweak vertical position of symbolic (text) footnote markers:
\newlength\@twast % tweaks asterisk
\newlength\@twdag % tweaks dagger
\newlength\@twdbldag % tweaks double dagger
\newlength\@twsect % tweaks section mark
\newlength\@tweight % tweaks 8, reliably the tallest digit


%% footnotesize is calculated by layout, based on normal font size and skip.
%% It is used only for actual footnotes!

%
\newcounter{@fnsymbolcount} % counter, footenote symbolic markers
  \setcounter{@fnsymbolcount}{1}
\newcounter{@fnnumbercount} % counter, footnote numerical markers
  \setcounter{@fnnumbercount}{1}
\newcounter{@rnnumbercount} % counter, endnote markers (always numerical)
  \setcounter{@rnnumbercount}{1}
\newcounter{@maxfnsymbol} % max footnote symbol count before recycle
%
\gdef\ResetFootnote{% symbols or numbers
  \setcounter{@fnsymbolcount}{1}%
  \setcounter{@fnnumbercount}{1}%
}
\gdef\ResetFootnoteSymbol{\setcounter{@fnsymbolcount}{1}} % only symbols
\gdef\Resetendnote{\setcounter{@rnnumbercount}{1}}
%
\newtoggle{@usenomark} % when true: no mark, no increment count
\newtoggle{@placedfootnotenumber} % true if any numerical footnote placed
%
\let\@myoldfootnote\footnote\relax % copies the original definition
\let\footnote\relax % so it can be re-defined, below
%
\gdef\@fourem{% length of rule separating footnotes from main text
  \vspace{-\nbs}%
  \noindent\strut\smash{\rule[-2pt]{0.33\textwidth}{0.05\@SetFontSize}}%
}
\let\footnoterule\@fourem
%


% \@makefnmark applies to the footnote marker in the flow of main text:
\gdef\@makefnmark{\iftoggle{@usenomark}{}{\@getfnmark}}
%
\long\gdef\@makefntext#1{% the actual footnote, at bottom of textblock
  \iftoggle{@usenomark}%
  {\forceindent#1}%
  {\forceindent\@getbotfnmark\,#1}%
} % end \@makefntext
% Now re-define \footnote:
\newcommand\footnote[2][]{%
  \ifthenelse{\equal{#1}{0}}{%
    \global\toggletrue{@usenomark}%
  }{%
    \global\togglefalse{@usenomark}%
  }%
  \gdef\footnoterule{\vfill\@fourem}%
  \begingroup%
  \def\footnotesize{% Not gdef. Local to footnote. Calculated during layout.
    \@setfontsize\footnotesize{\@myfootnotesizeN pt}{\@myfootnoteskipN pt}%
  }%
  \unskip\@myoldfootnote{#2}%
  \endgroup%
} % end \footnote
%
% \@rollfnsymbol prevents running out of symbolic markers:
\gdef\@rollfnsymbol{%
  \stepcounter{@fnsymbolcount}%
  \ifthenelse{\equal{\value{@fnsymbolcount}}{\value{@maxfnsymbol}}}{%
    \setcounter{@fnsymbolcount}{1}%
  }{}%
} % end \@rollfnsymbol
%
% \@getfnmark places a footnote marker in the running text.
% The marker depends upon whether it should be a number or a symbol.
% If the latter, then it depends on whether the symbols include asterisks.
% And, it depends upon the current count for that type of marker.
\gdef\@getfnmark{%
  \iftoggle{@usesymbolmark}%
  {%
    \global\togglefalse{@placedfootnotenumber}%
    \ifthenelse{\equal{\@myfnsymbols}{*}}{%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{1}}{%
        \charscale[1,0pt,-\@twast]{*}%
      }{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{2}}{%
        \charscale[0.8,0pt,-\@twdag]{†}%
      }{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{3}}{%
        \charscale[0.8,0pt,-\@twdbldag]{‡}%
      }{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{4}}{%
        \charscale[0.8,0pt,-\@twsect]{§}%
       }{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{5}}{%
        \charscale[1,0pt,-\@twast]{**}%
      }{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{6}}{%
        \charscale[0.8,0pt,-\@twdag]{††}%
       }{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{7}}{%
        \charscale[0.8,0pt,-\@twdbldag]{‡‡}%
      }{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{8}}{%
        \charscale[0.8,0pt,-\@twsect]{§§}%
      }{}%
    }{}%
    \ifthenelse{\equal{\@myfnsymbols}{†}}{%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{1}}{%
        \charscale[0.8,0pt,-\@twdag]{†}%
      }{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{2}}{%
        \charscale[0.8,0pt,-\@twdbldag]{‡}%
       }{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{3}}{%
        \charscale[0.8,0pt,-\@twsect]{§}%
      }{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{4}}{%
        \charscale[0.8,0pt,-\@twdag]{††}%
      }{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{5}}{%
        \charscale[0.8,0pt,-\@twdbldag]{‡‡}%
      }{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{6}}{%
        \charscale[0.8,0pt,-\@twsect]{§§}%
      }{}%
    }{}%
  }{%
    \global\toggletrue{@placedfootnotenumber}%
    \sups{\arabic{@fnnumbercount}}%
  }%
} % end \@getfnmark
%
% \@getbotfnmark places the marker in front of the actual footnote,
% towards the bottom of the textblock. It duplicates the marker used in
% running text, but is not elevated. Then, it increments the relevant count.
% Note that (unlike some other TeX document classes) this marker is at
% the indent, so that the footnote text is farther inward than the indent.
% This is the preferred style.
\gdef\@getbotfnmark{%
  \iftoggle{@usesymbolmark}%
  {%
    \ifthenelse{\equal{\@myfnsymbols}{*}}{%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{1}}{*}{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{2}}{†}{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{3}}{‡}{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{4}}{§}{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{5}}{**}{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{6}}{††}{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{7}}{‡‡}{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{8}}{§§}{}%
    }{}%
    \ifthenelse{\equal{\@myfnsymbols}{†}}{%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{1}}{†}{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{2}}{‡}{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{3}}{§}{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{4}}{††}{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{5}}{‡‡}{}%
      \ifthenelse{\equal{\value{@fnsymbolcount}}{6}}{§§}{}%
    }{}%
    \@rollfnsymbol%
  }{%
    \textrm{\arabic{@fnnumbercount}.}%
    \stepcounter{@fnnumbercount}%
  }%
} %end \@getbotfnmark
%
%% end footnotes



%% ENDNOTES
%% ----------------------------------------------------------------------------
% \endnote only places a marker. It does not store a note for later use.
% Any argument is non-printing. So \endnote{ancestry of yada} does not print
%   anything other than the endnote marker number, and does not save
%   `ancestry of Yada' for later use. The argument is a self-memo, so that you
%   remember why you want an endnote there, when you look at the source.
% Following \endnote or \endnotetext with [ will produce an error.
%   Reason: Confuses novel's commands with those from banned `endnote' package.
% Whenever \endnote is used, the marker number and page is added to a list,
%   and the list is typed into the log file after the document ends. That way,
%   you can hunt down where the endnotes markers were placed.
\newtoggle{@gotendnotes} % true if \endnote used
%
\long\gdef\@endnotelist{}
\newcounter{@endnotecount}
%
\def\@addendnote{%
  \global\toggletrue{@gotendnotes}%
  \stepcounter{@endnotecount}\sups{\arabic{@endnotecount}}%
  \long\edef\@endnotelist{%
    \@endnotelist\space (\arabic{@endnotecount},p.\thepage)%
  }%
}
\def\@nendnote#1{\@addendnote}
\def\@nenspace{\@addendnote\space}
\def\@nenerror{%
  \ClassError{novel}{\string\endnote\space cannot be followed by [ character}%
   {To avoid possible confusion with similar command from other packages, ^^J%
    you may not follow \string\endnote\space with [ character. ^^J%
    However, you may do \string\endnote\string{\string}[ if desired.}%
}
\def\@ndospace{\@ifnextchar[\@nenerror\@nenspace}
\def\endnote{\@ifnextchar\bgroup\@nendnote\@ndospace}
%%
% \endnotetext{ID}{text} where ID is (usually) the endnote number.
% If ID is other than space or tilde, it prints at left margin, followed by
%   period. Then the entire text is block-indented. Only one paragraph allowed.
% If ID is space or empty, then the entire text is block-indented. This is
%   the method for continuing a prior endnote to a new paragraph. The text
%   may begin with \forceindent, according to your needs.
\def\@nentexterror{%
  \ClassError{novel}{\string\endnotetext\space cannot be followed by [ character}%
   {To avoid possible confusion with similar command from other packages, ^^J%
    you may not follow \string\endnotetext\space with [ character. ^^J%
    This command takes two mandatory arguments. No optional argument.}%
}
%
\newcommand\nentext[2]{%
  \ifthenelse{\equal{#1}{\space}\OR\equal{#1}{}}%
    {\noindent\hangindent=\parindent\flexbox{\space}#2\par}%
    {\noindent\hangindent=\parindent\flexbox{\lnum{#1}. }#2\par}%
}
% In case the user inadvertently uses systax from `endnotes' package:
\def\endnotetext{\@ifnextchar[\@nentexterror\nentext}
%
%% end endnotes


%% See novel.cls for the accompanying \AtBeginDocument routine.


%% Pertains to some standard LaTeX footnote code:
\AtBeginShipout{\gdef\@fnafter{}}
%%


\gdef\@ActivateFootnotes{% called by `novel.cls' \AtBeginDocument
  % Pertains to novel-footnotes.sty:
  \LetLtxMacro\SetMarkerStyle\relax
  \gsetlength\footnotesep{0.8\nbs}
  % Adjusted position of footnote markers. Must wait for main font size:
  \gsetlength\@twast{\heightof{*}-\normalAringheight}
  \gsetlength\@twdag{\heightof{†}}
  \gsetlength\@twdag{0.8\@twdag-\normalAringheight}
  \gsetlength\@twdbldag{\heightof{‡}}
  \gsetlength\@twdbldag{0.8\@twdbldag-\normalAringheight}
  \gsetlength\@twsect{\heightof{§}}
  \gsetlength\@twsect{0.8\@twsect-\normalAringheight}
  \gsetlength\@tweight{\heightof{8}}%
  \gsetlength\@tweight{0.8\@tweight-\normalAringheight}%
  % Must wait to see how \SetFootnoteMarker was used:
  \ifthenelse{\equal{\@myfnsymbols}{*}}{\setcounter{@maxfnsymbol}{8}}{}
  \ifthenelse{\equal{\@myfnsymbols}{†}}{\setcounter{@maxfnsymbol}{6}}{}
  % Values to be used by footnotes:
  \FPdiv{\@myFontScale}{\strip@pt\@SetFontSize}{12}
  % Substitute for \footnotesize, but only works for actual footnotes,
  %   about 10pt with similarly reduced skip:
  \FPmul{\@myfootnotesizeN}{\@myFontScale}{10}
  \FPround{\@myfootnotesizeN}{\@myfootnotesizeN}{2}
  \FPmul{\@myfootnoteskipN}{\@myFontScale}{\strip@pt\nbs}
  \FPmul{\@myfootnoteskipN}{\@myfootnoteskipN}{0.84}
  \FPround{\@myfootnoteskipN}{\@myfootnoteskipN}{2}
}% end \@ActivateFootnotes






%% ATENDDOCUMENT
%% ----------------------------------------------------------------------------
%% Write a list of endnote (number,page) into log file,
% and Big Bad Warning if numerical footnotes and endnotes both used:
\AtEndDocument{%
  \iftoggle{@gotendnotes}{%
    \typeout{^^JClass `novel' Alert: You placed endnotes (number,page): ^^J%
     \@endnotelist ^^J}%
  }{}
  %
  \iftoggle{@placedfootnotenumber}{%
    \iftoggle{@gotendnotes}{%
      \ClassWarning{novel}{^^JBIG BAD WARNING! You used numbered footnotes ^^J%
        and numbered endnotes. Better change to symbolic footnotes! ^^J}%
    }{}
  }{}%
}% end \AtEndDocument
%%


%%
\endinput
%%
%% end of file `novel-Footnotes.sty'