% \iffalse meta-comment
%
%% File: footmisc.dtx (C) Copyright 1995-2011 Robin Fairbairns
%%                    (C) Copyright 2018-2022 Frank Mittelbach
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version.  The latest version
% of this license is in the file
%
%    https://www.latex-project.org/lppl.txt
%
% This bundle has the status "maintained" and the current maintainer
% is Frank Mittelbach.
%
% The development version of the bundle can be found at
%
%    https://github.com/FrankMittelbach/fmitex-footmisc/
%
% for those people who are interested or want to report an issue.
%
%
%
% We use the same body for the \cs{ProvidesFile} as for the
% \cs{ProvidesPackage} command.
%
%    \begin{macrocode}
%<*!debugins>
\NeedsTeXFormat{LaTeX2e}
%</!debugins>
%<*dtx>
\ProvidesFile{footmisc.dtx}%
%</dtx>
%<+package>\providecommand\DeclareRelease[3]{}
%<+package>\providecommand\DeclareCurrentRelease[2]{}
%<+package>
%<+package>\DeclareRelease{v5}{2011-06-06}{footmisc-2011-06-06.sty}
%<+package>\DeclareCurrentRelease{}{2022-02-14}
%<package>\ProvidesPackage{footmisc}%
%<*!debugins>
        [2022/03/08 v6.0d
%</!debugins>
%<package>     a miscellany of footnote facilities%
%<*dtx>
               footmisc package source file%
%</dtx>
%<*!debugins>
                   ]
%</!debugins>
%    \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}
\usepackage{hyperref}
%    \end{macrocode}
%
% We limit the things that we will index
%    \begin{macrocode}
\DoNotIndex{\#,\@MM,\@cclv,\@gobble,\@ifnextchar,\@ifundefined}
\DoNotIndex{\|,\advance,\begingroup,\bgroup,\box,\csname}
\DoNotIndex{\dagger,\ddagger,\def,\divide,\dp}
\DoNotIndex{\edef,\egroup,\ifx,\else,\fi,\endcsname,\endgroup,\end}
\DoNotIndex{\endinput,\ensuremath,\expandafter}
\DoNotIndex{\gdef,\global,\hbox,\hskip,\hss,\ht}
\DoNotIndex{\ifcase,\or,\ifdim,\ifhbox,\ifhmode,\ifnum,\ifvbox,
            \fi        ,\fi   ,\fi    ,\fi     ,\fi   ,\fi    }
\DoNotIndex{\ifvoid,\fi,\kern,\let,\long,\loop}
\DoNotIndex{\MessageBreak,\newbox,\newcommand,\newcounter}
\DoNotIndex{\newdimen,\newif,\newskip,\newtoks,\noexpand}
\DoNotIndex{\P,\p@,\par,\penalty,\protect,\providecommand}
\DoNotIndex{\relax,\renewcommand,\S,\setbox,\setcounter}
\DoNotIndex{\skip,\space,\the,\typeout,\vbox,\vskip}
\DoNotIndex{\wd,\xdef,\@}
\GetFileInfo{footmisc.dtx}
\EnableCrossrefs
% To get documented source of the package, comment out the next line,
% and uncomment the following one; otherwise, create yourself
% (somewhere on your LaTeX input path) a file ltxdoc.cfg that contains
% simply          \AtBeginDocument{\AlsoImplementation}
\OnlyDescription
%\AlsoImplementation
\setcounter{StandardModuleDepth}{1}
\begin{document}
\DocInput{footmisc.dtx}
\end{document}
%</driver>
%    \end{macrocode}
%
% \fi
%
%
%
% \title{\texttt{footmisc} ---\\
%        a portmanteau package\\
%        for customizing footnotes in \LaTeX\thanks{This file has
%          version number \fileversion, last revised \filedate}}
% \author{Robin Fairbairns\thanks{Formerly: University of Cambridge Computer
%     Laboratory, Cambridge, UK} \and
%   Frank Mittelbach\thanks{Responsible maintainer since 2018}}
% \maketitle
%
%
% \newcommand\fmi[1]{\begin{quote} NOTE: \itshape #1\end{quote}}
% \newcommand\NEW[1]{\marginpar{\mbox{}\hfill\fbox{New: #1}}}
% \providecommand\pkg[1]{\texttt{#1}}
%
%
% \section*{Copyright statement}
%
% \noindent Program: \texttt{footmisc.dtx}\par
% \noindent Copyright 1995--2011 Robin Fairbairns\par
% \noindent Copyright 2018--2022 Robin Fairbairns, Frank Mittelbach
%
% This program is offered under the terms
% of the \LaTeX{} Project Public License, version 1.3c of this license or
% (at your option) any later version.  The latest version of this
% license is in \texttt{https://www.latex-project.org/lppl.txt}, and version
% 1.3c or later is part of all distributions of \LaTeX{} version
% 2008 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
%
% \tableofcontents
%
%
% \section*{History}
%
% This package originated as support of a personal project, which I (Robin)
% was switching to \LaTeX{} 2e over the Christmas holiday period of
% 1993, using the first \ensuremath{\beta} release.
%
% In its first form, it was known as the ``footnote'' package, but by
% the time I had released it to CTAN, that name had already been
% used by a package written by Mark Wooding.  So the package is now
% known (as you can see) as ``footmisc''.
%
% Frank took over maintenance in 2018 but due to other commitments never
% got around finishing the changes he started to make in 2018.
%
% In 2022 a few new options (\texttt{abovefloats},
% \texttt{belowfloats}, and \texttt{bottomfloats}
% got introduced and the package now works
% with \textsf{hyperref} regardless of loading order. There arem
% however, still a few restrictions when using both packages together,
% in particular the \texttt{multiple} option does not fully work.
%
%
%
%
% \section{User interface~--- package options}
%
% The \textsf{footmisc} package provides several different
% customizations of the way footnotes 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 mostly rather simple~--- each one is presented as an
% option in the |\usepackage| command, and for most, nothing else
% needs to be done.  For example, to use a useful
% and consistent set, the author invokes the package with the
% command |\usepackage[perpage,para,symbol*]{footmisc}|.
%
% For a small number of options, there are additional parameters
% available; these are described in the subsections below.
%
% \subsection{Option \texttt{perpage}}
% \label{sec:perpagedoc}
%
% This option resets footnote numbering for each page of the document.
% It needs at least 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
% `\emph{Label(s) may have changed}', which will help the poor user to
% realize that (yet) another run is in order.
%
% \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.  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; in most other disciplines, such multiplicities
% of footnotes represent mere self-indulgence: the author of this
% package is disgracefully guilty of this.
%
% Please note that ``old'' \LaTeX{} installations may have problems
% with the algorithm for \texttt{para} footnotes on very wide pages
% (for example, those used by the \textsf{a0poster} class).  Recent
% \LaTeX{} installations use an improved technique that is believed
% not to be susceptible to this problem.
%
% \subsection{Option \texttt{side}}
%
% This option (suggested by Frank Mittelbach) causes footnotes to be
% typeset using the \cs{marginpar} command: this has the advantage
% that the note appears close to its ``call-up'', but has all the
% disadvantages associated with the \cs{marginpar} command (which
% consumes `float' slots, and doesn't always place itself correctly at
% the top of pages in two-sided documents).  Since the measure in
% which the footnote is to be typeset is likely to be pretty narrow,
% users of the \texttt{side} option are recommended also to use the
% \texttt{ragged} option, to avoid ugly spacing and line breaks.
%
% There is a further problem (apart from the occasional failure to
% place the marginal note on the correct side of the page) in
% two-sided documents: one would like `raggedness' to appear
% differently in different margins (setting the left, rather than the
% right, side ragged in the left margin).  (The author would welcome
% suggestions on means of addressing the problem.)
%
% \subsection{Option \texttt{ragged} and \cs{footnotelayout}}
%
% The package provides facilities for ragged right setting of
% footnotes (so long as the \texttt{para} option isn't in effect).
% The change is effected by use of the command \cs{footnotelayout};
% the package inserts this command into the start of the argument of
% \cs{footnotetext} (in effect: \cs{footnote} works, roughly, by
% calling the guts of \cs{footnotetext} at its end).
%
% If you want to use some special effect other than ragged right, feel
% free to change \cs{footnotelayout} yourself: some intriguing (and
% completely undesirable) results are no doubt available.  Change the
% setting simply by use of
% \cs{renewcommand}\cs{footnotelayout}\texttt{\dots}\@.  The
% \texttt{ragged} option simply sets \cs{footnotelayout} to set
% \cs{raggedright} or \cs{RaggedRight} as appropriate.  (If you intend
% to use the \textsf{ragged2e} package, load it before
% \textsf{footmisc}~--- if \textsf{footmisc} finds \cs{RaggedRight} is
% available, it automatically uses it in place of \cs{raggedright}.)
%
% \subsection{Option \texttt{symbol}}
%
% This option simply establishes that footnotes are `labelled' by
% a symbol sequence.  The command used is equivalent to that
% suggested in \LaTeX{} manuals such as Lamport's (the job performed
% by the option is very simple, and doesn't really need a package).
%
% Using symbols to `number' your footnotes can be problematic: there
% is a limited number of symbols, and \LaTeX{} will report an error if
% your footnotes exceed that limit.  To avoid such problems, consider
% the \texttt{symbol*} option, or the \cs{setfnsymbol} command (see
% the next two sections), or number your footnotes by the page (see
% section~\ref{sec:perpagedoc}).
%
% \subsection{Option \texttt{symbol*}}
% \label{doc-symbol*}
%
% This is the \texttt{symbol} option, but with protection against the
% tedium that arises because of the instability of the
% \texttt{perpage} option.  When executing the \texttt{perpage}
% option, the package often allocates footnotes to the wrong pages,
% only to correct itself on a later run (having warned the user of the
% need for the later run with a `\emph{Label(s) may have changed}'
% message).  In these circumstances the \texttt{symbol} option is
% prone to producing \LaTeX{} errors, which stop processing, and
% confound automatic generation procedures.  In the same situation,
% the \texttt{symbol*} option produces information messages and a
% warning message at end document, and the user may scan the log for
% those messages \emph{after} processing has stabilized.  The option
% produces numbers (17 and higher, in the case of the default symbol
% set) in place of symbols, when the footnote number is too large.
%
% \subsection{The \cs{setfnsymbol} and \cs{DefineFNsymbols} commands}
% \label{footnote-symbols}
%
% \fmi{At some point in the past this interface got extended, but the
%     documentation lags behind so this needs updating.}
%
% These commands permit the definition and use of alternative
% (ordered) sets of symbols for numbering footnotes.  \LaTeX{} of
% course comes with such a set ready-defined, but the choice of
% symbols isn't universally loved.
%
% You may define a set of symbols with the \cs{DefineFNsymbols}
% command.  \LaTeX{}'s default set would be defined by the command: 
% \begin{center}
%   \verb|\DefineFNsymbols*{lamport}|%
%   \unskip\verb|{*\dagger\ddagger\S\P|\texttt{\char`\\\char`\|\%}\\
%   \unskip\verb|          {**}{\dagger\dagger}{\ddagger\ddagger}}|
% \end{center}
% Defined this way, the symbol set produces a ``counter too large''
% error; a robust version of the set (cf.~the \texttt{symbol*} option
% (see \ref{doc-symbol*}) using the \cs{DefineFNsymbols} command
% without the optional |*|.
% You may select a set of symbols by use of the \cs{setfnsymbol}
% command; so to restore use of the default set, you would type:
% \begin{center}
%   \verb|\setfnsymbol{lamport}|
% \end{center}
%
% This package defines a small selection of alternative sets of
% symbols, using \cs{DefineFNsymbol}:
% \begin{center}
%   \begin{tabular}{ll}
%     \texttt{bringhurst} & $*\,\dagger\,\ddagger\,\S\,\|\,\P$ \\
%     \texttt{chicago}    & $*\,\dagger\,\ddagger\,\S\,\|\,\#$ \\
%     \texttt{wiley}      & $*\,\mathop{**}\,\dagger\,\ddagger\,\S\,\P\,\|$
%   \end{tabular}
% \end{center}
% together with a version of Lamport's original set that, with doubled
% versions of $\S$ and $\P$, and tripled versions of everything but
% the vertical bars, provides a symbol range to cover counters up to
% 16.
%
% This last set, known as \texttt{lamport*} is selected as the default
% symbol set by the package.
%
%
% \subsection{Options altering the footnotes/floats relationship}
%
% In \LaTeX{} the default order on a page is ``page text'' followed by
% ``footnotes'' (if any) followed by ``bottom floats'' (if any). The
% spacing between the three components depends of whether pages are
% always stretched to the same height (\cs{flushbottom} as used by the
% book class) or if they
% can run short  (\cs{raggedbottom} as used by the article or report
% class).
% If \cs{raggedbottom} is in force, then 
% \LaTeX{} would normally set the footnotes a mere
% \cs{skip}\cs{footins} distant from the bottom of the text and bottom
% floats follow separated by \cs{textfloatsep}. Both spaces might get
% stretched if \cs{flushbottom} is in force.
%
% If\NEW{2022-02}
% you want to diverge from this default placement, then  there are
% a number of alterations that can be made:
% \begin{itemize}
% \item the order of footnotes and floats can be swapped; and
% \item both footnotes and floats can be forced to the bottom (i.e.,
% \cs{raggedbottom} then only applies to pages with neither), or
% \item only one of them is forced to the bottom, the other stays
% close to the text.
% \end{itemize}
% These can be achieved by applying one or more of the options
% discussed below.
%
%
%
% \subsubsection{Option \texttt{bottom}}
%
% This option forces footnotes (but not the floats) to the bottom of the page and
% therefore by default also implies \texttt{belowfloats}. If
% \cs{raggedbottom} is in force then the excess space goes above the
% footnotes if any are present. If \cs{flushbottom} is in force there
% is no visible difference to just specifying \texttt{belowfloats}.

% \subsubsection{Option \texttt{bottomfloats}}
%
% If\NEW{2022-02}
% you want force only floats to the bottom while the footnotes stay close to the text
% use the option \texttt{bottomfloats}. If not overwritten this
% implies \texttt{abovefloats}.
%
% \subsubsection{Options \texttt{abovefloats} and \texttt{belowfloats}}
%
% These\NEW{2022-02}
% two options describe the footnote placement with respect to
% floats on the page. \LaTeX's default is \texttt{abovefloats}, but it
% can still be useful to specify it because it fixes the bug discussed
% in section~\ref{sec:spacebug}.
%
%
% \subsubsection{Combining the four options}
%
% By\NEW{2022-02}
% default, \texttt{bottom} and \texttt{bottomfloats} options put any excess
% space (i.e., when \cs{raggedbottom} is in force) between floats
% and footnotes if both are present on a given page. If only one of
% them is present, the excess space goes below the text. If you prefer
% both footnotes and floats at the bottom instead, you can achieve this as follows:
% \begin{description}
% \item[\normalfont\texttt{bottom,abovefloats}] This puts the footnotes above any
%   floats and both at the bottom when present.
% \item[\normalfont\texttt{bottomfloats,belowfloats}] This puts
%   floats and footnotes at the bottom but
%   footnotes last if both are present. If there are only footnotes
%   they are still placed at the very bottom (think of them as being
%   placed below the float ``area'' even if that has no floats inside).
% \end{description}
% The other combinations are duplicates, e.g.,
% \texttt{bottom,belowfloats} is the same as just specifying \texttt{bottom}.
%
%
% \subsubsection{Fixing a strange behavior of \LaTeX}
% \label{sec:spacebug}
%
% In\NEW{2022-02}
% the default case (if \pkg{footmisc} is not loaded) \LaTeX{} shows
% a somewhat strange discrepancy: on most pages the
% footnotes are attached a distance of \cs{skip}\cs{footins} from the
% main text, even if that page is run short (i.e., with
% \cs{raggedbottom} in force). However, whenever the is some
% infinite stretch at the end of the page, e.g., from using \cs{newpage} or
% \cs{clearpage} the footnotes are pushed to the bottom (in particular
% on the last page of a document or chapter).
%
% This is automatically corrected if \pkg{footmisc} is loaded with any
% of the options that deal with footnote placement, i.e.,
% \texttt{abovefloats}, \texttt{belowfloats}, \texttt{bottom}, or
% \texttt{bottomfloats}. In particular,
% if you want to have the standard \LaTeX{} placement (but with this
% strange behavior fixed, apply \texttt{abovefloats} (which is the
% normal order but with the bug fixed).
%
%
% \subsection{Option \texttt{marginal}}
%
% This option adjusts the position of footnote mark relative to the
% start of the line in which they appear (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; you
% may change that value with a \cs{setlength} command.)
%
% \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{hang}}
%
% This option sets the footnote mark flush with the margin, and makes
% the body of the footnote hang at an indentation of
% \cs{footnotemargin} (if that is a positive distance), or the width
% of the marker (if \cs{footnotemargin} $\leq0$).  The option code
% itself leaves \cs{footnotemargin} at its default value of 1.8em.
%
% The footnote itself may of course be longer than one paragraph; if
% so, the paragraphs will be separated by the vertical space specified
% by \cs{hangfootparskip}, and the second and subsequent paragraphs
% are indented by \cs{hangfootparindent}.  Default values are:
% \begin{center}
% \begin{tabular}{ll}
%   \cs{hangfootparskip}   & 0.5\cs{baselineskip} \\
%   \cs{hangfootparindent} & 0em
% \end{tabular}
% \end{center}
% The user may redefine these values (using
% \cs{renewcommand}): it is best to use the font-size-dependent
% measures (multiples of \cs{baselineskip} for the skip, multiples of
% |em| for the indent).  Note that the default has only one of the two
% values non-zero; both zero may result in easily-missed paragraph
% breaks, and both non-zero is not generally thought to be a
% good-looking option.
%
% \subsection{Option \texttt{norule}}
%
% This option suppresses the `normal' footnote rule, and advances
% \cs{skip}\cs{footins} a bit to compensate
%
% \subsection{Option \texttt{splitrule}}
%
% This option makes puts a full-width rule above the split-off part of
% a split footnote.  (Remember that split footnotes don't happen if
% you're doing paragraph footnotes.)
%
% The option provides three different \cs{footnoterule} commands:
% \begin{center}
% \begin{tabular}{ll}
% \cs{mpfootnoterule} & for use in minipages \\
% \cs{pagefootnoterule} & for normal footnotes on regular pages \\
% \cs{splitfootnoterule} & for the tail of a split footnote
% \end{tabular}
% \end{center}
% By default, \cs{mpfootnoterule} and \cs{pagefootnoterule} retain the
% original definition of \cs{footnoterule} (which nay have been
% modified by a \texttt{norule} option), while \cs{splitfootnoterule}
% becomes a full-width rule.
%
% \subsection{The \texttt{stable} option}
%
% This option deals with the problem of placing footnotes in section
% titles (and so on).  While there is (sometimes, just) justification
% for putting footnotes in titles, \LaTeX's treatment of the content
% of titles militates against them.  Of course, the title argument is
% ordinarily a moving one, and \cs{footnote} is a fragile command, but
% the real problem comes from the way the argument actually moves~---
% which is to two places.  The argument moves to the table of
% contents, where the footnote will (at least) look odd.  But the
% argument also moves to the marks that make up page headers, etc.,
% and \emph{there} it creates havoc, since page headers are executed
% in page make-up, and page make-up \emph{must not} create footnotes.
%
% If you use the \texttt{stable} option, the footnote won't move to
% the table of contents or the page headers, but it will be typeset
% correctly within the title itself.
%
% The situation with \cs{footnotemark} is less dire (it could in
% principle appear in page headers, for example); footnote marks
% appearing on pages other than where their text appears are none the
% less confusing, and the stable option treats \cs{footnotemark} in
% the same way that it treats \cs{footnote}.
%
% \subsection{The \texttt{multiple} option}
%
% This option deals with the case where the author needs to type
% things like
% \begin{verbatim}
%   mumble\footnote{blah}\footnote{grumble}
% \end{verbatim}
% Without special treatment, \LaTeX{} would output something like
% \begin{quote}
%   mumble\textsuperscript{1314}
% \end{quote}
% \noindent What the \texttt{multiple} option makes of the above is
% \begin{quote}
%   mumble\textsuperscript{13,14}
% \end{quote}
% which is what most people would expect.  The comma separator
% actually derives from the definition of \cs{multfootsep}, which
% may be changed by \cs{renewcommand} if the option is in effect.
%
% The option also treats \cs{footnotemark} in the same way.
%
% \subsection{User interface~--- miscellaneous commands}
%
% The package also defines some miscellaneous footnote-related
% commands.  The present group provides alternative means of producing
% footnote marks: \cs{footref} and \cs{mpfootnotemark}.
%
% When you're in a minipage, \cs{footnote} numbers run according to the
%  minipage's own footnote counter, and the marks are set in italic
% letters.  However, the numbers used by \cs{footnotemark} make
% reference to the `main'
% footnote counter, and are set in whatever is the current style for
% that: this behavior often surprises, and there's no obvious way in
% standard \LaTeX{} to ``get around'' it.  The command
% \cs{mpfootnotemark} gets around this problem in a minipage, by
% generating footnote marks in the same way as those used by
% \cs{footnote}.
%
% In fact, making reference to footnotes in
% general can be problematic: it can be done by noting down the
% value of the footnote
% marker in a counter (or the like) and then using the value in a
% subsequent \cs{footnotemark} or \cs{mpfootnotemark}.  This is a
% tedious way of going about things, and doesn't allow representation
% of all possible forms of footnote mark; \cs{footref} is a form of
% reference command that sets the reference as if it were
% a footnote.\footnote{This command is already provided by the \LaTeX{} format.}
% The label should be set \emph{within} the argument of the footnote
% command that is being labelled:
% \begin{verbatim}
% ...\footnote{Note text\label{fnlabel}}
% ...
% ... potato head\footref{fnlabel}
% \end{verbatim}
%
% \section{User interface~--- interactions with other packages}
%
% The \textsf{footmisc} package modifies several parts of the \LaTeX{}
% kernel; what gets modified depends on the options you select.  This
% behavior can cause problems with other packages, particularly those
% that also modify the kernel.
%
% Known interactions are:
% \begin{description}
% \item[\normalfont\textsf{setspace}] The \textsf{setspace} package
%   modifies the way line spacing is calculated in footnotes.
%   \textsf{Footmisc} knows about this, and preserves the change.
%   However, you \emph{must} load \textsf{setspace} \emph{before}
%   \textsf{footmisc}.
% \item[\normalfont\textsf{memoir} class] The class emulates
%   \textsf{setspace}, and we detect that emulation and deal with it
%   in the same way as \textsf{setspace}.
%
% \iffalse FMi: this should now work!
% \item[\normalfont\textsf{hyperref}] The \textsf{hyperref} package
%   has ambitions to make hyperlinks from footnote marks to the
%   corresponding footnote body; naturally this causes grief to
%   \textsf{footmisc}, and unfortunately no remedy is currently
%   known.  If you use \textsf{footmisc}, suppress hyperref's
%   hyper-footnotes, by loading it as:\\
%   \quad\verb|\usepackage[hyperfootnotes=false,...]{hyperref}|\\
%   Further work on the interaction between the two packages is
%   proposed, but not yet scheduled.
% \fi
%
% \item[\normalfont\textsf{manyfoot}] The \textsf{manyfoot} package
%   permits several independent sequences of footnotes.  Some
%   preliminary work towards interworking with \textsf{footmisc} has
%   been completed, but more remains to be done at the time of
%   writing.
%
% \item[\normalfont\textsf{hyperref}] The \textsf{hyperref} package
%    works together with \textsf{footmisc} (as proved  by this
%    documentation), but at this point in time not all options of
%    \textsf{footmisc} can be used --- this will change over time.
% \end{description}
%
% \StopEventually{}
%
% \section{Code: Preliminaries}
%
% Well~--- here we go: let's make the package file:
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% Now declare what environment we need: version 6 needs a fairly recent \LaTeX.
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[2020/10/01]
%    \end{macrocode}
%
% We need a token register in case we have to patch \cs{@makecol}:
%    \begin{macrocode}
\newtoks\FN@temptoken
%    \end{macrocode}
%
% \begin{macro}{\protected@writeaux}
% This command is defined for future compatibility with Matt Swift's
% \textsf{newclude} package (still, after all this time, not out of
% beta status).
%    \begin{macrocode}
\providecommand\protected@writeaux{%
  \protected@write\@auxout
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l@advance@macro}
% \begin{macro}{\@@dvance@macro}
% \begin{macro}{\@advance@macro}
% We make the following (\cs{@@dvance@macro}) generalizable as follows
% (the global form isn't used in this package \dots\ yet):
%
%    \begin{macrocode}
\def\l@advance@macro{\@@dvance@macro\edef}
\def\@@dvance@macro#1#2#3{\expandafter\@tempcnta#2\relax
  \advance\@tempcnta#3\relax
  #1#2{\the\@tempcnta}%
}
%    \end{macrocode}
%
% Now we define a jolly little macro to advance a macro count (|#1|)
% by a given amount (|#2|).
%    \begin{macrocode}
\let\@advance@macro\l@advance@macro
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\footnotemargin}
% Finally, we define the length used by the \texttt{marginal} option,
% and initialize it as if we've not had the option.
%    \begin{macrocode}
\newdimen\footnotemargin
\footnotemargin1.8em\relax
%    \end{macrocode}
% \end{macro}
%
% \section{Package options}
%
% Most of the code of the package is contained within the option
% processing, one way or another (that which isn't, is executed after
% \cs{ProcessOptions} as a result of flags set in the option
% processing).
%
% \subsection{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 customization to the package.
%
%    \begin{macrocode}
\DeclareOption{symbol}{\renewcommand\thefootnote{\fnsymbol{footnote}}}
%    \end{macrocode}
%
% \subsection{The \texttt{symbol*} option}
%
% The robust version of the \texttt{symbol} option: if the current
% `symbol' option doesn't provide enough variants, use arabic footnote
% number.  We use a robust version of the ``extended ordinary'' symbol set,
% described later (in section~\ref{footnote-symbols}).
%    \begin{macrocode}
\newif\ifFN@robust \FN@robustfalse
\DeclareOption{symbol*}{%
  \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
  \FN@robusttrue
  \AtEndOfPackage{\setfnsymbol{lamport*-robust}}%
}
%    \end{macrocode}
%
% \subsection{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.
%
% \begin{macro}{\ifFN@para}
% Define the |para| option: now simply sets a marker for use later
% when defining the option's auxiliary code and when patching the
% output routine and so on.
%    \begin{macrocode}
\newif\ifFN@para  \FN@parafalse
\DeclareOption{para}{\ifFN@sidefn
    \PackageError{footmisc}{Option "\CurrentOption" incompatible with
      option "side"}%
      {I shall ignore "\CurrentOption"}%
  \else
    \FN@paratrue
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \texttt{side} option}
%
% \begin{macro}{\ifFN@sidefn}
% Simply changes the behavior of \cs{@footnotetext}; incompatible
% with paragraph footnotes.
%    \begin{macrocode}
\newif\ifFN@sidefn  \FN@sidefnfalse
\DeclareOption{side}{\ifFN@para
    \PackageError{footmisc}{Option "\CurrentOption" incompatible with
      option "para"}%
      {I shall ignore "\CurrentOption"}%
  \else
    \FN@sidefntrue
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \texttt{ragged} option}
%
% \begin{macro}{\footnotelayout}
% A very simple option that merely changes the definition of one
% macro.  Note detection of the presence of the \textsf{ragged2e}
% package.
%    \begin{macrocode}
\let\footnotelayout\@empty
\DeclareOption{ragged}{%
  \@ifundefined{RaggedRight}%
    {\renewcommand\footnotelayout{\linepenalty50 \raggedright}}%
    {\renewcommand\footnotelayout{\linepenalty50 \RaggedRight}}%
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \texttt{perpage} option}
%
% \begin{macro}{\ifFN@perpage}
% A footnote-numbering modification: a new algorithm replacing one
% from Brian T. Schellenberger, which has proved to be flawed.  We
% simply set a marker here, and define code later depending on the
% state of the marker (see section \ref{sec:perpage-code}).
%    \begin{macrocode}
\newif\ifFN@perpage
\FN@perpagefalse
\DeclareOption{perpage}{%
  \FN@perpagetrue
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \texttt{PPdebug} option}
%
% \begin{macro}{\ifFN@pp@debug}
% Sets a flag; the messages are generated in various places throughout
% the code.  The option is not available in the package as
% distributed: modify the |.ins| file to generate a version of the
% package that includes the option, if you feel you need it.
%    \begin{macrocode}
%<*PPdebug>
\newif\ifFN@pp@debug    \FN@pp@debugfalse
\DeclareOption{PPdebug}{\FN@pp@debugtrue}
%</PPdebug>
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Fixing the \LaTeX{} misbehavior with respect to spacing}
%
%
%  \begin{macro}{\ifFN@fixskip}
%    We maintain a boolean to decide if we want to fix that, by
% default we don't but if any placement option is given we apply the fix.
%    \begin{macrocode}
\newif\ifFN@fixskip      \FN@fixskipfalse
%    \end{macrocode}
%  \end{macro}
%
% \subsection{The footnote/float placement options}
%
% We have up to three blocks on a page (four if you count
% top-floats but they don't matter here). If there is any excess space that needs to be added the
% question is where that goes:
% \begin{enumerate}
% \item above footnotes and floats;
% \item between footnotes and floats;
% \item after footnotes and floats;
% \item nowhere in particular (everything is equally spaced out if
% \cs{flushbottom} is in force and close together otherwise).
% \end{enumerate}
%  We handle that with a 3-way switch differenciating the different
% bottom cases: \texttt{bottom}, \texttt{bottomfloats} or neither of
% the two options. Within those with split the coding based on whether
% or not \texttt{abovefloats} was given (explicitly or implicitly).

%
% \begin{macro}{\FN@bottomcases}
%    We record in which case we want to be in
%   \cs{FN@bottomcases}. The default is case 3 (no option).
%    \begin{macrocode}
\let\FN@bottomcases\thr@@
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{The \texttt{abovefloats}, \texttt{belowfloats} options}
%
% \begin{macro}{\ifFN@abovefloats}
%    All this needs to do is to set a flag to say that it should happen.
%    \begin{macrocode}
\newif\ifFN@abovefloats  \FN@abovefloatstrue
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{The \texttt{bottom} option}
%
%  \begin{macro}{\ds@bottom}
%  The \texttt{bottom} option implements case 1 and puts the footnotes
%  by default below the floats.
%    \begin{macrocode}
\DeclareOption{bottom}{%
  \let\FN@bottomcases\@ne
  \FN@abovefloatsfalse
%    \end{macrocode}
%    We also state that we want to fix \LaTeX{} space issue (as we do
%    in all other options.
%    \begin{macrocode}
  \FN@fixskiptrue
}
%    \end{macrocode}
%  \end{macro}
%
%
% \subsubsection{The \texttt{bottomfloats} option}
%
% \begin{macro}{ds@bottomfloats}
%    This option is for case 2. By default the footnotes are above
%    (close to the text).
%    \begin{macrocode}
\DeclareOption{bottomfloats}{%
  \let\FN@bottomcases\tw@
  \FN@abovefloatstrue \FN@fixskiptrue
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{ds@abovefloats,ds@belowfloats}
%    These options change the order and that's it. The important
%    aspect is that they are declared after the last two, otherwise
%    they can't overwrite them.
%    \begin{macrocode}
\DeclareOption{abovefloats}{\FN@abovefloatstrue  \FN@fixskiptrue}
\DeclareOption{belowfloats}{\FN@abovefloatsfalse \FN@fixskiptrue}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{The \texttt{marginal} option}
%
% Again, the processing of the option is pretty trivial:
%    \begin{macrocode}
\DeclareOption{marginal}{%
  \footnotemargin-0.8em\relax
}
%    \end{macrocode}
%
% \subsection{The \texttt{flushmargin} option}
%
% Again, the processing of the option is pretty trivial:
%    \begin{macrocode}
\DeclareOption{flushmargin}{%
  \footnotemargin0pt\relax
}
%    \end{macrocode}
%
% \subsection{The \texttt{hang} option}
%
% \begin{macro}{\ifFN@hangfoot}
% We need a switch, since \cs{@makefntext} needs to be patched.
%    \begin{macrocode}
\newif\ifFN@hangfoot  \FN@hangfootfalse
\DeclareOption{hang}{%
  \FN@hangfoottrue
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\hangfootparskip}
% \begin{macro}{\hangfootparindent}
% Layout parameters for hanging footnotes; \cs{hangfootparskip} and
% \cs{hangfootparindent} are (respectively) values to use for
% \cs{parskip} and \cs{parindent} when in hanging footnotes.
%    \begin{macrocode}
\newcommand*\hangfootparskip{0.5\baselineskip}
\newcommand*\hangfootparindent{0em}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{The \texttt{norule} option}
%
% Pretty simple too\dots
%
%    \begin{macrocode}
\DeclareOption{norule}{%
  \renewcommand\footnoterule{}%
  \advance\skip\footins 4\p@\@plus2\p@\relax
}
%    \end{macrocode}
%
% \subsection{The \texttt{splitrule} option}
%
% \begin{macro}{\split@prev}
% This is from a posting by Donald Arseneau dated 13 November 1996.
% The code relies on the fact that \LaTeX{} only uses inserts for
% footnotes, so that if any insert is going to be split, it's going to
% be a footnote.
%    \begin{macrocode}
\DeclareOption{splitrule}{%
  \gdef\split@prev{0}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\pagefootnoterule}
% \begin{macro}{\mpfootnoterule}
% \begin{macro}{\splitfootnoterule}
% Define defaults for the three footnote rules: note, we inherit the
% current state of \cs{footnoterule} for the two `regular' footnote
% defaults, and if we've been preceded by option \texttt{norule}, they
% will both become null\dots
%    \begin{macrocode}
  \let\pagefootnoterule\footnoterule
  \let\mpfootnoterule\footnoterule
  \def\splitfootnoterule{\kern-3\p@ \hrule \kern2.6\p@}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% Now redefine \cs{footnoterule} to distinguish the three situations.
%    \begin{macrocode}
  \def\footnoterule{\relax
    \ifx \@listdepth\@mplistdepth
%    \end{macrocode}
%
% In a minipage
%    \begin{macrocode}
      \mpfootnoterule 
    \else
      \ifnum\split@prev=\z@
%    \end{macrocode}
%
% Normal footnote on a regular page
%    \begin{macrocode}
        \pagefootnoterule
      \else
%    \end{macrocode}
%
% Second part of a split footnote 
%    \begin{macrocode}
        \splitfootnoterule
      \fi 
%    \end{macrocode}
%
% Remember a split for next page
%    \begin{macrocode}
      \xdef\split@prev{\the\insertpenalties}%
    \fi
  }%
}
%    \end{macrocode}
%
% \begin{macro}{\ifFN@stablefootnote}
% \subsection{The \texttt{stable} option}
%
% Simply set a flag: the code of this gets executed at the very end of
% the package.
%    \begin{macrocode}
\newif\ifFN@stablefootnote  \FN@stablefootnotefalse
\DeclareOption{stable}{\FN@stablefootnotetrue}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \texttt{multiple} option}
%
% \begin{macro}{\ifFN@multiplefootnote}
% Again, simply set a flag, for code that gets executed at the very
% very very end of the package.
%    \begin{macrocode}
\newif\ifFN@multiplefootnote  \FN@multiplefootnotefalse
\DeclareOption{multiple}{\FN@multiplefootnotetrue}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The start of the endgame}
%
% Exercise the options that the user has requested\dots
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
%
% \section{Hacking kernel commands}
%
% Various standard commands (some of them internal ones) need to be
% hacked to achieve our effects, and we do all of this now, according
% to flags set in option processing.
%
% \subsection{The output routine part}
%
%    We interface with \cs{@makecol} from the kernel. Eventually this
%    should move directly into the kernel.
%
%    In order for other packages to prepend or append code to
%    \cs{@makecol}, they can use the generic command hooks
%    \texttt{cmd/@makecol/before} and \texttt{cmd/@makecol/after}, so
%    there is nothing we need to do here.
%
%
%
%  \begin{macro}{\@makecol}
%    \cs{@makecol} is shortened a lot, basically all the hardwired
%    code in the middle has moved into a configuration point.
%    \begin{macrocode}
\def \@makecol {%
  \@kernel@before@cclv
  \setbox\@outputbox \box\@cclv
%    \end{macrocode}
%    The only real addition is the next command which either does
%    nothing or removes an infinite glue from the bottom of the
%    \cs{@outputbox}.
%    \begin{macrocode}
  \@outputbox@removebskip
%    \end{macrocode}
%    Any ``here'' floats in the \cs{@outputbox} are now handled so we
%    recycle their registers and put them back to the \cs{@freelist}.
%    \begin{macrocode}
  \let\@elt\relax
  \xdef\@freelist{\@freelist\@midlist}%
  \global \let \@midlist \@empty
%    \end{macrocode}
%    Here we have the configurable part.
% \fmi{Interface to configuration points will change in the future}
%    \begin{macrocode}
  \@makecol@appendblocks 
%    \end{macrocode}
%    The we deal with any \cs{enlargethispage} or run the normal code
%    to build a column.
%    \begin{macrocode}
  \ifvbox\@kludgeins
     \@makespecialcolbox
  \else
     \@makenormalcolbox
  \fi
  \global \maxdepth \@maxdepth
}
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\@outputbox@depth}
%    We need to know the depth of \cs{@outputbox} once in a
%    while. Rather than using a temp dimen (as it was done in the
%    past), we give it a proper register.
%    \begin{macrocode}
\newdimen\@outputbox@depth
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\@makenormalcolbox}
%    Taken out of \cs{@makecol} for readability.
%    \begin{macrocode}
\def \@makenormalcolbox {%
   \setbox\@outputbox \vbox to\@colht {%
       \@texttop
       \@outputbox@depth \dp\@outputbox
       \unvbox \@outputbox
       \vskip -\@outputbox@depth
       \@textbottom
      }%
}
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\@makespecialcolbox}
%    Make the colbox when \cs{enlargethispage} was used.
%    \begin{macrocode}
\def \@makespecialcolbox {%
   \@outputbox@append {\vskip-\@outputbox@depth}%
   \@tempdima \@colht
   \ifdim \wd\@kludgeins>\z@
     \advance \@tempdima -\ht\@outputbox
     \advance \@tempdima \pageshrink
     \setbox\@outputbox \vbox to \@colht {%
       \unvbox\@outputbox
       \vskip \@tempdima
       \@textbottom
       }%
   \else
     \advance \@tempdima -\ht\@kludgeins
     \setbox \@outputbox \vbox to \@colht {%
       \vbox to \@tempdima {%
         \unvbox\@outputbox
         \@textbottom}%
       \vss}%
   \fi
   {\setbox \@tempboxa \box \@kludgeins}%
}
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\@outputbox@removebskip}
%    
%    This is really a bug fix for the kernel, but perhaps one has to
%    make it optional because it is in there since day one). If
%    \cs{raggedbottom} is in force, footnotes get attached to the main
%    galley at a distance of \cs{footskip} on all pages except on
%    those that are ended by \cs{newpage} or \cs{clearpage} where the
%    \cs{vfil} from \cs{newpage} pushes the footnotes to the very bottom.
%
%    This is kind of a weird difference to a page  ending with
%    \cs{pagebreak}---in that case the page is also run
%    short, but the footnotes are not pushed to the bottom.
%
%    This is fixed by \cs{@outputbox@removebskip} but only if the
%    switch \texttt{FN@fixskip} is set to true (which is done whenever
%    \pkg{footmisc} is called with with an option specifying the
%    footnote placement, i.e., not  in the default case).
%    \begin{macrocode}
\ifFN@fixskip
  \def\@outputbox@removebskip{%
%    \end{macrocode}
%    We first test if we are in a \cs{raggedbottom} layout. If not we
%    do nothing, but we don't disable the code because
%    \cs{raggedbottom} may get used only for some parts of the
%    document.
%    \begin{macrocode}
    \ifx\@textbottom\relax \else
%    \end{macrocode}
%    We then append some negative glue at the end of \cs{@outputbox}
%    provided it has a glue stretch order of 1 or more (i.e., contains
%    a \texttt{fil} or \texttt{fill} part).
%    \begin{macrocode}
      \@outputbox@append{%
        \@tempskipa\lastskip
        \ifnum \gluestretchorder\@tempskipa>\z@
          \vskip-\@tempskipa
%    \end{macrocode}
%  \begin{macro}{\@outputbox@reinsertbskip}
%    We also record the value so that it can be reinserted
%    elsewhere. As we have to do this globally, we also need to
%    explicitly reset it if we don't find any such glue.
%    \begin{macrocode}
          \xdef\@outputbox@reinsertbskip
              {\noexpand\@outputbox@append{\vskip\the\@tempskipa}}%
        \else
          \global\let\@outputbox@reinsertbskip\relax
        \fi
      }%
   \fi
  }
%    \end{macrocode}
%    We need a trivial top-level definition for
%    \cs{@outputbox@reinsertbskip} in case the first page has no
%    bottom glue and the command gets called.
%    \begin{macrocode}
\let\@outputbox@reinsertbskip\relax
%    \end{macrocode}
%    If nothing should get fixed we set both commands to \cs{relax}.
%    \begin{macrocode}
\else
  \let\@outputbox@removebskip \relax
  \let\@outputbox@reinsertbskip\relax
\fi
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%
%  \begin{macro}{\@kernel@before@cclv}
%  \begin{macro}{\@kernel@before@footins}
%    These two commands are internal kernel hooks intended for tagging
%    support in case that is active. By default they do nothing (and
%    may have been defined already by \cs{DocumentMetadata}).
%    \begin{macrocode}
\providecommand\@kernel@before@cclv{}
\providecommand\@kernel@before@footins{}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%
%
%
% \subsection{The output routine configuration components}
%
%    Here we provide the components that are used to define
%    \cs{@makecol@appendblocks}.
%
%
%  \begin{macro}{@outputbox@append}
%
%    This general purpose command alters the \cs{@outputbox} box by
%    appending material to it. As this is a box typesetting operation
%    we make sure that the last line of the box reflects the true
%    depth of the last line (in case that is needed later). We also
%    expose the current depth of \cs{@outputbox} as
%    \cs{@outputbox@depth} before unboxing so that its value can be
%    used by \verb=#1= if wanted.
%    \begin{macrocode}
\def\@outputbox@append #1{%
     \setbox\@outputbox \vbox {%
       \boxmaxdepth \@maxdepth
       \@outputbox@depth\dp\@outputbox      % if needed in #1
       \unvbox \@outputbox
       #1%
     }%
}
%    \end{macrocode}
%  \end{macro}
%
%
%
%  \begin{macro}{\@outputbox@appendfootnotes}
%
%    This command appends the footnotes to the \cs{@outputbox} (if
%    there are any). If not then it does nothing.
%    \begin{macrocode}
\def\@outputbox@appendfootnotes {%
   \ifvoid\footins \else
%    \end{macrocode}
%    First come two configuration points: what to do if we are in a split
%    footnote situation and a second one that does some manipulation
%    of the \cs{footins} box before it gets appended.
% \fmi{this code will get revised as part of CP handling  in the future}
%    \begin{macrocode}
     \@makecol@handlesplitfootnotes
     \@makecol@preparefootinshook
%    \end{macrocode}
%    Then the footnotes are appended:
%    \begin{macrocode}
     \@outputbox@append{%
       \vskip \skip\footins
       \@kernel@before@footins
       \color@begingroup
         \normalcolor
         \footnoterule
%    \end{macrocode}
%    Support for \pkg{pdfcolfoot}, eventually this can go once color
%    is properly supported.
%    \begin{macrocode}
         \csname pdfcolfoot@current\endcsname
         \unvbox \footins
       \color@endgroup
      }%
  \fi
}
%    \end{macrocode}
%  \end{macro}
%
%
%
%  \begin{macro}{\@outputbox@attachfloats}
%  \begin{macro}{\@outputbox@attachtopfloats}
%  \begin{macro}{\@outputbox@attachbottomfloats}
%    Attaching top and bottom floats can usually be done in one go,
%    but for special layouts we might want more control so we provide
%    also separate commands.
%    \begin{macrocode}
\let \@outputbox@attachfloats \@combinefloats
%    \end{macrocode}
%    
%    \begin{macrocode}
\def \@outputbox@attachtopfloats {%
  \ifx \@toplist\@empty \else \@cflt \fi
}  
\def \@outputbox@attachbottomfloats {%
    \ifx \@botlist\@empty \else \@cflb \fi
}  
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%
%
%
%  \begin{macro}{\@makecol@handlesplitfootnotes}
%  \begin{macro}{\@makecol@splitfootnotemessagehook}
%    This is only an early draft and doesn't do much.
%    Contains  incomplete preparation for tagging commented out.
% \fmi{Interfaces and code will change in the future}
%    \begin{macrocode}
\def\@makecol@handlesplitfootnotes {%
%  \ifx\splitfootnote@continuation\@empty \else
%    \setbox\footins\vbox{\splitfootnote@continuation\unvbox\footins}%
%    \global\let\splitfootnote@continuation\@empty
%  \fi
  \ifnum\insertpenalties>\z@
    \@makecol@splitfootnotemessagehook
%    \setbox\footins\vbox{\unvbox\footins --- END at split}%
%    \gdef\splitfootnote@continuation    {--- START after split}%
  \fi
}
%\def\splitfootnote@continuation{}
%    \end{macrocode}
%    This  could issue warning if split footnotes are encountered.
%    \begin{macrocode}
\let \@makecol@splitfootnotemessagehook \@empty
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%
%
%  \begin{macro}{\@makecol@preparefootinshook}
%    
%    Configuration point to support manipulation of footins box
%    (result needs to be moved back in there). Used by the
%    \texttt{para} option.
% \fmi{Interface will change in the future}
%    \begin{macrocode}
\let \@makecol@preparefootinshook \@empty
%    \end{macrocode}
%
%    Footnote box layout for para footnotes;
%    this would also be the hook to support dblfootnotes (from the
%    \texttt{dblfnote} package if we integrate that).
%    \begin{macrocode}
\ifFN@para
  \def\@makecol@preparefootinshook {%
     \global\setbox\footins\vbox{\FN@makefootnoteparagraph}%
    }
\fi
%    \end{macrocode}
%  \end{macro}
%
% \fmi{Some temp interfaces until configuration points are available.}
%
%  \begin{macro}{\@if@flushbottom@TF}
%    Test for \cs{flushbottom} (currently not used).
%    \begin{macrocode}
\def\@if@flushbottom@TF{%
  \ifx\@textbottom\relax
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\@if@footnotes@TF}
%    Test if footnotes are present on the current page.
%    \begin{macrocode}
\def\@if@footnotes@TF{%
  \ifvoid\footins
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi
}
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\@if@bfloats@TF}
%    Test if bottom floats are around.
%    \begin{macrocode}
\def\@if@bfloats@TF{%
  \ifx \@botlist\@empty
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi
}
%    \end{macrocode}
%  \end{macro}
%
%
%
%
% \subsection{The \cs{@makecol} configuration based on options}
%
%
%    Placement of footnotes in relation to main galley and floats is
%    covered by the value of \cs{FN@bottomcases} (type of bottom option)
%    and the status of the switch \texttt{@abovefloats}.
%
%    \begin{macrocode}
\ifcase \FN@bottomcases\relax
%---------------------------------------------------------
% 0 = undefined
%---------------------------------------------------------
\ERROR
\or
%---------------------------------------------------------
% 1 = bottom option given
%---------------------------------------------------------
%    \end{macrocode}
%    All excess space are above the footnote and bottom float
%    blocks. The order of the blocks depend on \texttt{@abovefloats}:
%    \begin{macrocode}
  \ifFN@abovefloats
