% \iffalse meta-comment
%
% Copyright 1994 the LaTeX3 project and the individual authors.
% All rights reserved. For further copyright information see the file
% legal.txt, and any other copyright indicated in this file.
% 
% This file is part of the LaTeX2e system.
% ----------------------------------------
% 
%  This system is distributed in the hope that it will be useful,
%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% 
% 
% IMPORTANT NOTICE:
% 
% For error reports in case of UNCHANGED versions see bugs.txt.
% 
% Please do not request updates from us directly.  Distribution is
% done through Mail-Servers and TeX organizations.
% 
% You are not allowed to change this file.
% 
% You are allowed to distribute this file under the condition that
% it is distributed together with all files mentioned in manifest.txt.
% 
% If you receive only some of these files from someone, complain!
% 
% You are NOT ALLOWED to distribute this file alone.  You are NOT
% ALLOWED to take money for the distribution or use of either this
% file or a changed version, except for a nominal charge for copying
% etc.
% \fi
%
% \iffalse
%%% File: ltfloat
%
%<*driver>
% \fi
\ProvidesFile{ltfloat.dtx}[1994/12/10 v1.1g LaTeX Kernel (Floats)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltfloat.dtx}
\title{\filename}
\date{\filedate}
 \author{%
  Johannes Braams\and
  David Carlisle\and
  Alan Jeffrey\and
  Leslie Lamport\and
  Frank Mittelbach\and
  Chris Rowley\and
  Rainer Sch\"opf}

\begin{document}
\maketitle
 \DocInput{\filename}
\end{document}
%</driver>
% \fi
%
% \CheckSum{595}
%
% \section{Floats}
%
%  The different types of floats are identified by a \meta{type} name,
%  which is the name of the counter for that kind of float.  For
%  example, figures are of type `figure' and tables are of type `table'.
%  Each \meta{type} has associated a positive \meta{type number}, which
%  is a power of two.  E.g.,\\
%  figures might be have type number~1, tables type number~2, programs
%  type number~4, etc.
%
%  The locations where a float can go are specified by a
%  \meta{placement specifier}, which is a list of the possible
%  locations, each denoted by a letter as follows:
%    \begin{center}
%    \begin{tabular}{l@{ : }l@{ --- }l}
%     h & here   & at the current location in the text.\\
%     t & top    & at the top of a text page.\\
%     b & bottom & at the bottom of a text page.\\
%     p & page   & on a separate float page
%    \end{tabular}
%    \end{center}
%  In addition, in conjunction with these, you can use `!' which means
%  that the current values of the float positioning parameters are
%  ignored for this float. (Has no effect on `p', float page
%  positioning.)
%  For example, `pht' specifies that the float can appear in any of
%  three locations: page, here or top.
%
% \StopEventually{}
%
%
% \changes{v1.0a}{1994/03/04}{Initial version, split from latex.dtx}
% \changes{v1.0b}{1994/03/28}{Split further from ltherest.dtx}
% \changes{v1.0e}{1994/04/25}{Changed warning messages}
% \changes{v1.0e}{1994/04/25}{Removed obsolete tracing code}
% \changes{v1.0f}{1994/05/03}
%     {(CAR) Added \cmd{\@largefloatcheck}}
% \changes{v1.0f}{1994/05/03}{Removed unnecessary braces from
% arguments of \cmd{\@ifnextchar}}
% \changes{v1.0i}{1994/05/22}{Use new warning commands}
% \changes{v1.1e}{1994/11/17}
%         {\cs{@tempa} to \cs{reserved@a}}
% \changes{v1.1g}{1994/12/10}{Some temps reinserted temporarily}
%
% \subsection{Floating Environments}
%    \begin{macrocode}
%<*2ekernel>
\message{floats,}
%    \end{macrocode}
% \begin{oldcomments}
%
% Where floats may appear on a page, and how many may appear there
% are specified by the following float placement parameters.  The
% numbers are named like counters so the user can set them with
% the ordinary counter-setting commands.
%
%  \c@topnumber      : Number of floats allowed at the top of a column.
%  \topfraction      : Fraction of column that can be devoted to floats.
%  \c@dbltopnumber, \dbltopfraction 
%                    : Same as above, but for double-column floats.
%  \c@bottomnumber, \bottomfraction 
%                    : Same as above for bottom of page.
%  \c@totalnumber    : Number of floats allowed in a single column,
%                          including in-text floats.
%  \textfraction     :Minimum fraction of column that must contain text.
%  \floatpagefraction: Minimum fraction of page that must be taken
%                          up by float page.
%  \dblfloatpagefraction 
%                    : Same as above, for double-column floats.
%
% The document style must define the following.
%
%    \fps@TYPE   : The default placement specifier for floats of type
%                  TYPE. 
%
%    \ftype@TYPE : The type number for floats of type TYPE.
%
%    \ext@TYPE   : The file extension indicating the file on which the
%                  contents list for float type TYPE is stored.
%                    For example,  \ext@figure = 'lof'.
%
%    \fnum@TYPE  : A macro to generate the figure number for a caption.
%                  For example, \fnum@TYPE == Figure \thefigure.
%
%    \@makecaption{NUM}{TEXT} : 
%              A macro to make a caption, with NUM the value
%              produced by \fnum@... and TEXT the text of the caption.
%              It can assume it's in a \parbox of the appropriate width.
%
% \@float{TYPE}[PLACEMENT] : This macro begins a float environment for a
%     single-column float of type TYPE with PLACEMENT as the placement
%     specifier.  The default value of PLACEMENT is defined by
%     \fps@TYPE.  The environment is ended by \end@float.
%     E.g., \figure == \@float{figure}, \endfigure == \end@float.
%
%  \@float{TYPE}[PLACEMENT] ==
%   BEGIN
%     if hmode then \@bsphack
%                   \@floatpenalty := -10002
%              else \@floatpenalty := -10003
%     fi
%     \@captype ==L TYPE
%     \@dblflset
%     \@fps     ==L PLACEMENT
%     \@onelevel@sanitize \@fps 
%     add default PLACEMENT if at most ! in PLACEMENT == \@fpsadddefault
%     if inner
%       then LaTeX Error: 'Not in outer paragraph mode.'
%            \@floatpenalty := 0
%       else if \@freelist nonempty
%              then \@currbox  :=L head of \@freelist
%                   \@freelist :=G tail of \@freelist
%                   \count\@currbox :=G 32*\ftype@TYPE + 
%                                          bits determined by PLACEMENT
%              else \@floatpenalty := 0
%                   LaTeX Error: 'Too many unprocessed floats'
%            fi
%     fi
%     \@currbox :=G   \color@vbox
%                       \normalcolor
%                         \vbox{
%                          %% 15 Dec 87 --
%                          %% removed \boxmaxdepth :=L 0pt
%                          %% that made box 0 depth because it screwed
%                          %% things up. Instead, added \vskip0pt at end
%                               \hsize = \columnwidth
%                               \@parboxrestore
%                               Set outer@nobreak
%                               \@floatboxreset
%   END
%
%  \caption ==
%    BEGIN
%     \refstepcounter{\@captype}
%     \@dblarg{\@caption{\@captype}}
%    END
%
% In following definition, \par moved from after \addcontentsline to
% before \addcontentsline because the \write could cause
% an extra blank line to be added to the paragraph above the
% caption.  (Change made 12 Jun 87)
%
%  \@caption{TYPE}[STEXT]{TEXT} ==
%   BEGIN
%     \par
%     \addcontentsline{\ext@TYPE}{TYPE}{\numberline{\theTYPE}{STEXT}}
%     \begingroup
%       \@parboxrestore
%       \@normalsize
%       \@makecaption{\fnum@TYPE}{TEXT}
%       \par
%     \endgroup
%   END
%
%
%  \@dblfloat{TYPE}[PLACEMENT] : Macro to begin a float environment for
%     a double-column float of type TYPE with PLACEMENT as the placement
%     specifier.  The default value of PLACEMENT is 'tp'
%     The environment is ended by \end@dblfloat.
%     E.g., \figure* == \@dblfloat{figure}, 
%           \endfigure* == \end@dblfloat.
%
%  \@dblfloat{TYPE}[PLACEMENT] ==
%     Identical to \@float{TYPE}[PLACEMENT] except \hsize and \linewidth
%     are set to \textwidth.
%
%
%    \begin{macrocode}
\newcount\@floatpenalty
%    \end{macrocode}
%
%    \begin{macrocode}
\def\caption{\refstepcounter\@captype \@dblarg{\@caption\@captype}}
%    \end{macrocode}
%
% \end{oldcomments}
%
% \begin{macro}{\@caption}
% \changes{v1.0b}{1994/03/28}{Use \cs{normalsize} not \cs{@normalsize}}
%    \begin{macrocode}
\long\def\@caption#1[#2]#3{\par\addcontentsline{\csname
  ext@#1\endcsname}{#1}{\protect\numberline{\csname
  the#1\endcsname}{\ignorespaces #2}}\begingroup
    \@parboxrestore
    \normalsize
    \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  \endgroup}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@float}
% \begin{macro}{\@dblflset}
% \changes{v1.1a}{1994/10/31}{Macro added}
% \changes{v1.1g}{1994/12/10}{Macro removed temporarily}
% \changes{v1.1a}{1994/10/31}
%    {Major changes to parameter parsing, setting of local variables,
%    etc; two-column and one-column cases merged; space hacks moved}
% \changes{v1.1c}{1994/11/05}
%         {Add compatibility with old version of \cs{@xfloat}.}
% \changes{v1.1g}{1994/12/10}{Old version reinstated temporarily}
%
%    \begin{macrocode}
\def\@float#1{%
  \@ifnextchar[{\@xfloat{#1}}{\edef\reserved@a{\noexpand\@xfloat
    {#1}[\csname fps@#1\endcsname]}\reserved@a}}
%    \end{macrocode}
%    
% \end{macro}
% \end{macro}
%
%  \begin{macro}{\@dblfloat}
% \changes{v1.1a}{1994/10/31}
%     {Major changes since two-column and one-column cases merged}
% \changes{v1.1g}{1994/12/10}{Old version reinstated temporarily}
%
%    \begin{macrocode}
\def\@dblfloat{%
  \if@twocolumn\let\reserved@a\@dbflt\else\let\reserved@a\@float\fi
  \reserved@a}
%    \end{macrocode}
%  \end{macro}
%
%    
%  \begin{macro}{\fps@dbl}
% \changes{v1.1a}{1994/10/31}{Macro added}
% \changes{v1.1g}{1994/12/10}{Macro removed temporarily}
%  Note that all double floats have default fps `tp'.
%  \end{macro}
%  
%  \begin{macro}{\@setfps}
% \changes{v1.1a}{1994/10/31}{Macro added}
% \changes{v1.1c}{1994/11/05}
%         {Add compatibility with old version of \cs{@xfloat}.}
% \changes{v1.1g}{1994/12/10}{Macro removed temporarily}
%    This sets the fps, dealing with error conditions by adding
%    the default.
%    
%  \end{macro}
%
%  \begin{macro}{\@xfloat}
% \changes{LaTeX2e}{1993/12/05}{Command changed}
% \changes{LaTeX2e}{1994/01/21}{Added missing percent characters.}
% \changes{v1.1a}{1994/10/31}
%     {Major changes, removing setting of local variables, space hacks
%     etc; two-column and one-column cases merged}
% \changes{v1.1c}{1994/11/05}
%         {Add compatibility with old version of \cs{@xfloat}: but the
%         arguments, provided at exorbitant cost, are now completely
%         ignored}
% \changes{v1.1f}{1994/11/21}
%     {Missing percents reinserted after 4, 8: these are not numbers!}
% \changes{v1.1g}{1994/12/10}{Old version reinstated temporarily}
% \changes{v1.1g}{1994/12/10}{Sanitisation added temporarily}
%     The first part of this sets the count register that stores all
%     the information about the type and fps of the float.
%
%    We assume here that the default specifiers already contain no
%    active characters.
%
%    It may be better to store the defaults as numbers, rather than
%    symbol strings.
%
%    \begin{macrocode}
\def\@xfloat #1[#2]{%
   \def \@captype {#1}%
   \def \@fps {#2}%
   \@onelevel@sanitize \@fps 
   \def \reserved@b {!}%
   \ifx \reserved@b \@fps
     \@fpsadddefault
   \else
     \ifx \@fps \@empty
       \@fpsadddefault
     \fi
   \fi
   \ifhmode
     \@bsphack
     \@floatpenalty -\@Mii
   \else
     \@floatpenalty-\@Miii
   \fi
  \ifinner
     \@parmoderr\@floatpenalty\z@
  \else
    \@next\@currbox\@freelist
      {%
       \@tempcnta \sixt@@n
       \expandafter \@tfor \expandafter \reserved@a
         \expandafter :\expandafter =\@fps 
         \do
          {%
           \if \reserved@a h%
             \ifodd \@tempcnta
             \else
               \advance \@tempcnta \@ne
             \fi
           \fi
           \if \reserved@a t%
             \@setfpsbit \tw@
           \fi
           \if \reserved@a b%
             \@setfpsbit 4%
           \fi
           \if \reserved@a p%
             \@setfpsbit 8%
           \fi
           \if \reserved@a !%
             \ifnum \@tempcnta>15
               \advance\@tempcnta -\sixt@@n\relax
             \fi
           \fi
           }%
       \@tempcntb \csname ftype@\@captype \endcsname
       \multiply \@tempcntb \@xxxii
       \advance \@tempcnta \@tempcntb
       \global \count\@currbox \@tempcnta
       }%
    \@fltovf
  \fi
%    \end{macrocode}
%    The remainder sets up the box in which the float is typeset, and
%    the typesetting enevironment to be used.  It is essential to have
%    the extra box to avoid the unwanted space that would otherwise
%    often be put at the top of the float.
%
%    It ends with a hook; not sure how useful this is but it is needed
%    at present to deal with double-column floats.
% \task{CAR?}{Sort out hooks}
% \changes{v1.0a}{1994/03/07}
%     {(DPC) Extra group for colour}
% \changes{v1.0c}{1994/03/14}
%     {(DPC) Use \cmd{\color@begingroup}}
% \changes{v1.0g}{1994/05/13}
%     {(DPC) Use \cmd{\normalcolor}}
% \changes{v1.1a}{1994/10/31}
%     {(DPC/CAR) Extra box added to remove colour resetting from vmode}
% \changes{v1.1a}{1994/10/31}{Reset hook added}
% \changes{v1.1c}{1994/11/05}
%         {Use new \cs{color@hbox} concept.}
% \changes{v1.1f}{1994/11/21}
%         {Changed to \cs{color@vbox} so that large floats overflow
%          at the bottom}
% \changes{v1.1f}{1994/11/21}{Use \cs{@setnobreak}}
% \changes{v1.1f}{1994/11/21}{Added \cs{@setminipage}}
% \changes{v1.1f}{1994/11/21}{Added resetting of size and font}
%    \begin{macrocode}
  \global \setbox\@currbox
    \color@vbox
      \normalcolor
      \vbox \bgroup
        \hsize\columnwidth \@parboxrestore
        \reset@font
        \normalsize
        \@setnobreak
        \@setminipage
        \@floatboxreset
}
%    \end{macrocode}
%  \end{macro}
%  
%  \begin{macro}{\@setnobreak}
% \changes{v1.1f}{1994/11/21}{Macro added}
%    
%    \begin{macrocode}
\def \@setnobreak{%
  \if@nobreak
    \def\outer@nobreak{\global\@nobreaktrue}%
    \global\@nobreakfalse
  \fi
}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\@setminipage}
% \changes{v1.1f}{1994/11/21}{Macro added}
%    
%    \begin{macrocode}
\def \@setminipage{%
  \global\@minipagetrue
  \everypar{\global\@minipagefalse\everypar{}}%
}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\@floatboxreset}
% \changes{v1.1a}{1994/10/31}{Macro added}
%    
%    The default value of this is empty, for one-column floats.
%    \begin{macrocode}
\let \@floatboxreset \@empty
%    \end{macrocode}
%  \end{macro}
%  
% \begin{macro}{\end@float}
%    \begin{macrocode}
\def\end@float{%
        \par\vskip\z@skip      %% \par\vskip\z@ added 15 Dec 87
%    \end{macrocode}
% \changes{v1.0a}
%     {1994/03/07}{(DPC) Extra group for colour}
% \changes{v1.0c}{1994/03/14}
%     {(DPC) Use \cmd{\color@endgroup}}
% \changes{v1.0f}{1994/05/03}
%     {(CAR) Added \cmd{\@largefloatcheck}}
% \changes{v1.0h}{1994/05/20}{Restore outer value of @nobreak switch.}
% \changes{v1.1a}{1994/10/31}
%     {(DPC/CAR) Extra box added to remove colour resetting from vmode}
% \changes{v1.1c}{1994/11/05}
%         {Use new \cs{color@hbox} concept.}
%    \begin{macrocode}
% \changes{v1.1f}{1994/11/21}{Corrected positionof \cs{outer@nobreak}}
% \changes{v1.1f}{1994/11/21}{Added reset of minipage flag}
        \global\@minipagefalse   
        \outer@nobreak
      \egroup                  %% end of vbox
    \color@endbox
  \ifnum\@floatpenalty <\z@
%    \end{macrocode}
% We make sure that we never exceed |\textheight|, otherwise float
% will never get typeset (91/03/15 FMi).
%    \begin{macrocode}
    \@largefloatcheck
    \@cons\@currlist\@currbox
    \ifnum\@floatpenalty <-\@Mii
      \penalty -\@Miv
      \@tempdima\prevdepth    %% saving and restoring \prevdepth added
      \vbox{}%                %% 26 May 87 to prevent extra vertical
      \prevdepth \@tempdima   %% space when used in vertical mode
      \penalty\@floatpenalty
%    \end{macrocode}
% \changes{LaTeX2.09}{1992/03/18}
%         {(RmS) changed \cmd{\@esphack} to \cmd{\@Esphack}}
%    \begin{macrocode}
    \else
      \vadjust{\penalty -\@Miv \vbox{}\penalty\@floatpenalty}\@Esphack
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\end@dblfloat}
% \changes{v1.0f}{1994/05/03}{\cmd{\@largefloatcheck} added}
%    \begin{macrocode}
\def\end@dblfloat{%
\if@twocolumn
        \par\vskip\z@skip      %% \par\vskip\z@ added 15 Dec 87
%    \end{macrocode}
% \changes{v1.0a}
%     {1994/03/07}{(DPC) Extra group for colour}
% \changes{v1.0c}{1994/03/14}
%     {(DPC) Use \cmd{\color@endgroup}}
% \changes{v1.0f}{1994/05/03}
%     {(CAR) Added \cmd{\@largefloatcheck}}
% \changes{v1.0h}{1994/05/20}{Restore outer value of @nobreak switch.}
% \changes{v1.1a}{1994/10/31}
%     {(DPC/CAR) Extra box added to remove colour resetting from vmode}
% \changes{v1.1c}{1994/11/05}
%         {Use new \cs{color@hbox} concept.}
%    \begin{macrocode}
      \egroup                  %% end of vbox
      \outer@nobreak
    \color@endbox
  \ifnum\@floatpenalty <\z@
%    \end{macrocode}
% We make sure that we never exceed |\textheight|, otherwise float
% will never get typeset (91/03/15 FMi).
%    \begin{macrocode}
    \@largefloatcheck
    \@cons\@dbldeferlist\@currbox
  \fi
%    \end{macrocode}
% RmS 92/03/18 changed |\@esphack| to |\@Esphack|.
%    \begin{macrocode}
    \ifnum \@floatpenalty =-\@Mii \@Esphack\fi
\else
  \end@float
\fi
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\outer@nobreak}
% \changes{v1.0h}{1994/05/20}{Macro added: default is to do nothing.}
%    \begin{macrocode}
\let\outer@nobreak\@empty
%    \end{macrocode}
% \end{macro}
% 
%
%  \begin{macro}{\@largefloatcheck}
% \changes{v1.0e}{1994/04/25}{Command added}
% 
%    This calculates by how much a float is oversize for the page and
%    prints this in a warning message.
%    
%    \begin{macrocode}  
\def \@largefloatcheck{%
  \ifdim \ht\@currbox>\textheight
    \@tempdima -\textheight
    \advance \@tempdima \ht\@currbox
%    \end{macrocode}
% \changes{v1.0e}{1994/04/25}{Changed warning message to give more
% info}
%    \begin{macrocode}
    \@latex@warning {Float too large for page by \the\@tempdima}%
    \ht\@currbox \textheight
  \fi
}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\@dbflt}
%  \begin{macro}{\@xdblfloat}
% \changes{v1.1a}{1994/10/31}
%     {Macros removed: \cs{@dbflt}, \cs{@xdblfloat}}
% \changes{v1.1g}{1994/12/10}{Macros reinserted temporarily}
%    
%
%    \begin{macrocode}
\def\@dbflt#1{\@ifnextchar[{\@xdblfloat{#1}}{\@xdblfloat{#1}[tp]}}
\def\@xdblfloat#1[#2]{%
  \@xfloat{#1}[#2]\hsize\textwidth\linewidth\textwidth}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%
% Moved to ltoutput 93/12/16
%    \begin{macrocode}
%\newcount\c@topnumber
%\newcount\c@dbltopnumber
%\newcount\c@bottomnumber
%\newcount\c@totalnumber
%    \end{macrocode}
%
% An analysis of |\@floatplacement|:
%
% This should be called whenever |\@colht| has been set.
%    \begin{macrocode}
\def\@floatplacement{\global\@topnum\c@topnumber
    % Textpage bit, global:
   \global\@toproom \topfraction\@colht
   \global\@botnum  \c@bottomnumber
   \global\@botroom \bottomfraction\@colht
   \global\@colnum  \c@totalnumber
    % Floatpage bit, local:
   \@fpmin   \floatpagefraction\@colht}
%    \end{macrocode}
%
%  \begin{macro}{\@dblfloatplacement}
% \changes{LaTeX2e}{1993/12/05}{Command changed}
% 
%     This should be called only within a group.  Now changed to
%     provide extra checks in |\@addtodblcol|, needed when processing a
%     BANG float.
%    
%    \begin{macrocode}  
\def \@dblfloatplacement {%
%    \end{macrocode}
%    Textpage bit: global, but need not be.
%    \begin{macrocode}  
  \global \@dbltopnum \c@dbltopnumber
  \global \@dbltoproom \dbltopfraction\@colht
%    \end{macrocode}
%   This new bit uses |\@textmin| to locally store the amount of extra
%   room in the column.   
%    \begin{macrocode}
  \@textmin \@colht
  \advance \@textmin -\@dbltoproom
%    \end{macrocode}
%    Floatpage bit: must be local.
%    \begin{macrocode}
  \@fpmin \dblfloatpagefraction\textheight
  \@fptop \@dblfptop
  \@fpsep \@dblfpsep
  \@fpbot \@dblfpbot
}
%    \end{macrocode}
%  \end{macro}
%
%
% \begin{oldcomments}
%   MARGINAL NOTES:
%
%   Marginal notes use the same mechanism as floats to communicate
%   with the \output routine.  Marginal notes are distinguished from
%   floats by having a negative placement specification.  The command
%   \marginpar [LTEXT]{RTEXT} generates a marginal note in a parbox,
%   using LTEXT if it's on the left and RTEXT if it's on the right.
%   (Default is RTEXT = LTEXT.)  It uses the following parameters.
%
%   \marginparwidth : Width of marginal notes.
%   \marginparsep   : Distance between marginal note and text.
%        the page layout to determine how to move the marginal
%        note into the margin.   E.g., \@leftmarginskip ==
%        \hskip -\marginparwidth \hskip -\marginparsep .
%   \marginparpush  :  Minimum vertical separation between \marginpar's
%
%  Marginal notes are normally put on the outside of the page
%  if @mparswitch = true, and on the right if @mparswitch = false.
%  The command \reversemarginpar reverses the side where they
%  are put.  \normalmarginpar undoes \reversemarginpar.
%  These commands have no effect for two-column output.
%
%  SURPRISE: if two marginal notes appear on the same line of
%  text, then the second one could appear on the next page, in
%  a funny position.
%
%
%  \marginpar [LTEXT]{RTEXT} ==
%   BEGIN
%     if hmode then \@bsphack
%                   \@floatpenalty := -10002
%              else \@floatpenalty := -10003
%     fi
%     if inner
%       then LaTeX Error: 'Not in outer paragraph mode.'
%            \@floatpenalty := 0
%       else if \@freelist has two elements:
%              then get \@marbox, \@currbox  from \@freelist
%                   \count\@marbox :=G -1
%              else \@floatpenalty := 0
%                   LaTeX Error: 'Too many unprocessed floats'
%                   \@currbox, \@marbox := \@tempboxa    %%use \def
%            fi
%     fi
%     if optional argument
%       then %% \@xmpar ==
%            \@savemarbox\@marbox{LTEXT}
%            \@savemarbox\@currbox{RTEXT}
%       else %% \@ympar ==
%            \@savemarbox\@marbox{RTEXT}
%            \box\@currbox :=G \box\@marbox
%    fi
%    \@xympar 
%   END
%
% \reversemarginpar == BEGIN \@mparbottom   :=G 0
%                            @reversemargin :=G true
%                      END
%
% \normalmarginpar  == BEGIN \@mparbottom   :=G 0
%                            @reversemargin :=G false
%                      END
%
%    \begin{macrocode}
\def\marginpar{\ifhmode \@bsphack\@floatpenalty -\@Mii\else
   \@floatpenalty-\@Miii\fi\ifinner
      \@parmoderr\@floatpenalty\z@
    \else\@next\@currbox\@freelist{}{}\@next\@marbox\@freelist{\global
      \count\@marbox\m@ne}{\@floatpenalty\z@ \@fltovf
         \def\@currbox{\@tempboxa}\def\@marbox{\@tempboxa}}\fi
     \@ifnextchar [\@xmpar\@ympar}
%    \end{macrocode}
%
%    \begin{macrocode}
\long\def\@xmpar[#1]#2{\@savemarbox\@marbox{#1}\@savemarbox\@currbox
   {#2}\@xympar}
%    \end{macrocode}
%
%    \begin{macrocode}
\long\def\@ympar#1{\@savemarbox\@marbox{#1}\global\setbox\@currbox
     \copy\@marbox\@xympar}
%    \end{macrocode}
%
% \end{oldcomments}
% 
% \begin{macro}{\@savemarbox}
% \changes{v1.0b}{1994/03/12}
%     {(DPC) Extra group for colour}
% \changes{v1.0c}{1994/03/14}
%     {(DPC) Use \cmd{\color@begingroup}}
% \changes{v1.0d}{1994/04/18}
%     {(DPC) Remove Colour support}
% \changes{v1.1a}{1994/10/31}
%     {(DPC/CAR) Extra box added for colour}
% \changes{v1.1c}{1994/11/05}
%         {Use new \cs{color@hbox} concept.}
%    \begin{macrocode}
% \changes{v1.1f}{1994/11/21}{Changed to \cs{color@vbox} }
% \changes{v1.1f}{1994/11/21}{{Use \cs{@setnobreak} etc}
% \changes{v1.1f}{1994/11/21}{{Added \cs{@setminipage} etc}
% \changes{v1.1f}{1994/11/21}{Added resetting of size and font}
\long\def \@savemarbox #1#2{%
  \global\setbox #1%
    \color@vbox
      \vtop{%
        \hsize\marginparwidth
        \@parboxrestore 
        \reset@font
        \normalsize
        \@setnobreak
        \@setminipage
        \@marginparreset
        #2%
        \global\@minipagefalse   
        \outer@nobreak
        }%
    \color@endbox
}
%    \end{macrocode}
% \end{macro}
% 
%  \begin{macro}{\@marginparreset}
% \changes{v1.1f}{1994/11/21}{Macro added}
%    
%    \begin{macrocode}
\let \@marginparreset \relax
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{\@xympar}
%    \begin{macrocode}
%    \end{macrocode}
% \changes{LaTeX2.09}{1992/03/18}
%     {(RmS) added \cmd{\global}\cmd{\@ignorefalse}}
% \changes{v1.0b}{1994/03/12}
%     {(DPC) Extra bgroup for colour}
% \changes{1.0c}{1994/03/14}
%     {(DPC) Use \cmd{\color@begingroup}}
% \changes{v1.1a}{1994/10/31}
%     {(DPC/CAR) Extra box added since needed for floats}
% \changes{v1.1c}{1994/11/05}
%         {Use new \cs{color@hbox} concept.}
% \changes{v1.1f}{1994/11/21}{Changed to \cs{color@vbox} }
%     Setting the box here is done only because the code
%     uses \cs{end@float}; it will be empty and gets discarded. 
%    \begin{macrocode}
\def \@xympar{%
  \ifnum\@floatpenalty <\z@\@cons\@currlist\@marbox\fi
  \setbox\@tempboxa
    \color@vbox
      \vbox \bgroup
  \end@float
  \global \@ignorefalse \@esphack
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\reversemarginpar}
% \begin{macro}{\normalmarginpar}
%    \begin{macrocode}
\def\reversemarginpar{\global\@mparbottom\z@ \@reversemargintrue}
\def\normalmarginpar{\global\@mparbottom\z@ \@reversemarginfalse}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
\message{footnotes,}
%    \end{macrocode}
%
% \subsection{Footnotes}
%
% \begin{oldcomments}
%
%   \footnote{NOTE}       : User command to insert a footnote.
%
%   \footnote[NUM]{NOTE}: User command to insert a footnote numbered
%                       NUM, where NUM is a number -- 1, 2,
%                       etc.  For example, if footnotes are numbered
%                       *, **, etc. within pages, then \footnote[2]{...}
%                       produces footnote '**'.  This command does not
%                       step the footnote counter.
%
%   \footnotemark[NUM] : Command to produce just the footnote mark in
%                        the text, but no footnote.  With no argument,
%                        it steps the footnote counter before generating
%                        the mark.
%
%   \footnotetext[NUM]{TEXT} : Command to produce the footnote but no
%                              mark.  \footnote is equivalent to
%                              \footnotemark \footnotetext .
%
%   As in PLAIN, footnotes use \insert\footins, and the following
%   parameters: 
%
%   \footnotesize   : Size-changing command for footnotes.
%
%   \footnotesep    : The height of a strut placed at the beginning of
%                     every footnote.
%   \skip\footins   : Space between main text and footnotes.  The rule
%                     separating footnotes from text occurs in this
%                     space. This space lies above the strut of height
%                     \footnotesep which is at the beginning of the
%                     first footnote.
%   \footnoterule   : Macro to draw the rule separating footnotes from
%                     text. It is executed right after a \vspace of
%                     \skip\footins. It should take zero vertical
%                     space--i.e., it should to a negative skip to
%                     compensate for any positive space it occupies.
%                     (See PLAIN.TEX.)
%
%   \interfootnotelinepenalty : Interline penalty for footnotes.
%
%   \thefootnote : In usual LaTeX style, produces the footnote number.
%                  If footnotes are to be numbered within pages, then
%                  the document style file must include an \@addtoreset
%                  command to cause the footnote counter to be reset
%                  when the page counter is stepped.  This is not a good
%                  idea, though, because the counter will not always be
%                  reset in time to ensure that the first footnote on a
%                  page is footnote number one.
%
%   \@thefnmark : Holds the current footnote's mark--e.g., \dag or '1'
%                 or 'a'. 
%
%   \@mpfnnumber     : A macro that generates the numbers for \footnote
%                      and \footnotemark commands. It == \thefootnote
%                      outside a minipage environment, but can be
%                      changed inside to generate numbers for
%                      \footnote's.
%
%   \@makefnmark : A macro to generate the footnote marker from
%                 \@thefnmark The default definition is
%                 \hbox{$^\@thefnmark$}.
%
%   \@makefntext{NOTE} :
%        Must produce the actual footnote, using \@thefnmark as the mark
%        of the footnote and NOTE as the text.  It is called when
%        effectively  inside a \parbox, with \hsize = \columnwidth.
%          For example, it might be as simple as
%               $^{\@thefnmark}$
%
% NOTE
% In a minipage environment, \footnote and \footnotetext are redefined
% so that
%    (a) they use the counter mpfootnote
%    (b) the footnotes they produce go at the bottom of the minipage.
% The switch is accomplished by letting \@mpfn == footnote or mpfootnote
% and \thempfn == \thefootnote or \thempfootnote, and by redefining
% \@footnotetext to be \@mpfootnotetext in the minipage.
%
% \footnote{NOTE}  ==
%  BEGIN
%    \stepcounter{\@mpfn}
%    begingroup
%       \protect == \noexpand
%       \@thefnmark :=G eval (\thempfn)
%    endgroup
%    \@footnotemark
%    \@footnotetext{NOTE}
%  END
%
% \footnote[NUM]{NOTE} ==
%  BEGIN
%    begingroup
%       \protect == \noexpand
%       counter \@mpfn :=L NUM
%       \@thefnmark :=G eval (\thempfn)
%    endgroup
%    \@footnotemark
%    \@footnotetext{NOTE}
%  END
%
% \footnotemark      ==
%  BEGIN \stepcounter{footnote}
%        begingroup
%           \protect == \noexpand
%           \@thefnmark :=G eval(\thefootnote)
%        endgroup
%        \@footnotemark
%  END
%
% \footnotemark[NUM] ==
%   BEGIN
%       begingroup
%         footnote counter :=L NUM
%         \protect == \noexpand
%        \@thefnmark :=G eval(\thefootnote)
%       endgroup
%       \@footnotemark
%   END
%
% \@footnotemark ==
%   BEGIN
%    \leavevmode
%    IF hmode THEN \@x@sf := \the\spacefactor FI
%    \@makefnmark          % put number in main text
%    IF hmode THEN \spacefactor := \@x@sf FI
%   END
%
% \footnotetext      ==
%    BEGIN begingroup \protect == \noexpand
%                     \@thefnmark :=G eval (\thempfn)
%          endgroup
%          \@footnotetext
%    END
%
% \footnotetext[NUM] ==
%    BEGIN begingroup  counter \@mpfn :=L NUM
%                      \protect == \noexpand
%                      \@thefnmark :=G eval (\thempfn)
%          endgroup
%          \@footnotetext
%    END
%
%    \begin{macrocode}
\@definecounter{footnote}
\def\thefootnote{\arabic{footnote}}
%    \end{macrocode}
%
%    \begin{macrocode}
\@definecounter{mpfootnote}
\def\thempfootnote{\alph{mpfootnote}}
%    \end{macrocode}
%
% Default definition
%    \begin{macrocode}
\def\@makefnmark{\hbox{$^{\@thefnmark}\m@th$}}
%    \end{macrocode}
%
%    \begin{macrocode}
\newdimen\footnotesep
%    \end{macrocode}
%
% \end{oldcomments}
% \begin{macro}{\footnote}
% \changes{LaTeX2.09}{1991/11/01}
%         {(RmS) Added \cmd\let\cmd\protect\cmd\noexpand in
%          \cmd\footnote, \cmd\footnotemark,
%               and \cmd\footnotetext, since \cmd\xdef is used}
% \changes{LaTeX2.09}{1991/11/22}
%         {(RmS) Added \cmd\let\cmd\protect\cmd\noexpand in
%             \cmd{\@xfootnote}, \cmd{\@xfootnotemark},
%               and \cmd{\@xfootnotetext}}
% \changes{LaTeX2.09}{1992/11/26}
%         {(RmS) Changed all to 
%             `def`protect\string{`noexpand`protect`noexpand\string}}
% \changes{1994/11/26}{v1.1b}
%         {(ASAJ) Added \cs{protected@xdef}.}
%
%    \begin{macrocode}
\def\footnote{\@ifnextchar[\@xfootnote{\stepcounter{\@mpfn}%
     \protected@xdef\@thefnmark{\thempfn}%
     \@footnotemark\@footnotetext}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@xfootnote}
%    \begin{macrocode}
\def\@xfootnote[#1]{%
   \begingroup 
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
   \endgroup
   \@footnotemark\@footnotetext}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@footnotetext}
% \changes{LaTeX2.09}{1991/09/29}
%     {(RmS) added \cmd{\reset@font}}
% \changes{LaTeX2.09}{1992/11/26}
%     {(RmS) added protection for \cmd\edef}
% \changes{v1.0a}{1994/03/07}
%     {(DPC) Extra group for colour}
% \changes{v1.0c}{1994/03/14}
%     {(DPC) Use \cmd{\color@begingroup, add \cmd{\endgraf}}}
% \changes{v1.0d}{1994/04/18}
%     {(DPC) Remove Colour support}
% \changes{v1.0g}{1994/05/13}
%     {(DPC) Add new style colour support: \cs{normalcolor}}
% \changes{v1.0g}{1994/05/13}
%     {(DPC) Use \cs{@finalstrut}}
% \changes{v1.1a}{1994/10/31}
%     {(DPC/CAR) Move colour setting to output routine}
% \changes{v1.1b}{1994/11/04}
%     {(ASAJ) Added \cs{protected@edef}.}
% \changes{v1.1c}{1994/11/05}
%         {Removed \cs{normalcolor} (again)}
%    \begin{macrocode}
\long\def\@footnotetext#1{\insert\footins{%
    \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}}
%    \end{macrocode}
% \end{macro}
%
% \changes{1994/11/04}{v1.1b}{Added \cs{protected@xdef} to
%    \cs{footnotemark}.} 
%    \begin{macrocode}
\def\footnotemark{%
   \@ifnextchar[\@xfootnotemark
     {\stepcounter{footnote}%
      \protected@xdef\@thefnmark{\thefootnote}%
      \@footnotemark}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@xfootnotemark[#1]{%
   \begingroup 
      \c@footnote #1\relax
      \unrestored@protected@xdef\@thefnmark{\thefootnote}%
   \endgroup
   \@footnotemark}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@footnotemark{\leavevmode\ifhmode
  \edef\@x@sf{\the\spacefactor}\fi \@makefnmark
   \ifhmode\spacefactor\@x@sf\fi\relax}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\footnotetext{%
     \@ifnextchar [\@xfootnotenext
       {\protected@xdef\@thefnmark{\thempfn}%
    \@footnotetext}}

%    \end{macrocode}
%
%    \begin{macrocode}
\def\@xfootnotenext[#1]{%
  \begingroup 
     \csname c@\@mpfn\endcsname #1\relax
     \unrestored@protected@xdef\@thefnmark{\thempfn}%
  \endgroup
  \@footnotetext}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@mpfn{footnote}
\def\thempfn{\thefootnote}
%</2ekernel>
%    \end{macrocode}
%
% \Finale
%
