\def\fileversion{v1.2a}
\def\filedate{90/02/05}
\def\docdate {90/02/05}


%% \CheckSum{543}
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
%     
% \iffalse    This is a METACOMMENT
%           Everything up to the next `\ fi' (without a blank) will
%           be ignored.  This is necessary because `%' may no longer
%           be a comment mark when this file is read in.
%
% Style-option `multicol' to use with LaTeX v2.09
% Copyright (C) 1989,1990 Frank Mittelbach, all rights reserved.
%
% Copying of this file is authorized only if either
% (1) you make absolutely no changes to your copy, including name, or
% (2) if you do make changes, you name it something other than
%     multicol.doc or multicol.sty.
% This restriction helps ensure that all files developed at Mainz
% are identical.
%
%
% Error reports for UNCHANGED versions please to:
%
%                          F. Mittelbach
%                          Eichenweg 29
%                          D-6500 Mainz 1
%                          Federal Republic of Germany
%                 Bitnet:  <PZF5HZ@DRUEDS2>
%
%
%
% \fi
% 
% \changes{v1.0d}{89/05/17}{All lines shortened to 72 or less.}
% \changes{v1.0e}{89/06/21}{Redefinition of description env. to use
%                           `descriptionmargin'\quotechar=5pt 
%                           in documentation.}
% \changes{v1.0f}{89/07/11}{Changed `z@ to `0pt in redefinition of
%                           description.}
% \changes{v1.1a}{89/09/20}{`multicolssep changed to `multicolsep.}
% 
% \def\description{\list{}{\labelwidth 0pt \leftmargin\descriptionmargin
%    \itemindent-\leftmargin \let\makelabel\descriptionlabel}}
% \newdimen\descriptionmargin \descriptionmargin=5pt
%
% \DoNotIndex{\@M,\@Mi,\@bsphack,\@cclv,\@colht,\@currlist,\@deferlist}
% \DoNotIndex{\@elt,\@esphack,\@floatplacement}
% \DoNotIndex{\@ifundefined,\@ifnextchar,\@makecol}
% \DoNotIndex{\@ne,\@outputpage,\@scolelt,\@spaces,\@tempb,\@tempcnta}
% \DoNotIndex{\@warning,\@width}
% \DoNotIndex{\addvspace,\advance,\allowbreak}
% \DoNotIndex{\baselineskip,\begingroup,\box,\columnsep,\copy,\count}
% \DoNotIndex{\count@,\def,\dimen@,\divide,\docdate}
% \DoNotIndex{\edef,\eject,\egroup,\else,\endgroup,\endinput}
% \DoNotIndex{\fi,\fileversion,\filedate}
% \DoNotIndex{\gdef,\global}
% \DoNotIndex{\hbox,\hfil,\hrule,\ht,\hss}
% \DoNotIndex{\ifdim,\ifnum,\ifvoid,\ignorespaces,\insert,\immediate}
% \DoNotIndex{\let,\loop}
% \DoNotIndex{\maxdepth,\message,\multiply}
% \DoNotIndex{\newbox,\newcount,\newdimen,\newskip,\number,\newpage}
% \DoNotIndex{\outputpenalty,\p@,\penalty}
% \DoNotIndex{\relax,\repeat,\setbox,\skip,\space,\splitmaxdepth}
% \DoNotIndex{\splittopskip,\string,\sixt@@n}
% \DoNotIndex{\the,\thepage,\thr@@,\topskip,\tw@,\typeout}
% \DoNotIndex{\unvbox,\vbox,\vtop,\vfill,\vsplit,\voidb@x,\vrule}
% \DoNotIndex{\write,\wd}
% \DoNotIndex{\z@}
% 
% \title{An environment for multicolumn output\thanks{\EdNote This 
%        paper, with slight modification, is the basis for 
%        Mr.\ Mittelbach's citation
%        as the Donald~E. Knuth Scholar at the 1989 TUG Meeting.}
%       \thanks{This file
%        has version number \fileversion, last
%        revised \filedate, documentation dated \docdate.}}
% \author{Frank Mittelbach}
% \signature{\advance\hsize by 3pc
%       Frank Mittelbach\\
%       Eichenweg 29\\
%	D-6500 Mainz 1\\
%	Federal Republic of Germany\\
%	\net {\rm Bitnet:} pzf5hz@drueds2}
% \date{Printed \today}
% 
% \maketitle
% 
% \begin{abstract}
%   This article describes the use and the implementation of the {\sf
%   multicols} environment. This environment allows switching between
%   one and multicolumn format on the same page. Footnotes are handled
%   correctly (for the most part), but will be placed at the bottom of
%   the page and not under each column.  \LaTeX{}'s float mechanism,
%   however, is partly disabled in the current implementation and will
%   be added in a later version. At the moment only floats contributed
%   outside the scope of the environment will find their way into the
%   actual output.
% \end{abstract}
% 
% \begin{multicols}{3}[\section{Preface to version 1.2}]
%   After the article about the {\tt multicols} environment was
%   published in \TUB\ 10\#3, I got numerous requests for distributing
%   these macros. However I also got a changed version of my style
%   file together with a letter, asking me if I would include the
%   changes to get better paragraphing results in the case of narrow
%   lines. The main differences to my original style option where
%   additional parameters (like \verb+\multicoladjdemerits+ to be used
%   for \verb+\adjdemerits+ etc.) which would influence the line
%   breaking algorithm.
%
%   But actually resetting such parameters to zero or even worse to a
%   negative value won't give better line breaks inside the {\tt
%   multicols} environment. \TeX{}s line breaking algorithm will only
%   look at those possible line breaks which can be reached without a
%   badness higher than the current value of \verb+\tolerance+ (or
%   \verb+\pretolerance+ in the first pass). If this isn't possible,
%   then, as a last resort, \TeX{} will produce overfull boxes. All
%   those (and only those) possible break points will be considered
%   and finally the sequence which results in the fewest demerits will
%   be chosen. This means that a value of $-1000$ for
%   \verb+\adjdemerits+ simply instructs \TeX{} to prefer visibly
%   incompatible lines instead of producing better line breaks.
%
%   However with \TeX{} 3.0 it is possible to get decent line breaks
%   even in small columns by setting \verb+\emergencystretch+ to an
%   appropriate value. I implemented a version which is capable of
%   running both in the old and the new \TeX{} (actually it will
%   simply ignore the new feature if it is not available). The
%   calculation of \verb+\emergencystretch+ is probably incorrect. I
%   made a few tests but of course one has have much more experience
%   with the new possibilities to achieve the maximum quality.
%
%   In version 1.1a was a nice `feature': the penalty for using the
%   forbidden floats was their ultimate removal from \LaTeX{}s
%   \verb+\@freelist+ so that after a few \verb+\marginpar+s inside
%   the {\tt multicols} environment floats where disabled forever.
%   (Thanks to Chris Rowley for pointing this out.) I removed this
%   missbehaviour and at the same time decided to allow at least floats
%   spanning all columns, e.g.\ generated by \verb+\begin{figure*}+.
%   You can see the new functionality in table~\ref{tab:newcmds} which
%   was inserted at this very point.
%   \begin{table*}
%   \begin{center}
%   \begin{minipage}[t]{.55\textwidth}
%      \verb+\setemergencystretch+: This is a hook for people who like
%      to play around. It is supposed to set the
%      \verb+\emergencystretch+ \meta{dimen} register provided in the
%      new \TeX{} 3.0. The first argument is the number of columns and
%      the second one is the current \verb+\hsize+. At the moment the
%      default definition is $4{\tt pt} \times \verb+#1+$, i.e.\ the
%      \verb+\hsize+ isn't used at all. But maybe there are better
%      formulae.
%   \end{minipage}
%   \hfil
%   \begin{minipage}[t]{.35\textwidth}
%      \setlength{\emergencystretch}{20pt}
%      \verb+\set@floatcmds+: This is the hook for the experts who
%      like to implement a full float mechanism for the {\tt
%      multicols} environment. The \verb+@+ in the name should signal
%      that this might not be easy.
%   \end{minipage}
%   \end{center}
%   \caption[]{The new commands of {\tt multicol.sty} version 1.2.
%            Both commands might be removed if good solutions to these
%            open problems are found. I hope that these commands will
%            prevent that nearly identical style files derived from
%            this one are floating arround.}
%   \label{tab:newcmds}
%   \end{table*}
%   However single column floats are still forbidden and I don't think
%   I will have time to tackle this problem in the near future. As an
%   advice for all who want to try: wait for \TeX{} 3.0 it has a few
%   features which will make life much easier in multi-column
%   surroundings. Nevertheless we are working here at the edge of
%   \TeX{}s capabilities, really perfect solutions would need a
%   different approach than it was done in \TeX{}s page builder.
%
%   The text below is nearly unchanged, I only added documentation at 
%   places where new code was added.
% \end{multicols}
% 
% \begin{multicols}{3}[\section{Introduction}]
%   Switching between two column and one column layout is possible in
%   \LaTeX{}, but every use of \verb+\twocolumn+ or \verb+\onecolumn+
%   starts a new page. Moreover, the last page of two column output
%   isn't balanced and this often results in an empty, or nearly
%   empty, right column. When I started to write macros for {\tt
%   doc.sty} (see ``The {\tt doc}--Option'', \TUB\
%   volume 10~\#2, pp.~245--273) I thought that it would be nice to
%   place the index
%   on the same page as the bibliography. And balancing the last page
%   would not only look better, it also would save space; provided of
%   course that it is also possible to start the next article on the
%   same page. Rewriting the index environment was comparatively easy,
%   but the next goal, designing an environment which takes care of
%   footnotes, floats etc., was a harder task. It took me a whole
%   weekend\footnote{I started with the algorithm given in the \TeX
%   book on page 417. Without this help a weekend would not have been
%   enough.} to get together the few lines of code below and there is
%   still a good chance that I missed something after all.
% 
%   Try it and, hopefully, enjoy it; and {\em please\/} direct bug
%   reports and suggestions back to Mainz.
% \end{multicols}
%
% 
% \begin{multicols}{3}[\section{The User Interface}]
%
%   To use the environment one simply says\\*[2mm]
%     \hspace*{2mm}\verb+\begin{multicols}{+\meta{number}\verb+}+
%     \hspace*{12mm}\meta{multicolumn text}\\
%     \hspace*{2mm}\verb+\end{multicols}+\\[2mm]
%   where \meta{number} is the required number of columns and
%^^A\meta{multicolumn text} 
%   $\langle${\it multi\-column text\/}$\rangle$ may contain arbitrary
%   \LaTeX{} commands, except that floats and marginpars are not
%   allowed in the current implementation\footnote{This is dictated by
%   lack of time.  To implement floats one has to reimplement the
%   whole \LaTeX{} output routine.}.
% 
% \DescribeMacro\premulticols
% As its first action, the {\sf multicols} environment measures the
% current page to determine whether there is enough room for some
% portion of multicolumn output. This is controlled by the
% \meta{dimen} variable \verb+\premulticols+ which can be changed by
% the user with ordinary \LaTeX{} commands.
% \DescribeMacro\multicolsep
% If the space is less than \verb+\premulticols+, a new page is
% started.  Otherwise, a \verb+\vskip+ of \verb+\multicolsep+ is
% added.\footnote{Actually the added space may be less because we use
% {\tt\bslash addvspace} (see the \LaTeX{} manual for further
% information about this command).}
% 
% \DescribeMacro\postmulticols
% When the end of the {\sf multicols} environment is encountered, an
% analogous mechanism is employed, but now we test whether there is a
% space larger than \verb+\postmulticols+ available. Again we add
% \verb+\multicolsep+ or start a new page.
%
% It is often convenient to spread some text over all columns, just
% before the multicolumn output, without any page break in between. To
% achieve this the {\sf multicols} environment has an optional second
% argument which can be used for this purpose. For example, the text
% you are now reading was started with
% \begin{verbatim}
% \begin{multicols}{3}
%   [\section{The User
%             Interface}] ...   
%\end{verbatim}
% If such text is unusually long (or short) the value of
% \verb+\premulticols+ might need adjusting to prevent a bad page
% break.  We therefore provide a third argument which can be used to
% overwrite the default value of \verb+\premulticols+ just for this
% occasion. 
%
% \DescribeMacro\columnseprule
% Separation of columns with vertical rules is achieved by setting the
% parameter \verb+\columnseprule+ to some positive value.  In this
% article a value of {\sf.4pt} was used.
%
% \DescribeMacro\multicolbaselineskip
% Since narrow columns tend to need adjustments in interline spacing
% we also provide a \meta{skip} parameter called
% \verb+\multicolbaselineskip+ which is added to the
% \verb+\baselineskip+ parameter inside the {\sf multicols}
% environment.  Please use this parameter with care or leave it alone;
% it is intended only for style file designers since even small changes
% might produce totally unexpected changes to your document.
% 
%
%    \subsection{Balancing Columns}
% 
% Besides the previously mentioned parameters, some others are
% provided to influence the layout of the columns generated.
% 
% Paragraphing in \TeX{} is controlled by several parameters. One of
% the most important is called \verb+\tolerance+: this controlls the
% allowed `looseness' (i.e.\ the amount of blank space between words).
% Its default value is 200 (the \LaTeX{} \verb+\fussy+) which is too
% small for narrow columns. On the other hand the \verb+\sloppy+
% declaration (which sets \verb+\tolerance+ to $10000=\infty$) is too
% large, allowing really bad spacing.\footnote{Look at the next
% paragraph, it was set with the {\tt \bslash sloppy} declaration.}
% 
% \begin{sloppypar}
% We therefore use a \verb+\multicolstolerance+ parameter for the
% \verb+\tolerance+ value inside the {\sf multicols} environment.  Its
% default value is 9999 which is less than infinity but `bad' enough
% for most paragraphs in a multicolumn environment. Changing its value
% should be done outside the {\sf multicols} environment.  Since
% \verb+\tolerance+ is set to \verb+\multicolstolerance+ at the
% beginning of every {\sf multicol} environment one can locally
% overwrite this default by assigning \verb*+\tolerance = +^^A
% \meta{desired value}.
% \end{sloppypar}
% 
% Generation of multicolumn output can be divided into two parts.
% In the first part we are collecting material for a page, shipping
% it out, collecting material for the next page, and so on.
% As a second step, balancing will be done when the end of the
% {\sf multicols} environment is reached.
% In the first step \TeX{} might consider more material whilst
% finding the final columns than it actually use when shipping out the
% page. This might cause a problem if a footnote is encountered in
% the part of the input considered, but not used, on the current page.
% In this case the footnote might show up on the current page, while the
% footnotemark corresponding to this footnote might be set on the next 
% one.\footnote{The reason behind this behavior is the asynchronous
%               character of the \TeX{} {\it page\_builder}.
%               However, this
%               could be avoided by defining very complicated output
%               routines which don't use \TeX{} primitives like 
%               {\tt\bslash insert} but do everything by hand.
%               This is clearly beyond the scope of a weekend problem.}
% Therefore the {\sf multicols} environment gives a warning 
% message\footnote{This message will be generated even if there are no
%                  footnotes in this part of the text.}
% whenever it is unable to use all the material considered so far.
% 
% If you don't use footnotes too often the chances of something
% actually going wrong are very slim, but if this happens you can help
% \TeX{} by using a \verb+\pagebreak+ command in the final document.
% Another way to influence the behavior of \TeX{} in this respect is
% given by the counter variable `{\sf collectmore}'. If you use the
% \verb+\setcounter+ declaration to set this counter to \meta{number},
% \TeX{} will consider \meta{number} more (or less) lines before
% making its final decision. So a value of $-1$ may solve all your
% problems at the cost of slightly less optimal columns.
% 
% In the second step (balancing columns) we have other bells and
% whistles. First of all you can say \verb+\raggedcolumns+ if you
% don't want the bottom lines to be aligned.  The default is
% \verb+\flushcolumns+, so \TeX{} will normally try to make both the
% top and bottom baselines of all columns align.
% 
% Additionally you can set another counter, the `{\sf unbalance}'
% counter, to some positive \meta{number}. This will make all but the
% right-most column \meta{number} of lines longer than they would
% normally have been. `Lines' in this context refer to normal text
% lines (i.e.\ one \verb+\baselineskip+ apart); thus, if your columns
% contain displays, for example, you may need a higher \meta{number}
% to shift something from one column into another.
%
% Unlike `{\sf collectmore},' the `{\sf unbalance}' counter is reset
% to zero at the end of the environment so it only applies to one {\sf
% multicols} environment.
% 
% The two methods may be combined but I suggest using these features
% only when fine tuning important publications.
%
%
% \subsection{Tracing the output}
%
% To understand the reasoning behind the decisions \TeX{} makes when
% processing a {\sf multicols} environment, a tracing mechanism is
% provided.  If you set the counter `{\sf
% tracingmulticols}' to a positive \meta{number} you then will get
% some tracing information on the terminal and in the transcript file:
% \begin{description}
% \item[$\meta{number}=1$.]
%    \TeX{} will now tell you, whenever it enters or leaves a {\sf
%    multicols} environment, the number of columns it is working on
%    and its decision about starting a new page before or after the
%    environment.
% \item[$\meta{number}=2$.]
%    In this case you also get information from the balancing routine:
%    the heights tried for the left and right-most columns,
%    information about shrinking if the \verb+\raggedcolumns+
%    declaration is in force and the value of the `{\sf unbalance}'
%    counter if positive.
% \item[$\meta{number}\geq 3$.]
%    Setting \meta{number} to such a high value will additionally
%    place an \verb+\hrule+ into your output, separating the part of
%    text which had already been considered on the previous page from
%    the rest.  Clearly this setting should {\em not\/} be used for
%    the final output.
% \end{description}
% \end{multicols}
% 
% \StopEventually{\PrintIndex \PrintChanges \makesignature}
%
% 
% \begin{multicols}{2}[\section{The Implementation}
%         We are now switching to two-column output to show the
%         abilities of this environment (and bad layout decisions).]
%
% \subsection{Starting and Ending the {\sf multicols} Environment}
%
% As always we begin by identifying the latest version of this file
% on the VDU and in the transcript file but we abort if this file
% was already read in.
% \changes{v1.0e}{89/06/21}{Abort if file already read in.}
%    \begin{macrocode}
\@ifundefined{mult@cols}{}{\endinput}
\typeout{Style option: `multicol'
   \fileversion\space <\filedate> (FMi)}
\typeout{English documentation
 \@spaces\@spaces\space<\docdate> (FMi)}
%    \end{macrocode}
%
% \begin{macro}{\multicols}
%    As mentioned before, the {\sf multicols} environment has one
%    mandatory argument (the number of columns) and up to two optional
%    ones.  We start by reading the number of columns into the
%    \verb+\col@number+ register.
%    \begin{macrocode}
\def\multicols#1{\col@number#1\relax
%    \end{macrocode}
%    If the user forgot the argument, \TeX{} will complain about a
%    missing number at this point. The error recovery mechanism will
%    then use zero, which isn't a good choice in this case. So we
%    should now test whether everything is okay.
%    \begin{macrocode}
  \ifnum\col@number<\@ne
     \@warning{Using `\number\col@number'
       columns doesn't seem a good idea.^^J
       I therefore use two columns instead}%
     \col@number\tw@ \fi