%---------------------------------------------------------
%    \end{macrocode}
%    If footnotes above floats floats both are at the bottom:
%    \begin{macrocode}
    \def\@makecol@appendblocks {%
       \@if@footnotes@TF
          {\@outputbox@append{\vfill}}%
          {\@if@bfloats@TF{\@outputbox@append{\vfill}}%
                          {\@outputbox@reinsertbskip}}%
       \@outputbox@appendfootnotes
       \@outputbox@attachfloats
      }
%---------------------------------------------------------
  \else
%    \end{macrocode}
%    Otherwise only the footnotes are at the very bottom and floats
%    stay close to the text:
%    \begin{macrocode}
    \def\@makecol@appendblocks {%
       \@outputbox@attachfloats
       \@if@footnotes@TF
          {\@outputbox@append{\vfill}}%
          {\@outputbox@reinsertbskip}%
       \@outputbox@appendfootnotes
    }
  \fi
\or
%---------------------------------------------------------
% 2 = bottomfloats option given
%---------------------------------------------------------
  \ifFN@abovefloats
%---------------------------------------------------------
%    \end{macrocode}
%    Footnotes first then space then floats at bottom:
%    \begin{macrocode}
     \def\@makecol@appendblocks {%
        \@outputbox@appendfootnotes
        \@if@bfloats@TF
            {\@outputbox@append{\vfill}}%
            {\@outputbox@reinsertbskip}%
        \@outputbox@attachfloats
     }
%---------------------------------------------------------
  \else
%    \end{macrocode}
%    If \texttt{belowfloats} was given too, then the excess space ends
%    up directly below the text 
%    \begin{macrocode}
     \def\@makecol@appendblocks {%
       \@if@footnotes@TF
          {\@outputbox@append{\vfill}}%
          {\@if@bfloats@TF{\@outputbox@append{\vfill}}%
                          {\@outputbox@reinsertbskip}}%
        \@outputbox@attachfloats
        \@outputbox@appendfootnotes
     }
%---------------------------------------------------------
  \fi
\or
%---------------------------------------------------------
% 3 = neither bottom nor bottomfloats given
%---------------------------------------------------------
%    \end{macrocode}
%    In this case any excess space distribution is handled by
%    \cs{raggedbottom} or \cs{flushbottom} settings. In case of
%    \cs{raggedbottom} it goes to the bottom but we don't append
%    \cs{vfill} there. Instead we make use of the fact that
%    \cs{raggedbottom} already puts a stretchable space there, and if
%    we are in a \cs{flushbottom} scenario then any excess space is
%    supposed to be distributed across the whole page.
%    \begin{macrocode}
  \ifFN@abovefloats
%---------------------------------------------------------
    \def\@makecol@appendblocks {%
       \@outputbox@appendfootnotes
       \@outputbox@attachfloats
%    \end{macrocode}
%    We do, however, reinsert the bottom skip from \cs{newpage} if it
%    was taken out earlier. This is, strictly speaking, not necessary
%    in most cases, but it is a \cs{vfil} while \cs{raggedbottom} is
%    only generating \verb=\vspace{0pt plus .0001fil}=, so if you have
%    several \cs{vfil} on the page before the \cs{newpage} you would
%    alter the space distribution if one is taken out.
%    \begin{macrocode}
       \@outputbox@reinsertbskip
    }
  \else
%---------------------------------------------------------
%    \end{macrocode}
%    Same thing but with blocks swapped.
%    \begin{macrocode}
    \def\@makecol@appendblocks {%
       \@outputbox@attachfloats
       \@outputbox@appendfootnotes
       \@outputbox@reinsertbskip
}
%---------------------------------------------------------
  \fi
\else
%---------------------------------------------------------
% 3 > undefined
%---------------------------------------------------------
%    \end{macrocode}
%    The \cs{ERROR} here and above should never execute, like ``This
%    can't happen'' in the \TeX{} program code. If they execute then code
%    is badly broken.
%    \begin{macrocode}
\ERROR
\fi

%    \end{macrocode}
%
%
% \subsection{The requirements of \cs{@footnotetext}}
%
% Instead of (re)defining \cs{@footnotetext} we define
% \cs{FN@footnotetext} and at the end we check what we do with it,
% depending on whether or not \texttt{hyperref} was loaded.
%
% \begin{macro}{\ifFN@baselinestretch}
% \begin{macro}{\FN@singlespace}
% Whatever we do, we are going to patch \cs{@footnotetext}; so first
% of all, we'll check it's not been hacked by anyone other than
% \texttt{setspace.sty} (while we're at it we also record whether
% \texttt{setspace} is loaded).
% so we do this here:
%    \begin{macrocode}
\newif\ifFN@setspace
\@ifpackageloaded{setspace}{%
  \FN@setspacetrue
  \@ifclassloaded{memoir}{%
%    \end{macrocode}
% we're seeing \textsf{memoir}'s emulation of \textsf{setspace}
%    \begin{macrocode}
    \let\FN@baselinestretch\m@m@singlespace
  }{%
%    \end{macrocode}
% we're seeing \textsf{setspace} in its own right
%    \begin{macrocode}
    \let\FN@baselinestretch\setspace@singlespace
  }%
}{%
  \FN@setspacefalse
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% There's substantial patching to be done if we're doing paragraph
% footnotes:
%    \begin{macrocode}
\ifFN@para
  \long\def\FN@footnotetext#1{%
    \insert\footins{%
%    \end{macrocode}
% insert compatibility code with |setspace.sty| if necessary
%    \begin{macrocode}
      \ifFN@setspace
        \let\baselinestretch\FN@baselinestretch
      \fi
      \reset@font\footnotesize
      \interlinepenalty\interfootnotelinepenalty
      \splittopskip\footnotesep
      \splitmaxdepth \dp\strutbox
      \floatingpenalty\@MM 
      \hsize\columnwidth
      \@parboxrestore
      \protected@edef\@currentlabel{\csname p@footnote\endcsname\@thefnmark}%
      \color@begingroup
%    \end{macrocode}
%
% We set the paragraph in an \cs{hbox} and apply the fudge factor
% here (these days done with e\TeX{} methods):
%
%    \begin{macrocode}
        \setbox\FN@tempboxa\hbox{%
%    \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{\ignorespaces#1\strut
%    \end{macrocode}
%
% We insert a penalty here to help line breaking in the
% footnote paragraph; the value is taken from the \TeX{}book.
%
%    \begin{macrocode}
            \penalty-10\relax
            \hskip\footglue
          }% end of \@makefntext parameter
        }% end of \hbox
        \dp\FN@tempboxa\z@
        \ht\FN@tempboxa\dimexpr\wd\FN@tempboxa *%
                        \footnotebaselineskip / \columnwidth\relax
        \box\FN@tempboxa
      \color@endgroup
    }%
    \FN@mf@prepare
  }
%    \end{macrocode}
%
% If we're not doing paragraph footnotes, we now simply tag a
% \cs{FN@mf@prepare} command on the end of the definition; of course,
% there are different definitions according as whether we're using
% |side| footnotes\dots
%    \begin{macrocode}
\else
  \ifFN@sidefn
    \long\def\FN@footnotetext#1{%
      \marginpar{%
%    \end{macrocode}
% insert compatibility code with |setspace.sty| if necessary
%    \begin{macrocode}
        \ifFN@setspace
          \let\baselinestretch\FN@baselinestretch
        \fi
        \reset@font\footnotesize
        \protected@edef\@currentlabel{%
          \csname p@footnote\endcsname\@thefnmark
        }%
        \color@begingroup
          \@makefntext{%
            \ignorespaces#1%
          }%
        \color@endgroup
      }%
      \FN@mf@prepare
    }%
  \else
    \long\def\FN@footnotetext#1{%
      \insert\footins{%
%    \end{macrocode}
% insert compatibility code with \textsf{setspace} if necessary
%    \begin{macrocode}
        \ifFN@setspace
          \let\baselinestretch\FN@baselinestretch
        \fi
        \reset@font\footnotesize
        \interlinepenalty\interfootnotelinepenalty
        \splittopskip\footnotesep
        \splitmaxdepth \dp\strutbox
        \floatingpenalty\@MM 
        \hsize\columnwidth
        \@parboxrestore
        \protected@edef\@currentlabel{%
          \csname p@footnote\endcsname\@thefnmark
        }%
        \color@begingroup
          \@makefntext{%
            \rule\z@\footnotesep
            \ignorespaces#1\@finalstrut\strutbox
          }%
        \color@endgroup
      }%
      \FN@mf@prepare
    }%
  \fi
\fi
%    \end{macrocode}
%
%
%
%
%
% \subsection{Support code for paragraph footnotes}
%
% This code used (most inefficiently) to be in the argument of the
% \cs{DeclareOption}; this no doubt comes of that code having been
% written over Christmas 1993\dots
%
% Now all executed under the |para| conditional set in the option
% declaration.
%    \begin{macrocode}
\ifFN@para
%    \end{macrocode}
%
% \begin{macro}{\FN@tempboxa}
% \begin{macro}{\FN@tempboxb}
% \begin{macro}{\FN@tempboxb}
% We need some temporary boxes, and \LaTeX{} only defines one
%    \begin{macrocode}
  \let\FN@tempboxa\@tempboxa
  \newbox\FN@tempboxb
  \newbox\FN@tempboxc
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\footglue}
% A direct crib from the \TeX{}book:
%    \begin{macrocode}
  \newskip\footglue \footglue=1em plus.3em minus.3em
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@makefntext}
% 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).
% Note that the \cs{leavevmode} isn't necessary except in the case of
% footnotes in minipages, which otherwise end up with the
% \cs{@makefnmark} being executed in restricted vertical mode, which
% results in its \cs{hbox} ending up in a line of its own.
%
%    \begin{macrocode}
  \long\def\@makefntext#1{\leavevmode
    \@makefnmark\nobreak
    \hskip.5em\relax#1%
  }
%    \end{macrocode}
% \end{macro}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \begin{macro}{\footnotebaselineskip}
% We need to record a value for the baseline skip when in footnotes:
%    \begin{macrocode}
  \newdimen\footnotebaselineskip
  {%
    \footnotesize
    \global
      \footnotebaselineskip=\normalbaselineskip
  }
%    \end{macrocode}
% \end{macro}
%
%
 
% \begin{macro}{\FN@makefootnoteparagraph}
% For use in the output routine
%    \begin{macrocode}
  \long\def\FN@makefootnoteparagraph{\unvbox\footins \FN@makehboxofhboxes
    \setbox\FN@tempboxa=\hbox{\unhbox\FN@tempboxa \FN@removehboxes}%
%    \end{macrocode}
% Now we are ready to set the paragraph:
%    \begin{macrocode}
    \FN@setfootnoteparawidth
    \@parboxrestore
    \baselineskip=\footnotebaselineskip
    \noindent
    \rule{\z@}{\footnotesep}%
    \unhbox\FN@tempboxa\par
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\FN@makehboxofhboxes}
% \begin{macro}{\FN@removehboxes}
% Support code for \cs{FN@makefootnoteparagraph}
%    \begin{macrocode}
  \def\FN@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\FN@removehboxes{\setbox\FN@tempboxa=\lastbox
    \ifhbox
      \FN@tempboxa{\FN@removehboxes}%
      \unhbox\FN@tempboxa
    \fi
  }
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%
%
%
%  \begin{macro}{\FN@setfootnoteparawidth}
%    What we have to use as the width for the footnote paragraph
%   depends on whether or not we typeset in several columns. If single
%   column or normal two-column is used then the right value is
%   \cs{columnwidth}. However, inside a \texttt{multicols} environment
%   we need to use \cs{textwidth} as the footnotes there will span
%   across all columns.
%
%   To detect if we are inside such an environment we look at
%   \cs{doublecolnumber} which is only positive if inside such an
%   environment.
%    \begin{macrocode}
\@ifpackageloaded{multicol}
  {\def\FN@setfootnoteparawidth
    {\hsize\ifnum\doublecol@number>\@ne
                  \textwidth
            \else \columnwidth \fi}}
  {\def\FN@setfootnoteparawidth{\hsize\columnwidth}}
%    \end{macrocode}
% \end{macro}
%
%
%
%
%
% \subsection{The other footnote commands}\label{sec:perpage-code}
%
%
%   We delegate the perpage option to a different package \ldots
%    \begin{macrocode}
\ifFN@perpage
  \RequirePackage{perpage}
  \MakePerPage{footnote}
%    \end{macrocode}
%    Unfortunately \pkg{perpage} has a bug and doesn't handle founters
%    correctly which are part of a reset list of another counter,
%    e.g., it doesn't work correctly if you use the report class which
%    resets footnotes at each chapter start. As a result the first
%    footnote on the first page of a chapter starts with 2. We
%    therefore alter one \LaTeX{} internal if \pkg{perpage} is in use:
% \changes{v6.0c}{2022/03/07}{Fix an issue in perpage package (gh/03)}
% \changes{v6.0d}{2022/03/07}{Also support optional arg of \cs{MakePerPage} (gh/03)}
%    \begin{macrocode}
  \def\@stpelt#1{\global\csname c@#1\endcsname \m@ne
    \stepcounter{#1}%
    \pp@fix@MakePerPage{#1}%
  }
  \def\pp@fix@MakePerPage#1{%
      \ifnum \value{#1}>\z@
        \addtocounter{#1}\m@ne\fi
  }
%    \end{macrocode}
%    The above code may look a bit odd: the \cs{stepcounter} sets the
%    counter to zero and then we alter it if it is not zero.  The
%    reason is that \cs{stepcounter} resets other counters and when
%    perpage is loaded this results in updating counters on the reset
%    list to 1 (or to a higher starting value if \cs{MakePerPage} is
%    used with an optional argument, which is precisely the problem
%    here. By subtracting 1 in that case we set it back to 1 lower
%    than the starting value.
%
%    But to make this fully work we also need to update a support
%    command in \pkg{perpage}:
%    \begin{macrocode}
  \def\pp@cl@end@iii\stepcounter#1\pp@fix@MakePerPage#2{}
%    \end{macrocode}
%
%    \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}, to impose \cs{footnotelayout}, and to make the
% footnote body text hang, if appropriate.
%    \begin{macrocode}
\ifFN@para
\else
%    \end{macrocode}
%
% hanging footnote version:
%    \begin{macrocode}
  \long\def\@makefntext#1{%
    \ifFN@hangfoot
      \bgroup
%    \end{macrocode}
%
% get the marker so we can measure it:
%    \begin{macrocode}
      \setbox\@tempboxa\hbox{%
        \ifdim\footnotemargin>0pt
          \hb@xt@\footnotemargin{\@makefnmark\hss}%
        \else
          \@makefnmark
        \fi
      }%
%    \end{macrocode}
%
% use the width of the box to set up hanging (potentially for more
% than one paragraph); note that the hanging \cs{parskip} and
% \cs{parindent} are set \emph{after} we've executed \cs{leavevmode}(!)
%    \begin{macrocode}
      \leftmargin\wd\@tempboxa
      \rightmargin\z@
      \linewidth \columnwidth
      \advance \linewidth -\leftmargin
      \parshape \@ne \leftmargin \linewidth
      \footnotesize
%    \end{macrocode}
%
% stop the \cs{parshape} being overwritten:
%    \begin{macrocode}
      \@setpar{{\@@par}}%
%    \end{macrocode}
%
% and finally put the marker in its chosen place:
%    \begin{macrocode}
      \leavevmode
      \llap{\box\@tempboxa}%
      \parskip\hangfootparskip\relax
      \parindent\hangfootparindent\relax
    \else
%    \end{macrocode}
%
% ordinary (non-hanging) footnote version:
%    \begin{macrocode}
      \parindent1em
      \noindent
      \ifdim\footnotemargin>\z@
        \hb@xt@ \footnotemargin{\hss\@makefnmark}%
      \else
        \ifdim\footnotemargin=\z@
          \llap{\@makefnmark}%
        \else
          \llap{\hb@xt@ -\footnotemargin{\@makefnmark\hss}}%
        \fi
      \fi
    \fi
    \footnotelayout#1%
%    \end{macrocode}
%
% if we're hanging, close the hang group
%    \begin{macrocode}
    \ifFN@hangfoot
      \par\egroup
    \fi
  }
\fi
%    \end{macrocode}
%
% \section{Remaining requirements}
%
% We have to insert the code that executes the \texttt{stable} and
% \texttt{multiple} options.  Since \texttt{stable} may suppress the
% setting of a footnote altogether, we put the \texttt{multiple}
% option first, as otherwise we might get isolated superscripted
% commas that separate footnotes that have otherwise been suppressed.
%
% \subsection{The code that executes the \texttt{multiple} option}
%
% \begin{macro}{\multiplefootnotemarker}
% \begin{macro}{\multfootsep}
% \begin{macro}{\FN@footnotemark}
% \begin{macro}{\FN@mf@prepare}
% \begin{macro}{\FN@mf@check}
% This (revised) code derives from a suggestion by Alexander Rozhenko
% (the author of the \textit{manyfoot} package): the intention is that
% \textit{footmisc} and \textit{manyfoot} should be able to
% `interwork', in the sense that each would recognize the other's
% footnote marks and behave appropriately.  The trick is that
% both \cs{footnote}  and \cs{footnotemark} insert a marker (a
% cancelling pair of kerns of \cs{multiplefootnotemarker} (of opposite
% signs), which is detected in following \cs{footnote} or
% \cs{footnotemark} commands.  Note we have to take special
% precautions to ensure that the kerns are the last things added to
% the horizontal list by the commands.
%    \begin{macrocode}
\ifFN@multiplefootnote
  \providecommand*{\multiplefootnotemarker}{3sp}
  \providecommand*{\multfootsep}{,}
%
% FMi: not checking, more harm than gain  
%  \CheckCommand*\@footnotemark{%
%    \leavevmode
%    \ifhmode\edef\@x@sf{\the\spacefactor}\nobreak\fi
%    \@makefnmark
%    \ifhmode\spacefactor\@x@sf\fi
%    \relax
%  }
%
  \newcommand*\FN@footnotemark{%
    \leavevmode
    \ifhmode
      \edef\@x@sf{\the\spacefactor}%
      \FN@mf@check
      \nobreak
    \fi
    \@makefnmark
    \FN@mf@prepare
    \ifhmode\spacefactor\@x@sf\fi
    \relax
  }
  \def\FN@mf@prepare{%
    \kern-\multiplefootnotemarker
    \kern\multiplefootnotemarker\relax
  }
  \def\FN@mf@check{%
    \ifdim\lastkern=\multiplefootnotemarker\relax
      \edef\@x@sf{\the\spacefactor}%
      \unkern
      \textsuperscript{\multfootsep}%
      \spacefactor\@x@sf\relax
    \fi
  }
%    \end{macrocode}
%
% If we're not doing multiple, just create an empty \cs{FN@mf@prepare}
%    \begin{macrocode}
\else
  \let\FN@mf@prepare\relax
%    \end{macrocode}
%    Need to provide a definition for \cs{FN@footnotemark} in that case.
%    \begin{macrocode}
  \let\FN@footnotemark\@footnotemark
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{The code that executes the \texttt{stable} option}
%
% \begin{macro}{\ifFN@stablefootnote}
% \begin{macro}{\FN@sf@@footnote}
% The basic idea is to use the `original' code of \cs{footnote} (which
% this package may have hacked around something chronic) only if we're
% in typesetting mode (as determined by the state of the \cs{protect}
% command.  Otherwise, the command becomes an elaborate multistage
% `gobble'.
%    \begin{macrocode}
\ifFN@stablefootnote
\let\FN@sf@@footnote\footnote
\def\footnote{\ifx\protect\@typeset@protect
    \expandafter\FN@sf@@footnote
  \else
    \expandafter\FN@sf@gobble@opt
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\FN@sf@gobble@opt}
% \begin{macro}{\FN@sf@gobble@twobracket}
% Define \cs{FN@sf@gobble@opt} as a robust command that gobbles either
% an optional and a mandatory argument, or just a mandatory one.
%    \begin{macrocode}
\edef\FN@sf@gobble@opt{\noexpand\protect
  \expandafter\noexpand\csname FN@sf@gobble@opt \endcsname}
\expandafter\def\csname FN@sf@gobble@opt \endcsname{%
  \@ifnextchar[%]
    \FN@sf@gobble@twobracket
    \@gobble
}
\def\FN@sf@gobble@twobracket[#1]#2{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\FN@sf@@footnotemark}
% \begin{macro}{\FN@sf@gobble@optonly}
% \begin{macro}{\FN@sf@gobble@bracket}
% Now the same for \cs{footnotemark}
%    \begin{macrocode}
\let\FN@sf@@footnotemark\footnotemark
\def\footnotemark{\ifx\protect\@typeset@protect
    \expandafter\FN@sf@@footnotemark
  \else
    \expandafter\FN@sf@gobble@optonly
  \fi
}
\edef\FN@sf@gobble@optonly{\noexpand\protect
  \expandafter\noexpand\csname FN@sf@gobble@optonly \endcsname}
\expandafter\def\csname FN@sf@gobble@optonly \endcsname{%
  \@ifnextchar[%]
    \FN@sf@gobble@bracket
    {}%
}
\def\FN@sf@gobble@bracket[#1]{}
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \section{Symbol option variants}
%
% \begin{macro}{\setfnsymbol}
% \begin{macro}{\FN@fnsymbol@lamport}
% Lamport's choice of symbols for \cs{fnsymbol} wasn't entirely
% ``traditional'', so we (now) provide alternatives.  The
% \cs{setfnsymbol} command offers a small number of choices, and the
% user may define more still, using the \cs{DefineFNsymbols} or
% \cs{DefineFNsymbolsTM} commands, defined below.
%    \begin{macrocode}
\newcommand\setfnsymbol[1]{%
  \@bsphack
  \@ifundefined{FN@fnsymbol@#1}%
  {%
    \PackageError{footmisc}{Symbol style "#1" not known}%
    \@eha
  }{%
    \expandafter\let\expandafter\@fnsymbol\csname
                        FN@fnsymbol@#1\endcsname
  }%
  \@esphack
}
%    \end{macrocode}
%
% The default selection is Lamport's original, as represented in
% current \LaTeX{}~--- we preserve it in case we need to ``get back''
% to it.
%    \begin{macrocode}
\let\FN@fnsymbol@lamport\@fnsymbol
%</package>
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\if@tempswb}
% \begin{macro}{\@tempswbfalse}
% \begin{macro}{\@tempswbtrue}
% We need another temp conditional
%    \begin{macrocode}
\newif\if@tempswb
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\DefineFNsymbols}
% \begin{macro}{\@DefineFNsymbols}
% \begin{macro}{\@DefineFNsymbols@}
% \begin{macro}{\FN@build@symboldef}
% The macro \cs{DefineFNsymbols} allows the user to define a set of
% footnote symbols, to be used with the \cs{setfnsymbol} command.
% Syntax:\par\noindent
% \cs{DefineFNsymbols}|[*]|\marg{set name}\oarg{style}\marg{symbol list}
%
% If the optional asterisk is present, the set defined will produce an
% error if the symbol number is too large; otherwise it will quietly
% change to numbering in place of symbol use (a warning is produced at
% the end of the document). The set name is the future argument of
% \cs{setfnsymbol}).  The style (default \texttt{text}) gives the style
% the symbols are typeset (this is the \emph{correct} method, but
% unfortunately not  all symbols, even for Lamport's original set for
% \LaTeX{} \cs{fnsymbol} may be expressed this way in a sufficiently
% old \LaTeX{} distribution).  The symbol list is a set of objects to
% be used when the set is selected.
%
% Example of use:\par\noindent define a direct replacement for
% Lamport's original \cs{fnsymbol} command ---
%\begin{verbatim}
%\DefineFNsymbols*{lamport}[math]{*\dagger\ddagger\mathsection
%  \mathparagraph\|{**}{\dagger\dagger}{\ddagger\ddagger}%
%}
%\end{verbatim}
% Note that doubled-up (and worse\,---\,see below) symbols need braces
% around them.
%    \begin{macrocode}
\DeclareDocumentCommand\DefineFNsymbols {smO{text}m}{%
  \expandafter\ifx\csname FN@fnsymbol@#2\endcsname\relax
    \PackageInfo{footmisc}{Declaring symbol style #2}%
  \else
    \PackageWarning{footmisc}{Redeclaring symbol style #2}%
  \fi
  \toks@{}%
  \def\@tempb{\end}%
  \FN@build@symboldef#4\end
  \def\@tempc{math}%
  \def\@tempd{#3}%
  \expandafter\xdef\csname FN@fnsymbol@#2\endcsname##1{%
    \ifx\@tempc\@tempd
      \noexpand\ensuremath
    \else
      \noexpand\nfss@text
    \fi
    {%
      \noexpand\ifcase##1%
      \the\toks@
      \noexpand\else
      \IfBooleanTF#1{\noexpand\@ctrerr}%
        {\noexpand\FN@orange##1}%
      \noexpand\fi
    }%
  }%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\FN@build@symboldef#1{%
  \def\@tempa{#1}%
  \ifx\@tempa\@tempb
  \else
    \toks@\expandafter{\the\toks@\or#1}%
    \expandafter\FN@build@symboldef
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\DefineFNsymbolsTM}
% \begin{macro}{\@DefineFNsymbolsTM}
% \begin{macro}{\FN@build@symboldefTM}
%
% Now do the same job for the ``modern'' way of having both text and
% maths variants of everything.
%    \begin{macrocode}
\DeclareDocumentCommand\DefineFNsymbolsTM {smm}{%
  \expandafter\ifx\csname FN@fnsymbol@#2\endcsname\relax
    \PackageInfo{footmisc}{Declaring symbol style #2}%
  \else
    \PackageWarning{footmisc}{Redeclaring symbol style #2}%
  \fi
  \toks@{}%
  \def\@tempb{\end}%
  \FN@build@symboldefTM#3\end\@null
  \expandafter\xdef\csname FN@fnsymbol@#2\endcsname##1{%
    \noexpand\ifcase##1%
      \the\toks@
    \noexpand\else
      \IfBooleanTF#1{\noexpand\@ctrerr}%
        {\noexpand\FN@orange##1}%
      \noexpand\fi
  }%
}
%    \end{macrocode}
% Note that this version has two variants of every definition, so
% needs two stopper codes above.
%    \begin{macrocode}
\def\FN@build@symboldefTM#1#2{%
  \def\@tempa{#1}%
  \ifx\@tempa\@tempb
  \else
    \toks@\expandafter{\the\toks@\or\TextOrMath{#1}{#2}}%
    \expandafter\FN@build@symboldefTM
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\FN@orange}
% \begin{macro}{\@fnsymbol@orange}
% \begin{macro}{\@diagnose@fnsymbol@orange}
% Macros to deal with footnote symbols going out of range (when
% they're allowed to\,--\,e.g., in the \texttt{symbol*} option).
%    \begin{macrocode}
\def\FN@orange#1{%
  \ifFN@robust
    \@arabic#1%
    \@bsphack
    \PackageInfo{footmisc}{Footnote number \number#1 out of range}%
    \protect\@fnsymbol@orange
    \@esphack
  \else \@ctrerr \fi
}
\global\let\@diagnose@fnsymbol@orange\relax
\AtEndDocument{\@diagnose@fnsymbol@orange}
\def\@fnsymbol@orange{%
  \gdef\@diagnose@fnsymbol@orange{%
    \PackageWarningNoLine{footmisc}{Some footnote number(s)
      were out of range
      \MessageBreak
      see log for details%
    }%
  }%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\FN@fnsymbol@bringhurst}
% \begin{macro}{\FN@fnsymbol@chicago}
% \begin{macro}{\FN@fnsymbol@wiley}
% \begin{macro}{\FN@fnsymbol@lamport-robust}
% \begin{macro}{\FN@fnsymbol@lamport}
% These macros provide replacement orderings (and symbol sets) for
% footnote symbols, plus a robust version of the original Lamport set,
% and an extended version of Lamport's original
%    \begin{macrocode}
\DefineFNsymbolsTM{bringhurst}{%
  \textasteriskcentered *%
  \textdagger    \dagger
  \textdaggerdbl \ddagger
  \textsection   \mathsection
  \textbardbl    \|%
  \textparagraph \mathparagraph
}%
\DefineFNsymbolsTM{chicago}{%
  \textasteriskcentered *%
  \textdagger    \dagger
  \textdaggerdbl \ddagger
  \textsection   \mathsection
  \textbardbl    \|%
  \#\#%
}%
\DefineFNsymbolsTM{wiley}{%
  \textasteriskcentered *%
  {\textasteriskcentered\textasteriskcentered}{**}%
  \textdagger    \dagger
  \textdaggerdbl \ddagger
  \textsection   \mathsection
  \textparagraph \mathparagraph
  \textbardbl    \|%
}%
\DefineFNsymbolsTM{lamport-robust}{%
  \textasteriskcentered *%
  \textdagger    \dagger
  \textdaggerdbl \ddagger
  \textsection   \mathsection
  \textparagraph \mathparagraph
  \textbardbl    \|%
  {\textasteriskcentered\textasteriskcentered}{**}%
  {\textdagger\textdagger}{\dagger\dagger}%
  {\textdaggerdbl\textdaggerdbl}{\ddagger\ddagger}%
}
\DefineFNsymbolsTM*{lamport*}{%
  \textasteriskcentered *%
  \textdagger    \dagger
  \textdaggerdbl \ddagger
  \textsection   \mathsection
  \textparagraph \mathparagraph
  \textbardbl    \|%
  {\textasteriskcentered\textasteriskcentered}{**}%
  {\textdagger\textdagger}{\dagger\dagger}%
  {\textdaggerdbl\textdaggerdbl}{\ddagger\ddagger}%
  {\textsection\textsection}{\mathsection\mathsection}%
  {\textparagraph\textparagraph}{\mathparagraph\mathparagraph}%
  {\textasteriskcentered\textasteriskcentered\textasteriskcentered}{***}%
  {\textdagger\textdagger\textdagger}{\dagger\dagger\dagger}%
  {\textdaggerdbl\textdaggerdbl\textdaggerdbl}{\ddagger\ddagger\ddagger}%
  {\textsection\textsection\textsection}%%
    {\mathsection\mathsection\mathsection}%
  {\textparagraph\textparagraph\textparagraph}%%
    {\mathparagraph\mathparagraph\mathparagraph}%
}
\setfnsymbol{lamport*}
\DefineFNsymbolsTM{lamport*-robust}{%
  \textasteriskcentered *%
  \textdagger    \dagger
  \textdaggerdbl \ddagger
  \textsection   \mathsection
  \textparagraph \mathparagraph
  \textbardbl    \|%
  {\textasteriskcentered\textasteriskcentered}{**}%
  {\textdagger\textdagger}{\dagger\dagger}%
  {\textdaggerdbl\textdaggerdbl}{\ddagger\ddagger}%
  {\textsection\textsection}{\mathsection\mathsection}%
  {\textparagraph\textparagraph}{\mathparagraph\mathparagraph}%
  {\textasteriskcentered\textasteriskcentered\textasteriskcentered}{***}%
  {\textdagger\textdagger\textdagger}{\dagger\dagger\dagger}%
  {\textdaggerdbl\textdaggerdbl\textdaggerdbl}{\ddagger\ddagger\ddagger}%
  {\textsection\textsection\textsection}%%
    {\mathsection\mathsection\mathsection}%
  {\textparagraph\textparagraph\textparagraph}%%
    {\mathparagraph\mathparagraph\mathparagraph}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \section{Other miscellaneous commands}
%
%
% \subsection{Minipage \cs{footnotemark}s}
%
% \begin{macro}{\mpfootnotemark}
% Syntax: \cs{mpfootnotemark}\oarg{number}
%
% Here we define \cs{mpfootnotemark}, which has the same syntax as
% \cs{footnotemark}, and which applies the semantics of
% \cs{footnotemark} to the minipage footnote series.
%    \begin{macrocode}
\newcommand\mpfootnotemark{%
  \@ifnextchar[%
    \@xmpfootnotemark
    {%
      \stepcounter\@mpfn
      \protected@xdef\@thefnmark{\thempfn}%
      \@footnotemark
    }%
}
\def\@xmpfootnotemark[#1]{%
  \begingroup
    \csname c@\@mpfn\endcsname #1\relax
    \unrestored@protected@xdef\@thefnmark{\thempfn}%
  \endgroup
  \@footnotemark
}
%    \end{macrocode}
% \end{macro}
%
%
%   If \textsf{hyperref} was loaded first, it has saved
%   \cs{@footnotetext} and \cs{@footnotemark} away and then redefined
%   them. The saved versions are now wrong, so we reassign them.
%    \begin{macrocode}
\@ifpackageloaded{hyperref}{%
  \let\H@@footnotetext\FN@footnotetext
  \let\H@@footnotemark\FN@footnotemark
}{%
%    \end{macrocode}
%   If \textsf{hyperref} wasn't loaded we copy our new definitions to
%   \cs{@footnotetext} and \cs{@footnotemark} for actual use. If
%   \textsf{hyperref} is loaded later it will do its magic and save
%   our definitions.
%    \begin{macrocode}
  \let \@footnotetext \FN@footnotetext
  \let\@footnotemark  \FN@footnotemark
}
%    \end{macrocode}
%
%    \begin{macrocode}
\endinput
%</package>
%    \end{macrocode}
%
% \Finale
%
