Debian Codegraph @

texmf-dist/source/latex/ncctools/manyfoot.dtx

raw
1 % \iffalse
2 %%
3 %% File: manyfoot.dtx Copyright (C) 1998--2005 by Alexander I. Rozhenko
4 %%
5 %<package>\NeedsTeXFormat{LaTeX2e}[1993/12/01]
6 %<package>\ProvidesPackage{manyfoot}
7 %<package> [2019/08/03 v1.11 Many Footnote Levels Package (NCC)]
8 %
9 % \changes{v1.0}{1998/11/09}{Initial version}
10 % \changes{v1.1}{1998/11/13}{Compatibility problems solved}
11 % \changes{v1.2}{1998/11/15}{Such footnotes may now appear in minipages!}
12 % \changes{v1.3}{1998/11/23}{Floating support bug fixed}
13 % \changes{v1.4}{1998/12/19}{Hand footnotes are moved to nccfoots package}
14 % \changes{v1.4}{1998/12/19}{Options |ruled| and |para*| added}
15 % \changes{v1.5}{2003/02/26}{|\DeclareNewFootnote| command introduced}
16 % \changes{v1.5}{2003/02/26}{Compatibility with footmisc added}
17 % \changes{v1.5}{2003/02/27}{More compatibility with footmisc}
18 % \changes{v1.5}{2003/03/03}{|\Footnote|\marg{suffix} and
19 % |\Footnotemark|\marg{suffix} added}
20 % \changes{v1.5}{2003/03/16}{Option |perpage| added}
21 % \changes{v1.5}{2003/03/26}{The |\MFL@footnoterule| introduced
22 % for more compatibility with footmisc}
23 % \changes{v1.5}{2003/04/02}{Custom footnote rules support added}
24 % \changes{v1.6}{2003/05/11}{Restore |\footnotemargin| support occasionally removed}
25 % \changes{v1.6}{2003/05/12}{Add support for |multiple| option from footmisc}
26 % \changes{v1.7}{2004/09/20}{The |\ExtraParaSkip| command introduced}
27 % \changes{v1.8}{2004/11/23}{Minor corrections of the documentation}
28 % \changes{v1.9}{2005/02/10}{|\NCC@makemark| replaced with |\NCC@makefnmark|}
29 % \changes{v1.9}{2005/05/11}{Introduce the |\SetFootnoteHook| command}
30 % \changes{v1.10}{2005/09/11}{Remove overflow in calculation the fudge factor}
31 % \changes{v1.11}{2019/08/03}{Fix compatibility issues with multicol}
32 %
33 %<*driver>
34 \let\makeindex\relax
35 \documentclass{ltxdoc}
36 \usepackage[para]{manyfoot}
37 \DeclareNewFootnote{A}
38 \DeclareNewFootnote[para]{B}[roman]
39 \GetFileInfo{manyfoot.sty}
40 \begin{document}
41 \title{The \textsf{manyfoot} package\thanks{This file
42 has version number \fileversion, last
43 revised \filedate.}}
44 \author{Alexander I. Rozhenko\\[email protected]}
45 \date{\filedate}
46 \maketitle
47 \DocInput{manyfoot.dtx}
48 \end{document}
49 %</driver>
50 % \fi
51 %
52 % This package implements a command, |\newfootnote|, that adds
53 % footnote levels to the standard \LaTeX's footnote mechanism. Footnotes
54 % of every additional level are automatically grouped together
55 % on a \LaTeXe{} output page and are separated from another levels
56 % by the special vertical space and rule.
57 % The |\newfootnote| command allows customization of the
58 % way footnotes of additional level are represented in \LaTeXe{}
59 % documents. Two
60 % customization styles are available now: the |plain| style is the
61 % ordinary \LaTeX's style of footnote representation; the |para| style
62 % causes footnotes to be typeset as a run-in paragraph (derived from
63 % Donald Knuth's \TeX book and from another sources such as the package
64 % |fnpara| by Dominik Wujastyk and Chris Rowley and the package
65 % |footmisc| by Robin Fairbairns).
66 %
67 % An additional |\DeclareNewFootnote| command is introduced since the
68 % version~1.5 of the package. It simplifies creation of new
69 % footnote levels with automatic enumeration. Thanks to Frank Mittelbach
70 % for this suggestion and for many other proposals for the package
71 % improvement.
72 %
73 % Since version 1.5, a new footnote rule selection method is
74 % introduced (thanks to Christian Tapp |<[email protected]>|
75 % for the idea of this improvement). It allows a customization of
76 % footnote rules to be inserted before footnote levels.
77 %
78 % \tableofcontents
79 %
80 % \section{User Interface}
81 %
82 % \DescribeMacro\extrafootnoterule
83 % Footnotes of different levels are separated at the output page
84 % by the special footnote rule, |\extrafootnoterule|.
85 % By the default this command is empty. If you want to separate
86 % footnotes by a footnote rule you may redefine it
87 % or call the package with the |ruled| option:
88 % \begin{quote}
89 % |\usepackage[ruled]{manyfoot}|
90 % \end{quote}
91 % In this case, the |\extrafootnoterule| receives a value of the
92 % default footnote rule command.
93 %
94 % \DescribeMacro\defaultfootnoterule
95 % The default footnote rule is saved in the |\defaultfootnoterule| command
96 % at the beginning of document (we provide this for compatibility with
97 % the |splitrule| option of the \textbf{footmisc} package).
98 %
99 % The style |para| of footnotes typesetting needs many code. To save
100 % space, the support for this style is loaded with |para| or |para*| options.
101 % If you are going to use run-in paragraph footnotes indented as
102 % ordinary footnotes, use the package with the
103 % |para| option:
104 % \begin{quote}
105 % |\usepackage[para]{manyfoot}|
106 % \end{quote}
107 % To suppress indentation, use it with the |para*| option:
108 % \begin{quote}
109 % |\usepackage[para*]{manyfoot}|
110 % \end{quote}
111 % Note, that these options only \emph{allow} you to generate
112 % additional footnote levels in |para| style.
113 % But what style you prefer for every footnote level is up to you. For
114 % example, let as generate two footnote levels: the first---in ordinary
115 % style and the second---in |para| style. To do this we have to write
116 % the following code in the preamble of the document:
117 % \begin{quote}
118 % |\usepackage[para]{manyfoot}|\\
119 % |\newfootnote{A}|\\
120 % |\newfootnote[para]{B}|
121 % \end{quote}
122 % \DescribeMacro\newfootnote
123 % The mandatory parameter of |\newfootnote| is a \emph{suffix} to be added
124 % to the end of command names generated by |\newfootnote| command.
125 % The optional parameter is a customization
126 % style for generated footnote level (two styles now implemented, named
127 % |plain| and |para|; the default is |plain|).
128 %
129 % This example generates
130 % two commands, |\FootnotetextA| and |\FootnotetextB|, for insertion of
131 % a text into corresponding footnote levels. Their syntax
132 % is the following:
133 % \begin{quote}
134 % |\Footnotetext|\meta{suffix}\marg{marker}\marg{inserted
135 % text}
136 % \end{quote}
137 % They put the \meta{inserted text} marked with \meta{marker} into
138 % \TeX's insert register |\footins|\meta{suffix} (this insert is also
139 % generated by |\newfootnote| command). We use \emph{the hand} style of
140 % footnote marking, because the choice of how such footnotes have to be
141 % marked is user's one. Such a way simplifies the syntax of new commands
142 % and minimize a number of additional commands needed.
143 %
144 % \DescribeMacro\Footnotemark
145 % \DescribeMacro\Footnotetext
146 % \DescribeMacro\Footnote
147 % It is clear that accompany to |\Footnotetext|\meta{suffix} must
148 % present something like \emph{the hand footnote mark} command. Such
149 % commands are provided by |nccfoots| package which is automatically
150 % loaded in this package. Their syntax is the following:
151 % \begin{quote}
152 % |\Footnotemark|\marg{marker}\\
153 % |\Footnotetext|\marg{marker}\marg{inserted text}\\
154 % |\Footnote|\marg{marker}\marg{inserted text}
155 % \end{quote}
156 % The first command is useful for all footnote levels. Two last commands
157 % are the hand companions for \LaTeX's |\footnote...| commands.
158 %
159 % The question is what these commands have to do when \meta{marker} is
160 % empty? In such a case we leave the current marker unchanged.
161 % Therefore, |\Footnote| command is equal to
162 % \begin{quote}
163 % |\Footnotemark|\marg{marker}|\Footnotetext{}|\marg{inserted text}
164 % \end{quote}
165 % This is useful for |\Footnotetext|\meta{suffix} commands in
166 % |plain| style. For |para| style the empty \meta{marker} means
167 % the footnote without marker (this is the special case used for
168 % splitting long footnotes in |para| style; see below).
169 %
170 % Finally, we explain\footnoteA{This is the first A-level footnote.}
171 % on the previous example\footnoteB{This is the first B-level
172 % footnote.} how to automate\footnoteA{The second
173 % A-footnote.} enumeration of the
174 % additional\footnoteB{The second B-footnote.}
175 % footnote\footnoteA{The third A-footnote.}
176 % levels\footnoteB{The third very very very very very very very very very
177 % long B-footnote.} (we have used in this
178 % sentence a number of level's |A| and |B| footnotes to show how this
179 % package works). Let us enumerate the footnotes of |A|~level by arabic
180 % numbers and the footnotes of |B|~level by roman numbers. We allocate
181 % two new counters named |footnoteA| and |footnoteB| and define the
182 % corresponding |\footnote...| commands with automatic enumeration. The
183 % corresponding code is the following
184 % \begin{quote}
185 % |\newcounter{footnoteA}|\\
186 % |\newcommand{\footnoteA}{%|\\
187 % | \stepcounter{footnoteA}%|\\
188 % | \Footnotemark\thefootnoteA \FootnotetextA{}}|\\
189 % |\newcounter{footnoteB}|\\
190 % |\newcommand{\footnoteB}{%|\\
191 % | \stepcounter{footnoteB}%|\\
192 % | \Footnotemark\thefootnoteB \FootnotetextB\thefootnoteB}|\\
193 % |\renewcommand{\thefootnoteB}{\roman{footnoteB}}|
194 % \end{quote}
195 % To produce footnotes presented here, we have done the following
196 % \begin{verbatim}
197 % Finally, we explain\footnoteA{This is the first A-level
198 % footnote.} on the previous example\footnoteB{This is the first
199 % B-level footnote.} how to automate\footnoteA{The second
200 % A-footnote.} enumeration of the additional\footnoteB{The second
201 % B-footnote.} footnote\footnoteA{The third A-footnote.}
202 % levels\footnoteB{The third very very very very very very very
203 % very very long B-footnote.}\end{verbatim}
204 %
205 % \section{Declaring New Footnotes}
206 %
207 % \DescribeMacro\DeclareNewFootnote
208 % To create a new footnote level with automate enumeration, you need to
209 % type a bulk of code: create a new footnote level (e.g.~|\newfootnote{A}|),
210 % create a counter for automate enumeration (e.g.~|\newcounter{footnoteA}|),
211 % and create a footnote insertion command (e.g.~|\newcommand{\footnoteA}|).
212 % All these things can be automated with the |\DeclareNewFootnote| command
213 % used in the preamble only:
214 % \begin{quote}
215 % |\DeclareNewFootnote|\oarg{footnote style}\marg{suffix}\oarg{enumeration style}
216 % \end{quote}
217 % Here \meta{footnote style} is the customization style (|plain| is default) and
218 % \meta{enumeration style} is a style of numbering. This macro
219 % also prepares |\footnotemark|\meta{suffix}, |\footnotetext|\meta{suffix},
220 % |\Footnotemark|\meta{suffix}, and |\Footnote|\meta{suffix} commands for
221 % completeness.
222 % For example, the command |\DeclareNewFootnote{A}| creates the following:
223 % \begin{itemize}
224 % \item The new plain footnote level with \TeX's insert register |\footinsA|;
225 % \item The counter |footnoteA| with arabic numbering;
226 % \item The command |\FootnoteA|\marg{marker}\marg{inserted text};
227 % \item The command |\FootnotemarkA|\marg{marker};
228 % \item The command |\FootnotetextA|\marg{marker}\marg{inserted text};
229 % \item The command |\footnoteA|\oarg{number}\marg{inserted text};
230 % \item The command |\footnotemarkA|\oarg{number}; and
231 % \item The command |\footnotetextA|\oarg{number}\marg{inserted text}.
232 % \end{itemize}
233 % The first three |\Footnote...| commands work as their analogues without
234 % suffix, and the behavior of three last commands is just the same as for
235 % ordinary |\footnote|, |\footnotemark|, and |\footnotetext|.
236 % Examples of footnote controls shown in the previous section can be easy
237 % specified in the following two lines:
238 % \begin{quote}
239 % |\DeclareNewFootnote{A}|\\
240 % |\DeclareNewFootnote[para]{B}[roman]|
241 % \end{quote}
242 %
243 % \section{Custom Footnote Rules}
244 %
245 % \DescribeMacro\SelectFootnoteRule
246 % A custom footnote rule can be specified for every new footnote level.
247 % Just store the |\SelectFootnoteRule| command before a new footnote
248 % declaration. Its syntax is the following:
249 % \begin{quote}
250 % |\SelectFootnoteRule|\oarg{priority}\marg{rule name}\oarg{action}
251 % \end{quote}
252 % The \meta{priority} is a nonnegative integer number specifying an importance
253 % of the rule. It controls the process of a footnote rule selection while
254 % typeset (see more detail description below). The default priority is 0.
255 % The \meta{rule name} is a prefix of the footnote rule command to be used
256 % before the next footnote level. The command |\|\meta{rule name}|footnoterule|
257 % is used as a footnote rule. The \meta{action} parameter specifies an
258 % additional action to be applied just before the next footnote group if it
259 % is nonempty (for example, an action can produce a marginal mark near the
260 % footnote group). The default action is empty. A footnote rule and
261 % an action must insert a material of zero height in vertical mode.
262 %
263 % Two footnote rule commands are predefined:
264 % |\extrafootnoterule| and |\defaultfootnoterule|. The |\extrafootnoterule|
265 % is selected with zero priority before a new footnote level if no other
266 % footnote rule was selected with the |\SelectFootnoteRule| command. The
267 % |\defaultfootnoterule| is usually equal to the |\footnoterule|, but if
268 % the |\footnoterule| was redefined in the \textbf{footmisc} package with
269 % the |splitrule| option, the |\defaultfootnoterule| will save the
270 % original value of the footnote rule. So, if you want to select an ordinary
271 % footnote rule for the next footnote level, use the following command
272 % \begin{quote}
273 % |\SelectFootnoteRule{default}|
274 % \end{quote}
275 % The following example create four footnote levels with rule inserted between
276 % footnotes A,B and C,D:
277 % \begin{quote}
278 % |\DeclareNewFootnote{A}|\\
279 % |\DeclareNewFootnote[para]{B}[alph]|\\
280 % |\SelectFootnoteRule[1]{default}|\\
281 % |\DeclareNewFootnote{C}[roman]|\\
282 % |\DeclareNewFootnote{D}[Roman]|
283 % \end{quote}
284 % To use more custom footnote rules, you must create corresponding commands
285 % in some way.
286 %
287 % The algorithm of footnote rule insertion while a page output is the following:
288 % \begin{itemize}
289 % \item At first, we set the |\defaultfootnoterule| to be the current rule.
290 % Then we test the insert register of the standard footnote group.
291 % If it is empty, we set the priority of current rule to |1|,
292 % otherwise to |-1| (|-1| means that this rule is already played).
293 % \item After that, we do the following for every next footnote group.
294 % We compare the priority of current rule and the priority of rule
295 % linked with the next footnote group. If the current priority is less
296 % or equal to the next priority, the current rule is changed to the
297 % next rule and the current priority is set to the next priority.
298 % Then we test an insert register of the next footnote group.
299 % If this footnote group is nonempty, we insert the current rule
300 % before it and decrease the current priority to |-1| (played rule).
301 % \end{itemize}
302 %
303 % \DescribeMacro\footnoterulepriority
304 % The priority for the rule of standard footnote group is specified
305 % in the |\footnoterulepriority| command. Its default value is |1| (this means that
306 % the standard footnote rule is more important then every next rule of 0th priority).
307 % You can redefine this priority with the |\renewcommand|.
308 %
309 % \section{Add Hooks at the Beginning of Footnotes}
310 %
311 % \DescribeMacro\SetFootnoteHook
312 % Since version 1.9, a new command |\SetFootnoteHook|\marg{text} is introduced.
313 % This command is used before a new footnote declaration and specifies
314 % an action applied for such footnotes.
315 %
316 % If the new footnote level is plain, the hook is applied at the beginning of
317 % every its footnote. For example, the following declaration specifies
318 % A-footnotes with hang numbering:
319 % \begin{quote}
320 % |\SetFootnoteHook{\hangindent=1.8em\noindent}|\\
321 % |\DeclareNewFootnote{A}|
322 % \end{quote}
323 %
324 % For para-footnotes, the hook is applied in the output routine after
325 % merging all para-footnotes together. The following declaration specified
326 % B-footnotes starting with the word ``Cases:'' typeset in boldface:
327 % \begin{quote}
328 % |\SetFootnoteHook{\noindent\textbf{Cases:}\quad}|\\
329 % |\DeclareNewFootnote[para]{B}[alph]|\\
330 % \end{quote}
331 %
332 % \section{Per-page Footnotes Numbering}
333 %
334 % The per-page resetting of counters can be implemented with the |perpage|
335 % package by David Kastrup. For example, if you need to
336 % reset the |footnoteA| counter every page, just insert the following
337 % in the preamble of you document (after declaring the footnote level A of course):
338 % \begin{quote}
339 % |\usepackage{perpage}|\\
340 % |\MakePerPage{footnoteA}|
341 % \end{quote}
342 % If all new footnote levels declared with the |\DeclareNewFootnote| command
343 % must reset every page, use the |perpage| option:
344 % \begin{quote}
345 % |\usepackage[perpage]{manyfoot}|
346 % \end{quote}
347 % In this case, the |perpage| package is loaded automatically and the
348 % |\MakePerPage| command is applied to every counter created with the
349 % |\DeclareNewFootnote|.
350 %
351 % \section{Splitting of Para-Footnotes}
352 %
353 % The algorithm proposed by Donald Knuth for processing run-in
354 % paragraph footnotes has some shortages. Namely, small overfulls of
355 % output page frequently arise and the automatical splitting of long
356 % footnotes is impossible. First bug is corrected here (look at the
357 % implementation section below), but the second one couldn't be easily
358 % eliminated.
359 %
360 % \DescribeMacro\SplitNote
361 % To split a long footnote near the end of the output page we propose
362 % the following method. You should decide where the splitting have to be
363 % done. Then you split footnote ``by hands" into two parts. You leave
364 % \emph{the first part} at the same position in the text and complete its
365 % text by the command |\SplitNote|. You move \emph{the second part} down
366 % in the source file and attach it to any text corresponding to the next
367 % page via the |\Footnotetext...| command with \emph{the empty marker}.
368 % E.g. you source text will look as follows:
369 % \begin{verbatim}
370 % This text goes on the current
371 % page\footnoteB{This is the beginning of the long
372 % footnote ... the splitting must be here\SplitNote}
373 % ...
374 % This text goes on the next
375 % page\FootnotetextB{}{and the end of the split
376 % footnote is here ...}\end{verbatim}
377 % If both parts of split footnote get into the same output page, the
378 % splitting is ignored.
379 %
380 % \section{Footnotes within Minipages and Multicolumns}
381 %
382 % If you attach an additional level footnote to some text inside a
383 % minipage, it will appear at the bottom of the page nor the minipage.
384 %
385 % The package correctly works together with |multicol| package and
386 % gives good results when switching between one and two columns by
387 % \LaTeX's commands |\twocolumn| and |\onecolumn|.
388 %
389 % \section{Compatibility with footmisc}
390 %
391 % The |footmisc| package also provides the |para| option. You cannot
392 % use this option with |footmisc| if you plan to use it (or |para*|)
393 % with |manyfoot|.
394 %
395 % The footnote margins management from the |footmisc| package acts on the
396 % |manyfoot| also, but with some limitations concerning to footnotes
397 % in the |para| style:
398 % \begin{itemize}
399 % \item If the |manyfoot| package is loaded with the |para*| option,
400 % the margin management options of the |footmisc| package have no
401 % influence on additional footnotes of |manyfoot| in |para| style.
402 % \item If the |manyfoot| package is loaded with the |para| option,
403 % the margin management options |flushmargin| and |hang| of the
404 % |footmisc| package appropriately change the indentation of |para|
405 % footnotes created with the |manyfoot| package. More exactly, a
406 % nonnegative value of the |\footnotemargin| is taken into
407 % account in this case. But if a width of the starting footnote
408 % marker becomes greater than |0.8em|, the hang indentation of such
409 % footnote will exceed the value of |\footnotemargin|.
410 % \end{itemize}
411 % Footnotes having the |plain| style inherit all
412 % formatting specified in the |footmisc|, because they use the
413 % standard |\@makefntext| hook.
414 %
415 % \section{Add Extra Skip for Para-Footnotes}
416 %
417 % The algorithm used for calculation the vertical space occupied
418 % with para-footnotes has one serious disadvantage. It cannot exactly
419 % calculate how many vertical space the collected para-footnotes will
420 % occupy because the formatting of such footnotes in vertical box is
421 % applied in the output routine \textit{after} \TeX\ decides on page
422 % breaking. For example, if collected para-footnotes occupy 2.25 lines,
423 % the algorithm reserves the vertical space of |2.25\normalbaselineskip|
424 % for them, but when such footnotes will be formatted in vbox, 3 lines
425 % will be necessary of course. This is the reason why the use of
426 % para-footnotes can lead to page overfull. To compensate this
427 % overfull we use a special trick: we add a special space to
428 % a value of skip for all insert registers taking part with
429 % para-inserts.
430 % When the insertions are formatted in the output routine, the
431 % adjusted space is turned back. So, the additional space appears
432 % and the overfull disappears.
433 %
434 % The value of space to be adjusted is calculated as follows:
435 % \begin{center}
436 % |max(\footnotesep-\height\strut,0)+0.5\normalbaselineskip|
437 % \end{center}
438 % We take into account here that the
439 % value of |\footnotesep| can be larger than the height of |\strut|
440 % and the total height of para-footnotes is less than the required
441 % height by |0.5\baselineskip| on the average.
442 %
443 % \DescribeMacro\ExtraParaSkip
444 % Sometimes, the assumptions on the required extra space are wrong
445 % and footnotes can overlap on the text (this situation can occur
446 % in long tables). So, the new command, |\ExtraParaSkip|\marg{space},
447 % was introduced since version 1.7 (by the proposal of Uwe L\"uck
448 % |<[email protected]>| and Florian Kragl |<[email protected]>|)
449 % to adjust the default extra space.
450 % The command can be used in the preamble only.
451 % It can be used more than once. The later use of the command
452 % overrides the previous one.
453 %
454 % \StopEventually{}
455 %
456 % \section{The Implementation}
457 %
458 % First we load |nccfoots| package, containing hand footnote mark
459 % commands and the command |\NCC@makefnmark|\marg{marker} which
460 % generates marker in |\@thefnmark| command.
461 % \begin{macrocode}
462 %<*package>
463 \RequirePackage{nccfoots}
464 % \end{macrocode}
465 %
466 % \begin{macro}{\extrafootnoterule}
467 % Then we define the empty |\extrafootnoterule| command and implement |ruled|
468 % option that sets the |\extrafootnoterule| to be equal to the
469 % |\defaultfootnoterule|. The |\defaulfootnoterule| is later defined
470 % at the beginning
471 % of document. It is set to the |\pagefootnoterule| if the last is specified
472 % or to the |\footnoterule| if not.
473 % This trick provides the compatibility with the |splitrule| option of the
474 % \textbf{footmisc} package in which the default |\footnoterule| is saved
475 % in |\pagefootnoterule| and then redefined.
476 % \begin{macrocode}
477 \newcommand{\extrafootnoterule}{}
478 \DeclareOption{ruled}{\def\extrafootnoterule{\defaultfootnoterule}}
479 % \end{macrocode}
480 % \end{macro}
481 %
482 % \begin{macro}{\MFL@columnwidth}
483 % \begin{macro}{\MFL@floathook}
484 % We use the dimen |\MFL@columnwidth| instead of |\columnwidth| while
485 % producing the footnote for insertion. We set this dimen to be equal
486 % to |\columnwidth| at the beginning of document and within the
487 % |\@floatplacement| command. The command |\MFL@floathook| does this
488 % job. Later, in |para| option, we'll add to this hook the resetting of
489 % the fudge factor.
490 % \begin{macrocode}
491 \newdimen\MFL@columnwidth
492 \def\MFL@floathook{\MFL@columnwidth\columnwidth}
493 % \end{macrocode}
494 % \end{macro}
495 % \end{macro}
496 %
497 % \begin{macro}{\MFL@insert}
498 % The command |\MFL@insert|\marg{insert register}\marg{text}
499 % inserts the text to the insert register and sets the standard
500 % splitting parameters. We let this command to be equal |\MFL@mpinsert|
501 % when go into a minipage. To use this command after a minipage we save
502 % its value in |\MFL@realinsert| command.
503 % To support |multiple| option from |footmisc| we add the
504 % |\FN@mf@prepare| command from |footmisc| (suggested by Frank Mittelbach).
505 % \begin{macrocode}
506 \long\def\MFL@insert#1#2{%
507 \insert#1{\splittopskip\footnotesep \splitmaxdepth \dp\strutbox
508 \floatingpenalty\@MM #2%
509 }%
510 \FN@mf@prepare
511 }
512 \providecommand\FN@mf@prepare{}
513 \let\MFL@realinsert\MFL@insert
514 % \end{macrocode}
515 % \end{macro}
516 %
517 % \begin{macro}{\MFL@applyhook}
518 % The command |\MFL@applyhook|\marg{insert register} applies a hook
519 % corresponding to the given insert register.
520 % \begin{macrocode}
521 \def\MFL@applyhook#1{\csname MFL@hook\string#1\endcsname}
522 % \end{macrocode}
523 % \end{macro}
524 %
525 % \subsection{Footnote Styles Support}
526 %
527 % \DescribeMacro{\MFL@start...}
528 % Every additional footnote level has deal with its own
529 % \emph{insert register}
530 % which is allocated by the |\newfootnote| command. This insert register is
531 % automatically initialized with the same values as the |\footins|
532 % register. You can modify its parameters and do something more in
533 % the command
534 % \begin{quote}
535 % |\MFL@start|\meta{style}\marg{insert register}
536 % \end{quote}
537 % You must do all modifications globally, because this command is called
538 % within the group. It is called at the beginning of the document for
539 % every
540 % footnote of such style and is needed in the preamble only.
541 %
542 % \DescribeMacro{\MFL@fnote...}
543 % To put footnote into the insert register the command
544 % \begin{quote}
545 % |\MFL@fnote|\meta{style}\marg{insert
546 % register}\marg{marker}\marg{inserted text}
547 % \end{quote}
548 % is used. Note that you have to define it with |\long| modifier if you
549 % allow footnotes consisting of a number of paragraphs. You have to use
550 % the macros |\MFL@insert| and |\MFL@columnwidth| instead of |\insert|
551 % and |\columnwidth|.
552 %
553 % \DescribeMacro{\MFL@process...}
554 % And the last style customization command
555 % \begin{quote}
556 % |\MFL@process|\meta{style}\marg{insert register}
557 % \end{quote}
558 % is called within the output routine to prepare the box of the
559 % \meta{insert register} for joining it with another footnote inserts.
560 %
561 % Do some comments on joining algorithm. It joins together all nonempty
562 % footnote insert boxes and puts the result into |\footins| box. Special
563 % vertical space and footnote rule are added between every
564 % two neighboring nonempty inserts. This space
565 % is defined by the skip value from the second neighbor. In other words the skip
566 % of the \meta{insert register} is the vertical space to be added
567 % between
568 % this insert and any nonempty footnote insert coming before it in the
569 % \emph{list of footnote inserts}. Note that this skip can be
570 % modified while processing of the document (the |multicol| package
571 % multiplies |\skip| and |\count| of |\footins| to the number of columns
572 % when goes into multicolumns mode; we do the same with these parameters
573 % of all another footnote inserts to provide the compatibility with
574 % |multicol| package).
575 %
576 % \DescribeMacro{\MFL@skip}
577 % This command adds the vertical space just before the
578 % |\MFL@process...| command. The value of this space is also calculated
579 % in |\@tempskipa|. Note that this command is inserted
580 % \emph{between} vertical boxes in joining procedure. If processed box
581 % is the first nonempty footnote box (|\footins| register and all
582 % registers going in footins list before the processed insert are
583 % empty), the command |\MFL@skip| is ignored.
584 %
585 % \subsection{Plain Footnote Style}
586 %
587 % \begin{macro}{\MFL@startplain}
588 % \begin{macro}{\MFL@fnoteplain}
589 % \begin{macro}{\MFL@processplain}
590 % It is very simple. The commands
591 % |\MFL@startplain| and |\MFL@processplain| do nothing
592 % \begin{macrocode}
593 \let\MFL@startplain\@gobble
594 \@onlypreamble\MFL@startplain
595 \let\MFL@processplain\@gobble
596 % \end{macrocode}
597 % and the command |\MFL@fnoteplain| does near the same as the usual
598 % \@footnotetext command.
599 % \begin{macrocode}
600 \long\def\MFL@fnoteplain#1#2#3{\NCC@makefnmark{#2}%
601 \MFL@insert#1{\reset@font\footnotesize
602 \interlinepenalty\interfootnotelinepenalty
603 \hsize\MFL@columnwidth \@parboxrestore
604 \protected@edef\@currentlabel{\@thefnmark}%
605 \color@begingroup
606 \MFL@applyhook{#1}%
607 \@makefntext{%
608 \rule\z@\footnotesep\ignorespaces#3\@finalstrut\strutbox}%
609 \color@endgroup
610 }%
611 }
612 % \end{macrocode}
613 % \end{macro}
614 % \end{macro}
615 % \end{macro}
616 %
617 % \subsection{Para Footnote Style}
618 %
619 % \begin{macro}{\ifMFL@paraindent}
620 % This style is too complicated. We load its
621 % commands optionally. First we define |\ifMFL@paraindent| command to
622 % switch between indented and non-indented versions of |para| footnotes.
623 % \begin{macrocode}
624 \newif\ifMFL@paraindent \MFL@paraindenttrue
625 % \end{macrocode}
626 % \end{macro}
627 %
628 % Now we implement the |para| option.
629 % \begin{macrocode}
630 \DeclareOption{para}{%
631 % \end{macrocode}
632 %
633 % \begin{macro}{\footglue}
634 % The |\footglue| skip is the horizontal space between footnotes in
635 % run-in paragraph. It's name goes from \TeX book
636 % (Appendix D. Dirty Tricks) and we don't rename this
637 % register. This gives us an additional protection from the usage
638 % this package in the document where another package also provides
639 % footnotes in |para| style.
640 % \begin{macrocode}
641 \newskip\footglue
642 % \end{macrocode}
643 % Contrarily to |footmisc| package we initialize this skip in terms of
644 % the footnote size (nor the normal size).
645 % \begin{macrocode}
646 {\footnotesize \global\footglue=1em plus.3em minus.3em }
647 % \end{macrocode}
648 % \end{macro}
649 %
650 % \begin{macro}{\SplitNote}
651 % \begin{macro}{\ifMFL@split}
652 % The switch |MFL@split| provides footnote splitting and
653 % the command |\SplitNote| simply sets this switch to \emph{true}.
654 % \begin{macrocode}
655 \newif\ifMFL@split \MFL@splitfalse
656 \newcommand\SplitNote{\MFL@splittrue}
657 % \end{macrocode}
658 % \end{macro}
659 % \end{macro}
660 %
661 % \begin{macro}{\MFL@startpara}
662 % Now we prepare |para| support routines. The first is the starting
663 % routine.
664 % \begin{macrocode}
665 \def\MFL@startpara#1{%
666 % \end{macrocode}
667 % It adds to insert's skip additional space |\MFL@paraskip| (it is
668 % non-stretchable and is calculated at the beginning of the document).
669 % \begin{macrocode}
670 \global\advance\skip#1\MFL@paraskip
671 % \end{macrocode}
672 % Then we define the command named |\MFL@split\footins|\meta{suffix}
673 % which saves splitting information for the corresponding footnote
674 % level. While processing the document this command will have the
675 % |\MFL@applyhook|\marg{insert register} value (without splitting) or
676 % |\noindent| value (with splitting).
677 % \begin{macrocode}
678 \MFL@setsplit{#1}{\MFL@applyhook{#1}}%
679 }
680 \@onlypreamble\MFL@startpara
681 % \end{macrocode}
682 % \end{macro}
683 %
684 % \begin{macro}{\MFL@fnotepara}
685 % The next command inserts footnote into \meta{insert register}.
686 % We use Knuth's trick to inform the output procedure how many
687 % horizontal space occupy the footnote by modifying its vertical size
688 % as \emph{fudgefactor}${}\times{}$\emph{footnotebaselineskip} where
689 % \emph{fudgefactor} is the ratio of \emph{footnotebaselineskip} to
690 % |\columnwidth|. The real vertical size of such footnote is not needed
691 % because the footnote is save in |\hbox| nor |\vbox| and
692 % while processing to the run-in paragraph will be unboxed.
693 %
694 % This footnote command is not |\long| because the |\par| command cannot
695 % be used in |\hbox|. At the beginning we make footnote mark and
696 % set current label only if footnote mark was nonempty. We use below the
697 % temporary switch |@tempswa| to select the case of nonempty footnote
698 % mark.
699 % \begin{macrocode}
700 \def\MFL@fnotepara#1#2#3{\let\@thefnmark\@empty
701 \NCC@makefnmark{#2}%
702 \MFL@insert#1{\reset@font\footnotesize
703 \ifx\@thefnmark\@empty \@tempswafalse \else
704 \@tempswatrue
705 \protected@edef\@currentlabel{\@thefnmark}%
706 \fi
707 \color@begingroup
708 % \end{macrocode}
709 % Now we test the width of the footnote mark and if\/ it less than
710 % |0.8em| we calculate in |\@tempdima| the difference between |0.8em|
711 % and the natural width of the marker. This horizontal space is
712 % inserted before the footnote mark. Why it is needed? While the
713 % processing of |para| insert we set |\parindent| to |1em|. And taking
714 % into account that the marker width is at least |0.8em| we obtain the
715 % distance at least |1.8em| between the footnote text and the left
716 % margin. It is exactly the same distance as for footnotes in |plain|
717 % style. Why we add this space using |\hskip|? It should be removed
718 % when line will be broken at this point.
719 % We add this space when the switch |MFL@paraindent| is true.
720 % \begin{macrocode}
721 \if@tempswa
722 \setbox\@tempboxa\hbox{\@makefnmark}%
723 \ifMFL@paraindent
724 \@tempdima.8em \advance\@tempdima-\wd\@tempboxa
725 \ifdim \@tempdima<\z@ \@tempdima\z@ \fi
726 \else
727 \@tempdima\z@
728 \fi
729 \fi
730 \setbox\@tempboxa\hbox{%
731 \if@tempswa
732 \hskip\@tempdima\unhbox\@tempboxa\nobreak
733 \fi
734 % \end{macrocode}
735 % Well. Now we insert the footnote text into hbox and test the
736 % |MFL@split| switch.
737 % If it is true (splitting needed) we add at the end of text the special
738 % small penalty |-1|. It will indicate us where the splitting needed.
739 % In false case we set penalty |-10| and insert |\footglue| space.
740 % \begin{macrocode}
741 \ignorespaces#3\unskip\strut
742 \ifMFL@split \penalty\m@ne\space \else
743 \penalty-10 \hskip\footglue
744 \fi
745 }%
746 % \end{macrocode}
747 % And finally we use Knuth's trick.
748 % \begin{macrocode}
749 \dp\@tempboxa\z@ \ht\@tempboxa\MFL@fudgefactor\wd\@tempboxa
750 \box\@tempboxa
751 \color@endgroup
752 }%
753 }
754 % \end{macrocode}
755 % \end{macro}
756 %
757 % \begin{macro}{\MFL@processpara}
758 % This is the last procedure of |para| style which is called in the
759 % output routine. We must reorganize the box of the \meta{insert
760 % register} which is the ``vbox of hboxes".
761 % \begin{macrocode}
762 \def\MFL@processpara#1{%
763 % \end{macrocode}
764 % Firstly we redefine |\MFL@skip| command decreasing its skip by
765 % |\MFL@paraskip|.
766 % \begin{macrocode}
767 \advance\@tempskipa -\MFL@paraskip
768 \edef\MFL@skip{\vskip\the\@tempskipa\relax}%
769 \setbox#1\vbox{%
770 % \end{macrocode}
771 % Now we execute the first step of Knuth's algorithm: convert the ``vbox
772 % of hboxes" to ``hbox of hboxes".
773 % \begin{macrocode}
774 \unvbox#1\setbox\@tempboxa\hbox{}\MFL@makehhbox
775 % \end{macrocode}
776 % The second step is unhboxing of all first level hboxes. After that we
777 % have the normal hbox which can be easily converted to paragraph vbox.
778 % \begin{macrocode}
779 \setbox\@tempboxa\hbox{\unhbox\@tempboxa\MFL@removehboxes}%
780 % \end{macrocode}
781 % Now we set all needed parameters to prepare run-in paragraph.
782 % When we set a |\parindent|, we do test on the compatibility with
783 % |footmisc| package. If this package is in use, the |\footnotemargin|
784 % register is specified. To provide just the same indent of the first line
785 % for para footnotes as for ordinary footnotes, we calculate the par indent
786 % as |\footnotemargin-0.8em| (|0.8em| is the width of marker going after).
787 % This calculation is executed in the only case of nonnegative
788 % |\footnotemargin| value.
789 % \begin{macrocode}
790 \footnotesize
791 \hsize\MFL@columnwidth \@parboxrestore
792 \ifMFL@paraindent
793 \@ifundefined{footnotemargin}%
794 {\parindent\footglue}%
795 {\parindent\footnotemargin\relax
796 \ifdim\parindent<\z@ \parindent\footglue
797 \else \advance\parindent -0.8em \fi}%
798 \fi
799 % \end{macrocode}
800 % Then we call |\MFL@split\footins|\meta{suffix} macro to set |\noindent|
801 % if\/ it is needed (this case occurs when the footnote was splitted at
802 % the previous page) or apply its hook otherwise.
803 % \begin{macrocode}
804 \csname MFL@split\string#1\endcsname
805 % \end{macrocode}
806 % Here is the right place where |\footnotesep| rule have to be inserted.
807 % \begin{macrocode}
808 \rule\z@\footnotesep
809 % \end{macrocode}
810 % Finally, we convert prepared hbox to vbox and test the last penalty
811 % (it is
812 % the penalty of the last |para| footnote inserted into this vbox). This
813 % penalty is |-10| or |-1|. The case |-1| means that the last
814 % footnote continues onto the next page (splitting case; see the
815 % command |\MFL@fnotepara|). In this case we adjust the last line of
816 % paragraph to the right margin and set |\MFL@split\footins|\meta{suffix}
817 % macro to |\noindent|. Otherwise, we apply the hook as its default value.
818 % \begin{macrocode}
819 \unhbox\@tempboxa\unskip
820 \ifnum\lastpenalty=\m@ne \parfillskip\z@
821 \MFL@setsplit{#1}{\noindent}%
822 \else
823 \MFL@setsplit{#1}{\MFL@applyhook{#1}}%
824 \fi
825 }%
826 }
827 % \end{macrocode}
828 % \end{macro}
829 %
830 % \begin{macro}{\MFL@makehhbox}
831 % This procedure converts ``vbox of hboxes" to ``hbox of hboxes".
832 % Its implementation has minimal distinctions from the original code
833 % described in \TeX book. We removed from it the initialization of
834 % the accumulating box (|\@tempboxa|) and added a possibility some boxes
835 % in the list to be vboxes nor hboxes. Such vboxes arises because
836 % while processing a minipage we put all internal footnotes
837 % into vbox to prevent their splitting.
838 % We use the box 0 as the temporary box here.
839 % \begin{macrocode}
840 \def\MFL@makehhbox{%
841 \loop\setbox\z@\lastbox \ifhbox\z@
842 \setbox\@tempboxa\hbox{\box\z@\unhbox\@tempboxa}%
843 \repeat
844 \ifvbox\z@ \unvbox\z@ \MFL@makehhbox \fi
845 }
846 % \end{macrocode}
847 % \end{macro}
848 %
849 % \begin{macro}{\MFL@removehboxes}
850 % This is an internal procedure described in \TeX book to unboxing ``hbox
851 % of hboxes".
852 % \begin{macrocode}
853 \def\MFL@removehboxes{\setbox\@tempboxa\lastbox
854 \ifhbox\@tempboxa{\MFL@removehboxes}\unhbox\@tempboxa\fi
855 }
856 % \end{macrocode}
857 % \end{macro}
858 %
859 % \begin{macro}{\MFL@setsplit}
860 % This macro sets the value of |\MFL@split\footins|\meta{suffix} macro.
861 % \begin{macrocode}
862 \def\MFL@setsplit#1#2{%
863 \expandafter\gdef\csname MFL@split\string#1\endcsname{#2}%
864 }
865 % \end{macrocode}
866 % \end{macro}
867 %
868 % Finally, we have to prepare something for work.
869 % We add to |\MFL@floathook| the calculation of the fudge factor.
870 % Such a calculation is needed when we switch between one and two
871 % columns by the standard \LaTeX{} commands. The original Knuth's
872 % version of the algorithm produces an overflow if |\normalbaselineskip|
873 % greater or equal to |16pt|. In version 1.10, the calculation
874 % was improved to remove overflow. Now overflow appears when
875 % |\normalbaselineskip| is |64pt|. I think it will be enough for
876 % all applications. By the way, in ordinary cases the new version
877 % calculates the fudge factor two times more accurate than the
878 % Knuth's one.
879 % \begin{macrocode}
880 \g@addto@macro\MFL@floathook{%
881 \begingroup
882 \footnotesize \@tempdima\normalbaselineskip
883 \multiply \@tempdima \@cclvi
884 \@tempdimb \columnwidth
885 \divide \@tempdimb \@cclvi
886 \divide \@tempdima \@tempdimb
887 \xdef\MFL@fudgefactor{\strip@pt\@tempdima}%
888 \endgroup
889 }
890 % \end{macrocode}
891 %
892 % \begin{macro}{\MFL@paraskip}
893 % The last trick is the calculation of |\MFL@paraskip|~--- the skip
894 % which has to be added to the skip of all |para| style footnote
895 % inserts and then ``turned back" while preparing of run-in paragraph.
896 % Why it is needed? Two reasons. The first, the
897 % value of |\footnotesep| may be larger than the height of |\strut|.
898 % And we nowhere take into account this exceeding. The second, the
899 % total height of |para| footnotes is less then the real height of
900 % the prepared run-in paragraph by |0.5\baselineskip| on the average.
901 % So we have to add it to the |\skip| register for the compensation.
902 %
903 % \begin{macro}{\ExtraParaSkip}
904 % I new command, |\ExtraParaSkip|\marg{space}, is introduced here
905 % by the proposal of Uwe L\"uck |<[email protected]>|. Using it,
906 % everyone can adjust a value of skip to be added to all |\skip|
907 % registers of para-inserts.
908 % \begin{macrocode}
909 \newcommand*\ExtraParaSkip[1]{%
910 \def\MFL@xparaskip{\advance\@tempdima#1\relax}%
911 }
912 \let\MFL@xparaskip\relax
913 \@onlypreamble\ExtraParaSkip
914 \@onlypreamble\MFL@xparaskip
915 % \end{macrocode}
916 % \end{macro}
917 %
918 % We do calculations of the |\MFL@paraskip| at the beginning of
919 % the document.
920 % \begin{macrocode}
921 \AtBeginDocument{%
922 \begingroup
923 \footnotesize
924 \@tempdima\footnotesep
925 \advance\@tempdima -\ht\strutbox
926 \ifdim\@tempdima<\z@ \@tempdima\z@ \fi
927 \advance\@tempdima.5\normalbaselineskip
928 \MFL@xparaskip % Add extra para skip
929 \xdef\MFL@paraskip{\the\@tempdima\relax}%
930 \endgroup
931 }
932 }
933 % \end{macrocode}
934 % \end{macro}
935 %
936 % Finally, we implement |para*| option which suppresses indentation of
937 % |para| footnotes.
938 % \begin{macrocode}
939 \DeclareOption{para*}{%
940 \@ifundefined{MFL@startpara}{\ExecuteOptions{para}}{}%
941 \MFL@paraindentfalse
942 }
943 % \end{macrocode}
944 %
945 % \subsection{Perpage Option}
946 %
947 % The |perpage| option just sets the true value for the |MFL@perpage|:
948 % \begin{macrocode}
949 \newif\ifMFL@perpage \MFL@perpagefalse
950 \DeclareOption{perpage}{\MFL@perpagetrue}
951 % \end{macrocode}
952 % Now we can process the package options:
953 % \begin{macrocode}
954 \ProcessOptions\relax
955 % \end{macrocode}
956 % After that, we test the |MFL@perpage| and load the |perpage| package
957 % on demand:
958 % \begin{macrocode}
959 \ifMFL@perpage \RequirePackage{perpage}\fi
960 % \end{macrocode}
961 %
962 % \subsection{Additional Footnotes Support}
963 %
964 % \begin{macro}{\MFL@list}
965 % We initialize the list of all additional footnote levels to be empty.
966 % \begin{macrocode}
967 \def\MFL@list{}
968 % \end{macrocode}
969 % Its items will have the form |\@elt|\marg{style}\meta{insert register}
970 % \end{macro}
971 %
972 % \begin{macro}{\SelectFootnoteRule}
973 % Next we implement the footnote rule selection command.
974 % It defines the |\MFL@rule| command that is later used in the
975 % |\MFL@newinsert| command to specify accompany footnote level rule.
976 % \begin{macrocode}
977 \newcommand*{\SelectFootnoteRule}[2][0]{%
978 \edef\@tempa{\noexpand\MFL@selectrule{#1}{%
979 \expandafter\noexpand\csname #2footnoterule\endcsname}}%
980 \@ifnextchar[{\@tempa}{\@tempa[]}%
981 }
982 \def\MFL@selectrule#1#2[#3]{\def\MFL@rule{\MFL@joinrule{#1}{#2}{#3}}}
983 \SelectFootnoteRule{extra}% Set the default footnote rule
984 \@onlypreamble\SelectFootnoteRule
985 \@onlypreamble\MFL@selectrule
986 \@onlypreamble\MFL@rule
987 % \end{macrocode}
988 % \end{macro}
989 %
990 % \begin{macro}{\SetFootnoteHook}
991 % |\SetFootnoteHook|\marg{hook} saves a hook in the internal command.
992 % When a new footnote is created, this hook is applied to it.
993 % \begin{macrocode}
994 \newcommand{\SetFootnoteHook}[1]{\def\MFL@footnotehook{\MFL@fhook{#1}}}
995 \@onlypreamble\SetFootnoteHook
996 \@onlypreamble\MFL@footnotehook
997 \SetFootnoteHook{}% Empty hook by default
998 % \end{macrocode}
999 % \end{macro}
1000 %
1001 % \begin{macro}{\MFL@fhook}
1002 % |\MFL@fhook|\marg{hook}\marg{insert register} associates a hook with
1003 % the given insert register and resets the current hook.
1004 % \begin{macrocode}
1005 \long\def\MFL@fhook#1#2{%
1006 \expandafter\def\csname MFL@hook\string#2\endcsname{#1}%
1007 \SetFootnoteHook{}%
1008 }
1009 \@onlypreamble\MFL@fhook
1010 % \end{macrocode}
1011 % \end{macro}
1012 %
1013 % \begin{macro}{\newfootnote}
1014 % Then we implement the basic command which generates additional
1015 % footnote levels.
1016 % \begin{macrocode}
1017 \newcommand*{\newfootnote}[2][plain]{%
1018 % \end{macrocode}
1019 % Firstly, we test the \meta{style} to be valid.
1020 % \begin{macrocode}
1021 \@ifundefined{MFL@fnote#1}{%
1022 \PackageError{manyfoot}{Unknown footnote style #1}%
1023 {Known styles are `plain' and `para'\MessageBreak
1024 (if the package was loaded with the para or para* option)}}{}%
1025 % \end{macrocode}
1026 % Then we allocate and initialize a new insert
1027 % \begin{macrocode}
1028 \expandafter\MFL@newinsert\csname footins#2\endcsname
1029 % \end{macrocode}
1030 % generate |\Footnotetext|\meta{suffix} and its hook
1031 % \begin{macrocode}
1032 \edef\@tempa{\noexpand\newcommand
1033 \expandafter\noexpand\csname Footnotetext#2\endcsname
1034 {\expandafter\noexpand\csname MFL@fnote#1\endcsname{%
1035 \expandafter\noexpand\csname footins#2\endcsname}}%
1036 \noexpand\MFL@footnotehook{%
1037 \expandafter\noexpand\csname footins#2\endcsname}%
1038 }%
1039 \@tempa
1040 % \end{macrocode}
1041 % and finally add the description of this insert to the list of
1042 % additional footnote inserts.
1043 % \begin{macrocode}
1044 \@cons\MFL@list{{#1}\csname footins#2\endcsname}%
1045 }
1046 \@onlypreamble\newfootnote
1047 % \end{macrocode}
1048 % \end{macro}
1049 %
1050 % \begin{macro}{\MFL@newinsert}
1051 % The initialization of a new insert. A current rule selection command
1052 % is linked with the new insert by the insert count number.
1053 % \begin{macrocode}
1054 \def\MFL@newinsert#1{\newinsert#1%
1055 \expandafter\let\csname MFL@join\number #1\endcsname \MFL@rule
1056 \SelectFootnoteRule{extra}% Reset to default rule again
1057 \skip#1\skip\footins \dimen#1\dimen\footins \count#1\count\footins
1058 }
1059 \@onlypreamble\MFL@newinsert
1060 % \end{macrocode}
1061 % \end{macro}
1062 %
1063 % \begin{macro}{\MFL@makemark}
1064 % All additional footnote mark commands with automatic numbering are based
1065 % on the following command:
1066 % \begin{quote}
1067 % |\MFL@makemark|\marg{counter}\marg{stepcounter}\marg{command}\oarg{number}
1068 % \end{quote}
1069 % This command tests an optional parameter and, if it exists, prepares the marker
1070 % using the specified number. Otherwise, it at first executes the
1071 % \meta{stepcounter}\marg{counter} command (it is either |\stepcounter| or |\@gobble|)
1072 % and then makes a mark. Finally, it executes the \meta{command} parameter.
1073 % Check for |multiple| footnotes added as suggested by Frank Mittelbach.
1074 % \begin{macrocode}
1075 \def\MFL@makemark#1#2#3{%
1076 \FN@mf@check
1077 \@ifnextchar[{\MFL@xmkmark{#1}{#3}}{#2{#1}\MFL@mkmark{#1}{#3}}%
1078 }
1079 \providecommand\FN@mf@check{}
1080 \def\MFL@xmkmark#1#2[#3]{%
1081 \begingroup
1082 \csname c@#1\endcsname #3\relax
1083 \unrestored@protected@xdef\@thefnmark{\csname the#1\endcsname}%
1084 \endgroup
1085 #2%
1086 }
1087 \def\MFL@mkmark#1#2{\protected@xdef\@thefnmark{\csname the#1\endcsname}%
1088 #2%
1089 }
1090 % \end{macrocode}
1091 % \end{macro}
1092 %
1093 % \begin{macro}{\DeclareNewFootnote}
1094 % Now we define the service command simplifying creation of footnotes
1095 % in almost all cases.
1096 % \begin{macrocode}
1097 \newcommand*{\DeclareNewFootnote}[2][plain]{%
1098 \@ifnextchar[{\MFL@declare{#1}{#2}}{\MFL@declare{#1}{#2}[arabic]}%
1099 }
1100 \def\MFL@declare#1#2[#3]{%
1101 % \end{macrocode}
1102 % We start from creation a new footnote level:
1103 % \begin{macrocode}
1104 \newfootnote[#1]{#2}%
1105 % \end{macrocode}
1106 % Now we prepare the |\@tempa| command which will create other commands
1107 % at the end of macro. A counter creation command is prepared at first:
1108 % \begin{macrocode}
1109 \edef\@tempa{\noexpand\newcounter{footnote#2}%
1110 % \end{macrocode}
1111 % After that we prepare the redefinition of the enumeration style
1112 % \begin{macrocode}
1113 \noexpand\renewcommand
1114 \expandafter\noexpand\csname thefootnote#2\endcsname{%
1115 \expandafter\noexpand\csname @#3\endcsname
1116 \expandafter\noexpand\csname c@footnote#2\endcsname
1117 }%
1118 % \end{macrocode}
1119 % and specify the per-page resetting if necessary:
1120 % \begin{macrocode}
1121 \ifMFL@perpage \noexpand\MakePerPage{footnote#2}\fi
1122 % \end{macrocode}
1123 % Next we prepare the |\footnote|\meta{suffix} command:
1124 % \begin{macrocode}
1125 \noexpand\newcommand
1126 \expandafter\noexpand\csname footnote#2\endcsname{%
1127 \noexpand\MFL@makemark{footnote#2}{\noexpand\stepcounter}{%
1128 \noexpand\@footnotemark
1129 \noexpand\let\noexpand\@tempb\noexpand\@thefnmark
1130 \expandafter\noexpand\csname Footnotetext#2\endcsname{%
1131 \noexpand\@tempb
1132 }%
1133 }%
1134 }%
1135 % \end{macrocode}
1136 % After that we prepare the |\footnotemark|\meta{suffix} command:
1137 % \begin{macrocode}
1138 \noexpand\newcommand
1139 \expandafter\noexpand\csname footnotemark#2\endcsname{%
1140 \noexpand\MFL@makemark{footnote#2}{\noexpand\stepcounter}{%
1141 \noexpand\@footnotemark
1142 }%
1143 }%
1144 % \end{macrocode}
1145 % Then we prepare the |\footnotetext|\meta{suffix} command:
1146 % \begin{macrocode}
1147 \noexpand\newcommand
1148 \expandafter\noexpand\csname footnotetext#2\endcsname{%
1149 \noexpand\MFL@makemark{footnote#2}{\noexpand\@gobble}{%
1150 \noexpand\let\noexpand\@tempb\noexpand\@thefnmark
1151 \expandafter\noexpand\csname Footnotetext#2\endcsname{%
1152 \noexpand\@tempb
1153 }%
1154 }%
1155 }%
1156 % \end{macrocode}
1157 % Finally, we provide suffixed equivalents for |\Footnotemark|
1158 % and |\Footnote| commands:
1159 % \begin{macrocode}
1160 \noexpand\newcommand
1161 \expandafter\noexpand\csname Footnotemark#2\endcsname{%
1162 \noexpand\Footnotemark
1163 }%
1164 \noexpand\newcommand
1165 \expandafter\noexpand\csname Footnote#2\endcsname[1]{%
1166 \noexpand\Footnotemark{####1}%
1167 \expandafter\noexpand\csname Footnotetext#2\endcsname{####1}%
1168 }%
1169 }%
1170 % \end{macrocode}
1171 % And now all prepared commands are created:
1172 % \begin{macrocode}
1173 \@tempa
1174 }
1175 \@onlypreamble\DeclareNewFootnote
1176 \@onlypreamble\MFL@declare
1177 % \end{macrocode}
1178 % \end{macro}
1179 %
1180 % \begin{macro}{\MFL@start}
1181 % This command executes the |\MFL@start|\meta{suffix} command.
1182 % It works at the preamble of the document only once for every
1183 % additional footnote level.
1184 % \begin{macrocode}
1185 \def\MFL@start#1{\csname MFL@start#1\endcsname}
1186 \@onlypreamble\MFL@start
1187 % \end{macrocode}
1188 % \end{macro}
1189 %
1190 % \subsection{The Basic Implementation Part}
1191 %
1192 % Now we have to build into \LaTeXe{} the support for additional
1193 % footnote levels. There are a number of points where the modifications
1194 % should be done. We do all real modifications at the beginning of the
1195 % document. Here we prepare macros needed.
1196 %
1197 % \subsubsection{Modifications of Output Routine}
1198 %
1199 % \begin{macro}{\MFL@joinnotes}
1200 % First point of modifications is the output routine. We choose the
1201 % strategy of joining of the additional footnotes with |\footins|
1202 % at the points where it is really needed. The procedure
1203 % |\MFL@joinnotes| implements this job. It will be added later to the
1204 % beginning of |\@makecol| and |\@doclearpage| macros.\footnote{The
1205 % version 1.2 of this package added this procedure to the beginning of
1206 % \texttt{\bslash @specialoutput} instead of \texttt{\bslash
1207 % @doclearpage}. It was incorrect because
1208 % the special output routine is often called to add the next float to
1209 % the output page without ejecting it. As a result the additional
1210 % footnotes disappeared before floats. Thanks to Fran\c cois Patte who
1211 % found this bug.}
1212 %
1213 % Since version 1.5, the |\MFL@joinnotes| has a parameter~---
1214 % a command the joining procedure is called before. We add a protection
1215 % from double attempt for joining and restore the |\footnoterule| after
1216 % execution of the parameter command. The |MFL@joined| conditional command
1217 % is used for this purpose. Another improvement is concerned with the
1218 % footnote rule customization procedure introduced. We now manage
1219 % the footnote rule to be inserted before levels using the priorities.
1220 % The default priority for the standard |\footnoterule| is defined
1221 % with the |\footnoterulepriority| command.
1222 % \begin{macrocode}
1223 \newcommand{\footnoterulepriority}{1}
1224 \newif\ifMFL@joined \MFL@joinedfalse
1225 \def\MFL@joinnotes#1{%
1226 \ifMFL@joined #1%
1227 \else
1228 \let\MFL@savedrule \footnoterule
1229 % \end{macrocode}
1230 % After saving a footnote rule we test the standard footnote insert,
1231 % and prepare the current footnote rule for additional levels.
1232 % \begin{macrocode}
1233 \let\MFL@currule \defaultfootnoterule
1234 \ifvoid \footins
1235 \let\MFL@curpriority \footnoterulepriority
1236 \else
1237 \let\MFL@curpriority \m@ne
1238 \fi
1239 % \end{macrocode}
1240 % Now we join inserts.
1241 % \begin{macrocode}
1242 \let\MFL@elt\@elt
1243 \let\@elt\MFL@join \MFL@list
1244 \let\@elt\MFL@elt
1245 % \end{macrocode}
1246 % And finally, we process the parameter command and restore the |\footnoterule|.
1247 % \begin{macrocode}
1248 \MFL@joinedtrue #1\MFL@joinedfalse
1249 \let\footnoterule \MFL@savedrule
1250 \fi
1251 }
1252 % \end{macrocode}
1253 % The insert joining procedure simply calls the numbered join command
1254 % linked with the insert.
1255 % \begin{macrocode}
1256 \def\MFL@join#1#2{\csname MFL@join\number #2\endcsname{#1}{#2}}
1257 % \end{macrocode}
1258 % The last one calls the |\MFL@joinrule| command with 5 parameters:
1259 % \begin{quote}
1260 % |\MFL@joinrule|\marg{priority}\marg{rule}\marg{action}\marg{style}\marg{register}
1261 % \end{quote}
1262 % First we select the rule comparing the priority of current rule and
1263 % the new one.
1264 % \begin{macrocode}
1265 \def\MFL@joinrule#1#2#3#4#5{%
1266 \ifnum #1<\MFL@curpriority \else
1267 \let\MFL@currule#2%
1268 \def\MFL@curpriority{#1}%
1269 \fi
1270 \ifvoid#5\else
1271 % \end{macrocode}
1272 % Well. The current insert is nonempty. At first, we calculate the skip
1273 % of insert. Within |multicols| environment it has the size multiplied
1274 % in |\col@number| times matching to its natural size. Therefore, we
1275 % have to divide it by |\col@number| in such a case.
1276 % \begin{macrocode}
1277 \@tempskipa\skip#5%
1278 \MFL@ifmcol{\divide\@tempskipa\col@number}{}%
1279 \edef\MFL@skip{\vskip\the\@tempskipa\relax}%
1280 % \end{macrocode}
1281 % Now we process the current insert by the style processing driver
1282 % \begin{macrocode}
1283 \csname MFL@process#4\endcsname #5%
1284 % \end{macrocode}
1285 % and finally we join it with |\footins| insert and decrease the
1286 % current priority to |-1|.
1287 % \textit{Change request from Fank Mittelbach (version 1.11):}
1288 % The |\footins| insert should be set globally
1289 % for compatibility with the last version of multicol.
1290 % \begin{macrocode}
1291 \ifvoid\footins
1292 \let\footnoterule\MFL@currule
1293 \global\setbox\footins\vbox{#3\unvbox#5}%
1294 \else
1295 \global\setbox\footins\vbox{%
1296 \unvbox\footins\MFL@skip\MFL@currule#3\unvbox#5%
1297 }%
1298 \fi
1299 \let\MFL@curpriority \m@ne
1300 \fi
1301 }
1302 % \end{macrocode}
1303 % \end{macro}
1304 %
1305 % \begin{macro}{\MFL@reinsout}
1306 % When the special output is called to process float insertion, all
1307 % accumulated footnotes should be reinserted after the output box.
1308 % This job carries out |\@reinserts| command. We will add to it
1309 % the reinsertion of all additional footnotes with the help of
1310 % |\MFL@reinsout| macro. Note that |\@reinserts| command is called at
1311 % two points: when the float is the marginal note
1312 % (|\count\@currbox|~=~0) or when it is the real float. At the second
1313 % case we must take into account the height of all additional footnotes
1314 % by adding it to the |\@pageht| value.
1315 % \begin{macrocode}
1316 \def\MFL@reinsout#1#2{\ifvoid#2\else
1317 \ifnum\count\@currbox>\z@
1318 \advance\@pageht \ht#2%
1319 \advance\@pageht \skip#2%
1320 \advance\@pageht \dp#2%
1321 \fi
1322 \insert#2{\unvbox#2}%
1323 \fi
1324 }
1325 % \end{macrocode}
1326 % \end{macro}
1327 %
1328 % \subsubsection{Minipages Support}
1329 %
1330 % \begin{macro}{\MFL@reinsert}
1331 % The command reinserts all additional footins by adding if\/
1332 % necessary the empty insertion (such a way is used in |multicol|).
1333 % It is used in |minipage| and |multicols| environments.
1334 % The point of using it at a minipage is the beginning of the minipage.
1335 % Using this command we release the additional footnote boxes to
1336 % accumulate footnotes inside the minipage.
1337 % \begin{macrocode}
1338 \def\MFL@reinsert{{\let\@elt\MFL@reins \MFL@list}}
1339 \def\MFL@reins#1#2{\ifvoid#2\else\insert#2{}\fi}
1340 % \end{macrocode}
1341 % \end{macro}
1342 %
1343 % \begin{macro}{\MFL@mpinsert}
1344 % Here we define the minipage insertion command which manually adds
1345 % vbox to the insertion box. The last footnote within minipage can
1346 % split. So, we specially enclose it into vbox and unvbox the
1347 % previous last footnote.
1348 % \begin{macrocode}
1349 \long\def\MFL@mpinsert#1#2{%
1350 \global\setbox#1\vbox{%
1351 \unvbox#1\setbox\@tempboxa\lastbox
1352 \ifvbox\@tempboxa \unvbox\@tempboxa \fi
1353 \vbox{#2}%
1354 }%
1355 }
1356 % \end{macrocode}
1357 % \end{macro}
1358 %
1359 % \begin{macro}{\MFL@mpreinsert}
1360 % This macro is useful when we really insert footnotes at the end of the
1361 % minipage. We suppress splitting of all minipage insertions except
1362 % the last one. To do this we extract the last box from the insertion
1363 % box, then put another footnotes into the insert enclosing them into
1364 % vbox, and then put the last unvboxed footnote.
1365 % \begin{macrocode}
1366 \def\MFL@mpreinsert#1#2{%
1367 \ifvoid#2\else
1368 \setbox\@tempboxa\vbox{\unvbox#2\global\setbox#2\lastbox}%
1369 \setbox\z@\box#2%
1370 \ifdim\ht\@tempboxa>\z@ \MFL@realinsert#2{\box\@tempboxa}\fi
1371 \MFL@realinsert#2{\unvbox\z@}%
1372 \fi
1373 }
1374 % \end{macrocode}
1375 % Then we define two hooks which will be added to the beginning and to
1376 % the end of a minipage. We do them in not inner mode only (for
1377 % the first level minipages).
1378 % \end{macro}
1379 %
1380 % \begin{macro}{\MFL@minipage}
1381 % We release all box registers of the additional inserts at the
1382 % beginning of\/ minipage to use
1383 % them inside the minipage to accumulate inner inserts.
1384 % \begin{macrocode}
1385 \def\MFL@minipage{%
1386 \ifinner\else
1387 \MFL@reinsert \let\MFL@insert\MFL@mpinsert
1388 \fi
1389 }
1390 % \end{macrocode}
1391 % \end{macro}
1392 %
1393 % \begin{macro}{\MFL@endminipage}
1394 % We simply reinsert all footnotes at the end of the first level
1395 % minipage.
1396 % \begin{macrocode}
1397 \def\MFL@endminipage{%
1398 \ifinner\else
1399 {\let\@elt\MFL@mpreinsert \MFL@list}%
1400 \fi
1401 }
1402 % \end{macrocode}
1403 % \end{macro}
1404 %
1405 % \subsubsection{Multicol Package Support}
1406 %
1407 % \begin{macro}{\MFL@mult}
1408 % The command modifies parameters of the insert register.
1409 % It is useful in the scope of |multicol| package only.
1410 % \begin{macrocode}
1411 \def\MFL@mult#1#2{%
1412 \multiply\count#2\col@number
1413 \multiply\skip#2\col@number
1414 }
1415 % \end{macrocode}
1416 % \end{macro}
1417 %
1418 % \begin{macro}{\MFL@ifmcol}
1419 % The next macro tests the multicolumn mode. There are two
1420 % conditions which have to be satisfied if we are in the multicolumn
1421 % mode: the value of |\col@number| should be greater then 1 and the
1422 % value of |\footins| count should be at least 2000.
1423 % \begin{macrocode}
1424 \def\MFL@ifmcol#1#2{\@tempswafalse
1425 \ifnum\col@number>\@ne
1426 \ifnum\count\footins>1999 \@tempswatrue \fi
1427 \fi
1428 \if@tempswa #1\else #2\fi
1429 }
1430 % \end{macrocode}
1431 % \end{macro}
1432 %
1433 % \subsection{What Do We Do at the Beginning of Document?}
1434 %
1435 % \begin{macrocode}
1436 \AtBeginDocument{%
1437 % \end{macrocode}
1438 % Firstly, we process starting commands for every level
1439 % \begin{macrocode}
1440 {\let\@elt\MFL@start \MFL@list}
1441 % \end{macrocode}
1442 % Then we define the |\defaultfootnoterule| to provide compatibility
1443 % with \textbf{footmisc}. We set it equal to |\pagefootnoterule|
1444 % or |\footnoterule|.
1445 % \begin{macrocode}
1446 \@ifundefined{defaultfootnoterule}{%
1447 \@ifundefined{pagefootnoterule}%
1448 {\let\defaultfootnoterule\footnoterule}%
1449 {\let\defaultfootnoterule\pagefootnoterule}%
1450 }{}%
1451 % \end{macrocode}
1452 % Then we modify |\@doclearpage| and |\@makecol| commands by added
1453 % the joining algorithm at their beginning.
1454 % \begin{macrocode}
1455 \let\MFL@doclearpage\@doclearpage
1456 \def\@doclearpage{\MFL@joinnotes\MFL@doclearpage}
1457 \let\MFL@makecol\@makecol
1458 \def\@makecol{\MFL@joinnotes\MFL@makecol}
1459 % \end{macrocode}
1460 % Then we modify |\@reinserts| command of the output routine to
1461 % process reinsertion of all additional footnotes.
1462 % \begin{macrocode}
1463 \g@addto@macro\@reinserts{%
1464 \let\MFL@elt\@elt
1465 \let\@elt\MFL@reinsout \MFL@list
1466 \let\@elt\MFL@elt
1467 }
1468 % \end{macrocode}
1469 % Then we execute |\MFL@floathook| and add it into |\@floatplacement|
1470 % command which is called when the column mode is
1471 % changed. One important note: in the multicolumn mode of |multicol|
1472 % package the width of footnotes is unchanged. So, we test
1473 % this case by the command |\MFL@ifmcol|.
1474 % \begin{macrocode}
1475 \MFL@floathook
1476 \g@addto@macro\@floatplacement{\MFL@ifmcol{}{\MFL@floathook}}
1477 % \end{macrocode}
1478 %
1479 % The next is the |minipage| environment. We modify |\@iiiminipage| and
1480 % |\endminipage| adding to them hooks describe earlier.
1481 % \begin{macrocode}
1482 \let\MFL@iminipage\@iiiminipage
1483 \def\@iiiminipage{\MFL@minipage\MFL@iminipage}
1484 \g@addto@macro\endminipage\MFL@endminipage
1485 % \end{macrocode}
1486 %
1487 % Finally, we do some tricks to provide the compatibility with
1488 % |multicol| package. If this package is loaded, the command
1489 % |\multi@column@out| should be defined
1490 % \begin{macrocode}
1491 \@ifundefined{multi@column@out}
1492 % \end{macrocode}
1493 % If it is undefined, the |multicol| specific commands are not useful.
1494 % So, we delete |\MFL@mult| command and modify |\MFL@ifmcol| command to
1495 % choose the second case every time.
1496 % \begin{macrocode}
1497 {\@onlypreamble\MFL@mult \let\MFL@ifmcol\@secondoftwo}
1498 % \end{macrocode}
1499 % If |multicol| package presents, we add the joining algorithm to the
1500 % beginning of |\multi@column@out| command
1501 % \begin{macrocode}
1502 {\let\MFL@mcolout\multi@column@out
1503 \def\multi@column@out{\MFL@joinnotes\MFL@mcolout}
1504 % \end{macrocode}
1505 % and add the multiplication of additional footins parameters
1506 % by the number of columns to the end of |\init@mult@footins| command.
1507 % We can't do this globally. So, we save the previous value of |\@elt|
1508 % command and then restore it after the calculation.
1509 % We also modify |\reinsert@footnotes| command.
1510 % \begin{macrocode}
1511 \g@addto@macro\init@mult@footins{%
1512 \let\MFL@elt\@elt
1513 \let\@elt\MFL@mult \MFL@list
1514 \let\@elt\MFL@elt
1515 }
1516 \g@addto@macro\reinsert@footnotes{\MFL@reinsert}
1517 }
1518 }
1519 %</package>
1520 % \end{macrocode}
1521 \endinput