%    \end{macrocode}
%    Now we can safely look for the optional arguments.
%    \begin{macrocode}
  \@ifnextchar[\mult@cols{\mult@cols[]}}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\mult@cols}
%    The \verb+\mult@cols+ macro grabs the first optional argument
%    (if any) and looks for the second one.
%    \begin{macrocode}
\def\mult@cols[#1]{\@ifnextchar[%
%    \end{macrocode}
%    This argument should be a \meta{dimen} denoting the minimum free
%    space needed on the current page to start the environment. If the
%    user didn't supply one, we use \verb+\premulticols+ as a
%    default.
%    \begin{macrocode}
  {\mult@@cols{#1}}%
  {\mult@@cols{#1}[\premulticols]}}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\mult@@cols}
%    After removing all arguments from the input we are able
%    to start with \verb+\mult@@cols+.
%    First we look to see if statistics are requested:
%    \begin{macrocode}
\def\mult@@cols#1[#2]{%
  \ifnum\c@tracingmulticols>\z@
      \typeout{^^J^^JStarting multicolumn
               output with \the\col@number
               \space columns:^^J}\fi   
%    \end{macrocode}
%    Then we measure the current page to see whether a useful portion
%    of the multicolumn environment can be typeset.  This routine
%    might start a new page.
%    \begin{macrocode}
   \enough@room#2%
%    \end{macrocode}
%    Now we output the first argument and produce vertical space
%    above the columns. (Note that this argument corresponds to the
%    first optional argument of the {\sf multicols} environment.)
%    \begin{macrocode}
   #1\par\addvspace\multicolsep 
%    \end{macrocode}
%    We start a new grouping level to hide all subsequent changes
%    (done in \verb+\prepare@multicols+ for example) and finish by
%    suppressing initial spaces.
%    \begin{macrocode}
   \begingroup
   \prepare@multicols\ignorespaces}
%    \end{macrocode}
% \end{macro} 
%
% \begin{macro}{\enough@room}
% \changes{v1.0c}{89/05/12}{Penalty 0 added to empty the contribution
%                           list.}
%    The \verb+\enough@room+ macro used
%    above isn't perfect but works reasonably well in this context. We
%    measure the free space on the current page by subtracting
%    \verb+\pagetotal+ from \verb+\pagegoal+. This isn't entirely
%    correct since it doesn't take the `shrinking' (i.e.\
%    \verb+\pageshrink+) into account.  The `recent contribution list'
%    might be nonempty so we start with \verb+\par+ and an explicit
%    \verb+\penalty+.\footnote{See the documentation of {\tt\bslash
%    endmulticols} for further details.}
%    \begin{macrocode}
\def\enough@room#1{\par \penalty\z@
   \page@free \pagegoal
   \advance \page@free -\pagetotal
%    \end{macrocode}
%    Now we test whether tracing information is required:
%    \begin{macrocode}
   \ifnum \c@tracingmulticols>\z@
     \typeout{Current page:}%
     \message{\@spaces goal height=%
       \the\pagegoal: used \the\pagetotal
       \space -> free=\the\page@free}%
     \typeout{\@spaces needed \the#1
              (for \string#1)}\fi
%    \end{macrocode}
%    Our last action is to force a page break if there isn't enough
%    room left.
%    \begin{macrocode}
   \ifdim \page@free <#1\newpage \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\prepare@multicols}
%    When preparing for multicolumn output several things must
%    be done. First we remove everything from the `current page'
%    and save it in the box \verb+\partial@page+.
%    \begin{macrocode}
\def\prepare@multicols{%
  \output{\global\setbox\partial@page
                 \vbox{\unvbox\@cclv}}\eject
%    \end{macrocode}
%    Then we assign new values to \verb+\vbadness+, \verb+\hbadness+
%    and \verb+\tolerance+ since it's rather hard for \TeX{} to
%    produce `good' paragraphs within narrow columns.
% \changes{v1.2a}{90/02/05}{`vbadness 10001 now.}
%    \begin{macrocode}
  \vbadness10001 \hbadness5000
  \tolerance\multicoltolerance 
%    \end{macrocode}
%    Since nearly always the first pass will fail we ignore it
%    completely telling \TeX{} to hyphenate directly.
% \changes{v1.2a}{90/02/05}{`pretolerance -1 because it nearly never
%                            succeeds.}
%    \begin{macrocode}
  \pretolerance\m@ne
%    \end{macrocode}
%    For use with the new \TeX{} we set \verb+\emergencystretch+ to
%    $\verb+\col@number+ \times 4pt$. However this is only a guess
%    so at the moment this is done in a macro
%    \verb+\setemergencystretch+ which gets the current \verb+\hsize+
%    and the number of columns as arguments. Therefore users are able
%    to figure out their own formula.
% \changes{v1.2a}{90/02/05}{`setemergencystretch added.}
%    \begin{macrocode}
  \setemergencystretch\col@number\hsize    
%    \end{macrocode}
%    Another hook to allow people adding their own extensions without
%    making a new style option is \verb+\set@floatcmds+ which handles
%    any redefinitions of \LaTeX{}s internal float commands to work
%    with the {\tt multicols} environment. At the moment it is only
%    used to redefine \verb+\@dblfloat+ and \verb+\end@dblfloat+.
% \changes{v1.2a}{90/02/05}{`set@floatcmds added.}
%    \begin{macrocode}
  \set@floatcmds
%    \end{macrocode}
%    We also set the register \verb+\doublecol@number+ for later use.
%    This register should contain $2\times \verb+\col@number+$.
%    \begin{macrocode}
  \doublecol@number\col@number
  \multiply\doublecol@number\tw@
%    \end{macrocode}
%    Additionally, we advance \verb+\baselineskip+ by
%    \verb+\multicolbaselineskip+ to allow corrections for narrow
%    columns.
%    \begin{macrocode}
  \advance\baselineskip\multicolbaselineskip
%    \end{macrocode}
%    The thing to do is to assign a new value to \verb+\vsize+.
%    \LaTeX{} maintains the free room on the page (i.e.\ the page
%    height without the space for already contributed floats) in the
%    register \verb+\@colroom+. We must subtract the height of
%    \verb+\partial@page+ to put the actual free room into this
%    variable.
%    \begin{macrocode}
  \advance\@colroom-\ht\partial@page
%    \end{macrocode}
%    Since we have to set \verb+\col@umber+ columns on one page,
%    each with a height of \verb+\@colroom+, we have to assign
%    $
%      \verb+\vsize+  = \verb+\col@number+ \times \verb+\@colroom+
%    $
%    in order to collect enough material before entering the 
%    \verb+\output+ routine again.
%    \begin{macrocode}
  \vsize\col@number\@colroom
%    \end{macrocode}
%    But this might not be enough since we use \verb+\vsplit+ later to
%    extract the columns from the gathered material. Therefore we add
%    some `extra lines,' the number depending on the value of the
%    `{\sf collectmore}' counter.
%    \begin{macrocode}
  \advance\vsize\c@collectmore\baselineskip
%    \end{macrocode}
% \changes{v1.0e}{89/06/21}{`columnwidth changed to `textwidth.}
% \changes{v1.0e}{89/06/21}{So this file will
%                           work with the `twocolumn' command.}
%    The \verb+\hsize+ of the columns is given by the formula:
%    \[
%       { \verb+\columnwidth+ - (\verb+\col@number+-1) 
%                             \times
%                             \verb+\columnsep+
%        \over
%        \verb+\col@number+}
%    \]
%    This will be achieved with:
%    \begin{macrocode}
  \hsize\columnwidth \advance\hsize\columnsep
  \advance\hsize-\col@number\columnsep
  \divide\hsize\col@number 
%    \end{macrocode}
%    We also set \verb+\linewidth+ to \verb+\hsize+ but leave
%    \verb+\columnwidth+ unchanged. This is inconsistent,
%    but \verb+\columnwidth+ is used only by floats (which
%    aren't allowed in their current implementation) and by the 
%    \verb+\footnote+ macro. Since we want pagewide
% footnotes\footnote{I'm not sure that I really want pagewide
%                       footnotes. But balancing of the last page can
%                       only be achieved with this approach or with a
%                       multi-path algorithm which is complicated and
%                       slow. But it's a challenge to everybody to
%                       prove me wrong!  Another possibility is to
%                       reimplement a small part of the {\it
%                       fire\_up\/} procedure in \TeX{} (the program).
%                       I think that this is the best solution if you
%                       are interested in complex page makeup, but it
%                       has the disadvantage that the resulting
%                       program cannot be called \TeX{} thereafter.}
%    this simple trick saves us from rewriting the \verb+\footnote+
%    macros.
% \changes{v1.0e}{89/06/21}{Setting of `columnwidth' removed.}
%    \begin{macrocode}
  \linewidth\hsize 
%    \end{macrocode}
%    Now we switch to a new \verb+\output+ routine which will be used
%    to put the gathered column material together.
%    \begin{macrocode}
  \output{\multi@columnout}%
%    \end{macrocode}
%    Finally we handle the footnote insertions. We have to multiply
%    the magnification factor and the extra skip by the number of
%    columns since each footnote reduces the space for every column
%    (remember that we have pagewide footnotes).  If, on the other
%    hand, footnotes are typeset at the very end of the document, our
%    scheme still works since \verb+\count\footins+ is zero then, so it
%    will not change.
%    \begin{macrocode}
  \multiply\count\footins\col@number
  \multiply\skip \footins\col@number
%    \end{macrocode}
%    For the same reason (pagewide footnotes), the \meta{dimen}
%    register controlling the maximum space used for footnotes isn't
%    changed.  Having done this, we must reinsert all the footnotes
%    which are already present (i.e.\ those encountered when the
%    material saved in \verb+\partial@page+ was first processed). This
%    will reduce the free space (i.e.\ \verb+\pagetotal+) by the
%    appropriate amount since we have changed the magnification
%    factor, etc.\ above.
%    \begin{macrocode}
  \reinsert@footnotes}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\endmulticols}
%    When the end of the {\sf multicols} environment is sensed we have
%    to balance the gathered material. We end the current paragraph
%    with \verb+\par+ but this isn't sufficient since \TeX{}s {\it
%    page\_builder} will not totally empty the contribution
%    list.\footnote{This once caused a puzzling bug where some of the
%    material was balanced twice, resulting in some overprints.  The
%    reason was the {\tt\bslash eject} which was placed at the end of
%    the contribution list. Then the {\it page\_builder} was called
%    (an explicit {\tt\bslash penalty} will empty the contribution
%    list), but the line with the {\tt\bslash eject} didn't fit onto
%    the current page.  It was then reconsidered after the output
%    routine had ended, causing a second break after one line.}
%    Therefore we must also add an explicit \verb+\penalty+.  Now the
%    contribution list will be emptied and, if its material doesn't
%    all fit onto the current page then the output routine will be
%    called before we change it.
%    \begin{macrocode}
\def\endmulticols{\par\penalty\z@
%    \end{macrocode}
%    Now it's safe to change the output routine in order to balance
%    the columns.
%    \begin{macrocode}
  \output{\balance@columns}\eject
%    \end{macrocode}
%    The output routine above will take care of the \verb+\vsize+ and
%    reinsert the balanced columns, etc. But it can't reinsert the
%    \verb+\footnotes+ because we first have to restore the
%    \verb+\footins+ parameter since we are returning to one column
%    mode. This will be done in the next line of code; we simply close
%    the group started in \verb+\multicols+.
%    \begin{macrocode}
  \endgroup \reinsert@footnotes
%    \end{macrocode}
%    We also set the `{\sf unbalance}' counter to its default. This is
%    done globally since \LaTeX{} counters are always changed this
%    way.\footnote{Actually, we are still in a group started by the
%    {\tt \bslash begin} macro, so {\tt\bslash global} must be used
%    anyway.}
%    \begin{macrocode}
  \global\c@unbalance\z@
%    \end{macrocode}
%    We also take a look at the amount of free space on the current
%    page to see if it's time for a page break.  The vertical space
%    added thereafter will vanish if \verb+\enough@room+ starts a new
%    page.
%    \begin{macrocode}
  \enough@room\postmulticols
  \addvspace\multicolsep
%    \end{macrocode}
%    If statistics are required we finally report that we have
%    finished everything.
%    \begin{macrocode}
  \ifnum\c@tracingmulticols>\z@
     \typeout{^^JEnding multicolumn
              output.^^J^^J}\fi}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\c@unbalance}
% \SpecialMainIndex{\c@collectmore}
% \SpecialMainIndex{\c@tracingmulticols}
% \SpecialMainIndex{\col@number}
% \SpecialMainIndex{\doublecol@number}
% \SpecialMainIndex{\premulticols}
% \SpecialMainIndex{\multicoltolerance}
% \SpecialMainIndex{\page@free}
% \SpecialMainIndex{\premulticols}
% \SpecialMainIndex{\postmulticols}
% \SpecialMainIndex{\multicolsep}
% \SpecialMainIndex{\multicolbaselineskip}
% \SpecialMainIndex{\partial@page}
%    Let us end this section by allocating all the registers used so
%    far.
%    \begin{macrocode}
\newcount\c@unbalance     \c@unbalance   = 0
\newcount\c@collectmore   \c@collectmore = 0
\newcount\c@tracingmulticols 
                     \c@tracingmulticols = 0
\newcount\col@number 
\newcount\doublecol@number
\newcount\multicoltolerance
                   \multicoltolerance = 9999
\newdimen\page@free
\newdimen\premulticols  \premulticols = 50pt
\newdimen\postmulticols \postmulticols= 20pt
\newskip\multicolsep 
      \multicolsep = 12pt plus 4pt minus 3pt
\newskip\multicolbaselineskip 
                   \multicolbaselineskip=0pt 
%    \end{macrocode}
%    We also need a box into which the ``current page'' can be put.
%    \begin{macrocode}
\newbox\partial@page
%    \end{macrocode}
% \end{macro}
%
% \subsection{The output routines}
%
% We first start with some simple macros. When typesetting the page we
% save the columns either in the box registers 0, 2, 4,\ldots\
% (locally) or 1, 3, 5,\ldots\ (globally). This is \PlainTeX{} policy
% to avoid an overflow of the save stack.
%
% \begin{macro}{\process@cols}
%    Therefore we define a \verb+\process@cols+ macro to help us in
%    using these registers in the output routines below. It has two
%    arguments: the first one is a number; the second one is the
%    processing information.  It loops starting with \verb+\count@=#1+
%    (\verb+\count@+ is a scratch register defined in \PlainTeX),
%    processes argument \verb+#2+, adds two to \verb+\count@+,
%    processes argument \verb+#2+ again, etc.\ until \verb+\count@+ is
%    higher than \verb+\doublecol@number+.  It might be easier to
%    understand it through an example, so we first define it and
%    explain its usage afterwards.
%    \begin{macrocode}
\def\process@cols#1#2{\count@#1\relax
     \loop #2%
     \advance\count@\tw@
     \ifnum\count@<\doublecol@number 
   \repeat}
%    \end{macrocode}
% \end{macro}
% 
%
% \begin{macro}{\page@sofar}
%    We now define \verb+\page@sofar+ to give an example of the
%    \verb+\process@cols+ macro. \verb+\page@sofar+ should output
%    everything on the `current page'. So we start by unboxing
%    \verb+\partial@page+ (i.e.\ the part above the {\sf multicols}
%    environment).  If the \verb+\partial@page+ is void (i.e.\ if the
%    {\sf multicols} environment started on a new page or if we
%    typeset several pages within the {\sf multicols} environment)
%    this will produce nothing.
%    \begin{macrocode}
\def\page@sofar{\unvbox\partial@page 
%    \end{macrocode}
%    Now we output the columns gathered assuming that they are saved
%    in the box registers 2 (left column), 4 (second column), \ldots\
%    However, the last column (i.e.\ the right-most) should be saved in
%    box register 0.\footnote{You will see the reason for this numbering
%                             when we look at the output routines
%                             {\tt\bslash multi@columnout} and
%                             {\tt\bslash balance@column}.}
%    First we ensure that the columns have equal width. We use
%    \verb+\process@cols+ for this purpose, starting with
%    $\verb+\count@+=0$. Therefore \verb+\count@+ loops through
%    0, 2,\ldots (to \verb+\doublecol@number+).
%    \begin{macrocode}
   \process@cols\z@{\wd\count@\hsize}%
%    \end{macrocode}
%    Now we put all columns together in an \verb+\hbox+ of width
%    \verb+\textwidth+
%    \begin{macrocode}
   \hbox to\textwidth{%
%    \end{macrocode}
%    separating them with a rule if desired.
%    \begin{macrocode}
     \process@cols\tw@{\box\count@
       \hss\vrule\@width\columnseprule\hss}%
%    \end{macrocode}
%    As you will have noticed, we started with box register 2 (i.e.\
%    the left column). So this time \verb+\count@+ looped through 2,
%    4,\ldots\ Finally we add box 0 and close the \verb+\hbox+.
%    \begin{macrocode}
     \box\z@}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\reinsert@footnotes}
%    Before we tackle the bigger output routines we define just one
%    more macro which will help us to find our way through the
%    mysteries later. \verb+\reinsert@footnotes+ will do what its name
%    indicates: it reinserts the footnotes present in
%    \verb+\footinbox+ so that they will be reprocessed by \TeX{}'s
%    {\it page\_builder}.
%    \begin{macrocode}
\def\reinsert@footnotes{\ifvoid\footins\else
         \insert\footins{\unvbox\footins}\fi}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\multi@columnout}
%    Now we can't postpone the difficulties any longer.  The
%    \verb+\multicolumnout+ routine will be called in two situations.
%    Either the page is full (i.e.\ we have collected enough material
%    to generate all the required columns) or a float or marginpar is
%    sensed.  In the latter case the \verb+\outputpenalty+ is less
%    than $-10001$, otherwise the penalty which triggered the output
%    routine is higher.  Therefore it's easy to distinguish both
%    cases: we simply test this register.
%    \begin{macrocode}
\def\multi@columnout{%
   \ifnum\outputpenalty <-\@Mi
%    \end{macrocode}
%    If this was a float or a marginpar we call \verb+\speci@ls+
%    \begin{macrocode}
   \speci@ls \else
%    \end{macrocode}
%    otherwise we contruct the final page. Actually a
%    \verb+\clearpage+ will be silently accepted, producing the same
%    effects as a \verb+\newpage+, since we didn't distinguish between
%    a penalty of $-10000$ and $-10001$ (produced by a
%    \verb+\clearpage+).  Let us now consider the normal case. We have
%    to \verb+\vsplit+ the columns from the accumulated material in
%    box 255.  Therefore we first assign appropriate values to
%    \verb+\splittopskip+ and \verb+\splitmaxdepth+.
%    \begin{macrocode}
   \splittopskip\topskip 
   \splitmaxdepth\maxdepth
%    \end{macrocode}
%    Then we calculate the current column height (in \verb+\dimen@+).
%    Note that the height of \verb+\partial@page+ is already
%    substracted from \verb+\@colroom+ so we can use its value as a
%    starter.
%    \begin{macrocode}
   \dimen@\@colroom
%    \end{macrocode}
%    But we must also substract the space occupied by footnotes on the
%    current page. Note that we first have to reset the skip register
%    to its normal value.
%    \begin{macrocode}
   \divide\skip\footins\col@number
   \ifvoid\footins \else
      \advance\dimen@-\skip\footins 
      \advance\dimen@-\ht\footins   \fi
%    \end{macrocode}
%    Now we are able to \verb+\vsplit+ off all but the last column.
%    Recall that these columns should be saved in the box registers 2,
%    4,\ldots
%    \begin{macrocode}
   \process@cols\tw@{\setbox\count@
            \vsplit\@cclv to\dimen@}%
%    \end{macrocode}
%    Then the last column follows.
%    \begin{macrocode}
   \setbox\z@\vsplit\@cclv to\dimen@
%    \end{macrocode}
%    Having this done we hope that box 255 is emptied. If not, we
%    reinsert its contents.
%    \begin{macrocode}
   \ifvoid\@cclv \else 
       \unvbox\@cclv
       \penalty\outputpenalty
%    \end{macrocode}
%    If the `{\sf tracingmulticols}' counter is 3 or higher we also
%    add a rule. And in any case we inform the user about our bad
%    luck.
%    \begin{macrocode}
       \ifnum \c@tracingmulticols>\tw@ 
                    \hrule\allowbreak \fi
       \@warning{I moved some lines to 
                     the next page.^^J
            \@spaces Footnotes on page
         \thepage\space might be wrong}\fi     
%    \end{macrocode}
%    With a little more effort we could have done better. If we had,
%    for example, recorded the shrinkage of the material in
%    \verb+\partial@page+ it would be now possible to try higher
%    values for \verb+\dimen@+ (i.e.\ the column height) to overcome
%    the problem with the nonempty box 255. But this would make the
%    code even more complex so I skipped it in the current
%    implementation.
%    
%    Now we use \LaTeX{}'s standard output 
%    mechanism.\footnote{This will produce a lot of overhead since both
%                       output routines are held in memory. The correct
%                       solution would be to redesign the whole output
%                       routine used in \LaTeX.}
%    Admittedly this is a funny way to do it.
%    \begin{macrocode}
   \setbox\@cclv\vbox{\page@sofar}%
%    \end{macrocode}
%    The macro \verb+\@makecol+ adds all floats assigned for the
%    current page to this page.  \verb+\@outputpage+ ships out the
%    resulting box.  Note that it is just possible that such floats
%    are present even if we do not allow any inside a {\sf multicols}
%    environment.
%    \begin{macrocode}
   \@makecol\@outputpage
%    \end{macrocode}
%    Now we reset \verb+\@colroom+ to \verb+\@colht+ which is \LaTeX's
%    saved value of \verb+\textheight+.
%    \begin{macrocode}
   \global\@colroom\@colht
%    \end{macrocode}
%    Then we process deferred floats waiting for their chance to be
%    placed on the next page.
%    \begin{macrocode}
   \process@deferreds
%    \end{macrocode}
%    If the user is interested in statistics we inform him about the
%    amount of space reserved for floats.
%    \begin{macrocode}
   \ifnum\c@tracingmulticols>\@ne
     \typeout{Colroom: \the\@colht\space
              after float space removed
              = \the\@colroom }\fi
%    \end{macrocode}
%    Having done all this we must prepare to tackle the next page.
%    Therefore we assign a new value to \verb+\vsize+.  New, because
%    \verb+\partial@page+ is now empty and \verb+\@colroom+ might be
%    reduced by the space reserved for floats.
%    \begin{macrocode}
   \global\vsize\col@number\@colroom 
   \global\advance\vsize
      \c@collectmore\baselineskip
%    \end{macrocode}
%    We also have to readjust the \verb+\footins+ skip register.
%    \begin{macrocode}
   \multiply\skip\footins\col@number\fi}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\speci@ls}
%    We left out two macros: \verb+\process@deferreds+ and
%    \verb+\speci@ls+.  If we encounter a float or a marginpar in the
%    current implementation we simply warn the user that this is not
%    allowed.  Then we reinsert the page and its footnotes.
%    \begin{macrocode}
\def\speci@ls{%
   \typeout{Floats and marginpars not
            allowed inside `multicols'
            environment!}%
   \unvbox\@cclv\reinsert@footnotes
%    \end{macrocode}
%    Additionally we empty the \verb+\@currlist+ to avoid later error
%    messages when the \LaTeX{} output routine is again in force.
%    But first we have to place the boxes back onto the
%    \verb+\@freelist+. (\verb+\@elt+s default is \verb+\relax+ so
%    this is possible with \verb+\xdef+.)
% \changes{v1.2a}{90/02/05}{Float boxes freed.}
%    \begin{macrocode}
   \xdef\@freelist{\@freelist\@currlist}%
   \gdef\@currlist{}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\process@deferreds}
%    \verb+\process@deferreds+ is a simplified version of \LaTeX{}'s
%    \verb+\@startpage+.  We first call the macro
%    \verb+\@floatplacement+ to save the current user parameters in
%    internal registers.  Then we start a new group and save the
%    \verb+\@deferlist+ temporarily in the macro \verb+\@tempb+.
%    \begin{macrocode}
\def\process@deferreds{%
   \@floatplacement 
   \begingroup
    \let\@tempb\@deferlist
%    \end{macrocode}
%    Our next action is to (globally) empty \verb+\@deferlist+ and
%    assign a new meaning to \verb+\@elt+.  Here \verb+\@scolelt+ is a
%    macro that looks at the boxes in a list to decide whether they
%    should be placed on the next page (i.e.\ on \verb+\@toplist+ or
%    \verb+\@botlist+) or should wait for further processing.
%    \begin{macrocode}
    \gdef\@deferlist{}%
    \let\@elt\@scolelt
%    \end{macrocode}
%    Now we call \verb+\@tempb+ which has the form
%    \begin{center}
%      \verb+\@elt+\meta{box register}\verb+\@elt+\meta
%                        {box register}\ldots{}
%    \end{center}
%    So \verb+\@elt+ (i.e.\ \verb+\@scolelt+) will distribute the
%    boxes to the three lists.
%    \begin{macrocode}
      \@tempb \endgroup}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{ifshr@nking}
% \begin{macro}{\raggedcolumns}
% \begin{macro}{\flushcolumns}
% \changes{v1.1a}{89/09/20}{`flushedcolumns renamed to `flushcolumns.}
%    The \verb+\raggedcolumns+ and \verb+\flushcolumns+
%    declarations are defined with the help of a new \verb+\if...+
%    macro.
%    \begin{macrocode}
\newif\ifshr@nking
%    \end{macrocode}
%    The actual definitions are simple: we just switch to {\sf true}
%    or {\sf false} depending on the desired action. To avoid extra
%    spaces in the output we enclose these changes in
%    \verb+\@bsphack+\ldots{}\allowbreak\verb+\@esphack+.
%    \begin{macrocode}
\def\raggedcolumns{%
   \@bsphack\shr@nkingtrue\@esphack}
\def\flushcolumns{%
   \@bsphack\shr@nkingfalse\@esphack}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\balance@columns}
%    Now for the last part of the show: the column balancing output
%    routine.  Since this code is called with an explicit penalty
%    (\verb+\eject+) there is no need to check for something special.
%    Therefore we start by assigning the values used by
%    \verb+\vsplit+.
%    \begin{macrocode}
\def\balance@columns{%
   \splittopskip\topskip
   \splitmaxdepth\maxdepth
%    \end{macrocode}
%    Next we measure the length of the current page and at the same
%    time save it in box register 0.
%    \begin{macrocode}
  \setbox\z@\vbox{\unvbox\@cclv}\dimen@\ht\z@
%    \end{macrocode}
%    Then we try to find a suitable starting point for the calculation
%    of the column height.  It should be less than the height finally
%    chosen, but large enough to reach this final value in only a few
%    iterations.
%    \begin{macrocode}
   \advance\dimen@\col@number\topskip
   \advance\dimen@-\col@number\baselineskip
   \divide\dimen@\col@number
%    \end{macrocode}
%    At the user's request we start with a higher value (or lower, but
%    this usually only increases the number of tries).
%    \begin{macrocode}
   \advance\dimen@\c@unbalance\baselineskip
%    \end{macrocode}
%    We type out statistics if we were asked to do so.
%    \begin{macrocode}
   \ifnum\c@tracingmulticols>\@ne 
      \typeout{Balance columns:
        \ifnum\c@unbalance=\z@\else 
       (off balance=\number\c@unbalance)\fi}%
   \fi
%    \end{macrocode}
%    Now we try to find the final column height.  We start by setting
%    \verb+\vbadness+ to infinity (i.e.\ $10000$) to suppress
%    underfull box reports while we are trying to find an acceptable
%    solution.  We do not need to do it in a group since at the end of
%    the output routine everything will be restored. The setting of
%    the final columns will nearly always produce underfull boxes with
%    badness $10000$ so there is no point in warning the user about
%    it.
% \changes{v1.2a}{90/02/05}{Group around main loop removed.}
%    \begin{macrocode}
   \vbadness\@M \loop
%    \end{macrocode}
%    In order not to clutter up \TeX{}'s valuable main memory with
%    things that are no longer needed, we empty all globally used box
%    registers. This is necessary if we return to this point after an
%    unsucessful trial.  We use \verb+\process@cols+ for this purpose,
%    starting with $1$.  Note the extra braces around this macro call.
%    They are needed since \PlainTeX{}'s
%    \verb+\loop+\ldots{}\allowbreak\verb+\repeat+ mechanism cannot be
%    nested on the same level of grouping.
%    \begin{macrocode}
    {\process@cols\@ne{\global\setbox\count@
                             \box\voidb@x}}%
%    \end{macrocode}
%    The contents of box $0$ are now copied globally to box~$1$.
%    (This will be the right-most column, as we shall see later.)
%    \begin{macrocode}
     \global\setbox\@ne\copy\z@
%    \end{macrocode}
%    Using \verb+\vsplit+ we extract the other columns from box
%    register $1$.  This leaves box register $0$ untouched so that we
%    can start over again if this trial was unsuccessful.
%    \begin{macrocode}
   {\process@cols\thr@@{\global\setbox\count@
                     \vsplit\@ne to\dimen@}}%
%    \end{macrocode}
%    After \verb+\process@cols+ has done its job we have the following
%    situation:
%    \begin{center}
%      \begin{tabular}{r@{$\:\:\longleftarrow\:\:$}l}
%        box $0$ & all material \\
%        box $3$ & first column \\
%        box $5$ & second column \\
%        \multicolumn{1}{c}{$\vdots$} &
%        \multicolumn{1}{c}{$\vdots$} \\
%        box $1$ & last column
%      \end{tabular}
%    \end{center}
%    We report the height of the first column.
%    \begin{macrocode}
    \ifnum\c@tracingmulticols>\@ne
       \message{\@spaces First column
                = \the\ht\thr@@}\fi
%    \end{macrocode}
%    If \verb+\raggedcolumns+ is in force we also shrink the first
%    column to its natural height and optionally inform the user.
%    \begin{macrocode}
    \ifshr@nking \global\setbox\thr@@
                 \vbox{\unvbox\thr@@}%
       \ifnum\c@tracingmulticols>\@ne
          \message{ after shrinking 
                    \the\ht\thr@@}\fi\fi
%    \end{macrocode}
%    Then we give information about the last column.
%    \begin{macrocode}
    \ifnum\c@tracingmulticols>\@ne
      \message{<> last column = \the\ht\@ne}%
      \typeout{}\fi
%    \end{macrocode}
%    We check whether our trial was successful.  The test used is very
%    simple: we merely compare the first and the last column.  Thus
%    the intermediate columns may be longer than the first if
%    \verb+\raggedcolumns+ is used.  If the right-most column is
%    longer than the first then we start over with a larger value for
%    \verb+\dimen@+.
%    \begin{macrocode}
    \ifdim\ht\@ne >\ht\thr@@
    \global\advance\dimen@\p@
    \repeat
%    \end{macrocode}
%    Now we save the actual height of box register 3 (i.e.\ the left
%    column) in the \meta{dimen} register \verb+\dimen@+ since
%    otherwise this information will be lost when processing the code
%    below.\footnote{The value of {\tt\bslash dimen@} may differ from
%    the height of box register 3 when we use the {\tt\bslash
%    raggedcolumns} declaration.}
%    \begin{macrocode}
   \dimen@\ht\thr@@
%    \end{macrocode}
%    Then we move the contents of the odd-numbered box registers to
%    the even-numbered ones, shrinking them if requested.
%    \begin{macrocode}
   \process@cols\z@{\@tempcnta\count@ 
        \advance\@tempcnta\@ne
        \setbox\count@\vtop to\dimen@
           {\unvbox\@tempcnta
            \ifshr@nking\vfill\fi}}%
%    \end{macrocode}
%    This will bring us into the position to apply \verb+\page@sofar+.
%    But first we have to set \verb+\vsize+ to a value suitable for
%    one column output.
%    \begin{macrocode}
   \global\vsize\@colroom 
   \global\advance\vsize\ht\partial@page
   \page@sofar}
%    \end{macrocode}
%    As we already know, reinserting of footnotes will be done in the
%    macro \verb+\endmulticols+.
% \end{macro}
%
% \section{New macros and hacks for version 1.2}
%
% \begin{macro}{\emergencystretch}
% \begin{macro}{\setemergencystretch}
%    If we don't use \TeX{} 3.0 \verb+\emergencystretch+ is undefined
%    so in this case we simply add it as an unused \meta{dimen}
%    register.
%    \begin{macrocode}
\@ifundefined{emergencystretch}
     {\newdimen\emergencystretch}{}
\emergencystretch 1pt
%    \end{macrocode}
% \changes{v1.2a}{90/02/05}{Macro added.}
%    My tests showed that the following formula worked pretty well.
%    Nevertheless the \verb+\setemergencystretch+ macro also gets
%    \verb+\hsize+ as second argument to enable the user to try
%    different formulae.
%    \begin{macrocode}
\def\setemergencystretch#1#2{%
   \emergencystretch 4pt
   \multiply\emergencystretch#1}
%    \end{macrocode}
% \end{macro}
% \end{macro}


% \begin{macro}{\set@floatcmds}
% \changes{v1.2a}{90/02/05}{Macro added.}
%    Even if this should be used as a hook we use a \verb+@+ in the
%    name since it is more for experts.
%    \begin{macrocode}
\def\set@floatcmds{%
 \let\@dblfloat\@dbflt
 \def\end@dblfloat{\par
   \vskip\z@\egroup
%    \end{macrocode}
%    This is cheap (defering the floats until after the current page)
%    but any other solution would go deep into \LaTeX{}s output
%    routine and I don't like to work on it until I know which parts
%    of the output routine have to be reimplemented anyway for 2.10
%    and 3.0.
%    \begin{macrocode}
   \ifnum\@floatpenalty<\z@
%    \end{macrocode}
%    We have to add the float to the \verb+\@deferlist+ because we
%    assume that outside the {\tt multicols} environment we are in one
%    column mode. This is not entierly correct, I already used the {\tt
%    multicols} environment inside of \LaTeX{}s \verb+\twocolumn+
%    declaration but it will do for most applications.
%    \begin{macrocode}
     \@cons\@deferlist\@currbox
   \fi
   \ifnum\@floatpenalty=-\@Mii
     \@esphack
   \fi}}
%    \end{macrocode}
% \end{macro}
%
% \end{multicols}
%
%
% \Finale


\endinput
