From 4443aa712503e8404b2152c761c2ab5e1a98d197 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Sun, 2 Nov 2014 21:50:27 +0000
Subject: bigfoot (2nov14)

git-svn-id: svn://tug.org/texlive/trunk@35482 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/tex/latex/bigfoot/bigfoot.sty | 516 +++++++++++++++---------
 1 file changed, 317 insertions(+), 199 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/bigfoot/bigfoot.sty')

diff --git a/Master/texmf-dist/tex/latex/bigfoot/bigfoot.sty b/Master/texmf-dist/tex/latex/bigfoot/bigfoot.sty
index 4a27b6154ee..ce4c14b6e6f 100644
--- a/Master/texmf-dist/tex/latex/bigfoot/bigfoot.sty
+++ b/Master/texmf-dist/tex/latex/bigfoot/bigfoot.sty
@@ -22,12 +22,13 @@
 %% in the same archive or directory.)
 %%
 %% bigfoot is part of the bigfoot bundle for critical typesetting
-%% Copyright 2004, 05, 06  David Kastrup <dak@gnu.org>
+%% Copyright 2004--2014  David Kastrup <dak@gnu.org>
+%%
+%% The license notice and corresponding source code for this file are
+%% contained in bigfoot.dtx.
 %%
 \NeedsTeXFormat{LaTeX2e}
-\def\FN@next $#1: #2 #3${#2}
-\ProvidesPackage{bigfoot}[\FN@next $Date: 2006/07/15 21:24:56 $
-  \FN@next $Revision: 1.25 $ makes footnotes work]%}
+\ProvidesPackage{bigfoot}[2014/10/23 2.0 makes footnotes work]
 
 \DeclareOption{para}{\PackageInfo{bigfoot}{Compatibility option `para'
   has no effect:^^J%
@@ -41,6 +42,9 @@
     \else\@makefnmark\nobreak\fi}}
 
 \DeclareOption{ruled}{\PassOptionsToPackage{ruled}{manyfoot}}
+\DeclareOption{robust}{\def\FN@makefncall{\FN@makefnrobust}}
+\DeclareOption{fragile}{\def\FN@makefncall{\FN@makefnfragile}}
+\ExecuteOptions{robust}
 \DeclareOption{verbose}{\AtBeginDocument{%
     \def\@testdef #1#2#3{%
       \def\reserved@a{#3}%
@@ -78,12 +82,13 @@
   }%
 }
 
-\def\MFL@minipage{%
-  \ifinner\else
-    \let\MFL@mpinsertsave\MFL@insert
-    \MFL@reinsert \let\MFL@insert\MFL@mpinsert
-  \fi
-}
+\def\FN@divert{%
+  \let\MFL@mpinsertsave\MFL@insert
+  \MFL@reinsert \let\MFL@insert\MFL@mpinsert}
+\def\FN@enddivert{{\let\@elt\MFL@mpreinsert \MFL@list}}
+
+\def\MFL@minipage{\ifinner\else \FN@divert\fi}
+\def\MFL@endminipage{\ifinner\else \FN@enddivert\fi}
 \def\MFL@mpreinsert#1#2{%
   \ifvoid#2\else
     \setbox\@tempboxa\vbox\bgroup\unvbox#2%
@@ -193,6 +198,12 @@
   \let\@elt\relax
   \expandafter\protected@xdef\csname FN@stack@#1\endcsname{%
     \iffalse}\fi}
+\ifx\FN@beforebreak\@undefined
+  \let\FN@beforebreak\@empty
+\fi
+\ifx\FN@afterbreak\@undefined
+  \let\FN@afterbreak\@empty
+\fi
 \def\FN@cache#1{\csname FN@cache\number#1\endcsname}
 \def\FN@sortlist{{%
   \setbox\z@\lastbox
@@ -233,7 +244,7 @@
   \global\setbox\FN@cache#2=\box\voidb@x}
 \def\@makefnvtext#1{%
   \FN@specific\FN@masterinsert\@makefntext{%
-    \clubpenalties\tw@\@MM\clubpenalty
+    \clubpenalties\thr@@\@MM\clubpenalty\z@
     \vadjust{\nobreak\vskip-\baselineskip}\nobreak\hfill\break#1}}
 \ifx\@preparefnhtext\@undefined
 \def\@preparefnhtext{{%
@@ -255,6 +266,9 @@
   \FN@tempinfo}
 \fi
 \def\@makefnstartbox{%
+  \ifdefined\setspace@singlespace
+    \def\baselinestretch{\setspace@singlespace}%
+  \fi
   \reset@font\footnotesize
   \hsize\MFL@columnwidth \@parboxrestore
   \interlinepenalty\FN@specific\FN@masterinsert\interfootnotelinepenalty
@@ -274,7 +288,7 @@
 \ifx\@makefnvbox\@undefined
   \def\@makefnvbox#1{\vbox{%
       \@makefnstartbox
-      \clubpenalties\tw@\@MM\clubpenalty
+      \clubpenalties\thr@@\@MM\clubpenalty\z@
       \let\@thefnmark\@empty
       \FN@specific\FN@masterinsert\@makefntext{\rule\z@\footnotesep
         \nobreak
@@ -282,7 +296,7 @@
       \@makefnendbox}}}
 \fi
 \def\hfootfraction{0.9}
-\def\vtypefraction{0.6}
+\def\vtypefraction{0.7}
 \def\FN@assembleboxes{%
   \ifhbox\z@
     \dimen@\dp\z@
@@ -298,12 +312,13 @@
     \setbox\z@\@makefnvbox{%
       {\unhbox\FN@tempbox}%
       \setbox\z@\lastbox\FN@joinhboxes}%
-    \ifdim\FN@vfound>\dimexpr\vtypefraction\p@*\FN@found\relax
-      \ifdim\dimexpr \ht\z@+\dp\z@>\hfootfraction\dimen@ii
-        \global\setbox\FN@tempbox\box\tw@
-        \setbox\z@\@makefnvbox{\let\@makefnbreak\FN@pseudofillbreak
-            {\unhbox\FN@tempbox}\setbox\z@\lastbox\FN@joinhboxes}%
-      \fi
+    \ifcase
+      \ifdim\FN@vfound>\dimexpr\vtypefraction\p@*\FN@found\relax \@ne\fi
+      \ifdim\dimexpr \ht\z@+\dp\z@>\hfootfraction\dimen@ii \@ne\fi \z@
+    \or
+      \global\setbox\FN@tempbox\box\tw@
+      \setbox\z@\@makefnvbox{\let\@makefnbreak\FN@pseudofillbreak
+          {\unhbox\FN@tempbox}\setbox\z@\lastbox\FN@joinhboxes}%
     \fi
     \setbox\tw@\box\voidb@x
     \ht\z@\dimexpr \ht\z@+\dp\z@-\dimen@\relax
@@ -338,8 +353,8 @@
   \xdef\FN@found{\number\numexpr\FN@found+\@ne}%
 }
 \def\FN@pseudobreak{%
-    {\parskip\z@skip\parfillskip\z@skip\parindent\z@\vadjust{}\par\noindent
-      \vadjust{\nobreak\vskip-\baselineskip}\nobreak\hfill\break}}
+  {\parskip\z@skip\parfillskip\z@skip\parindent\z@\vadjust{}\par\noindent
+    \vadjust{\nobreak\vskip-\baselineskip}\nobreak\hfill\break}}
 \def\FN@pseudofillbreak{\nobreak\hskip\parfillskip\FN@pseudobreak}
 \def\@makefnbreak{\FN@magicglue {\footnotesep+\dp\strutbox}%
   {\footnotesep+\dp\strutbox+\baselineskip}%
@@ -398,7 +413,7 @@
   \stepcounter{FN@totalid}%
   \NCC@makemark{#3}%
   \ifnum#2<\FN@masterinsert
-    \FN@colorstackbgroup\MFL@minipage
+    \FN@colorstackbgroup\FN@divert
     \FN@newslot\FN@masterslot
     \count@\FN@id
     \dimen@=\dimexpr64\p@*\FN@masterinsert-\c@FN@totalid sp\relax
@@ -419,43 +434,60 @@
       \ifx\FN@boxtype\vbox \normalcolor\nobreak
       \else \FN@specific{#2}\@preparefnhtext \normalcolor
       \fi
-      \FN@specific{#2}\@makefntext
-      \iffalse\fi
-      \expandafter\xdef\csname FN@ht\number#2\endcsname{\the\footnotesep}%
-      \expandafter\xdef\csname FN@dp\number#2\endcsname{\the\dp\strutbox}%
-      \marks\FN@master{\FN@masterslot}%
-      \marks\FN@slave{\number\FN@id}%
-      \nobreak
-      \bgroup
-        \aftergroup\FN@commonending
-        \ifx\FN@boxtype\vbox
-           \rule\z@\footnotesep
-        \else
-          \ifx\FN@par\par\else
-            \let\FN@@par\par
-            \let\FN@@noindent\noindent
-            \let\FN@@indent\indent
-          \fi
-           \everyvbox\expandafter{\expandafter\everyvbox
-             \expandafter{\the\everyvbox}%
-             \let\par\FN@@par
-             \let\noindent\FN@@noindent
-             \let\indent\FN@@indent
-             \the\everyvbox}%
-           \let\par\FN@par
-           \let\noindent\FN@noindent
-           \let\indent\FN@indent
-        \fi
-        \afterassignment\ignorespaces
-        \expandafter\FN@fnotecommonii
-      \else
+      \expandafter \FN@makefncall
+  \else
     \PackageError{bigfoot}{#2 forbidden in \FN@masterinsert.}%
     {Higher-placed footnotes can't be anchored in inferior ones.^^J%
     I am not putting this text in a footnote.  History:%
 \FN@errorstack}%
     \rule{1em}{\ht\strutbox}%
 \fi}
-\def\FN@fnotecommonii#{\let\next}
+\providecommand{\FN@seitenobreak}{\nobreak}
+\def\FN@makefnstart{%
+  \expandafter\xdef\csname FN@ht\number\FN@masterinsert\endcsname
+    {\the\footnotesep}%
+  \expandafter\xdef\csname FN@dp\number\FN@masterinsert\endcsname
+    {\the\dp\strutbox}%
+  \expandafter\xdef\csname FN@wd\number\FN@masterinsert\endcsname
+    {\the\hsize}%
+  \marks\FN@master{\FN@masterslot}%
+  \marks\FN@slave{\number\FN@id}%
+  \nobreak
+  \ifx\FN@boxtype\vbox
+    \rule\z@\footnotesep
+  \else
+    \ifx\FN@par\par\else
+      \let\FN@@par\par
+      \let\FN@@noindent\noindent
+      \let\FN@@indent\indent
+    \fi
+     \everyvbox\expandafter{\expandafter\everyvbox
+       \expandafter{\the\everyvbox}%
+       \let\par\FN@@par
+       \let\noindent\FN@@noindent
+       \let\indent\FN@@indent
+       \the\everyvbox}%
+     \let\par\FN@par
+     \let\noindent\FN@noindent
+     \let\indent\FN@indent
+  \fi
+  \FN@seitenobreak
+  \afterassignment\ignorespaces}
+\def\FN@makefnrobust#{%
+  \FN@specific\FN@masterinsert\@makefntext
+  \iffalse\fi
+  \bgroup
+    \aftergroup\FN@robustending
+    \FN@makefnstart
+    \let\next}
+\def\FN@robustending{%
+  \expandafter\expandafter\expandafter
+  \expandafter\expandafter\expandafter\expandafter
+  \iffalse  \FN@specific\FN@masterinsert\@makefntext\fi
+  \FN@commonending}
+\long\def\FN@makefnfragile#1{%
+  \FN@specific\FN@masterinsert\@makefntext
+  {\FN@makefnstart#1\FN@commonending}}
 \newmarks\FN@color
 \def\FN@colorstackbgroup{\let\FN@savecolorstack\FN@colorstack
   \global\let\FN@colorstack\@empty
@@ -469,8 +501,8 @@
   \let\reset@color\FN@reset@color
   \let\color@begingroup\FN@color@begingroup}
 
-\def\FN@colorstackegroup{\egroup\ifx\FN@colorstack\@empty
-  \global\let\FN@colorstack\FN@savecolorstack \fi}
+\def\FN@colorstackegroup{\egroup
+  \global\let\FN@colorstack\FN@savecolorstack}
 
 \def\FN@colorstackfinish{\def\@elt##1##2{\FN@@reset@color##2}%
   \FN@colorstack
@@ -505,9 +537,6 @@
   #1%
   \let\@elt\relax}
 \def\FN@commonending{%
-  \expandafter\expandafter\expandafter
-  \expandafter\expandafter\expandafter\expandafter
-  \iffalse  \FN@specific\FN@masterinsert\@makefntext\fi
   \@makefnendbox
   \ifx\FN@boxtype\vbox\@finalstrut\strutbox \else \unskip \fi
   \FN@colorstackfinish
@@ -525,9 +554,12 @@
   \wd\z@\dimen@
   \dp\z@\FN@masterslot sp\relax
   \MFL@insert\FN@masterinsert{\nointerlineskip\box\z@}%
+  \ifdim\lastkern=\z@ \let\FN@next\@empty\else
+    \edef\FN@next{\kern\the\lastkern\relax}\unkern
+  \fi
   \marks\FN@slave{\number\FN@id}%
-  \MFL@endminipage
-  \FN@colorstackegroup
+  \expandafter\FN@enddivert\expandafter\FN@colorstackegroup
+  \FN@next
 }
 \dimen\footins\maxdimen
 \gdef\FN@nestlist{}
@@ -542,7 +574,7 @@
   \ifcase
     \ifvoid\z@\m@ne\fi \FN@config\z@
     \ifnum\dp\z@=\count@\else \FN@freeslot{\number\dp\z@}\fi
-    \FN@retaindelayed
+    \expandafter\FN@retaindelayed
   \or
     {\FN@retaindelayed \nointerlineskip \box\z@}%
   \else \unpenalty \setbox\z@\lastbox
@@ -592,8 +624,9 @@
 
 \expandafter\expandafter\expandafter\let\FN@cache\FN@savebox=\@cclv
 
-\expandafter\def\csname FN@ht\number\FN@savebox\endcsname{\topskip}%
+\expandafter\def\csname FN@ht\number\FN@savebox\endcsname{\z@skip}%
 \expandafter\def\csname FN@dp\number\FN@savebox\endcsname{\maxdepth}
+\expandafter\def\csname FN@wd\number\FN@savebox\endcsname{\columnwidth}
 
 \def\FN@list{\MFL@list\@elt{}\footins}
 
@@ -654,7 +687,8 @@
 \def\FN@insertmarks{%
   {\setbox\z@\copy\@cclv
     \splittopskip-\maxdimen\relax
-    \vbadness=\maxdimen
+    \vbadness=\@M
+    \vfuzz=\maxdimen
     \loop
     \ifvoid\z@\else
       {\let\@elt\FN@pseudomarks
@@ -666,9 +700,16 @@
       {\setbox\z@\vsplit\z@ to\maxdimen}%
       \next
     \repeat}}
+\def\FootnoteMinimum{1sp}
 \def\FootnoteMainMinimum{0pt}
+\expandafter\def\csname\string\FootnoteMinimum\number\FN@savebox
+\endcsname{\FootnoteMainMinimum}
 \savingvdiscards=\@ne
+\newcount\FN@outputflag
+\FN@outputflag=3158345
 \output{%
+  \let\@elt\relax
+  \ifvoid\@cclv \PackageError{bigfoot}{Empty box 255 in \output}\fi
   \ifnum\outputpenalty=-13750
     \ifnum\insertpenalties>\z@
       \PackageError{bigfoot}{Too much insertion material}{%
@@ -676,7 +717,7 @@
         gather all floating insertions in a single pass.^^J%
         Complain to the author if you consider this a bug}%
     \fi
-    \global\advance\FN@outervsize\dimexpr\ht\@cclv-\vsize\relax
+    \global\advance\FN@outervsize\dimexpr\ht\@cclv-\vsize
     \global\setbox\@cclv\box\voidb@x
   \else
   \edef\FN@outputpenalty{\number\outputpenalty}%
@@ -684,21 +725,16 @@
     \ifvoid\@holdpg
       \FN@sweeptopmarks
     \fi
-    \ifvoid\@cclv
-      \global\FN@outervsize\z@
-    \else
-      \global\FN@outervsize\ht\@cclv
-      \global\setbox\@cclv\vbox{\unvbox\@cclv\boxmaxdepth\maxdepth}%
-      \global\advance\FN@outervsize-\ht\@cclv\relax
-    \fi
+    \FN@nest@iterate{\FN@insertouterspace\global\FN@outervsize
+      \dimexpr\z@}%
+    \global\advance\FN@outervsize\ht\@cclv
+    \global\setbox\@cclv\vbox{\unvbox\@cclv\boxmaxdepth\maxdepth}%
     \global\let\FN@vsadjustlist\@empty
     \FN@normaloutput
   \else
-    \ifvbox\@cclv
-      \dimen@\ht\@cclv
-      \global\setbox\@cclv\vbox{\unvbox\@cclv\boxmaxdepth\maxdepth}%
-      \global\advance\FN@outervsize\dimexpr\dimen@-\ht\@cclv\relax
-    \fi
+    \FN@nest@iterate{\FN@insertouterspace\global\advance\FN@outervsize
+      \dimexpr\ht\@cclv}%
+    \global\setbox\@cclv\vbox{\unvbox\@cclv\boxmaxdepth\maxdepth}%
     \FN@nest@iterate\FN@maybeinvalidatecache
     \vskip\z@skip
     \unvbox\FN@savebox
@@ -714,36 +750,46 @@
       \ifnum\FN@outputpenalty=-13751 \@ne\fi \tw@
     \or
       \FN@vsadjustlist
-      \global\setbox\@cclv\vbox{\pagediscards}%
       \global\setbox\@cclv\lastbox
       \unskip
       \ifnum\FN@outputpenalty=-13749
         \FN@normaloutput
       \else
         \the\FN@output
+        \@pageht-\vsize
+        \let\@currbox\footins
+        \@reinserts
+        \global\vsize-\@pageht
       \fi
     \else
       \dimen@\topskip
       \FN@vsadjustlist
       \setbox\z@\lastbox
       \unskip
-      \global\setbox\@cclv\vbox{\unvbox\z@
-        \ifnum\outputpenalty<\@M \penalty\outputpenalty\fi
-        \pagediscards
-        \ifvbox\@cclv
-          \global\setbox\@cclv\vbox{\break\unvbox\@cclv}%
-          {\splittopskip-\maxdimen \setbox\z@\vsplit\@cclv to\z@}%
-          \unvbox\@cclv
+      \global\setbox\@cclv\vbox{%
+        \unvbox\z@
+        \global\setbox\@cclv\vbox{\break\unvbox\@cclv}%
+        {\splittopskip-\maxdimen \setbox\z@\vsplit\@cclv to\z@}
+        \ifnum\outputpenalty=\@M
+          \setbox\z@\vbox{\pagediscards
+            \FN@cleanpagepenalty}%
+          \unvbox\z@
+        \else
+          \penalty\outputpenalty
+          \pagediscards
         \fi
+        \unvbox\@cclv
         \boxmaxdepth\maxdepth}%
       \global\outputpenalty\FN@outputpenalty\relax
       \ifdim\dimen@>\z@
         \hrule\@height\z@\@depth\z@
         \unvcopy\FN@topmarkbox
         \penalty-13750
+        \penalty\FN@outputflag
         \hrule\@height\z@\@depth\z@
         \FN@insertmarks
         \penalty-13749
+        \penalty\FN@outputflag
         \FN@prepareoutput
         \global\topskip-\maxdimen
         \global\vsize0.5\maxdimen
@@ -755,13 +801,13 @@
   \fi
   \fi}
 \def\FN@normaloutput{%
-  \FN@nest@iterate{\FN@insertouterspace\global\FN@vsize\dimexpr\z@}%
+  \global\FN@vsize\FN@outervsize
+  \global\advance\FN@vsize-\ht\@cclv\relax\relax
   \FN@nest@iterate\FN@sortinsert
   \FN@nest@iterate\FN@clearcache
-  \xdef\FN@config{\noexpand\@elt{\number0\botmarks\FN@slave}%
+  \xdef\FN@config{\@elt{\number0\botmarks\FN@slave}%
     {\number\maxdimen}}%
   \FN@nest@iterate\FN@reconfig
-  \global\advance\FN@vsize\FN@outervsize\relax
   \ifcase
     \ifnum\insertpenalties>\z@ \@ne\fi
     \ifnum\outputpenalty>-\@M
@@ -770,16 +816,20 @@
     \fi
     \ifdim\FN@vsize<\glueshrink\FN@vsize \thr@@ \fi
     \ifx\FN@vsadjustlist\@empty \else \thr@@\fi\z@
-    \ifvbox\@cclv
-      {\vbadness\maxdimen
-        \global\setbox\@cclv\vbox
-          spread\FN@vsize{\unvbox\@cclv\boxmaxdepth\maxdepth}}%
-    \fi
+    {\vbadness\@M
+      \vfuzz\maxdimen
+      \global\setbox\@cclv\vbox
+      spread\FN@vsize{\unvbox\@cclv\boxmaxdepth\maxdepth}}%
     \the\FN@output
+    \let\@currbox\footins
+    \@pageht-\vsize
+    \@reinserts
+    \global\vsize-\@pageht
     \FN@nest@iterate\FN@clearcache
   \or
     \FN@restartoutput
     \penalty -13749
+    \penalty \FN@outputflag
   \or
     \dimen@=\dimexpr\FN@vsize-\glueshrink\FN@vsize\relax
     \FN@prepareoutput
@@ -790,12 +840,11 @@
   \else
     \edef\FN@masterid{\number\maxdimen}%
     \def\FN@masterslot{-1}%
-    \global\setbox\@cclv\vbox{%
-      \box\@cclv}%
+    \global\setbox\@cclv\vbox{\box\@cclv}%
     \xdef\FN@config{\noexpand\@elt{\number0\botmarks\FN@slave}%
       {\number\maxdimen}}%
     \global\setbox\FN@savebox\vbox{}%
-    \gdef\FN@badness{0}%
+    \gdef\FN@penalties{0}%
     \edef\FN@defaultpenalty{\ifnum\outputpenalty<\@M
         \number\outputpenalty
       \else
@@ -804,51 +853,55 @@
     \@elt{}\FN@savebox\FN@nestlist\FN@mainsplitreturn
     \let\@elt\relax
     \global\setbox\FN@savebox\box\voidb@x
-    \count@\vbadness
-    \vbadness\maxdimen
-    \global\setbox\@cclv\vbox spread\FN@vsize\bgroup
-      \unvbox\@cclv
-      \ifnum\lastpenalty>\z@
-        \unpenalty
-        \global\setbox\FN@tempbox\lastbox
-      \else
-        \global\setbox\FN@tempbox\box\voidb@x
-      \fi
-      \setbox\z@\lastbox
-      \ifvoid\z@
-        \ifvbox\FN@tempbox
-          \ifnum\outputpenalty<\@M
-            \global\setbox\FN@tempbox{\unvbox\FN@tempbox
-              \penalty\outputpenalty}%
-          \fi
-          \global\outputpenalty=\@M
+    {%
+      \vbadness\@M
+      \vfuzz\maxdimen
+      \global\setbox\@cclv\vbox spread\FN@vsize{%
+        \unvbox\@cclv
+        \ifnum\lastpenalty>\z@
+          \unpenalty
+          \global\setbox\FN@tempbox\lastbox
+        \else
+          \global\setbox\FN@tempbox\box\voidb@x
         \fi
-        \egroup \global\setbox\@cclv\box\voidb@x
-      \else
-        \MFL@removevboxes
-        \unvbox\z@
-        \let\FN@defaultpenalty\@M
-        \FN@getbreakpenalty
         \setbox\z@\lastbox
-        \ifcase
-          \ifvbox\FN@tempbox \@ne\fi
-          \ifvoid\z@ \else \@ne\fi \z@
-        \or
-          \global\setbox\FN@tempbox\vbox{\unvbox\z@
-            \unvbox\FN@tempbox
+        \ifvoid\z@
+          \ifvbox\FN@tempbox
             \ifnum\outputpenalty<\@M
-              \penalty\outputpenalty
-            \fi}%
-          \global\outputpenalty\FN@breakpenalty
+              \global\setbox\FN@tempbox{\unvbox\FN@tempbox
+                \penalty\outputpenalty}%
+            \fi
+            \global\outputpenalty=\@M
+          \fi
+        \else
+          \MFL@removevboxes
+          \unvbox\z@
+          \edef\FN@defaultpenalty{\number\@M}%
+          \FN@getbreakpenalty
+          \setbox\z@\lastbox
+          \global\setbox\FN@tempbox\vbox\bgroup\unvbox\z@
+            \unvbox\FN@tempbox
+            \ifnum\lastnodetype<\z@
+            \egroup\global\setbox\FN@tempbox\box\voidb@x
+            \else
+              \ifnum\outputpenalty<\@M
+                \penalty\outputpenalty
+              \fi
+            \egroup
+            \global\outputpenalty\FN@breakpenalty
+          \fi
         \fi
-        \boxmaxdepth\maxdepth\egroup
-      \fi
-    \vbadness\count@
+        \boxmaxdepth\maxdepth}%
+    }%
     \setbox\z@\box\FN@tempbox
     \let\@elt\relax
     \dimen@=\dimexpr\FN@vsize-\glueshrink\FN@vsize\relax
     \ifcase
-      \ifvoid\z@ \else\thr@@\fi
+      \ifvoid\z@ \ifnum\outputpenalty>-\@M
+                    \ifdim\dimen@<\z@ \else \@ne \fi
+                 \fi
+      \else \thr@@
+      \fi
       \ifdim\ht\@cclv<\normalbaselineskip \@ne\fi
       \ifdim\dimen@<\normalbaselineskip \tw@\fi \@ne
     \or
@@ -859,18 +912,28 @@
       \global\advance\FN@outervsize-\vsize
       \global\deadcycles\z@
     \or
-    \setbox\tw@\vbox{%
-      \the\FN@output
-    }%
-    \unvbox\tw@
-    \unvbox\z@
-    \FN@nest@iterate\FN@clearcache
-  \or
+      \setbox\tw@\vbox{%
+        \the\FN@output
+      }%
+      \unvbox\tw@
+      \unvbox\z@
+      \let\@currbox\footins
+      \@pageht-\vsize
+      \@reinserts
+      \global\vsize-\@pageht
+      \FN@nest@iterate\FN@clearcache
+    \or
       \FN@restartoutput
       \penalty -13751
+      \penalty\FN@outputflag
       \unvbox\z@
+      \ifnum\outputpenalty>\@M
+      \else \penalty
+            \ifnum\outputpenalty=\@M \z@ \else\outputpenalty\fi
+      \fi
+    \fi
   \fi
-  \fi}
+}
 \def\FN@prepareoutput{%
   {\let\@elt\FN@recordinsertparam
    \xdef\FN@vsadjustlist{%
@@ -888,6 +951,7 @@
   \hrule\@height\z@\@depth\z@
   \unvcopy\FN@topmarkbox
   \penalty -13750
+  \penalty\FN@outputflag
   \hrule\@height\z@\@depth\z@
   \FN@insertmarks
   \FN@prepareoutput
@@ -900,11 +964,11 @@
     \nointerlineskip\copy\z@
     \setbox\z@
       \vbox{\unvbox\z@
-        \count@\FN@defaultpenalty\relax
+        \count@\@M
         \FN@getbreakpenaltyii
         \xdef\FN@tempinfo{\edef\noexpand\FN@breakpenalty{%
-            \number\ifnum\count@>-\@M \count@
-                   \else -\@M \fi}}}}%
+            \number\ifnum\count@=\@M \FN@defaultpenalty \else \count@\fi
+          }}}}%
   \FN@tempinfo}
 
 \def\FN@getbreakpenaltyii{%
@@ -923,12 +987,39 @@
     \count@\lastpenalty
     \unpenalty \expandafter\FN@getbreakpenaltyii
   \fi}
+\def\FN@cleanpagepenalty{%
+  \ifcase
+    \ifnum\lastnodetype<\z@ \m@ne\fi
+    \ifnum\lastnodetype<11 \@ne\fi
+    \ifnum\lastnodetype>13 \@ne\fi
+    \numexpr\lastnodetype-9\relax
+  \or
+    \PackageError{bigfoot}{Illegal node type}{This can't happen}%
+  \or
+    \skip@=\lastskip \unskip
+    \expandafter \FN@cleanpagepenalty \expandafter\vskip\the
+    \expandafter\skip@
+  \or
+    \dimen@=\lastkern \unkern
+    \expandafter \FN@cleanpagepenalty \expandafter\kern\the
+    \expandafter\dimen@
+  \or
+    \count@\lastpenalty \unpenalty
+    \ifnum\count@=\FN@outputflag
+      \unpenalty\expandafter\expandafter\expandafter\FN@cleanpagepenalty
+    \else
+      \expandafter\FN@cleanpagepenalty\expandafter
+      \penalty\the\expandafter\expandafter\expandafter\count@
+    \fi
+  \fi
+  \relax}
 \def\FN@mainsplitreturn{}
 \newdimen\FN@myvsize
 \newcount\bigfoottolerance
 \bigfoottolerance=100
 \def\FN@getbadness#1{%
-  {\hfuzz\maxdimen\hbadness\maxdimen\setbox\z@\hbox to\z@{\hskip-#1}}}
+  {\hfuzz\maxdimen\hbadness\@M\setbox\z@\hbox to\z@{\hskip-#1}}}
+\providecommand\footnotecarryratio{2}
 \def\FN@newlevel#1#2#3\FN@mainsplitreturn{%
   \count@\FN@cache#2%
   \ifvoid\count@
@@ -937,23 +1028,33 @@
     {\def\FN@currentinsertion{#2}%
      \def\FN@currentrecursion{#3}%
      \let\FN@entryconfig\FN@config
-     \let\FN@entrybadness\FN@badness
+     \let\FN@entrypenalties\FN@penalties
      \splittopskip\csname FN@ht\number#2\endcsname\relax
      \splitmaxdepth\csname FN@dp\number#2\endcsname\relax
-     \vbadness=\maxdimen
+     \hsize\csname FN@wd\number#2\endcsname\relax
+     \vbadness=\@M
      \vfuzz\maxdimen
      \let\@elt\relax
      \expandafter\FN@newleveli\expandafter}%
   \fi}
 \def\FN@newleveli{%
-    \dimen@\dimexpr\ht\count@+\dp\count@\relax
+    \dimen@\dimexpr\ht\count@
+      \ifnum\FN@currentinsertion=\FN@savebox
+        +\maxdepth
+      \else
+        +\dp\count@
+      \fi\relax
     \global\advance\FN@vsize\dimexpr \dimen@
       *\count\FN@currentinsertion/\@m\relax\relax
     \global\setbox\count@\vbox\bgroup\unvbox\count@
       \ifnum\lastpenalty=\z@
         \setbox\tw@\box\voidb@x
         \setbox\z@\lastbox
-        \FN@myvsize=\dimexpr\dimen@-\ht\z@-\dp\z@\relax
+        \FN@myvsize=\ifnum\lastnodetype<\z@
+          \z@
+        \else
+          \dimexpr\dimen@-\ht\z@-\dp\z@\relax
+        \fi
       \else
         \unpenalty
         \setbox\tw@\lastbox
@@ -967,13 +1068,14 @@
         \ht\z@=\dimexpr\ht\z@+\dp\z@-\dimen@\relax
         \dp\z@\dimen@
       \fi
-      \edef\FN@bestebadness{\number\maxdimen}%
+      \edef\FN@bestcost{\number\maxdimen}%
+      \let\FN@bestbadness\FN@bestcost
       \let\FN@bestconfig\@undefined
-      \let\FN@bestvsize\z@skip
+      \def\FN@bestvsize{-\maxdimen}%
       \let\FN@splitcolors\@empty
       \ifnum\FN@currentinsertion=\FN@savebox
       \else
-        \def\FN@defaultpenalty{-\@M}%
+        \edef\FN@defaultpenalty{\number-\@M}%
         \edef\FN@masterslot{\number\dp\z@}%
         \edef\FN@masterid{\FN@slotget\FN@masterslot}%
       \fi
@@ -983,17 +1085,19 @@
         \setbox\z@\vbox{\vskip-\glueexpr(\FN@vsize-\dimexpr\FN@vsize
           \relax\@minus\glueshrink\FN@vsize)%
           *\@m/\count\FN@currentinsertion
+          \penalty\z@
           \unvbox\z@
           \ifnum\FN@defaultpenalty>-\@M
-            \penalty\FN@defaultpenalty\nointerlineskip
+            \penalty\FN@defaultpenalty\relax\nointerlineskip
             \vbox to\maxdimen{}%
           \fi}%
         \setbox\tw@\vsplit\z@ to%
           \dimexpr\FN@vsize*\@m/\count\FN@currentinsertion
-          -\FN@myvsize
+          -\FN@myvsize-\splitmaxdepth
         \relax
         \ifnum\FN@defaultpenalty>-\@M
           \setbox\z@\vbox\bgroup\unvbox\z@\setbox\z@\lastbox
+            \unskip
             \unpenalty
             \ifnum\lastnodetype<\z@
               \egroup \setbox\z@\box\voidb@x
@@ -1009,22 +1113,6 @@
         \ifnum\FN@currentinsertion=\FN@savebox
           \edef\FN@slaveid{\splitbotmarks\FN@slave}%
           \FN@contribute@tw@
-          \ifdim\FootnoteMainMinimum>\FN@myvsize
-            \loop
-              \setbox\tw@\vsplit\z@ to\z@
-              \edef\FN@slaveid{\splitbotmarks\FN@slave}%
-              \FN@contribute@tw@
-            \ifcase\ifdim\FootnoteMainMinimum>\FN@myvsize
-              \ifvoid\z@
-                \@ne
-              \else
-                \tw@
-              \fi\fi \z@
-            \or
-              \PackageWarning{bigfoot}{too little main material}%
-            \else
-            \repeat
-          \fi
         \else
           \ifnum0\splitbotmarks\FN@master=\FN@masterslot \else
             \loop
@@ -1069,12 +1157,13 @@
   \fi
   \FN@currentrecursion
   \let\@elt\relax
-  \xdef\FN@badness{\number\FN@entrybadness}%
+  \xdef\FN@penalties{\number\FN@entrypenalties}%
   \FN@checkcurrent
   \ifnum
-    \ifdim\skip@>\z@ \FN@ebadness \else \FN@badness \fi >\FN@bestebadness
+    \ifdim\skip@>\z@ \FN@ebadness \else \FN@penalties \fi
+    >\FN@bestcost\relax
   \else
-    \xdef\FN@badness{\number\FN@entrybadness}%
+    \xdef\FN@penalties{\number\FN@entrypenalties}%
     \FN@vsizerecurse
     \FN@checkcurrent
   \fi
@@ -1093,20 +1182,52 @@
     \expandafter \FN@splitfurther
   \fi}
 \def\FN@checkcurrent{%
+  \FN@getbreakpenalty
+  \ifnum\FN@breakpenalty<-\@M
+    \edef\FN@breakpenalty{\number-\@M}%
+  \fi
+  \ifnum\FN@currentinsertion=\FN@savebox
+  \else
+    \ifdim\FN@specific\FN@currentinsertion\footnotecarryratio\p@>\z@
+      \skip@
+      \ifdim\FN@specific\FN@currentinsertion\footnotecarryratio\p@>\p@
+          \dimexpr\ht\z@+\dp\z@\relax
+          \@plus-\dimexpr((\FN@myvsize+\ht\z@+\dp\z@)
+                          *\p@/\dimexpr
+                          \FN@specific\FN@currentinsertion
+                          \footnotecarryratio\p@)\relax
+      \else
+          \FN@specific\FN@currentinsertion
+          \footnotecarryratio
+          \dimexpr\ht\z@+\dp\z@\relax
+          \@plus-\dimexpr\FN@myvsize+\ht\z@+\dp\z@\relax
+      \fi
+      \relax
+      \FN@getbadness\skip@
+      \xdef\FN@penalties{\number\numexpr\FN@penalties+\badness}%
+    \fi
+  \fi
   \skip@\glueexpr\FN@vsize-\FN@myvsize
    *\count\FN@currentinsertion/\@m\relax
-  \FN@getbreakpenalty
   \FN@getbadness\skip@
-  \xdef\FN@badness{\number\numexpr\FN@badness+%
+  \xdef\FN@penalties{\number\numexpr\FN@penalties+%
     \FN@breakpenalty+\@M}%
   \ifnum\badness>\@M
     \edef\FN@ebadness{\number\numexpr\maxdimen-\@ne}%
   \else
     \ifnum\badness=\@M
-      \edef\FN@ebadness{\number\numexpr\maxdimen-\tw@}%
+      \ifdim\skip@<\vsize
+        \edef\FN@ebadness{\number\numexpr\maxdimen-\tw@}%
+      \else
+        \edef\FN@ebadness{\number\numexpr\maxdimen}%
+      \fi
     \else
       \edef\FN@ebadness{\number\numexpr
-        \FN@badness+\badness}%
+        \FN@penalties+\badness
+        \ifdim\FN@specific\FN@currentinsertion\FootnoteMinimum>\FN@myvsize
+          1000000
+        \fi
+        }%
     \fi
   \fi
   \dimen@\glueexpr\FN@bestvsize\relax
@@ -1117,10 +1238,10 @@
          \@ne
       \fi
     \fi
-    \ifnum\FN@bestebadness>\FN@ebadness \@ne\fi
-    \ifnum\FN@bestebadness<\FN@ebadness \tw@\fi
+    \ifnum\FN@bestcost>\FN@ebadness \@ne\fi
+    \ifnum\FN@bestcost<\FN@ebadness \tw@\fi
     \ifdim\skip@<\z@
-      \ifdim\dimen@<\skip@ \@ne \else \tw@\fi
+      \ifdim\dimen@<\skip@ \@ne \fi \tw@
     \fi
     \ifdim\dimen@>\skip@ \@ne\fi \tw@}
 \def\FN@mayberecordbest{%
@@ -1128,8 +1249,8 @@
     \FN@checkforbest
   \or
     \xdef\FN@tempinfo{\def\noexpand\FN@bestvsize{\the\skip@}%
-      \def\noexpand\FN@bestebadness{\FN@ebadness}%
-      \def\noexpand\FN@bestbadness{\number\FN@badness}%
+      \def\noexpand\FN@bestcost{\FN@ebadness}%
+      \def\noexpand\FN@bestbadness{\number\FN@penalties}%
       \def\noexpand\FN@bestconfig{\FN@config}%
       \def\noexpand\FN@bestslaveid{\FN@slaveid}%
       \def\noexpand\FN@bestsplitcolors{\FN@splitcolors}%
@@ -1144,9 +1265,7 @@
       \copy\z@\break\nointerlineskip
       \copy\FN@tempbox\penalty\FN@tempbox
       \let\@elt\FN@copycachebox
-      \FN@currentrecursion
-      \xdef\FN@tempinfo{\FN@myvsize=\the\FN@myvsize\relax}}%
-    \FN@tempinfo
+      \FN@currentrecursion}%
     \setbox\z@
     \vbox\bgroup
       \unvbox\z@
@@ -1157,8 +1276,8 @@
   \ifcase\FN@checkforbest
   \or
     \xdef\FN@tempinfo{\def\noexpand\FN@bestvsize{\the\skip@}%
-      \def\noexpand\FN@bestebadness{\FN@ebadness}%
-      \def\noexpand\FN@bestbadness{\number\FN@badness}%
+      \def\noexpand\FN@bestcost{\FN@ebadness}%
+      \def\noexpand\FN@bestbadness{\number\FN@penalties}%
       \def\noexpand\FN@bestconfig{\FN@config}%
       \def\noexpand\FN@bestslaveid{\FN@slaveid}%
       \def\noexpand\FN@bestsplitcolors{\FN@splitcolors}%
@@ -1173,7 +1292,7 @@
   \or
     \global\let\FN@config\FN@bestconfig
     \global\FN@vsize\FN@bestvsize
-    \global\let\FN@badness\FN@bestbadness
+    \global\let\FN@penalties\FN@bestbadness
     \egroup
     \setbox\z@\vbox{\unvbox\tw@ \FN@restoreboxes}%
     \let\FN@splitcolors\FN@bestsplitcolors
@@ -1184,7 +1303,7 @@
   \ifnum\FN@currentinsertion=\FN@savebox
   \else
     \setbox\z@\vbox{%
-      \dimen@\dp\z@
+      \prevdepth\dp\z@
       \unvbox\z@
       \ifvoid\FN@tempbox
       \else
@@ -1192,16 +1311,18 @@
           \marks\FN@master{\FN@masterslot}%
           \marks\FN@slave{\FN@slaveid}%
           \FN@coloraftersplit\FN@splitcolors
+          \FN@specific\FN@currentinsertion\FN@afterbreak
           \nobreak
           \unvbox\FN@tempbox}%
+        \FN@specific\FN@currentinsertion\FN@beforebreak
         \ht\FN@tempbox
         \dimexpr\ht\FN@tempbox+\dp\FN@tempbox-\FN@masterslot sp\relax
         \dp\FN@tempbox\FN@masterslot sp\relax
         \wd\FN@tempbox\maxdimen
       \fi
-      \ifdim\dimen@<\splitmaxdepth
-        \hrule\@height-\dimen@ \@width\z@
-         \@depth \splitmaxdepth \relax \fi}%
+    \ifdim\prevdepth<\splitmaxdepth
+       \hrule\@height-\prevdepth \@width\z@
+             \@depth \splitmaxdepth \relax \fi}%
     \ht\z@=\dimexpr\ht\z@+\dp\z@-\FN@masterslot sp\relax
     \dp\z@=\FN@masterslot sp
   \fi
@@ -1300,16 +1421,13 @@
   \csname MFL@start#1\endcsname{#2}\fi#3}
 \@onlypreamble\FN@maybestart
 \AtBeginDocument{\@ifundefined{footinsdefault}%
-  {\DeclareNewFootnote[plain]{default}%
+  {\newfootnote[plain]{default}%
     {\let\@elt\FN@maybestart
-      \MFL@list\relax}}{}%
-  \let\c@footnote\c@footnotedefault
-  \let\thefootnote\thefootnotedefault
-  \def\thefootnotedefault{\thefootnote}%
+      \MFL@list\relax}
+  }{}%
+  \def\@footnotetext{\Footnotetextdefault{}}
+  \def\p@footnotedefault{\p@footnote}
 }
-\def\footnote{\footnotedefault}
-\def\footnotemark{\footnotemarkdefault}
-\def\footnotetext{\footnotetextdefault}
 \endinput
 %%
 %% End of file `bigfoot.sty'.
-- 
cgit v1.2.3

