%\iffalse meta-comment, etc.
%% This is footnote.dtx, and it's -*-LaTeX-*- text
%
% We use the same body for the \cs{ProvidesFile} as for the
% \cs{ProvidesPackage} command.
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1995/06/01]
%<*dtx>
\ProvidesFile{footnote.dtx}
%</dtx>
%<package>\ProvidesPackage{footnote}
        [1996/08/04 v3.2a
%<package>     a hotchpotch of footnote facilites%
%<*dtx>
               footnote source file%
%</dtx>
                   ]
%    \end{macrocode}
%
% Code to enable LaTeX processing of the file without the intervention
% of a driver file.
%    \begin{macrocode}
%<*driver>
\setcounter{errorcontextlines}{999}
\documentclass{ltxdoc}
\GetFileInfo{moreverb.dtx}
    \EnableCrossrefs
%   \DisableCrossrefs
%   \CodelineIndex
% lose all those silly index entries
\DoNotIndex{\def,\the,\toks@,\bgroup,\egroup,\begingroup,\endgroup}
\DoNotIndex{\expandafter,\if,\ifx,\else,\fi,\fi,\futuredef,\futurelet}
\DoNotIndex{\aftergroup,\gdef,\iffalse,\ifcat,\ifnum,\fi,\fi,\fi,\let}
\DoNotIndex{\long,\m@ne,\next,\next@,\noexpand,\outer,\relax,\show}
\DoNotIndex{\space,\string,\toksdef,\tw@,\@ne,\z@}
\setcounter{StandardModuleDepth}{1}
\begin{document}
\DocInput{footnote.dtx}
\end{document}
%</driver>
%    \end{macrocode}
% \fi
%
% \CheckSum{461}
% \StopEventually{}
%
% \title{\texttt{footnote} ---\\
%        a portmanteau package\\
%        for customising footnotes in \LaTeXe\thanks{This file has
%          version number \fileversion, last revised \filedate}}
% \author{Robin Fairbairns\thanks{University of Cambridge Computer
%     Laboratory, Pembroke St., Cambridge, CB2 3QG, UK
%     (\texttt{rf@cl.cam.ac.uk})}}
% \maketitle
%
% \section{User interface}
%
% The |footnote| package provides four different customisations of the
% way foonotes are represented in \LaTeXe{} documents (the sources of
% the code in this package are various, but all of it has been
% massaged by the author; where the code comes from elsewhere, there
% are attributions given below, somewhere or other).
%
% The interface to the
% package's options is very simple~--- each one is presented as an
% option in the |\usepackage| command.  For example, to use a useful
% and consistent set, the author invokes the package with the
% command |\usepackage[perpage,para,symbol]{footnote}|.
%
% \subsection{Option \texttt{perpage}}
%
% This option resets footnote numbering for each page of the document.
% It is derived from |pagefoots.sty| by Brian T. Schellenberger
% (|bts@unx.sas.com|), but I've done quite a lot of
% \LaTeX(2\ensuremath{_{\textstyle\varepsilon}})-isation of the code.
% It needs two passes to do this correctly (though it comes as close
% as possible on the first pass).  You generally have to make two
% passes with \LaTeX{} anyway, to get the cross-references right, so
% an additional pass for this purpose shouldn't cause any additional
% problem.  The option includes code to report that `Label(s) may have
% changed', which will help the poor user to realise that another run
% is in order\dots
%
% \subsection{Option \texttt{para}}
%
% This option (derived from code by Dominik Wujastyk and Chris Rowley)
% causes footnotes to be typeset as a single paragraph at the bottom
% of the page on which they occur.  In the case that there is only one
% footnote on the page, no effect will be observed.  However, if there
% are several footnotes on the page, they will be run together in the
% page foot, each introduced by its footnote mark.  This arrangement
% can save considerable space, but one should bear in mind Jill
% Knuth's admonition on page 125 of the \TeX book: \textsl{Don't use
% footnotes in your books, Don}.  The original demand for the option
% came from the needs of those preparing critical editions; such
% documents typically have large numbers of small footnotes, which
% look ridiculous if each is typeset in a paragraph of its own.  One
% imagines that even Jill Knuth would accept such usage\dots
%
% \subsection{Option \texttt{symbol}}
%
% This option causes footnotes within the document to be `numbered'
% with symbols rather than numbers; since the symbol set (derived from
% command |\fnsymbol|) is somewhat restricted (it contains only 9
% distinct symbols, and does not wrap round), this option only makes
% sense in documents which have very few footnotes in total, or which
% invoke option \texttt{perpage}.
%
% \subsection{Option \texttt{bottom}}
%
% This option forces footnotes to the bottom of the page; this is only
% noticeably useful in case that \cs{raggedbottom} is in effect, when
% \LaTeX{} would normally set the footnotes a mere
% \cs{skip}\cs{footins} distant from the bottom of the text.
%
% \subsection{Option \texttt{marginal}}
%
% This option adjusts the position of footnote mark relative to the
% start of the line in which they appear (the the option is
% incompatible with option \texttt{para}, for obvious reasons).
%
% When this option is in effect, the footnote is set
% \cs{footnotemargin} relative to the left margin of the page; the
% default setting for \cs{footnotemargin} is -0.8em, which means that
% the footnote mark will be set jutting 0.8em into the margin.  If
% \cs{footnotemargin} is a positive length, the footnote mark will be
% set with its right edge \cs{footnotemargin} from the margin.  (In
% the absence of the option, \cs{footnotemargin} is set to 1.8em.)
%
% \subsection{Option \texttt{flushmargin}}
%
% This option is as option marginal, but sets the footnote marker
% flush with, but just inside the margin from, the text of the
% footnote.
%
% \subsection{Option \texttt{norule}}
%
% This option suppresses the `normal' footnote rule, and advances
% \cs{skip}\cs{footins} a bit to compensate
%
% \section{Code: Preliminaries}
%
% Well~--- here we go: let's make the package file:
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% Now declare what environment we need:
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
%    \end{macrocode}
%
% Sometimes, we need a little verbosity for debugging.  This can be
% achieved by un-commenting this line:
%
%    \begin{macrocode}
%\setcounter{errorcontextlines}{999}
%    \end{macrocode}
%
% \section{The package's `initial code'}
%
% This conditional used to be declared inside |pagefoots.sty| (I don't
% much like it, but\ldots); I've renamed it from |\ifisdigit| and
% moved it `outer' (damn that mechanism).
%    \begin{macrocode}
%\newif\if@@digit
%    \end{macrocode}
%
% This command is defined differently in Matt Swift's \textsf{newclude}
% package (yet to hit the streets), and we also define it here in a
% compatible way
%
%    \begin{macrocode}
\providecommand\protected@writeaux{%
  \protected@write\@auxout
}
%    \end{macrocode}
%
% The counter here is used to detect whether any hacking needs doing
% to \LaTeX's output routine.  After processing options, the value of
% the counter is \ensuremath{<0} if the |bottom| option has been
% exercised, and \emph{odd} if |para| option has been exercised.
%    \begin{macrocode}
\def\FN@outputflag{0}
%    \end{macrocode}
%
% The same job for whether we are to patch \cs{footnote} is done with
% this counter.  Its value is 9 if the |perpage| option has been
% exercised (the curious value being chosen such that if either of
% \cs{FN@outputflag} or \cs{PP@footflag} has been touched, their sum
% is non-zero.
%    \begin{macrocode}
\def\PP@footflag{0}
%    \end{macrocode}
%
% Now we define a jollly little macro to advance a macro count (|#1|)
% by a given amount (|#2|).
%    \begin{macrocode}
\def\@advance@macro#1#2{\expandafter\@tempcnta#1\relax
                        \advance\@tempcnta#2\relax
                        \edef#1{\the\@tempcnta}}
%    \end{macrocode}
%
% Finally, we define the length used by the \texttt{marginal} option,
% and initialise it as if we've not had the option.
%    \begin{macrocode}
\newdimen\footnotemargin
\footnotemargin1.8em\relax
%    \end{macrocode}
%
% \section{The \texttt{symbol} option}
%
% This is a declaration that appears in the original \LaTeX{} book.
% Since it appeared in the old |pagefoots.sty| (presumably since it
% goes so naturally with the |perpage| option), I've added this
% trivial piece of customisation to the package.
%
%    \begin{macrocode}
\DeclareOption{symbol}{\renewcommand\thefootnote{\fnsymbol{footnote}}}
%    \end{macrocode}
%
% \section{The \texttt{para} option}
%
% The basis of the code for this option comes from \TeX{}book, p.398
% ff.~(``Dirty Tricks''), though it does (of course) avoid
% redefining |\\| which has some other (somewhat significant) uses in
% \LaTeX{}!  The user should be aware of
% Knuth's note on the limitations of this method of doing the job: the
% \TeX{} stack is used four times per footnote, and the stack is
% limited (see the \TeX{}book, p.300 ff.).  If you have very large
% numbers of footnotes (in the hundreds), and encounter the error
% ``|! TeX capacity exceeded, sorry (... save size ...)|'', you may
% need to break your text into smaller sections and compile the
% separately.  Fortunately (say the comments on the original
% |fnpara.sty|) this is very easy to do with \LaTeX{}, provided that
% you reset the footnote counter to make the joins seamless.
%
% First we define a means of hiding |\par| in a case where we need it
% within the declaration of the |para| option
%
%    \begin{macrocode}
\def\FN@unhbox@par#1{\unhbox#1\par}
%    \end{macrocode}
%
% We need some temporary boxes
%
%    \begin{macrocode}
\let\FN@tempboxa\@tempboxa
\newbox\FN@tempboxb
\newbox\FN@tempboxc
%    \end{macrocode}
%
% Define the |para| option
%    \begin{macrocode}
%\typeout{Declaring para}
\DeclareOption{para}{%
%    \end{macrocode}
%
% We will patch the source of \LaTeX{} for this; we don't do
% the job here~--- we simply set a flag for the postamble to do it
% using |patch.tex|
%
% Another direct crib from the \TeX{}book:
%
%    \begin{macrocode}
\newskip\footglue \footglue=1em plus.3em minus.3em
%    \end{macrocode}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The standard classes set the footnote mark flush with the text of
% the footnote, but that's not appropriate for paragraph footnotes, we
% find.
%
% There's not much point in patching this code from the original,
% since the only things it has in common with the original are the
% footnote mark and the footnote text (which last is the argument).
%
%    \begin{macrocode}
\long\def\@makefntext#1{\@makefnmark\nobreak\hskip.5em\relax#1}
%    \end{macrocode}
%
% We also need to patch the output routine's handling of footnotes.
% Since this isn't the only instance of this requirement in this
% package, we simply set a flag for it to be done later.
%
%    \begin{macrocode}
\@advance@macro\FN@outputflag1
%    \end{macrocode}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% We need to record a value for the baseline skip when in footnotes:
%
%    \begin{macrocode}
{\footnotesize \newdimen\footnotebaselineskip
  \global
  \footnotebaselineskip=\normalbaselineskip}
%    \end{macrocode}
%
% Now we derive a fudge factor from the baselineskip we've just
% established\footnote{We use \cs{strip@pt} which is defined for use
% in the \LaTeXe{} kernel, but not documented: this is a potential
% problem, but I don't imagine it will be, since the definition is
% obviously \emph{right}}:
% 
%    \begin{macrocode}
\@tempdima=\footnotebaselineskip \multiply\@tempdima by 1024
\divide \@tempdima by \columnwidth \multiply\@tempdima by 64
\xdef\fudgefactor{\strip@pt\@tempdima }
%\typeout{Done that - \string\fudgefactor is \fudgefactor}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\makefootnoteparagraph{\unvbox\footins \makehboxofhboxes
  \setbox\FN@tempboxa=\hbox{\unhbox\FN@tempboxa \removehboxes}
%    \end{macrocode}
%CCCC  ---now we are ready to set the paragraph:
%    \begin{macrocode}
    \hsize\columnwidth
    \@parboxrestore
    \baselineskip=\footnotebaselineskip
    \noindent
%    \end{macrocode}
%CCCC ---this is where the strut is needed:
%    \begin{macrocode}
  \rule{\z@}{\footnotesep}%
  \FN@unhbox@par{\FN@tempboxa}
}
\def\makehboxofhboxes{\setbox\FN@tempboxa=\hbox{}
  \loop\setbox\FN@tempboxb=\lastbox \ifhbox\FN@tempboxb
  \setbox\FN@tempboxa=\hbox{\box\FN@tempboxb\unhbox\FN@tempboxa}\repeat}
\def\removehboxes{\setbox\FN@tempboxa=\lastbox
  \ifhbox\FN@tempboxa{\removehboxes}\unhbox\FN@tempboxa \fi}
%
}
%    \end{macrocode}
%
% \section{The \texttt{perpage} option}
%
% A footnote-numbering modification from Brian T. Schellenberger.
% Brian's code is ``redistributable by anybody to anybody for any
% price'', subject to crediting his contribution (which I do herewith:
% a nice piece of stuff, Brian), and subject to reasonable conditions
% about distributing modified versions (which include sending a copy
% back to him).
% 
%    \begin{macrocode}
%\typeout{Declaring perpage}
\DeclareOption{perpage}{%
%    \end{macrocode}
%
% The footnote code itself.
%
% \cs{PP@footnote}: stuff for handling footnotes numbered per page.
%
%    \begin{macrocode}
\def \PP@footnote
  {%
%    \end{macrocode}
%
% Are we in a minipage?  If so, there's no issue, since they're all
% done and finished in themselves, and footnotes can't defer to a new
% page\dots
%
%    \begin{macrocode}
  \if@minipage\else
%    \end{macrocode}
%
% Make a \cs{newfoot@mark} for the next time
%
%    \begin{macrocode}
     \if@filesw
        \edef \@tempa
           {%
           \noexpand\protected@writeaux\relax
              {%
              \string\newfoot@mark{\thepage}%
                 {\the\c@footnote}{\noexpand\thepage}%
              }%
           }%
        \@tempa
     \fi
%    \end{macrocode}
%
% Now we look at the name that might have been created by a
% \cs{newfoot@mark} when the |.aux| file was scanned at begin
% document.
%
%    \begin{macrocode}
     \edef \@tempa {ft@\thepage-\the\c@footnote}%
     \expandafter\ifx\csname\@tempa\endcsname \relax
     \else
%    \end{macrocode}
%
% The name is defined: we need to replace the footnote number with
% what (should have) happened last time
%
%    \begin{macrocode}
        \begingroup
           \global\expandafter\c@footnote
               \csname\@tempa\endcsname\relax
           \xdef \@thefnmark {\thefootnote}%
        \endgroup
     \fi
%    \end{macrocode}
%
% Close the conditional (minipage) around the whole thing
%
%    \begin{macrocode}
  \fi
  }
%    \end{macrocode}
%
% Macros for use while reading the |.aux| file at \cs{begin}|{document}|:
%
% \cs{ft@page} is what page we might appear to be on; \cs{ft@foot} is
% the footnote number last used.
%
%    \begin{macrocode}
\def\ft@page{0}
\def\ft@foot{0}
%    \end{macrocode}
%
% \cs{newfoot@mark}s appear in the |.aux| file (unless this is the
% first time around); each one contains:
% \begin{itemize}
% \item nominal page where the typesetting seemed to be happening at
%   the time the \cs{footnote} was typeset, as by \cs{thepage},
%   \cs{immediate} at the time the footnote was encountered.
% \item nominal footnote number on that page.
% \item actual page it occurs on, as by \cs{thepage} deferred to
%   \cs{shipout} time.
% \end{itemize}
%
%    \begin{macrocode}
\def \newfoot@mark #1#2#3{%
%    \end{macrocode}
%
% We don't even try to play funny games if the actual page isn't a
% number:
%
%    \begin{macrocode}
  \@ifdigit{#3}{%
%    \end{macrocode}
%
% Well, it is a number: is it different from the page number we might
% expect?  If \cs{ft@page} has got ahead of itself, reset it to zero;
% if the actual page has gone ahead of \cs{ft@page}, we set
% \cs{ft@page} from it and reset \cs{ft@foot}
%
%    \begin{macrocode}
    \expandafter\ifnum \ft@page > #3\relax
      \def\ft@page{0}%
    \else
      \expandafter\ifnum \ft@page < #3\relax
        \def\ft@page{#3}
        \def\ft@foot{0}%
    \fi\fi}%
%    \end{macrocode}
%
% if the `actual page' wasn't numeric, we simply reset \cs{ft@page}
%
%    \begin{macrocode}
   {\def\ft@page{0}}%
