Debian Codegraph @

texmf-dist/source/latex/bigfoot/bigfoot.dtx

raw
1 % \iffalse
2 %%
3 %% bigfoot is part of the bigfoot bundle for critical typesetting
4 %% Copyright 2004--2015 David Kastrup <[email protected]>
5 %%
6 %% The license notice and corresponding source code for this file are
7 %% contained in bigfoot.dtx.
8 %%
9 % This program is free software; you can redistribute it and/or modify
10 % it under the terms of the GNU General Public License as published by
11 % the Free Software Foundation; either version 2 of the License, or
12 % (at your option) any later version.
13 %
14 % This program is distributed in the hope that it will be useful,
15 % but WITHOUT ANY WARRANTY; without even the implied warranty of
16 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 % GNU General Public License for more details.
18 %
19 % You should have received a copy of the GNU General Public License
20 % along with this program; if not, write to the Free Software
21 % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 % \fi
23 % \CheckSum{4580}
24 % \GetFileInfo{bigfoot.sty}
25 % \title{The \texttt{bigfoot} package\\version \fileversion}
26 % \date{\filedate}
27 % \author{David Kastrup\thanks{[email protected]}}
28 % \maketitle
29 % Purpose of this package is to provide a one-stop solution to almost
30 % all problems related to footnotes. You can use it as a drop-in
31 % replacement of the \texttt{manyfoot} package, but without many of
32 % its shortcomings, and quite a few features of its own. It uses the
33 % existing document class layouts for footnotes, so you can usually
34 % use it without having to worry about the looks.
35 %
36 % Features are:
37 % \begin{itemize}
38 % \item You can specify and use multiple footnote apparatus.
39 % Footnotes for an apparatus lower on the
40 % page\footnoteB{like this one} can be anchored in an
41 % apparatus\footnote{The plural of ``apparatus'' is actually
42 % ``apparatus''\footnoteB{Well, actually ``apparat\=us'' with a
43 % long ``u'', but that's just obvious in spoken Latin.}}
44 % that is higher on the page.
45 % \item The last footnote in each apparatus may be broken to the next
46 % page.\footnote{This will probably be interesting for footnotes
47 % that contain stuff like math equations\footnoteB+{Like
48 % \begin{equation}
49 % \label{eq:1}
50 % \sum_{k=1}^\infty \frac{1}{k^2} = \frac{\pi^2}{6}
51 % \end{equation}} or lists\footnoteB+{Like
52 % \begin{itemize}
53 % \item This, or
54 % \item this.
55 % \end{itemize}}.}
56 % Any subordinate footnote anchors that get moved to the next page
57 % will take the corresponding footnote with them.
58 % \item The order of footnotes in an apparatus is `natural': it starts
59 % with any footnote that may have been broken from the next page,
60 % followed by footnotes from the current page in the order of the
61 % appearance of their footnote
62 % marks.\footnoteB{This footnote appears above notes on notes.}
63 % Where the order of appearance in the document differs from the
64 % order in the source code, you will usually want to use the
65 % \cmd{\MakeSorted} command from the |perpage| package to get the
66 % numbering fixed appropriately.
67 % \item Footnotes can be formatted in separate paragraphs, or be run
68 % into a single paragraph. The choice is made per footnote
69 % apparatus, but can be overridden for single
70 % footnotes.\footnote{I.e., footnotes with display
71 % math\footnoteB{We had this already, right?} or list
72 % environments\footnoteB{And this looks familiar, too.} have to be
73 % done in vertical mode.}
74 % \item If footnotes are run into one paragraph, a variety of criteria
75 % makes sure that this formatting is only chosen when it saves
76 % noticeable space and delivers visually attractive results.
77 % \item Parameters for footnote formatting can be specified globally,
78 % or separately for each footnote.
79 % \item The material in footnotes can contain |\verb|-like material
80 % without problems.\footnote{We wrote \verb+|\verb|-like+ above in
81 % the main text.\footnoteB{Well, this is not so impressive. But we
82 % wrote \verb/\verb+|\verb|-like+/ in the footnote then.}}
83 % \item You can use color in footnotes. If a footnote gets broken
84 % across pages, the color at the point of the break will get resumed
85 % on the next page. Actually, the whole color stack will get
86 % reinstated.
87 % \end{itemize}
88 % As an example of how simple the usage can be, here is the
89 % documentation driver for this document:
90 % \begin{macrocode}
91 %<*driver>
92 \documentclass{ltxdoc}
93 \usepackage{bigfoot}
94 \usepackage{tabularx}
95 \usepackage{hyperref}
96 % \end{macrocode}
97 % After loading the packages, we declare two footnote blocks. One is
98 % the default footnote block, another block is called~|B| and is
99 % numbered with letters. The letters start new on each page. Both
100 % footnote blocks default to in-paragraph footnotes. Since the
101 % block~|B| can get entries from both the main text as well as the
102 % default footnote block, the entries are not necessarily generated in
103 % page order. So we need to use a sorted counter to fix this (feel
104 % free to try what happens when using an unsorted counter).
105 % \begin{macrocode}
106 \DeclareNewFootnote[para]{default}
107 \DeclareNewFootnote[para]{B}[alph]
108 \MakeSortedPerPage{footnoteB}
109 % \end{macrocode}
110 % In addition, we add an alternate footnote sequence that can be
111 % interspersed with the normal footnotes by use of the
112 % \cmd{\footnote'} command which we effectively define here.
113 % \begin{macrocode}
114 \newcounter{footalt}
115 \def\thefootalt{\fnsymbol{footalt}}
116 \MakeSortedPerPage[2]{footalt}
117 \WithSuffix\def\footnotedefault'{\refstepcounter{footalt}%
118 \Footnotedefault{\thefootalt}}
119 % \end{macrocode}
120 % Actually, that already was all. We can now start the document. The
121 % following makes sure that we get the full documentation only by
122 % compiling the separate driver file:
123 % \begin{macrocode}
124 \begin{document}
125 \OnlyDescription
126 %<driver> \AlsoImplementation
127 \DocInput{bigfoot.dtx}
128 \end{document}
129 %</driver>
130 % \end{macrocode}
131 % In order to be useful without additional hassle, the normal footnote
132 % level will be called |default|. If no such style has been defined
133 % at the start of the document, it will get defined and used for
134 % ordinary footnotes, fixing quite a few problems of \LaTeX's own
135 % footnote placement algorithms.
136 %
137 % Apart from that, usage is very much like that of |manyfoot|, so for
138 % the customization possibilities of |bigfoot| with regards to
139 % multiple footnote blocks and rules between them, refer to
140 % |manyfoot|'s documentation.
141 %
142 % |bigfoot| contains a lot of bells and whistles for defining your
143 % footnote formats and can use different formats for different
144 % footnote blocks. Those expert options are not documented separately
145 % yet: look through the code sections to see them explained.
146 % \StopEventually{}
147 % \section{The implementation}
148 % \subsection{Startup code}
149 % We declare the package and several compatibility options supposed to
150 % make |bigfoot| a drop-in replacement for |manyfoot|.
151 % \begin{macrocode}
152 %<*style>
153 \NeedsTeXFormat{LaTeX2e}
154 \ProvidesPackage{bigfoot}[2015/08/30 2.1 makes footnotes work]
155
156 \DeclareOption{para}{\PackageInfo{bigfoot}{Compatibility option `para'
157 has no effect:^^J%
158 Spacing will be guessed from `\string\@makefntext' unless^^J%
159 `\string\@preparefnhtext' is redefined}}
160
161 \DeclareOption{para*}{\PackageInfo{bigfoot}{Compatibility option
162 `para*':^^J%
163 Redefining `\string\@preparefnhtext'}%
164 \def\@preparefnhtext{\ifx\@thefnmark\@empty
165 \else\@makefnmark\nobreak\fi}}
166
167 \DeclareOption{ruled}{\PassOptionsToPackage{ruled}{manyfoot}}
168 % \end{macrocode}
169 % The normal processing makes footnote text macros allow verbatim and
170 % similar. We call this |robust| processing though it is not totally
171 % accurate. This is the default. There is also an option |fragile|
172 % which will not allow this, but may be required for some definitions
173 % of \cmd{\@makefntext}. It turns out that most document classes work
174 % with the `robust' option, but there might be some that fail, and
175 % there might be some footnote-modifying packages that also can cause
176 % failure.
177 % \begin{macrocode}
178 \DeclareOption{robust}{\def\FN@makefncall{\FN@makefnrobust}}
179 \DeclareOption{fragile}{\def\FN@makefncall{\FN@makefnfragile}}
180 \ExecuteOptions{robust}
181 % \end{macrocode}
182 % The |verbose| option talks about changed labels at the end of a
183 % run. It is for debugging instable configurations that fail to
184 % converge after a number of \TeX\ runs. The output is probably
185 % obscure.
186 % \begin{macrocode}
187 \DeclareOption{verbose}{\AtBeginDocument{%
188 \def\@testdef #1#2#3{%
189 \def\reserved@a{#3}%
190 \expandafter \ifx \csname #1@#2\endcsname
191 \reserved@a
192 \else \@tempswatrue
193 \typeout{Changed label #1/#2:
194 \csname #1@#2\endcsname->#3}%
195 \fi}}}
196 % \end{macrocode}
197 % The |trace| option is only available if you used |docstrip| while
198 % explicitly requesting |trace| functionality. If you set the |trace|
199 % option, the next option specifies a bit map of trace bits.
200 %
201 % The following bits can be set in tracing:
202 % \begin{tabular}{rl}
203 % 1&break decisions\\
204 % 2&horizontal box building\\
205 % 4&allocation stuff\\
206 % 8&output routine stuff\\
207 % 16&retained and kept boxes
208 % \end{tabular}
209 % \begin{macrocode}
210 %<trace>\DeclareOption{trace}{%
211 %<trace>\DeclareOption*{\ftflags=\CurrentOption\relax
212 %<trace> \DeclareOption*{\OptionNotUsed}}%
213 %<trace> \AtEndOfPackage{\RequirePackage{trace}\relax
214 %<trace> \errorcontextlines\maxdimen
215 %<trace> \showboxdepth4
216 %<trace> \showboxbreadth100
217 %<trace> \tracingonline=\@ne}%
218 %<trace>}
219 % \end{macrocode}
220 % The |tracepage| option is followed by another option specifying the
221 % page to be traced. If you use it, tracing happens only on the
222 % specified page. Only a single page can be specified.
223 % \begin{macrocode}
224 %<trace>\def\FN@tracepage{\c@page}
225 %<trace>\DeclareOption{tracepage}{%
226 %<trace> \DeclareOption*{\edef\FN@tracepage{\CurrentOption}%
227 %<trace> \DeclareOption*{\OptionNotUsed}}}
228 %<trace>\newcount\ftflags
229 %<trace>\def\foottrace#1{\ifnum\numexpr(\ftflags+(#1))/(2*#1)*(2*#1)%
230 %<trace> =\numexpr(\ftflags+3*#1/2)/#1*#1\relax
231 %<trace> f\else t\fi\ifnum\FN@tracepage=\c@page t\else n\fi}
232 \ProcessOptions*
233 % \end{macrocode}
234 % |hyperref|'s footnote support will just cause trouble. So if
235 % |hyperref| was already loaded or is going to be loaded, we turn off
236 % its footnote support. If you think you know what you are doing, you
237 % can use \cmd{\hypersetup} to turn it on again before the start of
238 % the document. Unfortunately, it appears like \cmd{\hypersetup}
239 % refuses to be called more than once, so this actually does not work
240 % unless you load |hyperref| last.
241 % \begin{macrocode}
242 \ifx\hypersetup\@undefined
243 \PassOptionsToPackage{hyperfootnotes=false}{hyperref}
244 \else
245 \hypersetup{hyperfootnotes=false}
246 \fi
247 % \end{macrocode}
248 % We require the |etex| package because
249 % \begin{enumerate}
250 % \item We need the facilities of the \eTeX\ engine; and where they
251 % are not available, the error messages from not finding the |etex|
252 % package or from loading it into the wrong engine make much more
253 % sense than what would happen otherwise.
254 % \item We allocate quite a few registers, and the danger of running
255 % out of them is smaller when the extra registers of \eTeX\ are
256 % taken into account. Now unfortunately the LaTeX team has decided
257 % in 2015 to do its own extended allocation scheme incompatible with
258 % the |etex| package, so we need to guard against this load in case
259 % the new LaTeX allocation scheme is detected.
260 % \end{enumerate}
261 % We need the |manyfoot| package to build on. The |suffix| and
262 % |perpage| package are needed for some small stuff.
263 % \begin{macrocode}
264 \ifx\e@alloc\@undefined
265 \RequirePackage{etex}
266 \fi
267 \RequirePackage{manyfoot}
268 \RequirePackage{suffix}
269 \RequirePackage{perpage}
270 % \end{macrocode}
271 % \subsection{Fixes to the \texttt{manyfoot} package}
272 % While those fixes have been submitted once to the author of
273 % |manyfoot|, they have not made it into its distribution at the
274 % current point of time. In the interest of stability, it would
275 % probably be best just to incorporate the parts from |manyfoot| that
276 % get used by |bigfoot|. This has not yet been done.
277 %
278 % \begin{macro}{\MFL@reinsout}
279 % We need the appropriate splitting parameters set for the footnote
280 % again. \cmd{\MFL@realinsert} does that, but it has the disadvantage
281 % that it uses \cmd{\strutbox}, and that may be set to arbitrary
282 % values at the time the output routine is invoked. |manyfoot|
283 % already has this problem with minipages: the split sizes will be
284 % those of the font at the end of the minipage instead of those at the
285 % time the footnote body was set up. So we do this here, and see
286 % later for more info about how to do this right:
287 % \begin{macrocode}
288 \def\MFL@reinsout#1#2{\ifvoid#2\else
289 \ifnum\count\@currbox>\z@
290 \advance\@pageht \ht#2%
291 \advance\@pageht \skip#2%
292 \advance\@pageht \dp#2%
293 \fi
294 \MFL@realinsert{#2}{\unvbox#2}%
295 \fi
296 }
297 % \end{macrocode}
298 % \end{macro}
299 % \begin{macro}{\MFL@reins}
300 % Actually, I don't get the purpose of the following line in the
301 % first place. But if we do need it for some reason, it is rather
302 % certain that we don't want this empty insert to float. Use
303 % \cmd{\MFL@realinsert}, or set the floatingpenalty the hard way.
304 % \begin{macrocode}
305 \def\MFL@reins#1#2{\ifvoid#2\else\insert#2{\floatingpenalty\@MM}\fi}
306 % \end{macrocode}
307 % \end{macro}
308 % \begin{macro}{\MFL@mpinsert}
309 % \begin{macro}{\MFL@minipage}
310 % The structure of the \cmd{\MFL@mpinsert} box is overly
311 % complicated, and it is a bad idea to unpack the boxes put into it
312 % too early: the \cmd{\lastbox} command is pretty inefficient when
313 % the list before it is long due to unpacking. So we just leave
314 % everything packed in its own boxes, and unpack only at the moment
315 % when we are reinserting.
316 % \begin{macrocode}
317 \long\def\MFL@mpinsert#1#2{%
318 \global\setbox#1\vbox{%
319 \unvbox#1%
320 \nointerlineskip
321 \vbox{#2}%
322 }%
323 }
324
325 \def\FN@divert{%
326 \let\MFL@mpinsertsave\MFL@insert
327 \MFL@reinsert \let\MFL@insert\MFL@mpinsert}
328 \def\FN@enddivert{{\let\@elt\MFL@mpreinsert \MFL@list}}
329
330 \def\MFL@minipage{\ifinner\else \FN@divert\fi}
331 \def\MFL@endminipage{\ifinner\else \FN@enddivert\fi}
332 % \end{macrocode}
333 % \end{macro}
334 % \end{macro}
335 % \begin{macro}{\MFL@mpreinsert}
336 % When reinserting, we put all but the last insertion into one
337 % humongous blob. This is so that the last insertion can be split
338 % by \TeX's paragraph splitting routines. The footnote types that
339 % |bigfoot| supports will never get split by \TeX, anyhow, but it is
340 % conceivable that other extension packages for manyfoot work
341 % differently. There is one difference, though: we let a slave mark
342 % escape into the main vertical list.
343 % \begin{macrocode}
344 \def\MFL@mpreinsert#1#2{%
345 \ifvoid#2\else
346 \setbox\@tempboxa\vbox\bgroup\unvbox#2%
347 \global\setbox#2\lastbox
348 \setbox\z@\lastbox
349 \ifvoid\z@
350 \egroup
351 \setbox\z@\box#2%
352 \else
353 \MFL@removevboxes \unvbox\z@
354 \egroup
355 \setbox\z@\box#2%
356 \MFL@mpinsertsave#2{\unvbox\@tempboxa}%
357 \fi
358 \ifvoid\z@\else
359 \MFL@mpinsertsave#2{\unvbox\z@}%
360 \fi
361 \marks\FN@slave{\number\FN@id}%
362 \fi}
363 % \end{macrocode}
364 % \end{macro}
365 % \begin{macro}{\MFL@removevboxes}
366 % This trick works like \cmd{\removehboxes} in the \TeX book's
367 % appendix~D.
368 % \begin{macrocode}
369 \def\MFL@removevboxes{{\setbox\z@\lastbox
370 \ifvbox\z@ \MFL@removevboxes \unvbox\z@\fi}}
371 % \end{macrocode}
372 % \end{macro}
373 % \begin{macro}{\NCC@makefnmark}
374 % This provides the command in case it is not present (some versions
375 % did not have it).
376 % \begin{macrocode}
377 \ifx\NCC@makemark\@undefined
378 \ifx\NCC@makefnmark\@undefined \else
379 \def\NCC@makemark{\NCC@makefnmark}
380 \fi
381 \fi
382 % \end{macrocode}
383 % \end{macro}
384 %
385 % While the above operations actually were fixes to |manyfoot|, now we
386 % actually patch it for our own purposes. When allocating a new
387 % footnote, we set its maximum dimension to \cmd{\maxdimen} (since no
388 % hard limit makes sense, given that we recalculate all respective
389 % sizes at output time) and allocate a cache box to go with it. We
390 % also add the insertion to the list of insertions in
391 % \cmd{\FN@nestlist}.
392 % \begin{macro}{\MFL@startplain}
393 % \begin{macro}{\MFL@startpara}
394 % \begin{macrocode}
395 \def\MFL@startplain#1{\global\dimen#1\maxdimen
396 \@cons\FN@nestlist{{}#1}%
397 \expandafter\expandafter\expandafter\newbox\FN@cache#1}
398
399 \let\MFL@startpara\MFL@startplain
400 % \end{macrocode}
401 % \end{macro}
402 % \end{macro}
403 % \begin{macro}{\RestyleFootnote}
404 % This macro gets two arguments: a footnote \meta{type}, and the
405 % style to be used for it. It works by redefining the corresponding
406 % |Footnotetext|\meta{type} macro.
407 % \begin{macrocode}
408 \def\RestyleFootnote#1#2{\expandafter\xdef
409 \csname Footnotetext#1\endcsname{\expandafter
410 \noexpand\csname MFL@fnote#2\endcsname{\csname footins#1\endcsname}}}
411 % \end{macrocode}
412 % \end{macro}
413 % \begin{macro}{\FN@stripfootins}
414 % \begin{macro}{\FN@restylefootnote}
415 % We need the same kind of functionality for a footnote specified by
416 % its footnote insertion. So we strip the footnote \meta{type} from
417 % the insertion macro name. Kind of ugly.
418 % \begin{macrocode}
419 \expandafter\def\expandafter\FN@stripfootins\string\footins{}
420
421 \def\FN@restylefootnote#1#2{{\edef\next{%
422 \noexpand\RestyleFootnote{\expandafter\FN@stripfootins
423 \string#1}{#2}}\next}}
424 % \end{macrocode}
425 % \end{macro}
426 % \end{macro}
427 %
428 % \subsection{Dealing with footnote-specific code}
429 % The formatting of footnotes is determined by macros such as
430 % \cmd{\@makefntext}. For several blocks of footnotes, we might want
431 % to have several different ways for formatting them. Whenever this
432 % is the case, we call them with
433 % \begin{quote}
434 % |\FN@specific|\marg{insert\#}\marg{macroname}
435 % \end{quote}
436 % This will use the default \meta{macroname} unless a special macro has
437 % been defined with something like
438 % \begin{quote}
439 % |\FootnoteSpecific\marg{type}|\def|\meta{macroname}\dots
440 % \end{quote}
441 % A number of other defining commands and constructs are available:
442 % those are pretty much like the ones for the \cmd{\WithSuffix} command
443 % implemented by the |suffix| package.
444 % \begin{macro}{\FN@specific}
445 % We use |\romannumeral| here just for the purpose of sustaining
446 % expansion. It expands to nothing when followed by |\z@|
447 % eventually. Thus expanding the expansion of \cmd{\FN@specific}
448 % again delivers the (unexpanded) final token to use.
449 % \begin{macrocode}
450 \def\FN@specific#1#2{\romannumeral
451 \ifcsname FN\string#2\number#1\endcsname
452 \expandafter
453 \z@\csname FN\string#2\number#1\expandafter\endcsname
454 \else\expandafter\z@
455 \expandafter#2\fi}
456 % \end{macrocode}
457 % \end{macro}
458 % \begin{macro}{\FootnoteSpecific}
459 % \begin{macro}{\FN@specific@ii}
460 % This is all a bit muddy, but quite similar to what the |suffix|
461 % package does, so you might want to look there for the explanation.
462 % \begin{macrocode}
463 \def\FootnoteSpecific#1{\count@\csname footins#1\endcsname\toks@{}%
464 \FN@specific@ii}
465
466 \long\def\FN@specific@ii#1#2{\toks@\expandafter{\the\toks@#1}%
467 \the\expandafter\toks@
468 \csname FN\string#2\number\count@\endcsname}
469
470 \WithSuffix\def\FN@specific@ii\long{\toks@\expandafter
471 {\the\toks@\long}\FN@specific@ii}
472
473 \WithSuffix\def\FN@specific@ii\global{\toks@\expandafter
474 {\the\toks@\global}\FN@specific@ii}
475
476 \WithSuffix\def\FN@specific@ii\expandafter{\expandafter
477 \FN@specific@ii\expandafter}
478 % \end{macrocode}
479 % \end{macro}
480 % \end{macro}
481 %
482 % \subsection{Putting footnotes into insertions}
483 % \subsubsection{Dealing with Ids}
484 % Since we have to store additional information for each footnote as
485 % long as it is not yet typeset, we allocate and deallocate numeric
486 % `id's on an as-needed base, since we do not want to store this
487 % sort of information indefinitely, with a large toll on hash space.
488 % So we work with indirect ids, where the unique ids are just
489 % referenced indirectly. We do this with `slots'.
490 % \begin{macro}{\FN@slotxdef}
491 % \begin{macro}{\FN@slotget}
492 % New slots are assigned values with \cmd{\FN@slotxdef}, which can
493 % be retrieved again with \cmd{\FN@slotget}.
494 % \begin{macrocode}
495 \def\FN@slotxdef#1{%
496 \global\expandafter\xdef\csname FN@slot#1\endcsname}
497
498 \def\FN@slotget#1{\csname FN@slot#1\endcsname}
499 %<trace>\def\FN@slotget#1{%
500 %<trace> \expandafter\FN@slotgetii\expandafter
501 %<trace> \FN@slotfreelist\expandafter
502 %<trace> {\number\number#1}}
503 %<trace>\def\FN@slotgetii#1#2{%
504 %<trace> \ifx#1\@empty \csname FN@slot#2\endcsname\else
505 %<trace> \ifnum#1=#2 \errmessage{Use after freed: #1}\else
506 %<trace> \expandafter\FN@slotgetii
507 %<trace> \csname FN@slot#1\endcsname{#2}\fi\fi}
508 % \end{macrocode}
509 % \end{macro}
510 % \end{macro}
511 % \begin{macro}{\FN@slotfreelist}
512 % \begin{macro}{\FN@nextslot}
513 % \cmd{\FN@slotfreelist} point to the first already allocated
514 % available id to be reused. If it is empty, none exist. In that
515 % case, \cmd{FN@nextslot} contains the next slot number to use.
516 % \begin{macrocode}
517 \def\FN@slotfreelist{}
518 \def\FN@nextslot{1}
519 % \end{macrocode}
520 % \end{macro}
521 % \end{macro}
522 % \begin{macro}{\FN@newslot}
523 % This allocates a new slot by setting the given macro to a
524 % currently unused slot number in decimal form. If there is
525 % something left in the freelist, it is assigned, otherwise a new
526 % slot gets allocated.
527 % \begin{macrocode}
528 \def\FN@newslot#1{%
529 \ifx\FN@slotfreelist\@empty
530 \edef#1{\FN@nextslot}%
531 \xdef\FN@nextslot{\number\numexpr \FN@nextslot+\@ne}%
532 \else
533 \let#1\FN@slotfreelist
534 \xdef\FN@slotfreelist{\csname FN@slot\FN@slotfreelist\endcsname}%
535 \fi
536 %<trace> \if\foottrace4\message{^^JAllocated #1^^J}\fi
537 }
538 % \end{macrocode}
539 % \end{macro}
540 % \begin{macro}{\FN@freeslot}
541 % This frees a given slot (by number) again by adding it to the
542 % freelist.
543 % \begin{macrocode}
544 \def\FN@freeslot#1{%
545 %<trace> \if\foottrace4\message{^^JFreeing #1^^J}\fi
546 \global\expandafter\let\csname FN@slot#1\endcsname=\FN@slotfreelist
547 \xdef\FN@slotfreelist{#1}}
548 % \end{macrocode}
549 % \end{macro}
550 %
551 % \subsubsection{Dealing with footnote stacks}
552 % Footnote stacks are used for paired footnotes that refer to a text
553 % range instead of a single text point. For example, you can use
554 % something like
555 % \begin{verbatim}
556 % Text \var<{was there}is here\var>
557 % \end{verbatim}
558 % To have a text variant ``was there'' for the original passage ``is
559 % here'', and mark it, say, as ``\textsuperscript{a}is
560 % here\textsuperscript{\textsl{a}}'' by employing the |suffix| package
561 % suitably. This would anchor the footnote at the start of the
562 % passage. It would also be imaginable to implement the syntax
563 % \begin{verbatim}
564 % Text \var<is here\var>{was there}
565 % \end{verbatim}
566 % for anchoring it at the end of the given passage.
567 % \begin{macrocode}
568 \global\let\FN@stacklist\@empty
569 % \end{macrocode}
570 % \begin{macro}{\DefineFootnoteStack}
571 % This command is used for defining a footnote stack. It gets a
572 % single argument which is the name of the stack and should consist
573 % just of ordinary character tokens.
574 % \begin{macrocode}
575 \def\DefineFootnoteStack#1{%
576 \global\expandafter\let\csname FN@stack@#1\endcsname\@empty
577 \@cons\FN@stacklist{{#1}}%
578 }
579 % \end{macrocode}
580 % \end{macro}
581 % At the end of the document, all stacks are checked to make sure they
582 % have been used up completely.
583 % \begin{macrocode}
584 \AtEndDocument{\FN@checkstacklist}
585
586 \def\FN@checkstacklist{{\let\@elt\FN@checkstack
587 \FN@stacklist}}
588
589 \def\FN@checkstack#1{{\let\@elt\FN@checkstackentry
590 \csname FN@stack#1@\endcsname}}
591
592 \def\FN@checkstackentry#1#2#3{%
593 \PackageError{bigfoot}{Unfinished #1 #2 from line #3}%
594 {The specified footnote range is uncomplete}}
595 % \end{macrocode}
596 % \begin{macro}{\PushFootnoteMark}
597 % This gets one argument, the name of the footnote stack. It pushes
598 % the current footnote mark name stored in \cmd{\@thefnmark} onto
599 % the footnote stack.
600 % \begin{macrocode}
601 \def\PushFootnoteMark#1{{\let\@elt\relax
602 \expandafter\unrestored@protected@xdef \csname FN@stack@#1\endcsname
603 {\@elt{#1}{\@thefnmark}{\number\inputlineno}\csname
604 FN@stack@#1\endcsname}}}
605 % \end{macrocode}
606 % \end{macro}
607 % \begin{macro}{\PopFootnoteMark}
608 % This gets one argument, the name of the footnote stack. It pops
609 % the value of \cmd{\@thefnmark} from the named footnote stack.
610 % \begin{macrocode}
611 \def\PopFootnoteMark#1{\expandafter
612 \ifx\csname FN@stack@#1\endcsname\@empty
613 \PackageError{bigfoot}{Empty footnote stack #1}%
614 {The specified footnote type has no uncompleted range}%
615 \else
616 {\let\@elt\FN@firstpop
617 \iffalse{\fi\csname FN@stack@#1\endcsname}}\fi}
618 % \end{macrocode}
619 % \end{macro}
620 % \begin{macrocode}
621 \def\FN@firstpop#1#2#3{\protected@xdef\@thefnmark{#2}%
622 \let\@elt\relax
623 \expandafter\protected@xdef\csname FN@stack@#1\endcsname{%
624 \iffalse}\fi}
625 % \end{macrocode}
626 %
627 % \subsubsection{Continuation marks}
628 %
629 % We add a possibility of adding continuation marks. While the box is
630 % assembled, immediately before the break, \cmd{\FN@beforebreak} gets
631 % called, and \cmd{\FN@afterbreak} is called at the top of the
632 % continuing box.
633 % \begin{macrocode}
634 \ifx\FN@beforebreak\@undefined
635 \let\FN@beforebreak\@empty
636 \fi
637 \ifx\FN@afterbreak\@undefined
638 \let\FN@afterbreak\@empty
639 \fi
640 % \end{macrocode}
641 %
642 %
643 %\subsubsection{The works}
644 %
645 % \begin{macro}{\FN@cache}
646 % Cacheboxes cache the typeset forms of the insertion boxes for a
647 % certain configuration of footnotes.
648 % \begin{macrocode}
649 \def\FN@cache#1{\csname FN@cache\number#1\endcsname}
650 % \end{macrocode}
651 % \end{macro}
652 % \cmd{\FN@sortlist} takes the current vertical list and sorts the
653 % contained boxes according to their width (which is supposed to
654 % contain the sort key).
655 %
656 % The algorithm is a pretty straightforward insertion sort with
657 % $O(n^2)$~steps. This is the best one can hope for without
658 % comparisons across non-adjacent list elements. For presorted lists,
659 % the performance will be $O(n)$, and that's what we expect to see for
660 % simple cases (and when there are no sortkeys yet). Any negative
661 % width will certainly hang the algorithm.
662 %
663 % It also happens that \TeX\ has a hardwired limit for grouping levels
664 % that hits at 255. Oops. We better not have a few hundred footnotes
665 % in a single block on one page\dots
666 % \begin{macrocode}
667 \def\FN@sortlist{{%
668 \setbox\z@\lastbox
669 \ifvoid\z@ \else \FN@sortlist\FN@sortlistii \fi}}
670
671 \def\FN@sortlistii{%
672 \setbox\tw@\lastbox
673 \ifvoid\tw@\else
674 \ifdim\wd\tw@<\wd\z@ {\FN@sortlistii}%
675 \fi\nointerlineskip\box\tw@\fi\nointerlineskip\box\z@}
676 % \end{macrocode}
677 % \begin{macro}{\FN@sortinsert}
678 % This function is an \cmd{\@elt} function that will sort the given
679 % insertion if it is non-empty and if there is no cache box present
680 % (which would imply that the insertion had already been sorted
681 % previously).
682 % \begin{macrocode}
683 \def\FN@sortinsert#1#2{\ifvoid\FN@cache#2%
684 \ifvoid#2\else\global\setbox#2\vbox{\unvbox#2%
685 \FN@sortlist}\fi\fi}
686 % \end{macrocode}
687 % \end{macro}
688 % \begin{macro}{\FN@maybeinvalidatecache}
689 % This is called after pulling in additional material from the
690 % page. If the material added an insertion, the cache is junk and
691 % must be regenerated.
692 % \begin{macrocode}
693 \def\FN@maybeinvalidatecache#1#2{%
694 \ifvoid#2\else\global\setbox\FN@cache#2=\box\voidb@x\fi}
695 % \end{macrocode}
696 % \end{macro}
697 % \begin{macro}{\FN@regeneratecache}
698 % This unconditionally regenerates one cache box. The structure of
699 % a cache box is basically a list of vertical boxes. All but the
700 % last such box are packed into a single vertical box which is then
701 % followed by the last vertical box.
702 % \begin{macrocode}
703 \def\FN@regeneratecache#1#2{%
704 \global\setbox\FN@cache#2=%
705 \ifvoid#2%
706 \box\voidb@x
707 \else
708 \vbox{\vbox{\unvcopy#2%
709 \setbox\z@\lastbox
710 \def\FN@masterinsert{#2}%
711 \FN@assembleboxes
712 \global\setbox\FN@cache#2\box\z@}%
713 \nointerlineskip \box\FN@cache#2}%
714 \fi}
715 % \end{macrocode}
716 % \end{macro}
717 % \begin{macro}{\FN@mayberegeneratecache}
718 % This regenerates the cache in case the cache box has been voided
719 % in order to mark it as invalid.
720 % \begin{macrocode}
721 \def\FN@mayberegeneratecache#1#2{%
722 \ifvoid\FN@cache#2%
723 \FN@regeneratecache{}#2%
724 \fi}
725 % \end{macrocode}
726 % \end{macro}
727 % \begin{macro}{\FN@cachesize}
728 % This calculates the size impact of a cache box on the current page
729 % as a term to be added into a \cmd{\glueexpr}-type of expression.
730 % \begin{macrocode}
731 \def\FN@cachesize#1#2{%
732 \ifvoid\FN@cache#2%
733 \else
734 +\skip#2+(\ht\FN@cache#2+\dp\FN@cache#2)*\count#2/\@m
735 \fi}
736 % \end{macrocode}
737 % \end{macro}
738 % \begin{macro}{\FN@clearcache}
739 % This just completely voids a cache register.
740 % \begin{macrocode}
741 \def\FN@clearcache#1#2{%
742 \global\setbox\FN@cache#2=\box\voidb@x}
743 % \end{macrocode}
744 % \end{macro}
745 %
746 % \begin{macro}{\@makefnvtext}
747 % Ok, this is one of the parts putting together footnotes in para
748 % mode. The footnotes themselves have already been formatted into
749 % hboxes (placed there with \cmd{\@preparefnhtext} in order to cater
750 % for proper indentation). \cmd{\@makefnvtext} then formats a
751 % single footnote block from horizontal mode pieces (vertical mode
752 % pieces are kept as-is).
753 % This takes text and typesets it in a single block. To get correct
754 % indentation, it breaks before the first footnote and adjusts the
755 % clubpenalties to move them to one line lower effectively.
756 % \cmd{\@makefnvtext} is called in vertical mode, and its argument
757 % is typeset in horizontal mode right after a break, inside of
758 % \cmd{\@makefntext}.
759 % \begin{macrocode}
760 \def\@makefnvtext#1{%
761 \FN@specific\FN@masterinsert\@makefntext{%
762 \clubpenalties\thr@@\@MM\clubpenalty\z@
763 \vadjust{\nobreak\vskip-\baselineskip}\nobreak\hfill\break#1}}
764 % \end{macrocode}
765 % \end{macro}
766 % \begin{macro}{\@preparefnhtext}
767 % This creates appropriate skips to be put before the horizontal
768 % material to make the indentation correct with a breakpoint before
769 % the footnote as well as when in run-in text. This is run once at
770 % the start of each horizontal mode footnote when it is first being
771 % typeset, in horizontal mode.
772 % \begin{macrocode}
773 \ifx\@preparefnhtext\@undefined
774 \def\@preparefnhtext{{%
775 \setbox\z@\vbox{\FN@specific\FN@masterinsert\@makefntext{%
776 \unskip\unpenalty\setbox\z@\lastbox
777 \dimen@
778 \ifnum\parshape>\z@
779 \dimexpr\parshapeindent\tw@-\parshapeindent\@ne\relax
780 \else \ifnum\hangafter=\@ne\hangindent \else
781 \ifnum\hangafter=\m@ne -\hangindent
782 \else \z@ \fi\fi\fi
783 \dimen@ii\dimen@
784 \ifhbox\z@ \advance\dimen@-\wd\z@
785 \setbox\z@\hbox{\unhbox\z@}%
786 \advance\dimen@\wd\z@
787 \fi
788 \xdef\FN@tempinfo{\hskip\the\dimen@
789 \vadjust{}\nobreak\hskip-\the\dimen@ii\relax}}}}%
790 \FN@tempinfo}
791 \fi
792 % \end{macrocode}
793 % Now we have in |\FN@tempinfo| the excess width of the label we don't
794 % want to preserve when doing in-paragraph footnote setting. A
795 % sequence of glue before a label now has to consist of stuff that
796 % vanishes at a breakpoint, followed by stuff that remains. We have
797 % to have two behaviors for the contents: behavior one is
798 % justification at the start of a line, behavior two is justification
799 % in the line. When we are at the start of the line, preceding
800 % interword space disappears swallowed and so the natural criterion
801 % for distinguishing those cases is this initial line break. This
802 % means that we can't avoid articifially adding a line break at the
803 % start of such a box. We will back up its height again. Some
804 % packages specify a |\hangindent| (I~know of no examples where they
805 % would actually set |\hangafter| to a value different from its
806 % default of~1, or set |\hangindent| to a negative value which would
807 % affect the right margin): due to our artifical line at the top, the
808 % indent will actually be active for the first line already. We back
809 % it out of the actual labels happening at the start of the line.
810 % Two-line parshapes have the same effect: the first line is not
811 % actually used, and we put the relevant info for the first line into
812 % the label. Different right indentation for the first line is
813 % something we can't simulate, but again, it should occur rarely.
814 % When |\parshape| is active, |\hangindent| is ignored.
815 % \end{macro}
816 % \begin{macrocode}
817 \def\@makefnstartbox{%
818 \ifdefined\setspace@singlespace
819 \def\baselinestretch{\setspace@singlespace}%
820 \fi
821 \reset@font\footnotesize
822 \hsize\MFL@columnwidth \@parboxrestore
823 \interlinepenalty\FN@specific\FN@masterinsert\interfootnotelinepenalty
824 \widowpenalty\FN@specific\FN@masterinsert\footnotewidowpenalty
825 \clubpenalty\FN@specific\FN@masterinsert\footnoteclubpenalty
826 \advance\linepenalty500\relax}
827
828 \def\@makefnendbox{%
829 \widowpenalty\FN@specific\FN@masterinsert\finalfootnotewidowpenalty}
830
831 \newcount\footnotewidowpenalty
832 \footnotewidowpenalty=250
833 \newcount\footnoteclubpenalty
834 \footnoteclubpenalty=250
835 \newcount\finalfootnotewidowpenalty
836 \finalfootnotewidowpenalty=4000
837 % \end{macrocode}
838 % \begin{macro}{\@makefnvbox}
839 % This is the formatting code for a vertical mode footnote box from
840 % already set horizontal material. It uses \cmd{\@makefnstartbox}
841 % for setting up the initial widow/club penalties, and
842 % \cmd{\@makefnendbox} for preparing the final end. It results in a
843 % vbox.
844 % \begin{macrocode}
845 \ifx\@makefnvbox\@undefined
846 \def\@makefnvbox#1{\vbox{%
847 \@makefnstartbox
848 \clubpenalties\thr@@\@MM\clubpenalty\z@
849 \let\@thefnmark\@empty
850 \FN@specific\FN@masterinsert\@makefntext{\rule\z@\footnotesep
851 \nobreak
852 #1\@finalstrut\strutbox
853 \@makefnendbox}}}
854 \fi
855 % \end{macrocode}
856 % \end{macro}
857 % \begin{macro}{\hfootfraction}
858 % \begin{macro}{\vtypefraction}
859 % Those parameters govern when a footnote block is going to be set
860 % completely in vertical mode. If a footnote block does not shrink
861 % to less than \cmd{\hfootfraction} its size when using in-paragraph
862 % notes or has at least \cmd{\vtypefraction} of forcedly vertical
863 % footnotes (specified as purely vertical, or vertical because of
864 % being large), it is set entirely in vertical mode.
865 % \begin{macrocode}
866 \def\hfootfraction{0.9}
867 \def\vtypefraction{0.7}
868 % \end{macrocode}
869 % \end{macro}
870 % \end{macro}
871 % \begin{macro}{\FN@assembleboxes}
872 % This will produce the finished product, by generating all boxes
873 % and concatenating them except for the last vbox. It is assumed
874 % that have already set |\box\z@| to |\lastbox| before calling this
875 % routine (or, more likely, have already assembled and split the
876 % last box). The last, not yet unpacked |\vbox| is left in
877 % |\box\z@| on return. The original id of the last box of a block
878 % is properly transferred to it.
879 %
880 % The last box might have come about by joining several horizontal
881 % boxes, so splitting it might separate footnotes. We deal with
882 % that problem at a different point of time by checking the
883 % respective Ids when breaking a vbox into pieces: if the split
884 % piece does not contain the last footnote beginning, we switch to a
885 % slow motion decomposal. \cmd{\FN@assembleboxes} is supposed to be
886 % entered and exited in vertical mode.
887 % \begin{macrocode}
888 \def\FN@assembleboxes{%
889 %<trace> \ifhmode \PackageError{bigfoot}{Unexpected hmode}{}\fi
890 \ifhbox\z@
891 \dimen@\dp\z@
892 %<trace> \MFL@checksinglebox\z@\z@{}{}%
893 \dimen@ii\z@
894 \setbox\tw@\box\voidb@x
895 \loop \advance\dimen@ii\dimexpr\ht\z@+\dp\z@\relax
896 \setbox\tw@\hbox{\box\z@\unhbox\tw@}%
897 \setbox\z@\lastbox
898 \ifhbox\z@
899 \repeat
900 {\FN@assembleboxes\nointerlineskip\unvbox\z@}%
901 % \end{macrocode}
902 % At this point of time, |\box\tw@| contains a plain hbox with nothing
903 % but the unadorned hboxes in horizontal mode to be joined into one
904 % footnote block. All preceding footnote blocks have been emptied
905 % into the current vertical list. We put the |\unvbox| operations in
906 % a group so that the paragraph shapes will not get reset over the
907 % break.
908 % \begin{macrocode}
909 \global\setbox\FN@tempbox\copy\tw@
910 \setbox\z@\@makefnvbox{%
911 {\unhbox\FN@tempbox}%
912 \setbox\z@\lastbox\FN@joinhboxes}%
913 \ifcase
914 \ifdim\FN@vfound>\dimexpr\vtypefraction\p@*\FN@found\relax \@ne\fi
915 \ifdim\dimexpr \ht\z@+\dp\z@>\hfootfraction\dimen@ii \@ne\fi \z@
916 \or
917 \global\setbox\FN@tempbox\box\tw@
918 \setbox\z@\@makefnvbox{\let\@makefnbreak\FN@pseudofillbreak
919 {\unhbox\FN@tempbox}\setbox\z@\lastbox\FN@joinhboxes}%
920 \fi
921 \setbox\tw@\box\voidb@x
922 \ht\z@\dimexpr \ht\z@+\dp\z@-\dimen@\relax
923 \dp\z@\dimen@
924 %<trace> \MFL@checksinglebox\z@\z@{}{}%
925 \else
926 \ifvbox\z@
927 %<trace> \MFL@checksinglebox\z@\z@{}{}%
928 {\setbox\z@\lastbox
929 \FN@assembleboxes\nointerlineskip\unvbox\z@}%
930 \fi
931 \fi}
932 % \end{macrocode}
933 % \end{macro}
934 % Ok, now follow a lot of fuzzy calculation routines. When we are
935 % considering truth values, |\p@| (1pt) corresponds to a value of
936 % ``true'', and |\z@| corresponds to ``false''.
937 % \begin{macro}{\FN@fuzzyeval}
938 % This calculates a ratio, something with which you multiply. The
939 % first two arguments of the function define an interval, and the
940 % third argument is a value in that interval. If |#3| is equal to
941 % |#1|, the resulting ratio is~0, if the |#3| is equal to |#2|, the
942 % resulting ratio is~1. Values in between are linearly
943 % interpolated. Values outside of the interval are mapped to 0
944 % and~1. If all three values are equal (hardly useful), 1 is
945 % returned.
946 % \begin{macrocode}
947 \def\FN@fuzzyeval#1#2#3{%
948 \ifdim\dimexpr(#3)<\dimexpr(#2)\relax
949 \ifdim\dimexpr(#3)>\dimexpr(#1)\relax
950 *(\dimexpr(#3)-(#1))%
951 /(\dimexpr(#2)-(#1))%
952 \else *\z@
953 \fi
954 \fi}
955 % \end{macrocode}
956 % \end{macro}
957 % \begin{macro}{\FN@fuzzyor}
958 % This returns probabilistic \textsc{or}:
959 % \[(|#1|+|#2|-|#1|\cdot|#2|)\]
960 % \begin{macrocode}
961 \def\FN@fuzzyor#1#2{(\p@-(\p@-(#1))*(\dimexpr\p@-(#2))/\p@)}
962 % \end{macrocode}
963 % \end{macro}
964 % \begin{macro}{\FN@magicclue}
965 % Ok, so here is the magic glue calculator. |#1| and~|#2| give the
966 % range over which the preceding line changes from `short' to `long'.
967 % |#3| and |#4| give the range over which the current line changes
968 % from `short' to `long'. Both are combined with a probabilistic or
969 % function, and then a penalty is chosen which ranges from |#5|
970 % to~|#6| for short to long.
971 % \begin{macrocode}
972 \def\FN@magicglue#1#2#3#4#5#6{%
973 %<trace> \if\foottrace2\traceon\fi
974 \dimen@\dimexpr\p@\FN@fuzzyeval{#1}{#2}\FN@lasthsize\relax
975 \dimen@ii\dimexpr\p@\FN@fuzzyeval{#3}{#4}{\ht\z@+\dp\z@}\relax
976 \dimen@\dimexpr\FN@fuzzyor\dimen@\dimen@ii
977 \count@\numexpr((#6)-(#5))*\dimen@/\p@+(#5)\relax
978 \xdef\FN@vfound{\the\dimexpr\FN@vfound+\dimen@}%
979 \ifnum\count@>-\@M
980 \penalty\count@
981 \hskip\glueexpr -\parfillskip+1em minus 0.5em\relax
982 \else
983 \FN@pseudobreak
984 \fi
985 \xdef\FN@found{\number\numexpr\FN@found+\@ne}%
986 }
987 % \end{macrocode}
988 % \end{macro}
989 % \begin{macro}{\FN@pseudobreak}
990 % This ends a line, but without introducing parskip and similar. It
991 % also `breaks in' the next line to get proper indentation. The
992 % main difference with regard to \cmd{\break} is that this restarts
993 % the reckoning of line numbers for the sake of \cmd{\clubpenalty}
994 % calculation.
995 % \begin{macrocode}
996 \def\FN@pseudobreak{%
997 {\parskip\z@skip\parfillskip\z@skip\parindent\z@\vadjust{}\par\noindent
998 \vadjust{\nobreak\vskip-\baselineskip}\nobreak\hfill\break}}
999 % \end{macrocode}
1000 % \end{macro}
1001 % \begin{macro}{\FN@pseudofillbreak}
1002 % This is basically just for separating paragraphs by force.
1003 % \begin{macrocode}
1004 \def\FN@pseudofillbreak{\nobreak\hskip\parfillskip\FN@pseudobreak}
1005 % \end{macrocode}
1006 %
1007 % \end{macro}
1008 % \begin{macro}{\@makefnbreak}
1009 % This calculates the glue for the standard horizontal footnotes.
1010 % \begin{macrocode}
1011 \def\@makefnbreak{\FN@magicglue {\footnotesep+\dp\strutbox}%
1012 {\footnotesep+\dp\strutbox+\baselineskip}%
1013 {\footnotesep+\dp\strutbox+0.5\baselineskip}%
1014 {\footnotesep+\dp\strutbox+2\baselineskip}{-200}{-12000}}
1015 % \end{macrocode}
1016 % \end{macro}
1017 % \cmd{\FN@joinhboxes} is called with box~0 set to the next box to be
1018 % appended to the current list (all preceding hboxes on the current
1019 % vertical list will have to go in front). \cmd{\FN@joinhboxes} is
1020 % entered in vertical mode, and will be exited in horizontal mode.
1021 % \begin{macrocode}
1022 \def\FN@joinhboxes{%
1023 %<trace> \ifvmode \errmessage{Unexpected vertical mode.}\fi
1024 \begingroup\setbox\z@\lastbox
1025 \ifhbox\z@ \FN@joinhboxes
1026 %<trace> \ifvmode \errmessage{Unexpected vertical mode.}\fi
1027 \endgroup
1028 \nobreak\hskip\parfillskip
1029 \@makefnbreak
1030 \else
1031 %<trace> \ifvbox\z@ \errmessage{Unexpected vbox.}\fi
1032 \endgroup
1033 \vadjust{\nobreak\vskip-\baselineskip}\nobreak\hfill\break
1034 \xdef\FN@vfound{\z@}%
1035 \xdef\FN@found{\z@}%
1036 \fi
1037 \xdef\FN@lasthsize{\the\dimexpr \ht\z@ +\dp\z@}%
1038 \unhbox\z@}
1039 % \end{macrocode}
1040 % \begin{macro}{\FN@par}
1041 % \begin{macro}{\FN@noindent}
1042 % \begin{macro}{\FN@indent}
1043 % In-paragraph footnotes are collected in horizontal mode. So
1044 % |\par|, \cmd{\noindent} and \cmd{\indent} simply don't work. We
1045 % replace them with something having the same effect when the boxes
1046 % get unhboxed. Note that this does not admit the tracking of
1047 % club/widow penalties: in a later version, it should get replaced
1048 % by something that actually allows for separate paragraphs. One
1049 % possibility would be to replace the current single hbox for an
1050 % in-paragraph footnote by an hbox of hboxes and unbox all of them
1051 % in separate paragraphs. But that glosses over the fact that a
1052 % multi-paragraph footnote does not make sense in anything but
1053 % vertical mode. So a saner way would probably be to close off the
1054 % hbox altogether and reinsert it into a vbox, restarting the whole
1055 % footnote in vertical mode. Both of those approaches would require
1056 % that no groups have been opened since the start of the footnote by
1057 % the time |\par| gets called. The below pseudosolution at least
1058 % has the advantage of not depending on the grouping structure at
1059 % all.
1060 % \begin{macrocode}
1061 \def\FN@par{\unskip\nobreak\hskip\parfillskip
1062 \vadjust{\vskip\parskip}\break\null\kern\parindent\ignorespaces}
1063 \def\FN@noindent{\unkern}
1064 \def\FN@indent{\unkern{\setbox\z@\null\wd\z@\parindent\box\z@}}
1065 % \end{macrocode}
1066 % \end{macro}
1067 % \end{macro}
1068 % \end{macro}
1069 % \begin{macro}{\MFL@fnoteplain}
1070 % \begin{macro}{\MFL@fnotepara}
1071 % We redefine |manyfoot|'s basic footnote calls to use our own,
1072 % versatile variant.
1073 % \begin{macrocode}
1074 \def\MFL@fnoteplain{\FN@fnotenested{plain}}
1075 \def\MFL@fnotepara{\FN@fnotenested{para}}
1076 % \end{macrocode}
1077 % \end{macro}
1078 % \end{macro}
1079 % \begin{macro}{\FN@fnotenested}
1080 % This is somewhat contorted: we want |\footnote+| to be in |plain|
1081 % style and |\footnote-| in |para| style regardless of the current
1082 % footnote style. Adding a second |+| or |-| after the first will
1083 % actually restyle all footnotes coming afterwards appropriately.
1084 % This should work for all footnote commands getting footnote text.
1085 % \begin{macrocode}
1086 \def\FN@fnotenested#1#2#3{%
1087 \edef\reserved@d{#1}%
1088 \FN@checkvariant{\edef\reserved@d}{%
1089 \FN@checkvariant{\FN@restylefootnote{#2}}%
1090 {\csname FN@fnote\reserved@d\endcsname{#2}{#3}}}}
1091
1092 \def\FN@checkvariant#1#2{\def\reserved@a{#1}%
1093 \def\reserved@b{#2}%
1094 \futurelet\reserved@c\FN@checkvariantii}
1095
1096 \def\FN@checkvariantii{%
1097 \ifx\reserved@c+%
1098 \reserved@a{plain}\expandafter\@firstoftwo
1099 \else\ifx\reserved@c-%
1100 \reserved@a{para}\expandafter\expandafter\expandafter
1101 \@firstoftwo
1102 \fi\fi
1103 \reserved@b}
1104 % \end{macrocode}
1105 % \end{macro}
1106 % In order to be able to sort footnotes according to the order of
1107 % their reference points, we use a sorted counter.
1108 % \begin{macrocode}
1109 \newcounter{FN@totalid}
1110 \MakeSorted{FN@totalid}
1111 % \end{macrocode}
1112 % \begin{macro}{\FN@fnoteplain}
1113 % \begin{macro}{\FN@fnotepara}
1114 % The actual commands are easy enough:
1115 % \begin{macrocode}
1116 \def\FN@fnoteplain{\FN@fnotecommon\vbox}
1117 \def\FN@fnotepara{\FN@fnotecommon\hbox}
1118 % \end{macrocode}
1119 % \end{macro}
1120 % \end{macro}
1121 % \begin{macro}{\FN@masterinsert}
1122 % This contains the insert number of the insert where the footnote
1123 % mark appears. If it appears in the main text, 255~will be used.
1124 % \begin{macrocode}
1125 \def\FN@masterinsert{\@cclv}
1126 % \end{macrocode}
1127 % \end{macro}
1128 % \begin{macro}{\FN@id}
1129 % \begin{macro}{\FN@master}
1130 % \begin{macro}{\FN@slave}
1131 % Here is the deal with master and slave ids: each footnote has a
1132 % unique master id. This master id is larger by one than the last
1133 % id of its subordinate footnotes. It is recorded in the mark
1134 % \cmd{\FN@master} in the footnote box at the start itself, although
1135 % with an indirection through the \cmd{\FN@newslot} mechanism since
1136 % the actual id can only become known after all subfootnotes have
1137 % been typeset. The same id is recorded in \cmd{\FN@slave} at the
1138 % ultimate end of the footnote.
1139 %
1140 % At the point where a \cmd{\FN@master} mark is placed, a default
1141 % \cmd{\FN@slave} mark is placed also with an id that is one less
1142 % than the smallest id generated from a footnote that is a
1143 % `descendent' of the current one. This makes it possible to
1144 % distinguish any split off subordinate footnotes. It must be noted
1145 % that this sentinel slave id will be the valid id of a completely
1146 % unrelated footnote! Since the value is only used for determining
1147 % one end of an \emph{open} interval of excluded ids, this is no
1148 % problem. All subordinate footnotes are numbered sequentially in
1149 % the order of \emph{completion}, so that any subordinate footnotes
1150 % have lower ids than their master.
1151 % \begin{macrocode}
1152 \newcount\FN@id
1153 \FN@id\@ne
1154 \newmarks\FN@master
1155 \newmarks\FN@slave
1156 % \end{macrocode}
1157 % \end{macro}
1158 % \end{macro}
1159 % \end{macro}
1160 % \begin{macro}{\FN@errorstack}
1161 % This records the history of nested footnotes in order to deliver
1162 % more useful error messages.
1163 % \begin{macrocode}
1164 \let\FN@errorstack\@empty
1165 % \end{macrocode}
1166 % \end{macro}
1167 % \begin{macro}{\FN@fnotecommon}
1168 % Well, this is the work horse if the footnote macro. Really bad
1169 % thing. We start off by stepping our absolute counter and making a
1170 % mark. \cmd{\leavevmode} is required so that the action of
1171 % |perpage.sty| is done smoothly.
1172 % \begin{macrocode}
1173 \def\FN@fnotecommon#1#2#3{%
1174 \leavevmode
1175 \stepcounter{FN@totalid}%
1176 \NCC@makemark{#3}%
1177 % \end{macrocode}
1178 % It is an error if the footnote insert number of the current
1179 % footnote does not correspond to a block below the current
1180 % insertion level.
1181 % \begin{macrocode}
1182 \ifnum#2<\FN@masterinsert
1183 \FN@colorstackbgroup\FN@divert
1184 \FN@newslot\FN@masterslot
1185 \count@\FN@id
1186 % \end{macrocode}
1187 % \cmd{\dimen@} is here set to a sorting criterion. This is
1188 % designed to make the conversion of footnote blocks as reliable as
1189 % possible. If we could guarantee convergence, just using
1190 % \cmd{\c@FN@totalid} would be sufficient for sorting. It turns out
1191 % that this is too sensitive to footnotes of different blocks
1192 % changing pages, so the number of the superior footnote block is
1193 % allowed to take precedence by multiplying it with 4194304 which is
1194 % unlikely to get exceeded by \cmd{\c@FN@totalid}.
1195 % \begin{macrocode}
1196 \dimen@=\dimexpr64\p@*\FN@masterinsert-\c@FN@totalid sp\relax
1197 \def\FN@masterinsert{#2}%
1198 \edef\FN@errorstack{\FN@errorstack^^J%
1199 \FN@masterinsert\space entered in line \number\inputlineno}%
1200 \let\FN@boxtype=#1%
1201 \setbox\z@#1\bgroup
1202 % \end{macrocode}
1203 % The following is for the likes of PDF\TeX\ which has its own idea
1204 % about how to restore a color stack.
1205 % \begin{macrocode}
1206 \let\current@color\default@color
1207 \FN@@color@begingroup
1208 \let\MFL@minipage\relax
1209 \let\MFL@endminipage\relax
1210 \@makefnstartbox
1211 % \end{macrocode}
1212 % We reset the list parameters in footnotes. Strictly speaking,
1213 % this is interfering with \LaTeX's standard operation, but the
1214 % standard operation does not make sense.
1215 % \begin{macrocode}
1216 \let\@listdepth\@mplistdepth \@mplistdepth\z@
1217 \@itemdepth\z@ \@enumdepth\z@
1218 \protected@edef\@currentlabel{\csname p@footnote%
1219 \expandafter\FN@stripfootins\string#2\endcsname\@thefnmark}%
1220 \ifx\FN@boxtype\vbox \normalcolor\nobreak
1221 \else \FN@specific{#2}\@preparefnhtext \normalcolor
1222 \fi
1223 % \end{macrocode}
1224 % Ok, now we do the call to \cmd{\@makefntext} which may occur in
1225 % one of several ways, depending on whether the `robust' or the
1226 % `fragile' package option got used.
1227 % \begin{macrocode}
1228 \expandafter \FN@makefncall
1229 \else
1230 % \end{macrocode}
1231 % We still needed to cater for the error of badly anchored footnotes:
1232 % \begin{macrocode}
1233 \PackageError{bigfoot}{#2 forbidden in \FN@masterinsert.}%
1234 {Higher-placed footnotes can't be anchored in inferior ones.^^J%
1235 I am not putting this text in a footnote. History:%
1236 \FN@errorstack}%
1237 \rule{1em}{\ht\strutbox}%
1238 \fi}
1239 % \end{macrocode}
1240 % \end{macro}
1241 % \begin{macro}{\FN@makefnstart}
1242 % This is called in the start of \cmd{\@makefntext}.
1243 % \begin{macrocode}
1244 \providecommand{\FN@seitenobreak}{\nobreak}
1245 \def\FN@makefnstart{%
1246 % \end{macrocode}
1247 % Record the footnote specific dimensions. It is assumed that they
1248 % don't change in the document, at least not before the footnote
1249 % gets actually placed.
1250 % \begin{macrocode}
1251 \expandafter\xdef\csname FN@ht\number\FN@masterinsert\endcsname
1252 {\the\footnotesep}%
1253 \expandafter\xdef\csname FN@dp\number\FN@masterinsert\endcsname
1254 {\the\dp\strutbox}%
1255 \expandafter\xdef\csname FN@wd\number\FN@masterinsert\endcsname
1256 {\the\hsize}%
1257 % \end{macrocode}
1258 % The footnote gets markers for identifying it and its starting block.
1259 % \begin{macrocode}
1260 \marks\FN@master{\FN@masterslot}%
1261 \marks\FN@slave{\number\FN@id}%
1262 \nobreak
1263 % \end{macrocode}
1264 % \cmd{\FN@commonending} will intervene before any tokens that are
1265 % shifted in due to switching back the color stack. Those will only
1266 % be executed once we completely relinquish control.
1267 % \begin{macrocode}
1268 \ifx\FN@boxtype\vbox
1269 \rule\z@\footnotesep
1270 \else
1271 \ifx\FN@par\par\else
1272 \let\FN@@par\par
1273 \let\FN@@noindent\noindent
1274 \let\FN@@indent\indent
1275 \fi
1276 \everyvbox\expandafter{\expandafter\everyvbox
1277 \expandafter{\the\everyvbox}%
1278 \let\par\FN@@par
1279 \let\noindent\FN@@noindent
1280 \let\indent\FN@@indent
1281 \the\everyvbox}%
1282 \let\par\FN@par
1283 \let\noindent\FN@noindent
1284 \let\indent\FN@indent
1285 \fi
1286 \FN@seitenobreak
1287 \afterassignment\ignorespaces}
1288 % \end{macrocode}
1289 % \end{macro}
1290 % \begin{macro}{\FN@makefnrobust}
1291 % After preparation, we now do the big bad trick for making
1292 % footnotes cooperate with \cmd{\verb} and other catcode changing
1293 % things: we call \cmd{\@makefntext} with an argument of
1294 % |\iffalse|. This kills off its expansion right at the point
1295 % where it would choose to place its argument.
1296 %
1297 % Furthermore, this swallows the opening brace of the footnote text
1298 % and then lets the footnote text progress. The closing group will
1299 % then trigger the processing via \cmd{\aftergroup}.
1300 % \begin{macrocode}
1301 \def\FN@makefnrobust#{%
1302 \FN@specific\FN@masterinsert\@makefntext
1303 \iffalse\fi
1304 \bgroup
1305 \aftergroup\FN@robustending
1306 \FN@makefnstart
1307 \let\next}
1308 % \end{macrocode}
1309 % \end{macro}
1310 % \begin{macro}{\FN@robustending}
1311 % Here we put in the missing part of \cmd{\@makefntext}.
1312 % \begin{macrocode}
1313 \def\FN@robustending{%
1314 \expandafter\expandafter\expandafter
1315 \expandafter\expandafter\expandafter\expandafter
1316 \iffalse \FN@specific\FN@masterinsert\@makefntext\fi
1317 \FN@commonending}
1318 % \end{macrocode}
1319 % \end{macro}
1320 % \begin{macro}{\FN@makefnfragile}
1321 % This is the escape route when the robust variant does not work.
1322 % In that case, |\verb| and similar won't work in footnotes.
1323 % \begin{macrocode}
1324 \long\def\FN@makefnfragile#1{%
1325 \FN@specific\FN@masterinsert\@makefntext
1326 {\FN@makefnstart#1\FN@commonending}}
1327 % \end{macrocode}
1328 %
1329 % \end{macro}
1330 %
1331 % Ok, color handling is a nuisance, to say the least. Split
1332 % footnotes need to close their color stack on the old page, and reopen
1333 % it on the new one. So we record the color stack state at each time
1334 % it changes in a marks register.
1335 % \begin{macrocode}
1336 \newmarks\FN@color
1337 \def\FN@colorstackbgroup{\let\FN@savecolorstack\FN@colorstack
1338 \global\let\FN@colorstack\@empty
1339 \bgroup
1340 \ifdefined\FN@savecolorstack\else
1341 \let\FN@@set@color\set@color
1342 \let\FN@@reset@color\reset@color
1343 \let\FN@@color@begingroup\color@begingroup
1344 \fi
1345 \let\set@color\FN@set@color
1346 \let\reset@color\FN@reset@color
1347 \let\color@begingroup\FN@color@begingroup}
1348
1349 \def\FN@colorstackegroup{\egroup
1350 \global\let\FN@colorstack\FN@savecolorstack}
1351
1352 \def\FN@colorstackfinish{\def\@elt##1##2{\FN@@reset@color##2}%
1353 \FN@colorstack
1354 \def\@elt##1##2{\noexpand\@elt{}{##2}}%
1355 \xdef\FN@colorstack{\FN@colorstack}%
1356 \let\@elt\relax
1357 \marks\FN@color{}}
1358
1359 \def\FN@reset@color{%
1360 \bgroup\def\@elt##1##2{\def\FN@next{##1}{\gdef\FN@colorstack{##2}}}%
1361 \let\FN@next\@empty
1362 \FN@colorstack
1363 \ifx\FN@next\@empty
1364 \FN@colorstackegroup
1365 \else \egroup
1366 \FN@@reset@color
1367 \marks\FN@color{\FN@colorstack}%
1368 \fi}
1369
1370 \def\FN@color@begingroup{%
1371 \let\reset@color\FN@@reset@color
1372 \let\color@begingroup\FN@@color@begingroup
1373 \let\set@color\FN@@set@color
1374 \color@begingroup}
1375
1376 \def\FN@set@color{\FN@@set@color
1377 \xdef\FN@colorstack{\@elt{\current@color}{\FN@colorstack}}%
1378 \marks\FN@color{\FN@colorstack}}
1379
1380 \def\FN@coloraftersplit#1{%
1381 \def\@elt##1##2{##2\def\current@color{##1}\set@color}%
1382 #1%
1383 \let\@elt\relax}
1384 % \end{macrocode}
1385 % \begin{macro}{\FN@commonending}
1386 % We'll eventually arrive here at the end of the footnote. Now we
1387 % again call \cmd{\@makefntext}, but this time pass it |\fi| as
1388 % its argument, and place |\iffalse| before its expansion. This
1389 % cuts away the start of the macro. If this start changes the tail
1390 % of the macro when executed, the whole trickery will not work. It
1391 % turns out that a large sampling of document classes (including the
1392 % standard ones) happens to work.
1393 % \begin{macrocode}
1394 \def\FN@commonending{%
1395 \@makefnendbox
1396 \ifx\FN@boxtype\vbox\@finalstrut\strutbox \else \unskip \fi
1397 \FN@colorstackfinish
1398 \color@endgroup
1399 \egroup
1400 \global\advance\FN@id\@ne
1401 \FN@slotxdef\FN@masterslot{\number\FN@id}%
1402 % \end{macrocode}
1403 % Now we want to get an upper estimate of the size. In case of a
1404 % horizontal box, we do this by creating a vertical box of it all
1405 % alone, and measuring that. Measuring the hbox itself is plain
1406 % out: \TeX's maximal dimension of something like 5\,m is already
1407 % busted with about two pages of material. We put the master slot
1408 % identification into the depth of the box, and arrange for the
1409 % total of depth and height of the box to still give the total depth
1410 % and height of its size on the page.
1411 % \begin{macrocode}
1412 \ifhbox\z@
1413 \global\setbox\FN@tempbox\copy\z@
1414 \setbox\tw@\@makefnvbox{\unhbox\FN@tempbox}%
1415 \ht\z@\dimexpr\ht\tw@+\dp\tw@-\FN@masterslot sp\relax
1416 \else
1417 \ht\z@\dimexpr\ht\z@+\dp\z@-\FN@masterslot sp\relax
1418 \fi
1419 % \end{macrocode}
1420 % Now we put the sorting criterion into the width of the box, and
1421 % then put the masterslot id into the depth.
1422 % \begin{macrocode}
1423 \wd\z@\dimen@
1424 \dp\z@\FN@masterslot sp\relax
1425 %<trace> \ifnum\z@<0\FN@slotget{\FN@masterslot} %
1426 %<trace> \else \errmessage{Inconsistent
1427 %<trace> \string\FN@masterslot=\FN@masterslot}\fi
1428 % \end{macrocode}
1429 % Now we just need to place the stuff into an insertion and record
1430 % the possibly changed slave id in order to know what subordinate
1431 % footnotes belong to this one.
1432 % \begin{macrocode}
1433 \MFL@insert\FN@masterinsert{\nointerlineskip\box\z@}%
1434 \ifdim\lastkern=\z@ \let\FN@next\@empty\else
1435 \edef\FN@next{\kern\the\lastkern\relax}\unkern
1436 \fi
1437 \marks\FN@slave{\number\FN@id}%
1438 \expandafter\FN@enddivert\expandafter\FN@colorstackegroup
1439 \FN@next
1440 }
1441 % \end{macrocode}
1442 % \end{macro}
1443 % A lot of stuff follows. This should really be cleaned up and
1444 % documented.
1445 % \begin{macrocode}
1446 \dimen\footins\maxdimen
1447 \gdef\FN@nestlist{}
1448
1449 \newdimen\FN@outervsize
1450 \newskip\FN@vsize
1451
1452 \newbox\FN@insertions
1453
1454 %<trace>\def\MFL@showone#1#2{\message{Box #2:}\showbox#2%
1455 %<trace> \MFL@checkconsistency{#2}%
1456 %<trace> \message{Cachebox #2:}\showbox\FN@cache#2}
1457 %<trace>
1458 %<trace>\def\MFL@checkconsistency#1{{%
1459 %<trace> \setbox\z@\vbox{\unvcopy#1%
1460 %<trace> \MFL@checkconsistencyi{#1}}}}
1461 % \end{macrocode}
1462 % \begin{macro}{\MFL@checksinglebox}
1463 % Check box~|#1| for consistency. If it is bad, output box~|#2|.
1464 % Execute |#3| if it was good, |#4| if it was bad.
1465 % \begin{macrocode}
1466 %<trace>\def\MFL@checksinglebox#1#2#3#4{%
1467 %<trace> \ifvoid#1\else
1468 %<trace> \ifnum\z@<0\FN@slotget{\number\dp#1} %
1469 %<trace> #3%
1470 %<trace> \else \errmessage{Inconsistent box #2}%
1471 %<trace> \showboxdepth4\showboxbreadth100
1472 %<trace> \showbox#2\relax
1473 %<trace> #4%
1474 %<trace> \fi\fi}
1475 % \end{macrocode}
1476 % \end{macro}
1477 % \begin{macrocode}
1478 %<trace>\def\MFL@checkconsistencyi#1{%
1479 %<trace> \unpenalty\unskip\unkern
1480 %<trace> \setbox\z@\lastbox
1481 %<trace> \MFL@checksinglebox\z@{#1}{{\MFL@checkconsistencyi{#1}}}{}}
1482 %<trace>
1483 %<trace>\def\MFL@showall{{%
1484 %<trace> \showboxbreadth=\maxdimen
1485 %<trace> \showboxdepth=4
1486 %<trace> \tracingonline=\@ne
1487 %<trace> \FN@nest@iterate\MFL@showone}}
1488 % \end{macrocode}
1489 % \begin{macro}{\FN@retaindelayed}
1490 % This is a complex macro that removes all boxes from the current
1491 % list that are not to be kept for the next page. It works on the
1492 % material from the original insertions, not the cache boxes.
1493 % The slot specified by \cmd{\count@} is not freed when encountered,
1494 % all others are freed upon removing the box. The last box is
1495 % returned in box~0 if any is retained. The vertical list might
1496 % have an unchecked part locked off in front by placing a
1497 % \cmd{\nobreak} penalty there. This penalty is removed, and the
1498 % list before it not touched.
1499 % \begin{macrocode}
1500 \def\FN@retaindelayed{%
1501 \setbox\z@\lastbox
1502 \ifcase
1503 \ifvoid\z@\m@ne\fi \FN@config\z@
1504 %<trace> \if\foottrace8\message{^^J\string\FN@retaindelayed:
1505 %<trace> dropping Id \FN@slotget{\number\dp\z@}}\fi
1506 %<trace> \if\foottrace{16}{\showboxdepth4 \showboxbreadth400
1507 %<trace> \tracingonline=\@ne\showbox\z@}\fi
1508 \ifnum\dp\z@=\count@\else \FN@freeslot{\number\dp\z@}\fi
1509 %<trace> \ifnum\dp\z@<\@ne \errmessage{Unidentified box}\fi
1510 \expandafter\FN@retaindelayed
1511 \or
1512 %<trace> \if\foottrace8\message{^^J\string\FN@retaindelayed:
1513 %<trace> retaining Id \FN@slotget{\number\dp\z@}}\fi
1514 %<trace> \if\foottrace{16}{\showboxdepth4 \showboxbreadth400
1515 %<trace> \tracingonline=\@ne\showbox\z@}\fi
1516 {\FN@retaindelayed \nointerlineskip \box\z@}%
1517 \else \unpenalty \setbox\z@\lastbox
1518 %<trace> \ifnum\lastnodetype>\m@ne
1519 %<trace> \errmessage{Unexpected node \number\lastnodetype}\fi
1520 %<trace> \ifvoid\z@ \else
1521 %<trace> \if\foottrace8\message{^^J\string\FN@retaindelayed:
1522 %<trace> carrying split box \FN@slotget{\number\dp\z@}}\fi
1523 %<trace> \if\foottrace{16}{\showboxdepth4 \showboxbreadth400
1524 %<trace> \tracingonline=\@ne\showbox\z@}\fi\fi
1525 \fi}
1526 % \end{macrocode}
1527 % \end{macro}
1528 % \begin{macro}{\MFL@processplain}
1529 % This gets called for actually inserting the processed material
1530 % into the footnote box. The current state of affairs is that
1531 % \cmd{\FN@config} contains all footnotes that should get
1532 % transferred to the next page completely. The cache boxes contain
1533 % the collected and typeset footnotes for typesetting on the current
1534 % page.
1535 %
1536 % The structure of a cachebox is currently as follows: it is filled
1537 % with vboxes containing the arranged material, optionally followed
1538 % by another box to be carried over to the next page flagged with a
1539 % \cmd{\nobreak} penalty.
1540 % \begin{macrocode}
1541 \def\MFL@processplain#1{%
1542 %<trace> \MFL@checkconsistency#1%
1543 \ifvoid\FN@cache#1%
1544 % \end{macrocode}
1545 % Now if the cache box is void, nothing gets typeset on the current
1546 % page. What we do, however, is to collect all boxes from the
1547 % original insertion that did not make it on this page and reinsert
1548 % them. \cmd{\count@} is cleared to zero to retain nothing special.
1549 % \begin{macrocode}
1550 \global\setbox\FN@tempbox\vbox\bgroup
1551 \unvbox#1%
1552 \count@\z@
1553 \let\@elt\FN@removecheck \FN@retaindelayed
1554 \ifvoid\z@ \egroup
1555 \else \nointerlineskip \box\z@ \egroup
1556 \MFL@realinsert{#1}{\unvbox\FN@tempbox}%
1557 \fi
1558 % \end{macrocode}
1559 % The following stops in the insertion process within the |manyfoot|
1560 % package.
1561 % \begin{macrocode}
1562 \expandafter\expandafter
1563 \fi\iffalse\fi
1564 % \end{macrocode}
1565 % Ok, this is the case when we have a nonvoid cache box.
1566 % \begin{macrocode}
1567 \global\setbox#1\vbox\bgroup%
1568 \unvbox\FN@cache#1%
1569 \ifnum\lastpenalty>\z@
1570 \unpenalty
1571 \setbox\z@\lastbox
1572 \else
1573 \setbox\z@\box\voidb@x
1574 \fi
1575 % \end{macrocode}
1576 % Ok, now box zero contains carryover material (if any). We
1577 % initialize \cmd{\count@} to this so that we will keep this carryover
1578 % material just once.
1579 % \begin{macrocode}
1580 \count@\dp\z@
1581 \global\setbox\FN@tempbox\vbox\bgroup
1582 \box\z@
1583 \nobreak
1584 \unvbox#1%
1585 \let\@elt\FN@removecheck \FN@retaindelayed
1586 \ifvoid\z@ \egroup \MFL@removevboxes\egroup
1587 \else \nointerlineskip \box\z@ \egroup
1588 \MFL@removevboxes \egroup
1589 \MFL@realinsert{#1}{\unvbox\FN@tempbox}%
1590 \fi}
1591
1592 \let\MFL@processpara\MFL@processplain
1593 % \end{macrocode}
1594 % \end{macro}
1595 % Ok, here is the bit about the caches: whenever we encounter a new
1596 % configuration, we have to first update the caches since we don't
1597 % know the sizes we are dealing with regarding the new configuration
1598 % until we do so. The caches are kept up to date globally. When we
1599 % are working at several levels in the recursion, we have a bottom
1600 % active level where we may are looking for a way to find a best break
1601 % and configuration. We will return at most one configuration once we
1602 % are finished. While we are working with a returned configuration,
1603 % adding more material on the current list will not require another
1604 % recursion as long as the totals stay underfull: the penalty
1605 % difference between underfull configurations becomes smaller while
1606 % the underfullness decreases, which means that smaller breaks that
1607 % have not been chosen before might become eligible if the penalties
1608 % allow for that. Only when the badness of underfullness remains
1609 % infinite can't we have any improvement.
1610 %
1611 % Ok, after we recurse for removing an underfull condition, the
1612 % resulting configuration can't actually be used further for breaks
1613 % with less remaining space. It is, however, clear that if less space
1614 % remains, there is no better break with the same configuration
1615 % leaving \emph{more} space: if there were, it would already have been
1616 % taken. That means that our goal height for the next break will be
1617 % chosen in order to reach the exact size met on the last recursion.
1618 % No break before that can be chosen on the next try, but a break
1619 % after it might then be taken.
1620 %
1621 % available, or an overfull one. If a deeper level at any point of
1622 % time returns an overfull configuration, we are finished. The best
1623 % configuration to be returned is the least underfull. If there is
1624 % none, the least overfull. The case of no underfull at all can only
1625 % happen if even splitting this and every subordinate level to minimal
1626 % height and recursing does not yield an underfull. At every level,
1627 % we need to maintain just a current split, and the previous best
1628 % split at most.
1629 %
1630 % When we change a configuration on recursing, we have to remember the
1631 % configurations for the previous best split. We can manage that by
1632 % sweeping the current cache values into a local box register
1633 % before recursing with a different configuration: we have to rebuild
1634 % the box registers for a different configuration, anyway. We don't
1635 % save the configuration from an overfull setting: when we rework the
1636 % list in slow motion mode, we can't help stopping the recursion by
1637 % reaching an overfull setting that is at least as good as the
1638 % initial one.
1639 %
1640 % When we return to a caller, we leave the cache in the configuration
1641 % of the best choice up to now: either we are returning an overfull
1642 % configuration and if it is not the best so far, the caller can
1643 % restore his better choice from his copy, or we are returning an
1644 % underfull configuration in which case the caller might still want to
1645 % improve upon it before returning to its caller in turn. New: If we
1646 % return an underfull configuration, we also return an ``optimal
1647 % penalty estimate'' that gives the best break point penalty under the
1648 % assumption that additional stretchability is present on the page.
1649 %
1650 % The purpose of this is to offer the possibility of avoiding widows
1651 % and similar by moving more material in some footnotes to the next
1652 % page in exchange for other material.
1653 %
1654 % At the current grouping level we empty out our current cache and
1655 % keep it for working purposes on the vertical list until we return
1656 % (nobody references it while we are working on it). We always enter
1657 % with an overfull configuration, meaning that \cmd{\FN@vsize} is
1658 % negative. It is calculated with the current cache\slash config
1659 % setting.
1660 %
1661 % There is a danger of overflow involved with that: if we keep a swept
1662 % complete configuration at each level of recursion, we need $O(n^2)$
1663 % of space here. The alternative would be to keep the history of how
1664 % the configuration came about. Since that might involve some
1665 % slow-motion splitting, this is also a speed issue. Since deep
1666 % recursion with pending best data at each level is not really
1667 % likely, and since we are not going to have that many footnote
1668 % levels to go around, anyway, we just rely on \LaTeX\ having been
1669 % started with sufficient memory.
1670 %
1671 % A workable compromise would be to just store the split boxes
1672 % from a configuration together with the configuration data for
1673 % reconstructing the rest. After all, we don't need to reconsider
1674 % such a configuration before actually typesetting anything. And
1675 % whenever we find an acceptable fit (neither underfull\slash
1676 % overfull), we could cut through all the hierarchy without having to
1677 % restore anything. This has not been implemented yet: at the moment
1678 % we go for the less complicated variation.
1679 %
1680 %
1681 % The algorithm we use here is a bit complicated. Whenever we
1682 % recurse, we have one of the following situations:
1683 % \begin{enumerate}
1684 % \item An overfull/underfull dilemma: including a minimal amount of
1685 % material at the current level will cause the page to become
1686 % overfull. This can be the case in connection with zero (in
1687 % case of interline penalties for larger blocks), one or more
1688 % subordinate footnotes and related footnotes.
1689 % \item A pure overfull dilemma: the page was overfull to start with,
1690 % we need to reduce it.
1691 % \item an underfull dilemma: some operation in the next level made
1692 % the page become underfull, only too much so. We can't make it
1693 % fuller on the current level, but we can make it even emptier,
1694 % and let the next level fill it up again.
1695 % \end{enumerate}
1696 %
1697 % In the current implementation, we just ignore the slight probability
1698 % that the optimum choice might lie with case~3. We don't
1699 % recurse for making the page fuller again. If we have an
1700 % overfull/underfull dilemma, the recursion will either give us a
1701 % less awful overfull box, or an underfull one. An overfull box that
1702 % occurs at the highest level of recursion can't be improved on any
1703 % lower level. So we never need to locally return an overfull box: we
1704 % can compare it to the best overfull box seen before, and if we turn
1705 % out better than that, we overwrite the global best overfull value
1706 % and return the best local underfull if there is such a one. The
1707 % best local underfull will then be refilled as much as possible on
1708 % the next level without changing the configuration. Actually, if we
1709 % need to change the configuration, this would also be fine as long as
1710 % we arrive at a better underfull eventually. But since a change of
1711 % configuration renders our previous split completely useless, as the
1712 % broken paragraph could look disastrously different under a changed
1713 % configuration, we would need to recurse again. We repeat this
1714 % recursing operation until we don't get an underfull solution
1715 % returned anymore. We then return the best underfull, if any. The
1716 % best overfull is stored globally, as mention before.
1717 %
1718 % Does this sound complicated? Unfortunately, it does. It also
1719 % sounds somewhat slow. For that reason, we do a few assumptions that
1720 % will facilitate a good average-case behavior. The first assumption
1721 % is that we will usually do fine by just splitting in the current
1722 % level (if at all) and not at all in subordinate levels.
1723 %
1724 % We do this assumption on the first pass used for gathering the size
1725 % information and collect the corresponding boxes in nested lists.
1726 % When the recursion tops out, it does so either with an overfull
1727 % page, or an underfull page. If it does with an underfull page, we
1728 % cache the current configuration for the next pass through the output
1729 % routine, so that we won't need to retypeset and measure assembled
1730 % boxes that have not gathered any new material. If we top out with an
1731 % overfull page, the previous underfull configuration is still worth
1732 % keeping as well, as it might become the material actually chosen to
1733 % be typeset.
1734 %
1735 % Ok, the current best configuration of the next recursion level is
1736 % gathered on the current vertical list, in a separate box. We use
1737 % box~2 for this purpose. A saved configuration consists of the
1738 % complete contents for the current cache box without the trailing
1739 % penalty indicating material from a single split box carried over to
1740 % the next page (boxes that are carried over completely to the next
1741 % page are not maintained here but rather reinserted by
1742 % \cmd{\MFL@processnested}). This penalty is added in case the box
1743 % is actually disassembled and returned: there is no possibility for
1744 % confusion since we only save such a configuration if indeed there is
1745 % a split present.
1746 % \begin{macrocode}
1747 \newtoks\FN@output
1748 \FN@output\output
1749
1750 \newbox\FN@tempbox
1751 \newinsert\FN@savebox
1752 \count\FN@savebox\@m
1753 \dimen\FN@savebox\maxdimen
1754 \skip\FN@savebox\z@skip
1755 \global\setbox\FN@savebox\box\voidb@x
1756
1757 \expandafter\expandafter\expandafter\let\FN@cache\FN@savebox=\@cclv
1758
1759 \expandafter\def\csname FN@ht\number\FN@savebox\endcsname{\z@skip}%
1760 \expandafter\def\csname FN@dp\number\FN@savebox\endcsname{\maxdepth}
1761 \expandafter\def\csname FN@wd\number\FN@savebox\endcsname{\columnwidth}
1762
1763 \def\FN@list{\MFL@list\@elt{}\footins}
1764
1765 \def\FN@sweepbox#1#2{\ifvoid#2\else
1766 \nointerlineskip\box#2\penalty#2\fi}
1767
1768 \def\FN@sweepcachebox#1#2{\nointerlineskip
1769 \box\FN@cache#2%
1770 \penalty\FN@cache#2}
1771
1772 \def\FN@copycachebox#1#2{\nointerlineskip
1773 \copy\FN@cache#2%
1774 \penalty\FN@cache#2}
1775
1776 \def\FN@restoreboxes{\count@\lastpenalty \unpenalty
1777 \ifnum\count@>\z@
1778 \global\setbox\count@\lastbox
1779 \expandafter\FN@restoreboxes
1780 \fi}
1781 % \end{macrocode}
1782 % \begin{macro}{\FN@removecheck}
1783 % This returns |\@ne| if and only if the current slot master is strictly
1784 % inside of the specified open interval. In this case it is not to
1785 % appear on the current page.
1786 % \begin{macrocode}
1787 \def\FN@removecheck#1#2{%
1788 \ifnum#1<\FN@slotget{\number\dp\z@} %
1789 \ifnum#2>\FN@slotget{\number\dp\z@} %
1790 \@ne\fi\fi}
1791 % \end{macrocode}
1792 % \end{macro}
1793 % Parameter recording merely records the relevant value of the
1794 % skip register and sets it to zero. The purpose is to avoid changes
1795 % of the reserved page space when we collect additional material from
1796 % a page where an insertion of the appropriate kind had already been
1797 % encountered. This is used for filling up underfull pages.
1798 % \begin{macrocode}
1799 \def\FN@recordinsertparam#1#2{\ifvoid#2\else
1800 \global\skip\number#2=\the\skip#2\relax\fi}
1801
1802 \def\FN@clearinsertparam#1#2{\ifvoid#2\else
1803 \global\skip#2=\z@skip\fi}
1804 % \end{macrocode}
1805 % \cmd{\FN@insertouterspace} will sum the size of the inserts manually.
1806 % \begin{macrocode}
1807 \def\FN@insertouterspace#1#2{\ifvoid#2\else
1808 +\skip#2+(\ht#2+\dp#2)*\count#2/\@m\fi}
1809
1810 \def\FN@list@iterate#1{\let\FN@eltsave\@elt
1811 \let\@elt#1%
1812 \FN@list
1813 \let\@elt\FN@eltsave}
1814
1815 \def\FN@nest@iterate#1{\let\FN@eltsave\@elt
1816 \let\@elt#1%
1817 \FN@nestlist
1818 \let\@elt\FN@eltsave}
1819 % \end{macrocode}
1820 %
1821 % \subsection{The output routine stuff}
1822 %
1823 % \paragraph{Marks}
1824 % This is used for sweeping all marks up for reinsertion.
1825 % \begin{macro}{\FN@allmarks}
1826 % \begin{macrocode}
1827 \def\FN@allmarks#1{\@elt{#1}%
1828 \ifnum#1<\count266
1829 \expandafter\FN@allmarks\expandafter{\number\numexpr#1+\@ne}%
1830 \fi}
1831 % \end{macrocode}
1832 % \end{macro}
1833 % \begin{macro}{\FN@sweeptopmarks}
1834 % \begin{macro}{\FN@topmarkbox}
1835 % This sweeps the current topmarks and places them into the global box
1836 % \cmd{\FN@topmarkbox}.
1837 % \begin{macrocode}
1838 \def\FN@sweeptopmarks{\global\setbox\FN@topmarkbox\vbox{%
1839 \def\@elt##1{\marks##1{\unexpanded\expandafter{\topmarks##1}}}%
1840 \FN@allmarks0}}
1841 \newbox\FN@topmarkbox
1842 % \end{macrocode}
1843 % \end{macro}
1844 % \end{macro}
1845 % \begin{macro}{\FN@establishmarks}
1846 % This sets marks from a marks sweep. The first argument is the
1847 % mark number, the second is from the first mark on the first scan,
1848 % the third argument from the bottom mark on the first scan, and the
1849 % fourth argument from the bottom mark on the second scan (with
1850 % additional mark entries). If second and third arguments don't
1851 % match, no mark gets placed.
1852 % \begin{macrocode}
1853 \long\def\FN@establishmarks#1#2{\edef\reserved@a{\unexpanded{#2}}%
1854 \edef\reserved@b{\unexpanded\expandafter{\splitbotmarks#1}}%
1855 \ifx\reserved@a\reserved@b
1856 \marks#1{\unexpanded\expandafter{\splitfirstmarks#1}}%
1857 \marks#1{\unexpanded\expandafter{\reserved@b}}%
1858 \fi}
1859 % \end{macrocode}
1860 % \end{macro}
1861 % \begin{macro}{\FN@markspassone}
1862 % This constitutes the first pass for mark collection. We do this
1863 % just to check whether there are any marks in the list.
1864 % \begin{macrocode}
1865 \def\FN@markspassone#1{\noexpand\FN@establishmarks{#1}%
1866 {\unexpanded\expandafter{\splitbotmarks#1}}}
1867 % \end{macrocode}
1868 % \end{macro}
1869 % \begin{macro}{\FN@insertmarks}
1870 % This routine transfers first and bottom marks from the current
1871 % |\box255| to the vertical list in order to get the marks right.
1872 % This is quite a bother, since we must detect the special case
1873 % where there are no marks at all in the list, and since we might
1874 % require the use of several \cmd{\vsplit} commands in a row, since
1875 % infinite stretch might make the optimal breakpoint lie before the
1876 % end of the box in spite of its large size.
1877 %
1878 % So we need to do the splitting in a loop, and do it twice, once
1879 % with artificial marks at the start. If those artificial marks
1880 % make it to \cmd{\splitbotmarks}, we don't place any actual marks.
1881 % \begin{macrocode}
1882 \def\FN@pseudomarks#1{\marks#1{X}}
1883 \def\FN@insertmarks{%
1884 {\setbox\z@\copy\@cclv
1885 \splittopskip-\maxdimen\relax
1886 \vbadness=\@M
1887 \vfuzz=\maxdimen
1888 \loop
1889 \ifvoid\z@\else
1890 {\let\@elt\FN@pseudomarks
1891 \setbox\z@\vbox{\FN@allmarks0\nobreak\unvcopy\z@}%
1892 \setbox\z@\vsplit\z@ to\maxdimen}%
1893 \let\@elt\FN@markspassone
1894 \edef\next{\FN@allmarks0}%
1895 \setbox\z@\vbox{\nobreak\unvbox\z@}%
1896 {\setbox\z@\vsplit\z@ to\maxdimen}%
1897 \next
1898 \repeat}}
1899 % \end{macrocode}
1900 % \end{macro}
1901 % \paragraph{Some stuff}
1902 %
1903 % \begin{macro}{\FootnoteMainMinimum}
1904 % This specifies the minimum amount of main text. You can make this
1905 % a complicated expression if you want to, for example by checking
1906 % the presence of particular footnotes.
1907 % \begin{macrocode}
1908 \def\FootnoteMinimum{1sp}
1909 \def\FootnoteMainMinimum{0pt}
1910 \expandafter\def\csname\string\FootnoteMinimum\number\FN@savebox
1911 \endcsname{\FootnoteMainMinimum}
1912 % \end{macrocode}
1913 % \end{macro}
1914 %
1915 %\paragraph{The output routine itself}
1916 %
1917 % This is our own output routine that does all the balancing stuff.
1918 % If we receive a forced penalty here, we must not do any of our
1919 % output processing on our own unless this is the choice of the
1920 % underlying output routine. We do want to have the `real' output
1921 % routine to have a correct idea about the size that the insertions
1922 % will take up. So the steps that we \emph{will} actually perform in
1923 % any case are sorting the insertions and calculating their real
1924 % size. If we have not had a forced penalty, we are free to exit the
1925 % output routine for gathering further material as there are no
1926 % expections of the underlying output routine when it should get
1927 % called. If we encountered a forced penalty, things are getting more
1928 % complicated. If the current page happens to be overfull after
1929 % adding the current material, we first need to ship out the material
1930 % for a regular page (after splitting off the necessary material for
1931 % the next page). We then reinsert the remaining split insertions,
1932 % any possibly split off page material and the penalty.
1933 %
1934 % \TeX\ is rather monotonous in its page break processing. Increase
1935 % the available page size, and the available page material will also
1936 % increase. There is a singular exception to that rule, and that are
1937 % split and floating insertions. However, we notice their presence by
1938 % a non-zero setting of \cmd{\insertpenalties}, and we can just
1939 % measure the material that they have taken up in a forced pass of the
1940 % output routine, adding that much to our request size. However, this
1941 % operation will change the penalties associated with the page breaks.
1942 %
1943 % Unfortunately, this is not sufficient: the penalty might have been
1944 % inserted with a box immediately preceding it. In that case the
1945 % penalty would have been guaranteed to eventually turn up in the
1946 % output routine. If we now reinsert merely all of the above stuff,
1947 % the penalty will just disappear. If we protect the penalty by
1948 % placing an empty box before it when none of it had been before it
1949 % before, we will get an empty page. Since we don't know whether the
1950 % penalty was supposed to disappear at the start of an empty page or
1951 % not, we will do the following: if the rest of |\box255| is nonvoid,
1952 % we just reinsert the split insertions followed by the rest of
1953 % \box255 and the penalty and return. If it is void, we call the
1954 % regular output routine, capturing its output in a |\vbox| of its
1955 % own. If the regular output routine failed to ship out the prepared
1956 % insertions, we just keep the original data either in their boxes or
1957 % in a reinserted insertion.
1958 %
1959 % It hides the relevant information from the `real' output routine
1960 % until such a time that we have enough material gathered to produce a
1961 % full page. The exception to this is when we have a special penalty
1962 % that gets passed through to the regular output routine.
1963 %
1964 % If we are on a material collecting spree, \cmd{\FN@savebox} contains
1965 % all boxes from the last output call time. At the point where we
1966 % enter the output routine, \cmd{\FN@vsize} contains the amount of
1967 % space available for mounting footnotes, after subtracting all
1968 % insertions of footnote variety. At most times in our output
1969 % routine, the variable will contain the amount of space left after
1970 % everything is put to the page including footnotes.
1971 % \begin{macrocode}
1972 \savingvdiscards=\@ne
1973 % \end{macrocode}
1974 % We have the following situations that can cause us to enter the
1975 % output routine:
1976 % \begin{enumerate}
1977 % \item The page has just filled up.
1978 % \item A magic output penalty has been encountered.
1979 % \item We are filling up a previously underfull page.
1980 % \item We are looking for missing insertions that may have floated.
1981 % \end{enumerate}
1982 %
1983 % We are trying to do bookkeeping on the effects of page size for
1984 % insertions that fall into the footnote class. While we do basic
1985 % bookkeeping for other insertions as well, this can only be
1986 % incomplete since we don't reinsert material. In consequence,
1987 % multiple material ending up in the same insertion might cause the
1988 % corresponding skip register to be accounted for several times.
1989 % \LaTeX\ does not really reuse insertions in that manner except for
1990 % footnotes, so we are mostly ok here.
1991 %
1992 % |bigfoot| usually does some lookahead in the main list in order to
1993 % obtain optimal breakpoints. It explicitly undoes the effect this
1994 % has on marks, but insertions are a different matter here. So floats
1995 % may appear on an earlier page than expected.
1996 %
1997 % If the output routine is invoked with a penalty of $-13750$, then
1998 % the page content is merely used for setting the \cmd{\topmarks}
1999 % array. In that case, we just clear out the output box and resume.
2000 % We don't fiddle with \cmd{\deadcycles} in order to catch foulups.
2001 %
2002 % Also we don't touch insertion boxes. There is a particular
2003 % situation where there \emph{are} insertions, namely if we are
2004 % collecting insertions after the last output routine has ended up
2005 % with a non-zero value of \cmd{\insertpenalties}. In this case, all
2006 % insertions we \emph{do} get are floating insertions, meaning that
2007 % they had a preceding insertion of the same class already on the last
2008 % page, and thus we have zeroed its skip register already. We are
2009 % assuming that a single pass with such a large \cmd{\vsize} is
2010 % sufficient for pulling all insertions. If that happens to be
2011 % incorrect, insertions need to get pulled in piecewise, but then we
2012 % are probably in big dodo with regard to page size accounting,
2013 % anyway.
2014 % \begin{macrocode}
2015 \newcount\FN@outputflag
2016 \FN@outputflag=3158345
2017 \output{%
2018 \let\@elt\relax
2019 \ifvoid\@cclv \PackageError{bigfoot}{Empty box 255 in \output}\fi
2020 %<trace> \if\foottrace8%
2021 %<trace> \message{entering output with
2022 %<trace> \outputpenalty=\the\outputpenalty:}%
2023 %<trace> {\showboxdepth4\showboxbreadth\maxdimen\showbox\@cclv}\fi
2024 \ifnum\outputpenalty=-13750
2025 %<trace> \if\foottrace8%
2026 %<trace> \message{Discarding box 255.}%
2027 %<trace> \fi
2028 \ifnum\insertpenalties>\z@
2029 \PackageError{bigfoot}{Too much insertion material}{%
2030 This error means that the output routine was not able to^^J%
2031 gather all floating insertions in a single pass.^^J%
2032 Complain to the author if you consider this a bug}%
2033 \fi
2034 \global\advance\FN@outervsize\dimexpr\ht\@cclv-\vsize
2035 \global\setbox\@cclv\box\voidb@x
2036 \else
2037 % \end{macrocode}
2038 % Note that a potential \cmd{\FN@vsadjustlist} will restore the
2039 % previous value of \cmd{\outputpenalty}. So we need to save it.
2040 % \begin{macrocode}
2041 \edef\FN@outputpenalty{\number\outputpenalty}%
2042 \ifvoid\FN@savebox
2043 \ifvoid\@holdpg
2044 \FN@sweeptopmarks
2045 \fi
2046 \FN@nest@iterate{\FN@insertouterspace\global\FN@outervsize
2047 \dimexpr\z@}%
2048 \global\advance\FN@outervsize\ht\@cclv
2049 \global\setbox\@cclv\vbox{\unvbox\@cclv\boxmaxdepth\maxdepth}%
2050 \global\let\FN@vsadjustlist\@empty
2051 % \end{macrocode}
2052 % \cmd{\FN@outervsize} now contains the value of \cmd{\pagegoal} at
2053 % the time of output. It should be \cmd{\vsize} adjusted by the
2054 % natural size of insertions. Note that \cmd{\FN@normaloutput} is not
2055 % required to return with a sensible value of \cmd{\outputpenalty}.
2056 % \begin{macrocode}
2057 \FN@normaloutput
2058 \else
2059 % \end{macrocode}
2060 % We now are in the situation that we already have collected material
2061 % previously. We can't be sure that adding a special penalty does not
2062 % take more than one output routine call before delivery. For that
2063 % reason, we don't rely on special outputs being special and always
2064 % subtract any additionally demanded \cmd{\vspace} from
2065 % \cmd{\FN@outervsize} before calling a special output, so that we can
2066 % afterwards compensate for it.
2067 % \begin{macrocode}
2068 \FN@nest@iterate{\FN@insertouterspace\global\advance\FN@outervsize
2069 \dimexpr\ht\@cclv}%
2070 \global\setbox\@cclv\vbox{\unvbox\@cclv\boxmaxdepth\maxdepth}%
2071 % \end{macrocode}
2072 % Now we invalidate the cache boxes for all insertions that had
2073 % changed due to the recent additions to the page (this does
2074 % \emph{not} affect \cmd{\FN@vsize}).
2075 % \begin{macrocode}
2076 \FN@nest@iterate\FN@maybeinvalidatecache
2077 % \end{macrocode}
2078 % We now update all boxes by inserting the previously collected
2079 % material in front of the boxes.
2080 % \begin{macrocode}
2081 \vskip\z@skip
2082 \unvbox\FN@savebox
2083 \loop
2084 \count@\lastpenalty
2085 \ifnum\count@>\z@
2086 \unpenalty
2087 \setbox\z@\lastbox
2088 \global\setbox\count@\vbox{\unvbox\z@\unvbox\count@}%
2089 \repeat
2090 \ifcase
2091 \ifnum\FN@outputpenalty=-13749 \@ne\fi
2092 \ifnum\FN@outputpenalty=-13751 \@ne\fi \tw@
2093 \or
2094 % \end{macrocode}
2095 % \cmd{\outputpenalty} is restored to the original value before the
2096 % total page is glued together.
2097 % \begin{macrocode}
2098 \FN@vsadjustlist
2099 %<trace> \if\foottrace8\message{receiving special penalty
2100 %<trace> \FN@outputpenalty, dissing box 255:}%
2101 %<trace> {\showboxdepth4 \showboxbreadth400
2102 %<trace> \tracingonline=\@ne\showbox\@cclv}\fi
2103 % \end{macrocode}
2104 % This special penalty means that we have been collecting floated
2105 % insertions right now. So |\box255| is actually empty except for
2106 % filler material. We restore the old box into it.
2107 % \begin{macrocode}
2108 \global\setbox\@cclv\lastbox
2109 \unskip
2110 %<trace> \ifnum\lastnodetype>\m@ne
2111 %<trace> \errmessage{Unexpected node \number\lastnodetype}\fi
2112 \ifnum\FN@outputpenalty=-13749
2113 \FN@normaloutput
2114 \else
2115 \the\FN@output
2116 \@pageht-\vsize
2117 \let\@currbox\footins
2118 \@reinserts
2119 \global\vsize-\@pageht
2120 \fi
2121 \else
2122 \dimen@\topskip
2123 \FN@vsadjustlist
2124 \setbox\z@\lastbox
2125 \unskip
2126 %<trace> \ifnum\lastnodetype>\m@ne
2127 %<trace> \errmessage{Unexpected node \number\lastnodetype}\fi
2128 % \end{macrocode}
2129 % Ok, now we reconstruct the box from its parts. We add the material
2130 % together, taking the previous output penalty and the current page
2131 % discards (if it belongs between those boxes, otherwise we leave it
2132 % on the list) for glueing the stuff together. The previous output
2133 % penalty then is irrelevant for further purposes and we replace it
2134 % again. \cmd{\FN@outervsize} has been
2135 % adjusted by the accumulated contributions of insertions to the page
2136 % size. Fiddling with it would not appear necessary or even prudent.
2137 % \begin{macrocode}
2138 %<trace>\if\foottrace8
2139 %<trace> \message{Box 255 before reglue
2140 %<trace> (outputpenalty=\the\outputpenalty):}%
2141 %<trace> {\showboxdepth4\showboxbreadth100\showbox\@cclv}\fi
2142 \global\setbox\@cclv\vbox{%
2143 % \end{macrocode}
2144 % Now we might have had a \cmd{\topskip} value designed for requesting
2145 % a given number of lines. We need to remove anything of that kind.
2146 % Splitting again achieves that. If the current page was empty except
2147 % for insertions, this means that we gain a new breakpoint. But
2148 % insertions with discardable material before them would be unusual.
2149 %
2150 % The only exception to this may happen if the current page contained
2151 % only insertions: in this case \TeX\ has made a page break before the
2152 % actually inserted \cmd{\topskip} glue (which will then arrive one
2153 % page later).
2154 %
2155 % Note that the pagediscards contain material corresponding to the
2156 % last breakpoint chosen, so they will either start with a penalty
2157 % of~10000 (which is what an actual outputpenalty gets replaced with)
2158 % or will start with discardable material. We clean it for that
2159 % reason.
2160 % \begin{macrocode}
2161 \unvbox\z@
2162 \global\setbox\@cclv\vbox{\break\unvbox\@cclv}%
2163 {\splittopskip-\maxdimen \setbox\z@\vsplit\@cclv to\z@}%
2164 \ifnum\outputpenalty=\@M
2165 \setbox\z@\vbox{\pagediscards
2166 \FN@cleanpagepenalty}%
2167 \unvbox\z@
2168 \else
2169 \penalty\outputpenalty
2170 \pagediscards
2171 \fi
2172 \unvbox\@cclv
2173 \boxmaxdepth\maxdepth}%
2174 %<trace>\if\foottrace8
2175 %<trace> \message{Box 255 reglued (outputpenalty=\FN@outputpenalty):}%
2176 %<trace> {\showboxdepth4\showboxbreadth100\showbox\@cclv}\fi
2177 \global\outputpenalty\FN@outputpenalty\relax
2178 % \end{macrocode}
2179 % Ok, now if \cmd{\topskip} is actually \emph{positive}, we have been
2180 % collecting material tentatively without having proper marks. We
2181 % then need to fill in the marks into the list and try again. Note
2182 % that we are not reinserting anything in order to compensate for
2183 % \cmd{\outputpenalty} being replaced by a nobreak: this is the job of
2184 % \cmd{\FN@normaloutput} when it decides to place material back on the
2185 % page. That is: when code is written that will make use of
2186 % pagediscards, it has to cater for their proper structure.
2187 % \begin{macrocode}
2188 \ifdim\dimen@>\z@
2189 %<trace> \if\foottrace8
2190 %<trace> \message{recycling special penalty}
2191 %<trace> \fi
2192 \hrule\@height\z@\@depth\z@
2193 \unvcopy\FN@topmarkbox
2194 \penalty-13750
2195 \penalty\FN@outputflag
2196 \hrule\@height\z@\@depth\z@
2197 \FN@insertmarks
2198 \penalty-13749
2199 \penalty\FN@outputflag
2200 \FN@prepareoutput
2201 \global\topskip-\maxdimen
2202 \global\vsize0.5\maxdimen
2203 \global\advance\FN@outervsize-\vsize
2204 \else
2205 \FN@normaloutput
2206 \fi
2207 \fi
2208 \fi
2209 \fi}
2210 % \end{macrocode}
2211 % \begin{macro}{\FN@normaloutput}
2212 % This is the normal output routine we use.
2213 % Now we have recovered a sensible state and glued everything together
2214 % that has been necessary. All insertion parameters are at their
2215 % standard values, and any insertions have been collected in the
2216 % respective boxes.
2217 % \begin{macrocode}
2218 \def\FN@normaloutput{%
2219 %<trace> \if\foottrace8\message{^^JEntering \string\FN@normaloutput:^^J}\fi
2220 % \end{macrocode}
2221 % \cmd{\FN@vsize} is now being set to the vertical size taken up by
2222 % the insertions, according to \TeX. Note that this does not include
2223 % flexibility. This much amount of space gets available on the
2224 % current page if we remove all insertions. This figures into
2225 % \cmd{\FN@vsize} as a \emph{positive} quantity since the insertion
2226 % size was taken from \cmd{\pagegoal}, and we reconstitute it in this
2227 % manner.
2228 % \begin{macrocode}
2229 \global\FN@vsize\FN@outervsize
2230 \global\advance\FN@vsize-\ht\@cclv\relax\relax
2231 % \end{macrocode}
2232 % Now we sort the inserts and regenerate the cache.
2233 % \begin{macrocode}
2234 \FN@nest@iterate\FN@sortinsert
2235 \FN@nest@iterate\FN@clearcache
2236 \xdef\FN@config{\@elt{\number0\botmarks\FN@slave}%
2237 {\number\maxdimen}}%
2238 %<trace> \if\foottrace8%
2239 %<trace> \message{\noexpand\FN@normaloutput start config: \FN@config^^J}%
2240 %<trace> \fi
2241 \FN@nest@iterate\FN@reconfig
2242 % \end{macrocode}
2243 % Note that \cmd{\FN@reconfig} subtracts the \emph{actual} size of all
2244 % insertions (after paragraphs have been combined and too early
2245 % insertions moved to the next page) and also subtracts the flexible
2246 % glues associated with the insertions' skip registers, so this
2247 % flexibility is typically negative. Since the cache registers have
2248 % been explicitly cleared, \cmd{\FN@reconfig} starts from the state
2249 % where indeed no insertions are present.
2250 % \begin{macrocode}
2251 \ifcase
2252 \ifnum\insertpenalties>\z@ \@ne\fi
2253 % \end{macrocode}
2254 % If we have floating insertions, we need to catch up with them. This
2255 % is done in case~1 which just places an immediate penalty and
2256 % recurses.
2257 %
2258 % Now here are a few cases that are only checked when we don't have a
2259 % special penalty:
2260 % \begin{macrocode}
2261 \ifnum\outputpenalty>-\@M
2262 % \end{macrocode}
2263 % The first case is if the page is underfull. We need more material then.
2264 % \begin{macrocode}
2265 \ifdim\FN@vsize>-\gluestretch\FN@vsize \tw@ \fi
2266 % \end{macrocode}
2267 % Second case is when there is not enough vertical minimum material.
2268 % \begin{macrocode}
2269 \ifdim\FootnoteMainMinimum>\ht\@cclv \tw@ \fi
2270 \fi
2271 % \end{macrocode}
2272 % Case 3 means page is overfull. If there are no missing insertions,
2273 % try to split.
2274 % \begin{macrocode}
2275 \ifdim\FN@vsize<\glueshrink\FN@vsize \thr@@ \fi
2276 % \end{macrocode}
2277 % page has appropriate size or we have special penalty. If we have
2278 % come here not the first time, we might have arrived at a non-optimal
2279 % break. So we attempt a split.
2280 % \begin{macrocode}
2281 \ifx\FN@vsadjustlist\@empty \else \thr@@\fi\z@
2282 % \end{macrocode}
2283 % Ok, now we get the default case in our big routine: case~0. We just
2284 % pass the result onto the output routine.
2285 % \begin{macrocode}
2286 {\vbadness\@M
2287 \vfuzz\maxdimen
2288 \global\setbox\@cclv\vbox
2289 spread\FN@vsize{\unvbox\@cclv\boxmaxdepth\maxdepth}}%
2290 \the\FN@output
2291 \let\@currbox\footins
2292 \@pageht-\vsize
2293 \@reinserts
2294 \global\vsize-\@pageht
2295 \FN@nest@iterate\FN@clearcache
2296 \or
2297 % \end{macrocode}
2298 % Case 1: We just pull in remaining insertions and are done. Note
2299 % that the special penalty here will get turned into an explicit
2300 % nobreak. So if we have no record of an actual outputpenalty, we
2301 % need to insert an artificial penalty of 0 here.
2302 % \begin{macrocode}
2303 \FN@restartoutput
2304 \penalty -13749
2305 \penalty \FN@outputflag
2306 \or
2307 % \end{macrocode}
2308 % Case 2: Now we want to gather additional material. This is somewhat
2309 % weird. We first gather our material with a `normal' setting of
2310 % topskip, and then we'll have another go at the material using proper
2311 % marks. We can't actually insert anything right now in order not to
2312 % introduce a premature breakpoint.
2313 % \begin{macrocode}
2314 \dimen@=\dimexpr\FN@vsize-\glueshrink\FN@vsize\relax
2315 \FN@prepareoutput
2316 \global\topskip \normalbaselineskip
2317 \global\vsize \dimen@
2318 \global\advance\FN@outervsize-\vsize
2319 \global\deadcycles\z@
2320 \else
2321 % \end{macrocode}
2322 % This is case 3: Fake our output box into something looking like a
2323 % cache box and do the optimal split routine. The output cache box
2324 % has a few deficiencies: its inner box is \emph{not} depth-extended
2325 % to some default measurement. That means that where page size
2326 % calculations are involved, one needs to \emph{disregard} its actual
2327 % depth and instead use \cmd{\maxdepth}. This is somewhat awkward and
2328 % prone to problems. One alternative might be to mark the box as
2329 % split, extend its depth in the split part and let it be followed by
2330 % nothing as lower part of the split. But we still would need to
2331 % account for the missing depth at the end.
2332 % \begin{macrocode}
2333 \edef\FN@masterid{\number\maxdimen}%
2334 \def\FN@masterslot{-1}%
2335 \global\setbox\@cclv\vbox{\box\@cclv}%
2336 \xdef\FN@config{\noexpand\@elt{\number0\botmarks\FN@slave}%
2337 {\number\maxdimen}}%
2338 %<trace> \ifvoid\FN@savebox \else \PackageError{bigfoot}{\FN@savebox
2339 %<trace> \space should be void!}{}\fi
2340 \global\setbox\FN@savebox\vbox{}%
2341 \gdef\FN@penalties{0}%
2342 \edef\FN@defaultpenalty{\ifnum\outputpenalty<\@M
2343 \number\outputpenalty
2344 \else
2345 0\fi}%
2346 \let\@elt\FN@newlevel
2347 \@elt{}\FN@savebox\FN@nestlist\FN@mainsplitreturn
2348 \let\@elt\relax
2349 %<trace> \if\foottrace8{\showboxdepth4\showboxbreadth100\showbox\@cclv}\fi
2350 \global\setbox\FN@savebox\box\voidb@x
2351 {%
2352 \vbadness\@M
2353 \vfuzz\maxdimen
2354 \global\setbox\@cclv\vbox spread\FN@vsize{%
2355 \unvbox\@cclv
2356 \ifnum\lastpenalty>\z@
2357 \unpenalty
2358 \global\setbox\FN@tempbox\lastbox
2359 \else
2360 \global\setbox\FN@tempbox\box\voidb@x
2361 \fi
2362 \setbox\z@\lastbox
2363 % \end{macrocode}
2364 % Now if a split has been done, |\box\FN@tempbox| contains the lower
2365 % part of the split. In either case, |\box\z@| contains the upper
2366 % part of the split (in a prepared form with the splitdiscards in a
2367 % box of their own). This may be void if there is no main text but
2368 % only footnotes. If we have carryover material, we add the current
2369 % outputpenalty there and set outputpenalty to a value indicating that
2370 % we have no outputpenalty to add at the end of the current list.
2371 % \begin{macrocode}
2372 \ifvoid\z@
2373 \ifvbox\FN@tempbox
2374 \ifnum\outputpenalty<\@M
2375 % The output penalty originally from below the split box gets appended
2376 % to the end of the split box.
2377 \global\setbox\FN@tempbox{\unvbox\FN@tempbox
2378 \penalty\outputpenalty}%
2379 \fi
2380 \global\outputpenalty=\@M
2381 \fi
2382 \else
2383 % \end{macrocode}
2384 % Ok, we have material to go to the next page. We unpack it and fish
2385 % out the break penalty from the last box. After checking it, put it in
2386 % box~0. A prospective current break penalty gets appended to the
2387 % carryover material. The fished-out break penalty becomes the new
2388 % value of outputpenalty.
2389 % \begin{macrocode}
2390 \MFL@removevboxes
2391 \unvbox\z@
2392 \edef\FN@defaultpenalty{\number\@M}%
2393 \FN@getbreakpenalty
2394 \setbox\z@\lastbox
2395 \global\setbox\FN@tempbox\vbox\bgroup\unvbox\z@
2396 \unvbox\FN@tempbox
2397 \ifnum\lastnodetype<\z@
2398 \egroup\global\setbox\FN@tempbox\box\voidb@x
2399 \else
2400 \ifnum\outputpenalty<\@M
2401 \penalty\outputpenalty
2402 \fi
2403 \egroup
2404 \global\outputpenalty\FN@breakpenalty
2405 \fi
2406 \fi
2407 \boxmaxdepth\maxdepth}%
2408 }%
2409 \setbox\z@\box\FN@tempbox
2410 \let\@elt\relax
2411 % \end{macrocode}
2412 % Ok, now we have in box~255 the split off stuff for the current
2413 % output routine, and in box~0 stuff that is going to follow
2414 % afterwards. If box~0 is not void, we were not able to make use of
2415 % all of box~255. There is a slight probability that by taking even
2416 % \emph{more} material from the main list, we might get a better
2417 % result (by being able to move footnote material to the next page
2418 % instead), but we don't make use of this possibility here. In
2419 % general, we assume that if box~0 is nonvoid, we take the resulting
2420 % split. Otherwise, if the page appears underfull, we pull in more
2421 % material. If the page is not underfull, we can pass it to the
2422 % output routine. If box~0 is void, the break was chosen at the
2423 % ultimate end of the vertical list. If it was not a forced break,
2424 % and if it is not an overfull case already, we pull in more material
2425 % in order to avoid widows in the main text.
2426 % \begin{macrocode}
2427 \dimen@=\dimexpr\FN@vsize-\glueshrink\FN@vsize\relax
2428 \ifcase
2429 \ifvoid\z@ \ifnum\outputpenalty>-\@M
2430 \ifdim\dimen@<\z@ \else \@ne \fi
2431 \fi
2432 \else \thr@@
2433 \fi
2434 \ifdim\ht\@cclv<\normalbaselineskip \@ne\fi
2435 \ifdim\dimen@<\normalbaselineskip \tw@\fi \@ne
2436 \or
2437 \FN@prepareoutput
2438 \global\topskip \normalbaselineskip
2439 \ifdim\dimen@<\normalbaselineskip \dimen@=2\baselineskip\fi
2440 \global\vsize \dimen@
2441 \global\advance\FN@outervsize-\vsize
2442 \global\deadcycles\z@
2443 \or
2444 %<trace> \if\foottrace8%
2445 %<trace> \message{^^JOutput: config is \FN@config...}\fi
2446 \setbox\tw@\vbox{%
2447 \the\FN@output
2448 %<trace> \if\foottrace8%
2449 %<trace> \ifnum\lastnodetype=\m@ne
2450 %<trace> \message{^^JOutput: end without carryover^^J}%
2451 %<trace> \else
2452 %<trace> \message{^^JOutput: end with carryover}}%
2453 %<trace> {\showboxdepth5 \showboxbreadth400
2454 %<trace> \tracingonline=\@ne\showbox\tw@
2455 %<trace> \fi
2456 %<trace> \fi
2457 }%
2458 \unvbox\tw@
2459 \unvbox\z@
2460 \let\@currbox\footins
2461 \@pageht-\vsize
2462 \@reinserts
2463 \global\vsize-\@pageht
2464 \FN@nest@iterate\FN@clearcache
2465 \or
2466 \FN@restartoutput
2467 \penalty -13751
2468 \penalty\FN@outputflag
2469 \unvbox\z@
2470 \ifnum\outputpenalty>\@M
2471 \else \penalty
2472 \ifnum\outputpenalty=\@M \z@ \else\outputpenalty\fi
2473 \fi
2474 \fi
2475 \fi
2476 %<trace> \if\foottrace8\message{^^JExiting \string\FN@normaloutput^^J}\fi
2477 }
2478 % \end{macrocode}
2479 % \end{macro}
2480 % \begin{macro}{\FN@prepareoutput}
2481 % This is a preparation for gathering more material. First sweep up
2482 % all the information about \cmd{\vsize}, \cmd{\topskip} and
2483 % \cmd{\outputpenalty}. After that, record the insertion skip
2484 % parameter of all insertions that have already been started, and
2485 % reset them to zero so that no additional space gets reserved for
2486 % them in case more material accumulates. We don't reset
2487 % \cmd{\topskip} here since the amount of newly requested material
2488 % will typically be in total lines, and \cmd{\topskip} might be the
2489 % only way to figure out the proper request size. If the current
2490 % depth and following height would make for a non-standard line
2491 % distance, we might have a problem here. There is no obvious way
2492 % to avoid it, though.
2493 % \begin{macrocode}
2494 \def\FN@prepareoutput{%
2495 {\let\@elt\FN@recordinsertparam
2496 \xdef\FN@vsadjustlist{%
2497 \global\vsize=\the\vsize
2498 \global\topskip=\the\topskip
2499 \global\outputpenalty=\the\outputpenalty\relax
2500 \FN@list}%
2501 \let\@elt\FN@clearinsertparam
2502 \FN@list}%
2503 % \end{macrocode}
2504 % Now we collect all boxes in the save box.
2505 % \begin{macrocode}
2506 %<trace> \ifvoid\FN@savebox \else \PackageError{bigfoot}{\FN@savebox
2507 %<trace> \space should be void in \string\FN@prepareoutput}{}\fi
2508 \global\setbox\FN@savebox\vbox{%
2509 \box\@cclv
2510 \FN@list@iterate\FN@sweepbox}}
2511 % \end{macrocode}
2512 % \end{macro}
2513 % \begin{macro}{\FN@restartoutput}
2514 % This is for the case where we are requesting additional material
2515 % and have to cater for sizes.
2516 % \begin{macrocode}
2517 \def\FN@restartoutput{%
2518 % \end{macrocode}
2519 % Calculate the remaining size on this page:
2520 % \begin{macrocode}
2521 \dimen@=\dimexpr\FN@vsize-\glueshrink\FN@vsize\relax
2522 % \end{macrocode}
2523 % We just pull in remaining insertions and are done.
2524 % \begin{macrocode}
2525 %<trace> \if\foottrace8\message{sending special penalty}\fi
2526 \hrule\@height\z@\@depth\z@
2527 \unvcopy\FN@topmarkbox
2528 \penalty -13750
2529 \penalty\FN@outputflag
2530 \hrule\@height\z@\@depth\z@
2531 \FN@insertmarks
2532 \FN@prepareoutput
2533 \global\topskip-\maxdimen\relax
2534 \global\vsize 0.5\maxdimen
2535 \global\advance\FN@outervsize-\vsize
2536 \global\deadcycles\z@
2537 }
2538 % \end{macrocode}
2539 % \end{macro}
2540 %
2541 % Ok, here is the deal. If the \cmd\FN@truevsize is negative, we have
2542 % an overfull vbox at our hand. We then start the splitting action.
2543 % We take the first non-split lowest footnote block and split it to
2544 % size, removing subordinate footnotes that we would not be able to
2545 % maintain. We do this recursively starting by the top footnote
2546 % block. It must be noted that it would be even better to start with
2547 % the highest-numbered footnote (which corresponds to the latest
2548 % finished footnote in \emph{logical} order, that in the source code),
2549 % but then we get the problem that we might have to remove boxes from
2550 % a footnote block that has already been split, and that is
2551 % troublesome (to put it mildly) in case where the footnote block is
2552 % set in paragraph mode. It's bad enough backtracking in a fixed
2553 % order across footnote blocks, going back and forward would be pretty
2554 % tough.
2555 %
2556 % So our recursion just walks the footnote blocks once top to bottom,
2557 % splitting and removing boxes that are not needed. When we recurse,
2558 % we have a dichotomy between current overfull and underfull boxes.
2559 % At each recursion level, we enter with an overfull configuration
2560 % that establishes the breakable section for the footnote block in
2561 % question.
2562 %
2563 % Suppose that we have already established a previous best
2564 % configuration. When we are recursing, we can only increase the
2565 % badness (a non-broken insertion box contributes nothing to the
2566 % overall badness or penalties, breaking the box causes a badness of
2567 % 10000, minus the break penalty, plus the break badness). So there
2568 % is no point in recursing if entry badness and break penalty are as
2569 % large as the previous best break penalty or more.
2570 %
2571 % Ok, so we construct the footnote block and try splitting it
2572 % to size. If this
2573 % gives us a \emph{good} underfull version, we return that (and break
2574 % out of recursion altogether). Otherwise we remember the underfull
2575 % version before the break and recurse on the overfull version. If
2576 % this returns an overfull version again, we return the underfull
2577 % version before the break. If it returns an underfull version, we
2578 % fill up the underfull version as much as possible without a change
2579 % of configuration, then select the best of the last underfull and
2580 % this as new local underfull. We then take the first overfull
2581 % combination (even allowing a change of configuration), throw away
2582 % the previous split in the next recursion level and recurse on the
2583 % now thoroughly overfull combination again.
2584 %
2585 % When recursion tops out, we compare the current overfull with the
2586 % previous one and record the best. We prefer keeping an older
2587 % overfull, all other things being equal.
2588 %
2589 % Ok, so what are the data structures we maintain when going through
2590 % all this folderol?
2591 %
2592 % We let the insertion boxes themselves remain untouched: that makes
2593 % it only a bit more complicated to maintain and access the relevant
2594 % boxes, but it might come handy at one time when somebody wants to
2595 % implement recursion that is not strictly top-to-bottom.
2596 %
2597 % Instead we return the relevant information in the cache boxes. The
2598 % total size of the cache boxes may not correspond to their actual
2599 % contents: in case a split box intended for the next page is stored
2600 % within them, its height is deducted from the total height of the
2601 % cache box (and, consequentially, from \cmd{\FN@vsize}).
2602 %
2603 % \cmd{\FN@vsize}, the amount of free space on the current page, is
2604 % only updated when changing levels of recursion. Instead we maintain
2605 % score of the accumulated size in the current insertion in
2606 % \cmd{\FN@myvsize}.
2607 %
2608 % What about the penalties and badness we collect? An unsplit
2609 % footnote block carries a penalty of~0 (so we need not take into
2610 % account unsplit footnote blocks at all during our bookkeeping, as
2611 % they are neutral), a split footnote block is prepenalized with a
2612 % penalty of~10000, plus the badness of the split, plus any penalties
2613 % associated with the split (limited to the $[-10000\ldots10000]$
2614 % range). This means that no operation on other footnote blocks can
2615 % lower an already accumulated score. This in turn means that we can
2616 % prune any operations leading to a worse score than the preceding
2617 % best score without having to actually recurse.
2618 %
2619 % This strategy will usually buy us a minimum number of split
2620 % footnotes (since the penalty of~10000 is not easy to compensate)
2621 % and corresponds rather closely to \TeX's own idea of footnote
2622 % splitting.
2623 %
2624 % The following routine will analyze the last box where the results
2625 % from \cmd{\splitdiscards} are stored and return the penalty
2626 % associated with the breakpoint in the macro
2627 % \cmd{\FN@breakpenalty}.
2628 % \begin{macro}{\FN@getbreakpenalty}
2629 % \begin{macrocode}
2630 \def\FN@getbreakpenalty{{\setbox\z@\lastbox
2631 \nointerlineskip\copy\z@
2632 \setbox\z@
2633 \vbox{\unvbox\z@
2634 \count@\@M
2635 \FN@getbreakpenaltyii
2636 \xdef\FN@tempinfo{\edef\noexpand\FN@breakpenalty{%
2637 \number\ifnum\count@=\@M \FN@defaultpenalty \else \count@\fi
2638 }}}}%
2639 \FN@tempinfo}
2640
2641 \def\FN@getbreakpenaltyii{%
2642 \ifcase
2643 \ifnum\lastnodetype<\z@ \m@ne\fi
2644 \ifnum\lastnodetype<11 \@ne\fi
2645 \ifnum\lastnodetype>13 \@ne\fi
2646 \numexpr\lastnodetype-9\relax
2647 \or
2648 \PackageError{bigfoot}{Illegal node type}{This can't happen}%
2649 \or
2650 \count@\z@ \unskip \expandafter\FN@getbreakpenaltyii
2651 \or
2652 \count@\z@ \unkern \expandafter\FN@getbreakpenaltyii
2653 \or
2654 \count@\lastpenalty
2655 \unpenalty \expandafter\FN@getbreakpenaltyii
2656 \fi}
2657 % \end{macrocode}
2658 % \end{macro}
2659 % \begin{macro}{\FN@cleanpagepenalty}
2660 % This is used for removing initial infinite penalties from the
2661 % pagediscards: those are artifacts of the page break routine.
2662 % \begin{macrocode}
2663 \def\FN@cleanpagepenalty{%
2664 \ifcase
2665 \ifnum\lastnodetype<\z@ \m@ne\fi
2666 \ifnum\lastnodetype<11 \@ne\fi
2667 \ifnum\lastnodetype>13 \@ne\fi
2668 \numexpr\lastnodetype-9\relax
2669 \or
2670 \PackageError{bigfoot}{Illegal node type}{This can't happen}%
2671 \or
2672 \skip@=\lastskip \unskip
2673 \expandafter \FN@cleanpagepenalty \expandafter\vskip\the
2674 \expandafter\skip@
2675 \or
2676 \dimen@=\lastkern \unkern
2677 \expandafter \FN@cleanpagepenalty \expandafter\kern\the
2678 \expandafter\dimen@
2679 \or
2680 \count@\lastpenalty \unpenalty
2681 \ifnum\count@=\FN@outputflag
2682 \unpenalty\expandafter\expandafter\expandafter\FN@cleanpagepenalty
2683 \else
2684 \expandafter\FN@cleanpagepenalty\expandafter
2685 \penalty\the\expandafter\expandafter\expandafter\count@
2686 \fi
2687 \fi
2688 \relax}
2689 % \end{macrocode}
2690 % \end{macro}
2691 % \begin{macro}{\FN@mainsplitreturn}
2692 % This is merely an argument delimiting control sequence to make it
2693 % possible to figure out which recursion levels still need visiting.
2694 % \begin{macrocode}
2695 \def\FN@mainsplitreturn{}
2696 % \end{macrocode}
2697 % \end{macro}
2698 % \begin{macro}{\FN@myvsize}
2699 % This is the size currently taken by this insertion.
2700 % \begin{macrocode}
2701 \newdimen\FN@myvsize
2702 % \end{macrocode}
2703 % \end{macro}
2704 % \begin{macro}{\bigfoottolerance}
2705 % This specifies what footnote arrangement penalty will be accepted
2706 % without looking for a better solution.
2707 % \begin{macrocode}
2708 \newcount\bigfoottolerance
2709 \bigfoottolerance=100
2710 % \end{macrocode}
2711 % \end{macro}
2712 % \begin{macro}{\FN@getbadness}
2713 % This takes a skip value of remaining space and negative
2714 % stretchability and shrinkability, and then calculates
2715 % \cmd{\badness} depending on how good the stretching accommodates
2716 % the remaining space.
2717 % \begin{macrocode}
2718 \def\FN@getbadness#1{%
2719 {\hfuzz\maxdimen\hbadness\@M\setbox\z@\hbox to\z@{\hskip-#1}}}
2720 % \end{macrocode}
2721 % \end{macro}
2722 % \begin{macro}{\FN@newlevel}
2723 % This is the main workhorse of |bigfoot|. It splits a particular
2724 % footnote level, recursing if necessary. The level list is
2725 % delimited with \cmd{\FN@mainsplitreturn}. The whole thing is
2726 % looped through while the splits are being optimized. While
2727 % recursing, \cmd{\FN@penalties} contains the accumulated penalities
2728 % of the current split configuration: a penalty of $10000$ for any
2729 % split (except the main list), plus the penalty at the split points
2730 % plus a `hangover' badness for the percentage of material carried
2731 % over to the following pages. If nothing is carried over, this
2732 % is~0, if more is carried over, we get a penalty according to the
2733 % proportion of carryover material, raised to the third power.
2734 % \begin{macro}{\footnotecarryratio}
2735 % The fractional variable \cmd{\footnotecarryratio} is used for
2736 % scaling the leftover material dimensions. After scaling with
2737 % \cmd{\footnotecarryratio}, the carried material is treated like
2738 % missing material in a glue calculation, while the stretchability
2739 % for this calculation is given by the total size of material before
2740 % breaking. So with a setting of~1, there should always be enough
2741 % stretchability, causing at most a penalty of~100. That's not very
2742 % effective, so we scale this up.
2743 %
2744 % The default value of~2 seems to provide a reasonable penalty for
2745 % leftover material. The actual purpose for this component of the
2746 % scoring is to penalize footnote blocks that seem to carry over
2747 % disproportionally much material to later pages.
2748 % \begin{macrocode}
2749 \providecommand\footnotecarryratio{2}
2750 % \end{macrocode}
2751 % \end{macro}
2752 % \cmd{\FN@ebadness} is an augmented value, but also counting in the
2753 % stretch badness for one particular configuration. Ebadness does
2754 % not make sense to evaluate more than temporarily: it is not passed
2755 % through the levels. Since \cmd{\FN@penalties} is globally
2756 % tampered with, its value at entry is saved in
2757 % \cmd{\FN@entrypenalties}. Whenever we recurse or return,
2758 % \cmd{\FN@vsize} contains the full information about the available
2759 % space on the page, even though locally we use \cmd{\FN@myvsize}, a
2760 % local value, to keep track of the locally reserved space. The
2761 % only time when we need to save \cmd{\FN@myvsize} should be when we
2762 % temporarily leave boxes in order to save the current
2763 % configuration.
2764 % \begin{macrocode}
2765 \def\FN@newlevel#1#2#3\FN@mainsplitreturn{%
2766 \count@\FN@cache#2%
2767 \ifvoid\count@
2768 %<trace> \if\foottrace1\message{Page=\thepage #2 is empty, recursing with
2769 %<trace> \the\FN@vsize^^J}%
2770 %<trace> \message{Config=\unexpanded\expandafter{\FN@config}^^J}\fi
2771 #3\FN@mainsplitreturn
2772 %<trace> \if\foottrace1%
2773 %<trace> \message{Page=\thepage #2 was empty,
2774 %<trace> returning with \the\FN@vsize^^J}%
2775 %<trace> \message{Config=\unexpanded\expandafter{\FN@config}^^J}\fi
2776 \else
2777 %<trace> \if\foottrace1\message{Entering #2 with \FN@penalties,
2778 %<trace> \FN@vsize=\the\FN@vsize,^^J%
2779 %<trace> Config=\unexpanded\expandafter{\FN@config}^^J}\fi
2780 {\def\FN@currentinsertion{#2}%
2781 \def\FN@currentrecursion{#3}%
2782 \let\FN@entryconfig\FN@config
2783 \let\FN@entrypenalties\FN@penalties
2784 \splittopskip\csname FN@ht\number#2\endcsname\relax
2785 \splitmaxdepth\csname FN@dp\number#2\endcsname\relax
2786 \hsize\csname FN@wd\number#2\endcsname\relax
2787 \vbadness=\@M
2788 \vfuzz\maxdimen
2789 \let\@elt\relax
2790 \expandafter\FN@newleveli\expandafter}%
2791 %<trace> \if\foottrace1\message{Exiting #2 with \FN@penalties,
2792 %<trace> \FN@vsize=\the\FN@vsize,^^J%
2793 %<trace> Config=\unexpanded\expandafter{\FN@config}^^J}\fi
2794 \fi}
2795 % \end{macrocode}
2796 % \end{macro}
2797 % \begin{macro}{\FN@newleveli}
2798 % \begin{macrocode}
2799 \def\FN@newleveli{%
2800 % \end{macrocode}
2801 % \cmd{\FN@vsize} already includes the size of the complete unsplit
2802 % insertion. When we recurse, it has to reflect the correct size at
2803 % the time of recursion. Rounding error problems don't permit us to
2804 % accumulate any sizes in \cmd{\FN@vsize} from processing our current
2805 % insertion, so we just subtract the whole insertion-related
2806 % content. We'll add stuff into it when recursing.
2807 % \begin{macrocode}
2808 \dimen@\dimexpr\ht\count@
2809 \ifnum\FN@currentinsertion=\FN@savebox
2810 +\maxdepth
2811 \else
2812 +\dp\count@
2813 \fi\relax
2814 \global\advance\FN@vsize\dimexpr \dimen@
2815 *\count\FN@currentinsertion/\@m\relax\relax
2816 % \end{macrocode}
2817 % Ok, now we are typesetting and collecting the best box. Notice
2818 % that we \emph{don't} exit this \cmd{\setbox} command until we have
2819 % found the best possible split. What we \cmd{\unvbox} here, stays
2820 % dormant except for the last box. When we collect configurations
2821 % from cache boxes, we don't collect anything from our current box
2822 % that is being assembled. So the whole action is confined within the
2823 % current list that will replace the cache box after splitting. The
2824 % meaning of boxes on the various levels are:\par\noindent
2825 % \begin{tabularx}{\linewidth}{ll@{:\hskip\tabcolsep}X}
2826 % 0&box0&where stuff gets collected as tentative material to be
2827 % unboxed with \cmd{\FN@removevboxes} once the insertion gets readied
2828 % for shipout\\
2829 % 0&box2&the previous best split that was found\\\hline
2830 % 1&box0&the material that gets worked off, the tail of the split\\
2831 % 1&box2&where the current split is assigned
2832 % \end{tabularx}
2833 % The structure of 0/box2 is the head of the split, followed by
2834 % |\break| penalty, followed by the tail of the split, followed by
2835 % |\penalty\FN@tempbox|, followed by pairs of cache boxes and
2836 % penalties indicating their box number. That way, the tail can get
2837 % restored immediately into |\FN@tempbox| when using
2838 % |\FN@restoreboxes|.
2839 % \begin{macrocode}
2840 \global\setbox\count@\vbox\bgroup\unvbox\count@
2841 % \end{macrocode}
2842 % We calculate \cmd{\FN@myvsize} as the total space taken up by this
2843 % insertion. The size of the last box is excluded since it will be
2844 % split now.
2845 % \begin{macrocode}
2846 \ifnum\lastpenalty=\z@
2847 \setbox\tw@\box\voidb@x
2848 \setbox\z@\lastbox
2849 \FN@myvsize=\ifnum\lastnodetype<\z@
2850 \z@
2851 \else
2852 \dimexpr\dimen@-\ht\z@-\dp\z@\relax
2853 \fi
2854 \else
2855 % \end{macrocode}
2856 % Now if the box has been split previously, we glue it back together
2857 % again. Since the lower part of the split has been \emph{subtracted}
2858 % from the total in \cmd{\dimen@}, we need to put it back into the
2859 % equation here. \cmd{\dimen@} contains the size of the box after
2860 % padding split material has been added.
2861 % \begin{macrocode}
2862 %<trace> \if\foottrace1\message{Regluing box 2}\fi
2863 \unpenalty
2864 \setbox\tw@\lastbox
2865 \setbox\z@\lastbox
2866 \FN@myvsize=\dimexpr\dimen@-\ht\z@-\dp\z@\relax
2867 \dimen@\dp\z@
2868 \setbox\z@{\unvbox\z@
2869 \setbox\z@\lastbox
2870 \unvbox\z@
2871 \unvbox\tw@}%
2872 \ht\z@=\dimexpr\ht\z@+\dp\z@-\dimen@\relax
2873 \dp\z@\dimen@
2874 \fi
2875 % \end{macrocode}
2876 % Ok, size is all accounted for. Go on with optimization. Note that
2877 % these definitions here are made in \emph{inner} level, so they can't
2878 % make it outside as the result of the optimization. If we drop out
2879 % of here without superceding them, something's completely rotten.
2880 % ^^A Fixme: Alpha pruning could be implemented by calling with
2881 % ^^A \FN@bestcost already set at entry to the best badness at
2882 % ^^A the respective level.
2883 % \begin{macrocode}
2884 \edef\FN@bestcost{\number\maxdimen}%
2885 \let\FN@bestbadness\FN@bestcost
2886 \let\FN@bestconfig\@undefined
2887 \def\FN@bestvsize{-\maxdimen}%
2888 \let\FN@splitcolors\@empty
2889 % \end{macrocode}
2890 % Ok, first attempt. One interesting feature is that we will never
2891 % have to rewind the boxes from a split: we can always just glue the
2892 % box together again. And apart from tentative splits which we might
2893 % revert if they cause a configuration change, we will not have to
2894 % bother about contributing too much. What we put in the box here
2895 % can stay.
2896 %
2897 % First we split to the remaining size. Since we still have all
2898 % subordinate footnotes considered fully, we need at least this split
2899 % size (in case of a configuration change, we will need more). After
2900 % having done the initial split, we continue splitting until we get
2901 % the necessary mark of the last footnote into our grasp: we can't
2902 % split before that.
2903 % \begin{macrocode}
2904 \ifnum\FN@currentinsertion=\FN@savebox
2905 \else
2906 \edef\FN@defaultpenalty{\number-\@M}%
2907 \edef\FN@masterslot{\number\dp\z@}%
2908 \edef\FN@masterid{\FN@slotget\FN@masterslot}%
2909 \fi
2910 % \end{macrocode}
2911 % Now we are building one tentative candidate for returning in
2912 % |\box\z@|. It will get discarded in case that a better candidate
2913 % was already found before this box completes.
2914 % \begin{macrocode}
2915 \setbox\z@
2916 \vbox\bgroup
2917 % \end{macrocode}
2918 % Ok, now stuff gets complicated: for the first, tentatively `optimal'
2919 % split, we want to have all available page stretchability properly
2920 % taken into account. So we take the box, and add the available page
2921 % stretchability at the top. Note that the stretchability is
2922 % registered negatively. If we are on the main vertical list, an
2923 % empty page can be an acceptable option, so we add a penalty of zero
2924 % to account for that. Note that any prospective true penalties will
2925 % already have disappeared into the page break.
2926 % \begin{macrocode}
2927 \let\FN@splitcolors\@empty
2928 \setbox\z@\vbox{\vskip-\glueexpr(\FN@vsize-\dimexpr\FN@vsize
2929 \relax\@minus\glueshrink\FN@vsize)%
2930 *\@m/\count\FN@currentinsertion
2931 \penalty\z@
2932 \unvbox\z@
2933 \ifnum\FN@defaultpenalty>-\@M
2934 \penalty\FN@defaultpenalty\relax\nointerlineskip
2935 \vbox to\maxdimen{}%
2936 \fi}%
2937 % \end{macrocode}
2938 % Ok, now we have pushed the additional available stretch onto the top
2939 % of box~0. Now we do the actual split to minimal size. That means
2940 % that we don't consider any of the shrinkability available on the
2941 % page: it might still be better employed in some recursive level.
2942 % \begin{macrocode}
2943 \setbox\tw@\vsplit\z@ to%
2944 \dimexpr\FN@vsize*\@m/\count\FN@currentinsertion
2945 -\FN@myvsize-\splitmaxdepth
2946 \relax
2947 \ifnum\FN@defaultpenalty>-\@M
2948 \setbox\z@\vbox\bgroup\unvbox\z@\setbox\z@\lastbox
2949 \unskip
2950 \unpenalty
2951 \ifnum\lastnodetype<\z@
2952 \egroup \setbox\z@\box\voidb@x
2953 \else
2954 \egroup
2955 \fi
2956 \fi
2957 % \end{macrocode}
2958 % Ok, now the top of box~2 contains unwanted additional
2959 % stretchability. The easiest way to get rid of it is by adding its
2960 % negation.
2961 % \begin{macrocode}
2962 \setbox\tw@\vbox{%
2963 \vskip\glueexpr(\FN@vsize-\dimexpr\FN@vsize
2964 \relax\@minus\glueshrink\FN@vsize)%
2965 *\@m/\count\FN@currentinsertion
2966 \unvbox\tw@\boxmaxdepth\splitmaxdepth}%
2967 % \end{macrocode}
2968 % Ok, now rinse and repeat if we haven't reached the last footnote
2969 % in the block.
2970 % \begin{macrocode}
2971 \ifnum\FN@currentinsertion=\FN@savebox
2972 \edef\FN@slaveid{\splitbotmarks\FN@slave}%
2973 \FN@contribute@tw@
2974 \else
2975 \ifnum0\splitbotmarks\FN@master=\FN@masterslot \else
2976 \loop
2977 \FN@contribute@tw@
2978 \setbox\tw@\vsplit\z@ to\z@
2979 \ifnum0\splitbotmarks\FN@master=\FN@masterslot
2980 \else
2981 \repeat
2982 \fi
2983 \let\FN@splitcolors\@empty
2984 \edef\FN@slaveid{\splitbotmarks\FN@slave}%
2985 \FN@contribute@tw@
2986 \fi
2987 % \end{macrocode}
2988 % All of the above was necessary to ensure that we actually have the
2989 % beginning of the relevant footnote in our material. From now on,
2990 % we are dealing with legal splits.
2991 % Ok, now we have to check whether the subordinate configuration has
2992 % changed.
2993 % \begin{macrocode}
2994 \ifx\FN@slaveid\@empty
2995 %<trace> \ifnum\FN@currentinsertion=\FN@savebox\else
2996 %<trace> \errmessage{Missing slaveid in \FN@currentinsertion}\fi
2997 \edef\FN@slaveid{\number0\topmarks\FN@slave}%
2998 \fi
2999 \ifnum\numexpr\FN@slaveid+\@ne<\FN@masterid
3000 \let\FN@next\FN@slaveid
3001 \else
3002 \let\FN@next\@empty
3003 \fi
3004 % \end{macrocode}
3005 % At this point of time, we have \cmd{\FN@masterid} set properly for
3006 % our purposes. It is to be used for returning any \emph{tail} part
3007 % of a box. \cmd{\FN@slaveid} is by necessity not empty. If any
3008 % footnote
3009 % has had its mark broken off, its id must be in the open range
3010 % between \cmd{\FN@slaveid} and \cmd{\FN@masterid}. So a nonempty
3011 % value of \cmd{\FN@next} at this point of time indicates that we have
3012 % to cater for a different configuration rather than the currently
3013 % cached one.
3014 % \begin{macrocode}
3015 \FN@splitfurther}
3016 % \end{macrocode}
3017 % \end{macro}
3018 % \begin{macro}{\FN@vsizerecurse}
3019 % This fixes the vertical size up and recurses once.
3020 % \begin{macrocode}
3021 \def\FN@vsizerecurse{%
3022 \global\advance\FN@vsize
3023 -\dimexpr\FN@myvsize*\count\FN@currentinsertion/\@m \relax\relax
3024 \let\@elt\FN@newlevel
3025 \FN@currentrecursion\FN@mainsplitreturn
3026 \let\@elt\relax
3027 \global\advance\FN@vsize
3028 \dimexpr\FN@myvsize*\count\FN@currentinsertion/\@m \relax\relax}
3029 % \end{macrocode}
3030 % \end{macro}
3031 %
3032 % \subsubsection{Main label for reconsideration}
3033 % When we are here, then there is not yet a split in the next footnote
3034 % blocks scheduled. We might have to restitch stuff together here,
3035 % though.
3036 % \begin{macro}{\FN@splitfurther}
3037 % \begin{macrocode}
3038 \def\FN@splitfurther{%
3039 \ifx\FN@next\@empty \else \let \FN@slaveid\FN@next \fi
3040 % \end{macrocode}
3041 % Ok, if our configuration now differs from the last one for which we
3042 % have cache boxes set up, we have to reconfigure. It it doesn't, we
3043 % just stitch the boxes together again in order to have correct size
3044 % info.
3045 % \begin{macrocode}
3046 \let\FN@next\FN@config
3047 \xdef\FN@config{%
3048 \@elt{\FN@slaveid}%
3049 {\FN@masterid}%
3050 \FN@entryconfig}%
3051 \ifx\FN@next\FN@config
3052 \let\@elt\FN@rejoin
3053 \else
3054 \let\@elt\FN@reconfig
3055 \fi
3056 \FN@currentrecursion
3057 \let\@elt\relax
3058 % \end{macrocode}
3059 % Ok, now we check whether the current configuration is a match for
3060 % the best previous one. Also we calculate the badness of the current
3061 % situation.
3062 % \begin{macrocode}
3063 \xdef\FN@penalties{\number\FN@entrypenalties}%
3064 \FN@checkcurrent
3065 % \end{macrocode}
3066 % No point in recursing if we can't beat the current best one.
3067 % However, if we find a forced break, this is considered perfect as
3068 % long as we are not overfull. Note that recursion can only increase
3069 % the badness if we are still underfull here, so there is no point in
3070 % using \cmd{\FN@penalties} as the deciding factor of whether there may
3071 % be a point in recursing: the current ebadness (which is never less
3072 % than the badness) already is minimal.
3073 % \begin{macrocode}
3074 \ifnum
3075 \ifdim\skip@>\z@ \FN@ebadness \else \FN@penalties \fi
3076 >\FN@bestcost\relax
3077 %<trace> \if\foottrace1%
3078 %<trace> \message{no recursion: \skip@=\the\skip@,
3079 %<trace> \noexpand\FN@bestvsize=\FN@bestvsize,
3080 %<trace> \noexpand\FN@ebadness=\FN@ebadness,
3081 %<trace> \noexpand\FN@penalties=\FN@penalties,
3082 %<trace> \noexpand\FN@bestcost=\FN@bestcost.}\fi
3083 \else
3084 %<trace> \if\foottrace1%
3085 %<trace> \message{before recursion: \skip@=\the\skip@,
3086 %<trace> \noexpand\FN@bestvsize=\FN@bestvsize,
3087 %<trace> \noexpand\FN@ebadness=\FN@ebadness,
3088 %<trace> \noexpand\FN@penalties=\FN@penalties,
3089 %<trace> \noexpand\FN@bestcost=\FN@bestcost.^^J
3090 %<trace> recurse with \noexpand\FN@penalties=\number\FN@entrypenalties.}\fi
3091 \xdef\FN@penalties{\number\FN@entrypenalties}%
3092 \FN@vsizerecurse
3093 \FN@checkcurrent
3094 %<trace> \if\foottrace1%
3095 %<trace> \message{after recursion: \skip@=\the\skip@,
3096 %<trace> \noexpand\FN@bestvsize=\FN@bestvsize,
3097 %<trace> \noexpand\FN@ebadness=\FN@ebadness,
3098 %<trace> \noexpand\FN@penalties=\FN@penalties,
3099 %<trace> \noexpand\FN@bestcost=\FN@bestcost.}\fi
3100 \fi
3101 % \end{macrocode}
3102 % Don't look further if we had a forced break or are overfull or are
3103 % at the end of the list.
3104 % \begin{macrocode}
3105 \ifcase
3106 \ifnum\FN@breakpenalty>-\@M \else \@ne \fi
3107 \ifvoid\z@ \@ne \fi
3108 \ifnum\badness<\@MM \else \@ne \fi
3109 \tw@
3110 \or
3111 \expandafter \FN@returnbest
3112 \else
3113 \FN@mayberecordbest
3114 \setbox\tw@\vsplit\z@ to\z@
3115 \edef\FN@next{\splitbotmarks\FN@slave}%
3116 \FN@contribute@tw@
3117 \expandafter \FN@splitfurther
3118 \fi}
3119 % \end{macrocode}
3120 % \end{macro}
3121 % \begin{macro}{\FN@checkcurrent}
3122 % Check out the badness of the current configuration. The last box
3123 % on the list is the material constituting the discardable material
3124 % after a split.
3125 % \begin{macrocode}
3126 \def\FN@checkcurrent{%
3127 \FN@getbreakpenalty
3128 \ifnum\FN@breakpenalty<-\@M
3129 \edef\FN@breakpenalty{\number-\@M}%
3130 \fi
3131 \ifnum\FN@currentinsertion=\FN@savebox
3132 \else
3133 \ifdim\FN@specific\FN@currentinsertion\footnotecarryratio\p@>\z@
3134 \skip@
3135 \ifdim\FN@specific\FN@currentinsertion\footnotecarryratio\p@>\p@
3136 \dimexpr\ht\z@+\dp\z@\relax
3137 \@plus-\dimexpr((\FN@myvsize+\ht\z@+\dp\z@)
3138 *\p@/\dimexpr
3139 \FN@specific\FN@currentinsertion
3140 \footnotecarryratio\p@)\relax
3141 \else
3142 \FN@specific\FN@currentinsertion
3143 \footnotecarryratio
3144 \dimexpr\ht\z@+\dp\z@\relax
3145 \@plus-\dimexpr\FN@myvsize+\ht\z@+\dp\z@\relax
3146 \fi
3147 \relax
3148 \FN@getbadness\skip@
3149 \xdef\FN@penalties{\number\numexpr\FN@penalties+\badness}%
3150 \fi
3151 \fi
3152 \skip@\glueexpr\FN@vsize-\FN@myvsize
3153 *\count\FN@currentinsertion/\@m\relax
3154 \FN@getbadness\skip@
3155 \xdef\FN@penalties{\number\numexpr\FN@penalties+%
3156 \FN@breakpenalty+\@M}%
3157 \ifnum\badness>\@M
3158 \edef\FN@ebadness{\number\numexpr\maxdimen-\@ne}%
3159 \else
3160 \ifnum\badness=\@M
3161 \ifdim\skip@<\vsize
3162 \edef\FN@ebadness{\number\numexpr\maxdimen-\tw@}%
3163 \else
3164 \edef\FN@ebadness{\number\numexpr\maxdimen}%
3165 \fi
3166 \else
3167 \edef\FN@ebadness{\number\numexpr
3168 \FN@penalties+\badness
3169 \ifdim\FN@specific\FN@currentinsertion\FootnoteMinimum>\FN@myvsize
3170 1000000
3171 \fi
3172 }%
3173 \fi
3174 \fi
3175 \dimen@\glueexpr\FN@bestvsize\relax
3176 }
3177 % \end{macrocode}
3178 % \end{macro}
3179 % \begin{macro}{\FN@checkforbest}
3180 % This generates 2 if the old stored best is better, 1~if the
3181 % current variation is better.
3182 % \begin{macrocode}
3183 \def\FN@checkforbest{%
3184 \ifnum\FN@breakpenalty>-\@M \else
3185 \ifnum\badness>\@M \else
3186 \@ne
3187 \fi
3188 \fi
3189 % \end{macrocode}
3190 % Ok, so the split was not as good as to cause us to return
3191 % immediately, and it also was not the last opportunity for a split
3192 % (which again would make us return immediately).
3193 % So we check if it is at least better than the last one, in which
3194 % case we need to replace the previous best.
3195 % \begin{macrocode}
3196 \ifnum\FN@bestcost>\FN@ebadness \@ne\fi
3197 \ifnum\FN@bestcost<\FN@ebadness \tw@\fi
3198 \ifdim\skip@<\z@
3199 \ifdim\dimen@<\skip@ \@ne \fi \tw@
3200 \fi
3201 \ifdim\dimen@>\skip@ \@ne\fi \tw@}
3202 % \end{macrocode}
3203 % \end{macro}
3204 % \begin{macro}{\FN@mayberecordbest}
3205 % This checks whether the current configuration is better than a
3206 % previously saved one. If it is, the previous configuration gets
3207 % replaced. The cache boxes itself are copied, not voided in the
3208 % process for efficiency reasons.
3209 % \begin{macrocode}
3210 \def\FN@mayberecordbest{%
3211 % \end{macrocode}
3212 % If the current break is forced and the page is not overfull, we take
3213 % the break.
3214 % \begin{macrocode}
3215 \ifcase
3216 \FN@checkforbest
3217 \or
3218 \xdef\FN@tempinfo{\def\noexpand\FN@bestvsize{\the\skip@}%
3219 \def\noexpand\FN@bestcost{\FN@ebadness}%
3220 \def\noexpand\FN@bestbadness{\number\FN@penalties}%
3221 \def\noexpand\FN@bestconfig{\FN@config}%
3222 \def\noexpand\FN@bestslaveid{\FN@slaveid}%
3223 \def\noexpand\FN@bestsplitcolors{\FN@splitcolors}%
3224 \def\noexpand\FN@breakpenalty{\FN@breakpenalty}%
3225 \FN@myvsize=\the\FN@myvsize\relax}%
3226 \global\setbox\FN@tempbox\box\z@
3227 \egroup
3228 \FN@tempinfo
3229 \let\FN@splitcolors\FN@bestsplitcolors
3230 \let\FN@slaveid\FN@bestslaveid
3231 % \end{macrocode}
3232 % Now all relevant info has been retrieved, and we collect the best
3233 % box info in |\box\tw@|. The structure of the information is as
3234 % follows: it starts with the current box in split form, first the
3235 % tail, then the start of the current split box.
3236 % This is then followed by a zero kern, and then by pairs of boxes and
3237 % penalties indicating the swept box.
3238 % \begin{macrocode}
3239 \setbox\tw@\vbox{%
3240 % \end{macrocode}
3241 % We don't need to place master/slave marks here: the necessary
3242 % information is available outside in the \cmd{\FN@masterslot} and
3243 % \cmd{\FN@slaveid} info and gets attached afterwards.
3244 % \begin{macrocode}
3245 \copy\z@\break\nointerlineskip
3246 \copy\FN@tempbox\penalty\FN@tempbox
3247 \let\@elt\FN@copycachebox
3248 \FN@currentrecursion}%
3249 \setbox\z@
3250 \vbox\bgroup
3251 \unvbox\z@
3252 \setbox\z@\box\FN@tempbox
3253 \fi}
3254 % \end{macrocode}
3255 % \end{macro}
3256
3257 % \begin{macro}{\FN@returnbest}
3258 % \begin{macrocode}
3259 \def\FN@returnbest{%
3260 \ifcase\FN@checkforbest
3261 \or
3262 \xdef\FN@tempinfo{\def\noexpand\FN@bestvsize{\the\skip@}%
3263 \def\noexpand\FN@bestcost{\FN@ebadness}%
3264 \def\noexpand\FN@bestbadness{\number\FN@penalties}%
3265 \def\noexpand\FN@bestconfig{\FN@config}%
3266 \def\noexpand\FN@bestslaveid{\FN@slaveid}%
3267 \def\noexpand\FN@bestsplitcolors{\FN@splitcolors}%
3268 \def\noexpand\FN@breakpenalty{\FN@breakpenalty}%
3269 \FN@myvsize=\the\FN@myvsize\relax}%
3270 \global\setbox\FN@tempbox\box\z@
3271 \egroup
3272 \FN@tempinfo
3273 \let\FN@splitcolors\FN@bestsplitcolors
3274 \let\FN@slaveid\FN@bestslaveid
3275 \global\FN@vsize\FN@bestvsize\relax
3276 % \end{macrocode}
3277 % Now all relevant info has been retrieved, and we collect the best
3278 % box info in |\box\tw@|. The structure of the information is as
3279 % follows: it starts with the current box in split form, first the
3280 % tail, then the start of the current split box.
3281 % This is then followed by a zero kern, and then by pairs of boxes and
3282 % penalties indicating the swept box.
3283 % \begin{macrocode}
3284 \or
3285 \global\let\FN@config\FN@bestconfig
3286 \global\FN@vsize\FN@bestvsize
3287 \global\let\FN@penalties\FN@bestbadness
3288 \egroup
3289 % \end{macrocode}
3290 % Restore the saved configuration.
3291 % \begin{macrocode}
3292 \setbox\z@\vbox{\unvbox\tw@ \FN@restoreboxes}%
3293 \let\FN@splitcolors\FN@bestsplitcolors
3294 \let\FN@slaveid\FN@bestslaveid
3295 \unvbox\z@
3296 \setbox\z@\lastbox
3297 \fi
3298 % \end{macrocode}
3299 % \begin{macrocode}
3300 \ifnum\FN@currentinsertion=\FN@savebox
3301 \else
3302 \setbox\z@\vbox{%
3303 \prevdepth\dp\z@
3304 \unvbox\z@
3305 \ifvoid\FN@tempbox
3306 \else
3307 \global\setbox\FN@tempbox\vbox{%
3308 \marks\FN@master{\FN@masterslot}%
3309 \marks\FN@slave{\FN@slaveid}%
3310 \FN@coloraftersplit\FN@splitcolors
3311 \FN@specific\FN@currentinsertion\FN@afterbreak
3312 \nobreak
3313 \unvbox\FN@tempbox}%
3314 \FN@specific\FN@currentinsertion\FN@beforebreak
3315 \ht\FN@tempbox
3316 \dimexpr\ht\FN@tempbox+\dp\FN@tempbox-\FN@masterslot sp\relax
3317 \dp\FN@tempbox\FN@masterslot sp\relax
3318 \wd\FN@tempbox\maxdimen
3319 \fi
3320 \ifdim\prevdepth<\splitmaxdepth
3321 \hrule\@height-\prevdepth \@width\z@
3322 \@depth \splitmaxdepth \relax \fi}%
3323 \ht\z@=\dimexpr\ht\z@+\dp\z@-\FN@masterslot sp\relax
3324 \dp\z@=\FN@masterslot sp
3325 \fi
3326 \nointerlineskip \box\z@
3327 % \end{macrocode}
3328 % If nothing is to be carried over, we just finish our assignment to
3329 % the cache box and return.
3330 % \begin{macrocode}
3331 \ifvoid\FN@tempbox \egroup
3332 % \end{macrocode}
3333 % If not, we add the carried-over box to the list, flag it with a
3334 % \cmd{\nobreak}, and subtract its size from the finished box. Please
3335 % note that the \cmd{\expandafter} chain will expand just
3336 % |\cmd\dimen@|, but everything following it will be evaluated only
3337 % after \cmd{\egroup}, thus using the new height of the box.
3338 % \begin{macrocode}
3339 \else
3340 \dimen@-\dimexpr\ht\FN@tempbox+\dp\FN@tempbox\relax
3341 \nointerlineskip\box\FN@tempbox
3342 \nobreak
3343 \expandafter\egroup
3344 \expandafter\ht\expandafter\count@\expandafter\dimexpr
3345 \the\dimen@+\ht\count@\relax
3346 \fi
3347 }
3348 % \end{macrocode}
3349 % \end{macro}
3350 %
3351 % \begin{macro}{\FN@contribute@tw@}
3352 % This will go from the state where we have the previous
3353 % \cmd{\splitdiscards} struttified on the current list some material
3354 % split off from box~0 in box~2 to a state where box~2 is
3355 % contributed to the current list.
3356 % \begin{macrocode}
3357 \def\FN@contribute@tw@{%
3358 % \end{macrocode}
3359 % First we change the current colors if we have any in our group. Not
3360 % sure if this is entirely correct.
3361 % \begin{macrocode}
3362 \begingroup\edef\FN@next{\splitbotmarks\FN@color}%
3363 \ifx\FN@next\@empty \endgroup\else \endgroup
3364 \edef\FN@splitcolors{\splitbotmarks\FN@color}\fi
3365 % \end{macrocode}
3366 % If the last box is void, there is no previous split to reconstitute.
3367 % \begin{macrocode}
3368 \setbox4\lastbox
3369 \ifvoid4 \setbox4\vbox{\splitdiscards}%
3370 \setbox\tw@\vbox{\unvbox\tw@\boxmaxdepth\splitmaxdepth}%
3371 \else
3372 % \end{macrocode}
3373 % Now the last box is a strut. We remove its outer dimensions from
3374 % the total account, and then add back its natural dimensions after
3375 % which we pour it back into the current list.
3376 % \begin{macrocode}
3377 \advance\FN@myvsize-\dimexpr\ht4+\dp4\relax
3378 \setbox4\vbox{\unvbox4}%
3379 \advance\FN@myvsize\dimexpr\ht4+\dp4\relax
3380 \unvbox4
3381 % \end{macrocode}
3382 % We want to contribute box~2 back without any topskip glue, so we
3383 % manually remove any such glue by splitting an empty box off.
3384 % \begin{macrocode}
3385 \setbox4\vbox{\splitdiscards}%
3386 \setbox\tw@\vbox{\break\unvbox\tw@}%
3387 {\splittopskip-\maxdimen \setbox\tw@\vsplit\tw@ to\z@}%
3388 % \end{macrocode}
3389 % Notice the effect of \TeX's special box scope rules: box~2 assigned
3390 % just right now will be affected by the split. The result of the
3391 % split will be an empty box that will temporarily overwrite box~2
3392 % within the group, but will be restored back to the split result on
3393 % exit. In this manner, any topskip glue will have disappeared.
3394 % After the split, box~2 is set to the natural depth and height of
3395 % its contents.
3396 %
3397 % We now add a sort of strut by putting all the discarded material
3398 % inside of a box that creates the proper size.
3399 % If this split is taken, the box is adjusted to have a full depth of
3400 % \cmd{\splitmaxdepth}, and we take this into account.
3401 % \begin{macrocode}
3402 \fi
3403 \ht4-\dp\tw@
3404 \dp4\ifdim\dp\tw@<\splitmaxdepth \splitmaxdepth \else \dp\tw@ \fi
3405 \advance\FN@myvsize\dimexpr \ht\tw@+\dp4\relax
3406 \unvbox\tw@
3407 \nointerlineskip
3408 \box4 }
3409 % \end{macrocode}
3410 % \end{macro}
3411 % \begin{macro}{\FN@uncontribute@tw@}
3412 % This is just the opposite: after a split, we revert its effects again.
3413 % \begin{macrocode}
3414 \def\FN@uncontribute@tw@{%
3415 \ifvoid\tw@ \else
3416 \setbox\tw@\vbox{\unvbox\tw@\splitdiscards}%
3417 \setbox\z@\vbox{\break\unvbox\z@}%
3418 {\splittopskip-\maxdimen \setbox\z@\vsplit\z@ to\z@}%
3419 \setbox\z@\vbox{\unvbox\tw@\unvbox\z@}\fi}
3420 % \end{macrocode}
3421 % \end{macro}
3422 % \begin{macro}{\FN@reconfig}
3423 % This reconfigures the insertion cache to contain only the boxes
3424 % that belong to this page. If the insertion box is empty, we can
3425 % skip all the folderol. If it isn't, we empty the cache box (the
3426 % number of which we place in \cmd{\count@}) and add its size back
3427 % to \cmd{\FN@vsize}.
3428 % \begin{macrocode}
3429 \def\FN@reconfig#1#2{\ifvoid#2%
3430 %<trace> \ifvoid\FN@cache#2\else
3431 %<trace> \errmessage{\FN@cache#2 should be void}\fi
3432 \else
3433 \count@\FN@cache#2%
3434 \ifvoid\count@\else
3435 \global\advance\FN@vsize
3436 \glueexpr(\ht\count@+\dp\count@)*\count#2/\@m+\skip#2\relax
3437 \global\setbox\count@ \box\voidb@x
3438 \fi
3439 % \end{macrocode}
3440 % Ok, now we have emptied the cache and readjusted the size. We now
3441 % fill the cache by first copying the insertion into it.
3442 % \begin{macrocode}
3443 \global\setbox\count@\vbox\bgroup\vbox\bgroup\unvcopy#2%
3444 \let\@elt\FN@removecheck
3445 \FN@retainkept
3446 % \end{macrocode}
3447 % Now if nothing was retained, we void the cachebox.
3448 % \begin{macrocode}
3449 \ifvoid\z@ \egroup\egroup \global\setbox\count@ \box\voidb@x
3450 % \end{macrocode}
3451 % Otherwise, we combine all the boxes that remain on the page.
3452 % \begin{macrocode}
3453 \else \def\FN@masterinsert{#2}%
3454 \FN@assembleboxes\global\setbox\count@\box\z@\egroup
3455 \nointerlineskip\box\count@\egroup
3456 % \end{macrocode}
3457 % Note that now all footnote boxes are collected into a single vbox,
3458 % followed by the last footnote box as another vbox.
3459 % Now we just need to reduce the available size on the page by the
3460 % height of the assembled material:
3461 % \begin{macrocode}
3462 \global\advance\FN@vsize
3463 -\glueexpr(\ht\count@+\dp\count@)*\count#2/\@m+\skip#2\relax
3464 \fi\fi}
3465 % \end{macrocode}
3466 % \end{macro}
3467 % \begin{macro}{\FN@rejoin}
3468 % This glues together cache boxes that have been split, without
3469 % regenerating them. This saves a lot of time as compared to
3470 % \cmd{\FN@reconfig}.
3471 % \begin{macrocode}
3472 \def\FN@rejoin#1#2{{%
3473 %<trace> \if\foottrace1\message{^^JRejoining #2}\fi
3474 \count@\FN@cache#2%
3475 \ifvoid\count@\else
3476 \global\advance\FN@vsize\dimexpr
3477 (\ht\count@+\dp\count@)*\count#2/\@m\relax
3478 \global\setbox\count@\vbox{%
3479 \unvbox\count@
3480 \ifnum\lastpenalty>\z@
3481 \unpenalty
3482 \setbox\tw@\lastbox
3483 \setbox\z@\lastbox
3484 \dimen@\dp\z@
3485 \setbox\z@\vbox{%
3486 \unvbox\z@
3487 \setbox\z@\lastbox
3488 \unvbox\z@
3489 \unvbox\tw@}%
3490 \ht\z@=\dimexpr\ht\z@+\dp\z@-\dimen@\relax
3491 \dp\z@=\dimen@
3492 \nointerlineskip
3493 \box\z@
3494 \fi}%
3495 \global\advance\FN@vsize-\dimexpr
3496 (\ht\count@+\dp\count@)*\count#2/\@m\relax
3497 \fi}}
3498 % \end{macrocode}
3499 % \end{macro}
3500 %
3501 % \begin{macro}{\FN@retainkept}
3502 % This relies on \cmd{\@elt} being set to \cmd{\FN@removecheck} which
3503 % expands to \cmd{\@ne} if |\box0| is strictly between the two values
3504 % from an entry of \cmd{\FN@config}, which means that it is material
3505 % that should get moved to the next page. In that case, we recurse
3506 % while dropping the box in question. Otherwise we keep it.
3507 % Recursion bottoms out when there are no boxes left. The function
3508 % leaves the last retained box in box~0; if there are no boxes to be
3509 % retained, this will be void.
3510 % \begin{macrocode}
3511 \def\FN@retainkept{%
3512 \setbox\z@\lastbox
3513 \ifcase
3514 \ifvoid\z@\m@ne\fi \FN@config\z@
3515 %<trace> \if\foottrace8\message{^^J\string\FN@retainkept:
3516 %<trace> retaining Id \FN@slotget{\number\dp\z@}}\fi
3517 %<trace> \if\foottrace{16}{\showboxdepth4 \showboxbreadth400
3518 %<trace> \tracingonline=\@ne\showbox\z@}\fi
3519 {\FN@retainkept \nointerlineskip \box\z@}%
3520 \or
3521 %<trace> \if\foottrace8\message{^^J\string\FN@retainkept:
3522 %<trace> dropping Id \FN@slotget{\number\dp\z@}}\fi
3523 %<trace> \if\foottrace{16}{\showboxdepth4 \showboxbreadth400
3524 %<trace> \tracingonline=\@ne\showbox\z@}\fi
3525 \FN@retainkept
3526 %<trace> \else
3527 %<trace> \ifnum\lastnodetype>\m@ne
3528 %<trace> \errmessage{Unexpected node \number\lastnodetype}\fi
3529 \fi}
3530 % \end{macrocode}
3531 % \end{macro}
3532 % Well, as the last measure, we change the output routine to our new
3533 % routine.
3534 % \begin{macrocode}
3535 \let\output\FN@output
3536 % \end{macrocode}
3537 % Ok, here is debugging code intercepting all calls of the regular
3538 % output routine and reporting its entry and exit states.
3539 % \begin{macrocode}
3540 %<trace> \newtoks\FN@tr@output
3541 %<trace> \FN@tr@output\output
3542 %<trace> \output{\if\foottrace8{%
3543 %<trace> \setbox\z@\vbox{%
3544 %<trace> \message{Calling regular output with
3545 %<trace> \outputpenalty=\the\outputpenalty, box255 as}%
3546 %<trace> \showbox\@cclv
3547 %<trace> \the\FN@tr@output
3548 %<trace> \message{Returning from regular output with
3549 %<trace> \ifnum\lastnodetype<\z@
3550 %<trace> empty vertical list.\else vlist:}}%
3551 %<trace> \showbox\z@
3552 %<trace> \unvbox\z@{{\fi}}}\else\the\FN@tr@output\fi}
3553 %<trace> \let\output\FN@tr@output
3554 % \end{macrocode}
3555 % If the footnote type ``default'' has not been declared by the time
3556 % the document starts, we do so at the start of the document.
3557 % Unfortunately, by this time the initialization code in |manyfoot|'s
3558 % own \cmd{\AtBeginDocument} hook has already run, so we manually run
3559 % the initialization hook just for the command we inserted ourselves.
3560 % \begin{macrocode}
3561 \def\FN@maybestart#1#2#3{\ifx#3\relax
3562 \csname MFL@start#1\endcsname{#2}\fi#3}
3563 \@onlypreamble\FN@maybestart
3564 \AtBeginDocument{\@ifundefined{footinsdefault}%
3565 {\newfootnote[plain]{default}%
3566 {\let\@elt\FN@maybestart
3567 \MFL@list\relax}%
3568 }{}%
3569 % \end{macrocode}
3570 % And since LaTeX's macros are inferior to our own (and would probably
3571 % not match too well), we reroot them to the default footnote style.
3572 % \begin{macrocode}
3573 \def\@footnotetext{\Footnotetextdefault{}}%
3574 \def\p@footnotedefault{\p@footnote}%
3575 }
3576 %</style>
3577 % \end{macrocode}
3578 %
3579 % \section{Various driver files}
3580 % The installer, in case it is missing. If it is to be used via
3581 % |make|, we don't specify an installation path, since
3582 % \begin{quote}
3583 % |make install|
3584 % \end{quote}
3585 % is supposed to cater for the installation itself.
3586 % \begin{macrocode}
3587 %<installer> \input docstrip
3588 %<installer&make> \askforoverwritefalse \nopreamble
3589 %<installer> \generate{
3590 %<installer> \file{bigfoot.drv}{\from{bigfoot.dtx}{driver}}
3591 %<installer> \file{perpage.drv}{\from{perpage.dtx}{driver}}
3592 %<installer> \file{suffix.drv}{\from{suffix.dtx}{driver}}
3593 %<installer&!make> \usedir{tex/latex/bigfoot}
3594 %<installer> \file{bigfoot.sty}{\from{bigfoot.dtx}{style}}
3595 %<installer> \file{perpage.sty}{\from{perpage.dtx}{style}}
3596 %<installer> \file{suffix.sty}{\from{suffix.dtx}{style}}
3597 %<installer> }
3598 %<installer> \endbatchfile
3599 % \end{macrocode}
3600 % \Finale
3601 % \endinput
3602 % Local Variables:
3603 % mode: doctex
3604 % TeX-master: "bigfoot.drv"
3605 % End: