summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/novel/novel-Footnotes.sty
blob: 7398356ff8fa18d817a31d09bbe956bf23b2e06f (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
%%
%% This is file `novel-Footnotes.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-Footnotes.sty}%
[2017/07/26 v1.32 LaTeX file (commands for footnotes and endnotes)]
%%


%% 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.



%% 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\my@oldfootnote\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\normalFontSize}}
}
\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{\@fourem}%
  \begingroup%
  \def\footnotesize{% Not gdef. Only here in footnote. Calculated during layout.
    \@setfontsize\footnotesize{\@myfootnotesizenum pt}{\@myfootnoteskipnum pt}%
  }%
  \unskip\my@oldfootnote{#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.
% The \memo{} command is helpful, to make a non-printing note to yourself.
% 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 when \endnote used
%
\long\gdef\@endnotelist{}
\newcounter{@endnotecount}
%
\DeclareDocumentCommand \endnote { }
{%
\global\toggletrue{@gotendnotes}%
\stepcounter{@endnotecount}\sups{\arabic{@endnotecount}}%
\long\edef\@endnotelist{\@endnotelist\space (\arabic{@endnotecount},p.\thepage)}%
}
%%
% \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.
\DeclareDocumentCommand \endnotetext { m +m }% xparse allows \end... commands!
{
  \ifthenelse{\equal{#1}{\space}\OR\equal{#1}{}}%
    {\noindent\hangindent=\parindent\flexbox{\space}#2\par}%
    {\noindent\hangindent=\parindent\flexbox{#1.}#2\par}%
}
%% end endnotes



%% ATBEGINDOCUMENT
%% -----------------------------------------------------------------------------
%%
\AtBeginDocument{
  \gdef\SetFootnoteMarker#1{%
    \typeout{^^JClass `novel' Alert: %
    \string\SetFootnoteMarker\space ineffective after Preamble.^^J}%
  }
  % Must wait for \nbs to be calculated:
  \setlength\footnotesep{0.8\nbs}
  % Must wait for main font and its size to be active:
  \newlength\@hoaring
  \setlength\@hoaring{\heightof{Å}}
  \global\@hoaring=\@hoaring
  \newlength\@twast % tweaks asterisk
  \setlength\@twast{\heightof{*}}
  \addtolength\@twast{-\@hoaring}
  \global\@twast=\@twast
  \newlength\@twdag % tweaks dagger
  \setlength\@twdag{\heightof{†}}
  \addtolength\@twdag{-0.2\@twdag}
  \addtolength\@twdag{-\@hoaring}
  \global\@twdag=\@twdag
  \newlength\@twdbldag % tweaks double dagger
  \setlength\@twdbldag{\heightof{‡}}
  \addtolength\@twdbldag{-0.2\@twdbldag}
  \addtolength\@twdbldag{-\@hoaring}
  \global\@twdbldag=\@twdbldag
  \newlength\@twsect % tweaks section mark
  \setlength\@twsect{\heightof{§}}
  \addtolength\@twsect{-0.2\@twsect}
  \addtolength\@twsect{-\@hoaring}
  \global\@twsect=\@twsect
  \newlength\@tweight % tweaks 8, reliably the tallest digit
  \setlength\@tweight{\heightof{8}}%
  \addtolength\@tweight{-0.2\@tweight}%
  \addtolength\@tweight{-\@hoaring}%
  \global\@tweight=\@tweight%
  % Must wait to see how \SetFootnoteMarker was used:
  \ifthenelse{\equal{\@myfnsymbols}{*}}{\setcounter{@maxfnsymbol}{8}}{}
  \ifthenelse{\equal{\@myfnsymbols}{†}}{\setcounter{@maxfnsymbol}{6}}{}
  %
} % end \AtBeginDocument
%%


%% 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{^^J^^JClass `novel' Alert: You placed endnotes (number,page):^^J%
    \@endnotelist%
    ^^J^^J}%
    }{}
  %
  \iftoggle{@placedfootnotenumber}%
    {\iftoggle{@gotendnotes}%
      {\typeout{^^JClass `novel' BIG BAD WARNING:^^J%
        Numbered footnotes and endnotes! Better use symbolic footnotes!^^J^^J}%
      }{}%
    }{}%
}% end \AtEndDocument
%%


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