%    \end{macrocode}
%
% Now advance our `expected' footnote number; if it's different from
% what would be typeset without our intervention, create a macro
% \cs{ft@}\meta{apparent-page}|-|\meta{natural-footnote} that contains
% the number that in fact needs to be typeset.
%    \begin{macrocode}
  \@advance@macro\ft@foot1
  \def\@tempa{#2}%
  \ifx \@tempa\ft@foot \else
     \expandafter \xdef \csname ft@#1-#2\endcsname {\ft@foot}%
  \fi
  }
%    \end{macrocode}
%
% Don't need that definition in the body of the code (though something
% similar is resurrected at end document).
%
%    \begin{macrocode}
\@onlypreamble\newfoot@mark
%    \end{macrocode}
%
% A simple bit of code to detect whether the argument it's offered is
% a number (at least to the extent of starting with a digit).
%
% Apparent external interface is:
%
% \noindent \cs{@ifdigit}\marg{poss digits}\marg{digit
%   text}\marg{non-digit text}
%
%    \begin{macrocode}
\def\@ifdigit#1{\expandafter\@digithelp\string#1\@digithelp}%
%    \end{macrocode}
%
% Behold, a piece of horrible code, slowly reducing in number of
% tokens as I find ways to improve it, which does the guts of
% \cs{@ifdigit}.  (The original was a sequence of \cs{if}s comparing
% to each digit in turn; this one at least is more fun\dots)
%
%    \begin{macrocode}
\def\@digithelp#1#2\@digithelp{%
  \ifnum `#1<`0
    \@triple@expandafter\@secondoftwo
  \else
    \ifnum `#1>`9
      \@triple@expandafter\@secondoftwo
    \else
      \@triple@expandafter\@firstoftwo
    \fi
  \fi}
%    \end{macrocode}
%
% Since we use \cs{@triple@expandafter}, we had better define it.  (I
% think the kernel could do with it, in fact\dots)
%
%    \begin{macrocode}
\providecommand\@triple@expandafter{\expandafter
  \expandafter\expandafter}
%    \end{macrocode}
%
% \cs{enddoc@newfoot@mark} is used to detect channges at the end of
% the run, when the new |.aux| file is scanned.  It's mostly the same
% as \cs{newfoot@mark}, except at its last gasp\dots
%
%    \begin{macrocode}
\def \enddoc@newfoot@mark #1#2#3{%
  \@ifdigit{#3}{%
    \expandafter\ifnum \ft@page > #3\relax
      \def\ft@page{0}%
    \else
      \expandafter\ifnum \ft@page < #3\relax
        \def\ft@page{#3}
        \def\ft@foot{0}%
    \fi\fi}%
   {\def\ft@page{0}}%
%    \end{macrocode}
%
% If our `expected' footnote number is different from what would be
% typeset without our intervention, check there was a macro
% \cs{ft@}\meta{apparent-page}|-|\meta{natural-footnote} containing
% the number that in fact needs to be typeset.
%
%    \begin{macrocode}
  \@advance@macro\ft@foot1
  \def\@tempa{#2}%
  \ifx \@tempa\ft@foot \else
    \expandafter \ifx \csname ft@#1-#2\endcsname \ft@foot
    \else\@tempswatrue
    \fi
  \fi
  }
%    \end{macrocode}
%
% At the end of the document, redefine \cs{newfoot@mark} to perform
% a check for footnote labels misbehaving when the |.aux| file is
% scanned:
%
%    \begin{macrocode}
\AtEndDocument{%
  \def\ft@page{0}
  \def\ft@foot{0}
  \let\newfoot@mark\enddoc@newfoot@mark
  }
%    \end{macrocode}
%
% Mark we've patching to do, and arrange that the reset list (of
% \cs{c@page} takes most of the strain\dots
%
%    \begin{macrocode}
\@advance@macro\PP@footflag9
\@addtoreset{footnote}{page}%
}
%    \end{macrocode}
%
% \section{The \texttt{bottom} option}
%
% All this needs to do is to reset the value of \cs{FN@outputflag} to
% be negative.  This is simply by subtracting two from it (which
% doesn't affect its oddness \dots{} or should that be \emph{oddity}?)
%    \begin{macrocode}
\DeclareOption{bottom}{%
  \@advance@macro\FN@outputflag{-2}
}
%    \end{macrocode}
%
% \section{The \texttt{marginal} option}
%
% Again, the processing of the option is pretty trivial:
%    \begin{macrocode}
\DeclareOption{marginal}{%
  \footnotemargin-0.8em\relax
}
%    \end{macrocode}
%
% \section{The \texttt{flushmargin} option}
%
% Again, the processing of the option is pretty trivial:
%    \begin{macrocode}
\DeclareOption{flushmargin}{%
  \footnotemargin0pt\relax
}
%    \end{macrocode}
%
% \section{The \texttt{norule} option}
%
% Pretty simple too\dots
%
%    \begin{macrocode}
\DeclareOption{norule}{%
  \renewcommand\footnoterule{}%
  \advance\skip\footins 4\p@\@plus2\p@\relax
}
%    \end{macrocode}
%
% \section{The start of the endgame}
%
% Exercise the options that the user has requested\dots
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
%
% \section{The output routine hacks}
%
% Now; do we need to mess about with the output routine?  If either
% |fnpara| or |bottom| has been invoked, we do.  In order to do this
% job, we use David Kastrup's |patch.tex|:
%    \begin{macrocode}
\expandafter\@tempcntb\PP@footflag\relax
\@advance@macro\FN@outputflag\@tempcntb\relax
% We rely on \@advance@macro to set \@tempcnta for us
\ifnum\@tempcnta=0
\else
\advance\@tempcnta-\@tempcntb\relax
%    \end{macrocode}
% \dots{} so we've patching to do.
%
% Since |patch| won't let us compare braces (for obvious reasons), but
% more significantly won't allow us use of \cs{bgroup} or \cs{egroup},
% we need private copies of the brace characters for one of our
% patches:
%
%    \begin{macrocode}
\let\FN@obrace{
\let\FN@cbrace} % this has the merit (at least) of satisfying emacs...
%    \end{macrocode}
%
% Now we get the patcher:
%    \begin{macrocode}
\input{patch}
%    \end{macrocode}
%
% Now we need to do our patches and then to get out of the way.
%
%    \begin{macrocode}
\ifnum\FN@outputflag<0
%    \end{macrocode}
%
% Option \textsf{bottom} was requested.
%
% In this case, we've to fix the size of \cs{vbox} that \cs{@makecol}
% uses if there's a footnote present on the page, and then stick a
% \cs{vfill} in it:
%
%    \begin{macrocode}
\gpatch\@makecol{}{\vbox\FN@obrace\boxmaxdepth\@maxdepth
                   \unvbox\@cclv\vskip\skip\footins
                     {\vbox to\@colht\FN@obrace\boxmaxdepth\@maxdepth
                      \unvbox\@cclv\vfill\relax\vskip\skip\footins}}
%    \end{macrocode}
%
% That completes \textsf{bottom}
%
%    \begin{macrocode}
\fi
%    \end{macrocode}
%
% Similarly, if we're doing paragraph footnotes, the actual grubby end
% of the work is done in the output routine; the need for this is
% signalled by the flag being odd.
%
%    \begin{macrocode}
\ifodd\@tempcnta
%    \end{macrocode}
%
% The output routine part of it simply makes a box out of the
% paragraph of footnotes, and then stuffing the contents of the box
% into that which is going to be \cs{ship}ped |out|.
%
%    \begin{macrocode}
\gpatch\@makecol{}{\normalcolor\footnoterule\unvbox\footins
                     {\normalcolor\footnoterule
                      \global\setbox\FN@tempboxc\vbox
                                      {\makefootnoteparagraph}%
                      \unvbox\FN@tempboxc}}
%    \end{macrocode}
%
% Paragraph footnotes also require that we patch \cs{@footnotetext},
% so we do this here, too:
%
%    \begin{macrocode}
\gpatch\@footnotetext#1{{#1}}{\@makefntext\FN@obrace
     \rule\z@\footnotesep
     \ignorespaces#1%
     \@finalstrut\strutbox\FN@cbrace
     {%
%    \end{macrocode}
%
% We set the paragraph in an \cs{hbox} and apply the fudge factor
% here:
%
%    \begin{macrocode}
     \setbox\FN@tempboxa=\hbox\FN@obrace
%    \end{macrocode}
%
% This needs a parameter; the rule should be moved to the beginning of
% the footnote paragraph, but the \cs{ignorespaces} should be left
% here.
%
%    \begin{macrocode}
        \@makefntext\FN@obrace
          \ignorespaces#1\strut
%    \end{macrocode}
%
% We insert a penalty\footnote{Well, a negative penalty~--- perhaps,
% more of an encouragement\dots} here to help line breaking in the
% footnote paragraph; the value is taken from the \TeX{}book.
%
%    \begin{macrocode}
          \penalty-10\relax
          \hskip\footglue
          \FN@cbrace% end of \@makefntext parameter
        \FN@cbrace% end of \hbox
     \dp\FN@tempboxa=0pt\ht\FN@tempboxa=\fudgefactor\wd\FN@tempboxa
     \box\FN@tempboxa
     }}
\fi
%    \end{macrocode}
%
% Finally, do we need to patch \cs{footnote}?  This is signalled by
% setting \cs{PP@footflag} to a non-zero value, and we set
% \cs{@tempcntb} to that before the last patching session:
%
%    \begin{macrocode}
\ifnum\@tempcntb=0
\else
\gpatch\footnote{}% Note that \footnote doesn't have arguments,
                  % whatever it says in the book...
                  {\@footnotemark{\PP@footnote\@footnotemark}}
\gpatch\footnotemark{}{\@footnotemark{\PP@footnote\@footnotemark}}
\fi
%    \end{macrocode}
%
% And lo!, we are done with patching
%    \begin{macrocode}
\endpatch
%    \end{macrocode}
% All of this occurred conditionally on the values of
% \cs{FN@outputflag} and \cs{PP@footflag}, so we now close that
% conditional.
%    \begin{macrocode}
\fi
%    \end{macrocode}
%
% Finally, if we're not doing paragraph footnotes, we redefine
% \cs{@makefntext} to take account of the value of
% \cs{footnotemargin}; the actual test is that the value of
% \cs{@tempcnta} should be even.
%    \begin{macrocode}
\ifodd\@tempcnta\else
  \def\@makefntext#1{%
    \parindent1em
    \noindent
    \ifdim\footnotemargin>0pt
      \hbox to 1.8em{\hss\@makefnmark}%
    \else
      \ifdim\footnotemargin=0pt
        \llap{$^{\@thefnmark}$}%
      \else
        \llap{\hbox to-\footnotemargin{$^{\@thefnmark}$\hss}}%
      \fi
    \fi
    #1}
\fi
%</package>
%    \end{macrocode}
%
% \Finale
%
\endinput
%
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
