Move a tag
[latex2e.git] / latex2e-20151001 / required / tools / multicol.dtx
blob022e536f757d38ebcc3bbf320a56440a803ff2d0
1 % \iffalse meta-comment
4 % This file is part of the Standard LaTeX `Tools Bundle'.
5 % -------------------------------------------------------
7 % It may be distributed and/or modified under the
8 % conditions of the LaTeX Project Public License, either version 1.3c
9 % of this license or (at your option) any later version.
10 % The latest version of this license is in
11 %    http://www.latex-project.org/lppl.txt
12 % and version 1.3c or later is part of all distributions of LaTeX
13 % version 2005/12/01 or later.
15 % The list of all files belonging to the LaTeX `Tools Bundle' is
16 % given in the file `manifest.txt'.
18 % \fi
20 % \iffalse    This is a METACOMMENT
22 %% Package `multicol' to use with LaTeX2e
23 %% Copyright 1989-2015 Frank Mittelbach
25 %%  In addition to the terms of LPPL any distributed version
26 %%  (unchanged or modified) of multicol has to keep the statement
27 %%  about the moral obligation for using multicol. In case of major
28 %%  changes where this would not be appropriate the author of the
29 %%  changed version should contact the copyright holder.
32 %%  Moral obligation for using multicol:
33 %%  ------------------------------------
35 %%  Users of multicol who wish to include or use multicol or a modified
36 %%  version in a proprietary and commercially market product are asked
37 %%  under certain conditions (see below) for the payment of a license
38 %%  fee.  The size of this fee is to be determined, in each instance,
39 %%  by the commercial user, depending on his/her judgment of the value of
40 %%  multicol for his/her product.
43 %%  The conditions for this are as follows:
45 %%   The producer of a proprietary and commercially market product
46 %%   that involves typesetting using multicol is asked to determine
47 %%   the value of a license fee for using multicol if
49 %%   - the product is a document and the producer has decided to
50 %%     include multicol to typeset (parts of) the document or has
51 %%     directed the author of the document to include multicol (for
52 %%     example, by providing a class file to be used by the author)
54 %%   - the product is a LaTeX class or package that includes multicol
57 %%   There is no moral obligation in case
59 %%   - the product is a document but producer has not directed
60 %%     the author to include multicol (in that case the moral obligation
61 %%     lies with the author of the document)
63 %%   - the product does not involve typesetting, e.g., consists, for
64 %%     example, of distributing multicol and its documentation.
66 %%   - the product is not proprietary, i.e., is made available as free
67 %%     software itself (which doesn't prohibit its commercial marketing)
69 %%   - multicol is used for non-commercial purposes
72 %% Determining a license fee might result in a license fee of zero
73 %% (i.e., no payment) in case a producer has determined that the use
74 %% of multicol has no enhancing effect on the product. This is a
75 %% plausible scenario, i.e., in the above two cases the producer is
76 %% only asked to evaluate the value of multicol for the product
77 %% not for the payment of a license fee per se (which might or might
78 %% not follow from this evaluation).
80 %% The license fee, if any, can be payed either to the LaTeX3 fund
81 %% (see ltx3info.txt in the base LaTeX distribution) or to the author of
82 %% the program who can be contacted at
84 %%     Frank.Mittelbach@latex-project.org
86 %<*dtx>
87           \ProvidesFile{multicol.dtx}
88 %</dtx>
89 %<package>\NeedsTeXFormat{LaTeX2e}[1997/12/01]
90 %<package>\ProvidesPackage{multicol}
91 %<driver> \ProvidesFile{multicol.drv}
92 % \fi
93 %         \ProvidesFile{multicol.dtx}
94           [2015/08/19 v1.8n  multicolumn formatting (FMi)]
97 %% \CheckSum{1894}
98 %% \CharacterTable
99 %%  {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
100 %%   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
101 %%   Digits        \0\1\2\3\4\5\6\7\8\9
102 %%   Exclamation   \!     Double quote  \"     Hash (number) \#
103 %%   Dollar        \$     Percent       \%     Ampersand     \&
104 %%   Acute accent  \'     Left paren    \(     Right paren   \)
105 %%   Asterisk      \*     Plus          \+     Comma         \,
106 %%   Minus         \-     Point         \.     Solidus       \/
107 %%   Colon         \:     Semicolon     \;     Less than     \<
108 %%   Equals        \=     Greater than  \>     Question mark \?
109 %%   Commercial at \@     Left bracket  \[     Backslash     \\
110 %%   Right bracket \]     Circumflex    \^     Underscore    \_
111 %%   Grave accent  \`     Left brace    \{     Vertical bar  \|
112 %%   Right brace   \}     Tilde         \~}
115 % \changes{v1.5n}{1997/06/05}{Applied improvement of documentation,
116 %          kindly done by Robin Fairbairns.}
117 % \changes{v1.4h}{1992/06/04}{Added mark tracing with
118 %                           tracingmulticols$\ge2$}
119 % \changes{v1.4a}{1992/02/11}{Added support for multicol in inner mode}
120 % \changes{v1.0d}{1989/05/17}{All lines shortened to 72 or less.}
121 % \changes{v1.0e}{1989/06/21}{Redefinition of description env. to use
122 %                           \cs{descriptionmargin}\quotechar=5pt
123 %                           in documentation.}
124 % \changes{v1.0f}{1989/07/11}{Changed \cs{z@} to 0pt in redefinition of
125 %                           description.}
126 % \changes{v1.1a}{1989/09/20}{\cs{multicolssep} changed to \cs{multicolsep}.}
128 % \def\description{\list{}{\labelwidth 0pt \leftmargin\descriptionmargin
129 %    \itemindent-\leftmargin \let\makelabel\descriptionlabel}}
130 % \newdimen\descriptionmargin \descriptionmargin=5pt
132 % \DoNotIndex{\@M,\@Mi,\@bsphack,\@cclv,\@colht,\@currlist,\@deferlist}
133 % \DoNotIndex{\@elt,\@esphack,\@floatplacement}
134 % \DoNotIndex{\@ifundefined,\@ifnextchar,\@makecol}
135 % \DoNotIndex{\@ne,\@outputpage,\@scolelt,\@spaces,\@tempb,\@tempcnta}
136 % \DoNotIndex{\@width}
137 % \DoNotIndex{\addvspace,\advance,\allowbreak}
138 % \DoNotIndex{\baselineskip,\begingroup,\box,\columnsep,\copy,\count}
139 % \DoNotIndex{\count@,\def,\dimen@,\divide,\docdate}
140 % \DoNotIndex{\edef,\eject,\egroup,\else,\endgroup,\endinput}
141 % \DoNotIndex{\fi,\fileversion,\filedate}
142 % \DoNotIndex{\gdef,\global}
143 % \DoNotIndex{\hbox,\hfil,\hrule,\ht,\hss}
144 % \DoNotIndex{\ifdim,\ifnum,\ifvoid,\ignorespaces,\insert,\immediate}
145 % \DoNotIndex{\let,\loop}
146 % \DoNotIndex{\maxdepth,\message,\multiply}
147 % \DoNotIndex{\newbox,\newcount,\newdimen,\newskip,\number,\newpage}
148 % \DoNotIndex{\outputpenalty,\p@,\penalty}
149 % \DoNotIndex{\relax,\repeat,\setbox,\skip,\space,\splitmaxdepth}
150 % \DoNotIndex{\splittopskip,\string,\sixt@@n}
151 % \DoNotIndex{\the,\thepage,\thr@@,\topskip,\tw@,\typeout}
152 % \DoNotIndex{\unvbox,\vbox,\vfill,\vsplit,\voidb@x,\vrule}
153 % \DoNotIndex{\write,\wd}
154 % \DoNotIndex{\z@}
156 % \MakeShortVerb{\|}
157 % \newcommand{\mc}{{\sf multicols}}
158 % \newcommand{\TUB}{{\sl TUGboat\/}}
159 % \newcommand{\TB}{{\sl\TeX book\/}}
162 % \setcounter{StandardModuleDepth}{2}
163 % \setcounter{collectmore}{3}
165 % \GetFileInfo{multicol.dtx}
166 % \title{An environment for multicolumn output\thanks{This file
167 %        has version number \fileversion, last
168 %        revised \filedate.}%
169 %       \thanks{Note: This package is released under terms which affect
170 %       its use in commercial applications. Please see the details at
171 %       the top of the source file.}}
172 % \author{Frank Mittelbach\\
173 %       {\rm Email:} see top of the source file}
174 % \date{Printed \today}
176 % \MaintainedByLaTeXTeam{tools}
177 % \maketitle
179 % \begin{abstract}
180 %   This article describes the use and the implementation of the \mc{}
181 %   environment. This environment allows switching between
182 %   one and multicolumn format on the same page. Footnotes are handled
183 %   correctly (for the most part), but will be placed at the bottom of
184 %   the page and not under each column.  \LaTeX{}'s float mechanism,
185 %   however, is partly disabled in this implementation.  At the
186 %   moment only page-wide floats (i.e., star-forms) can be used within
187 %   the scope of the environment.
188 % \end{abstract}
190 % \begin{multicols}{3}[\section*{Preface to version 1.8}]
191 %    The 1.8 release improves on the balancing approach. If due to a
192 %    limited number of break points (e.g., due to large objects) the
193 %    balanced columns exceed the available vertical space, then
194 %    balancing is canceled and a normal page is produced first. Some
195 %    overflow is allowed (controlled by the parameter
196 %    |\maxbalancingoverflow| which defaults to 12pt). This ensures
197 %    that we only cut a normal page if we get enough material carried
198 %    over to next page.
200 %    Also added was support for |\enlargethispage|. This means it is
201 %    now possible to request a page to be artificially  enlarged or
202 %    shortened. Note that if you enlarge pages by more than one line
203 %    you may have to increase the {\sf collectmore} counter value to
204 %    ensure that enough material is being picked up.
206 %    This command was used on the second page of this manual to shorten
207 %    it by one line, in order to get rid of a number of widow lines on
208 %    the following pages.
211 %    Finally, version 1.8 adds the command |\docolaction| to help with
212 %   more complicated actions that depend on the current column. This
213 %   command expects 3 arguments: code that is executed if we are in
214 %   the ``first'' column, code to execute if we end up in any
215 %   ``middle'' column (if there are more than two) and finally code to
216 %   execute if we are in the ``last'' column. Thus
217 %\begin{verbatim}
218 %  \docolaction{first}
219 %              {middle}{last}
220 %\end{verbatim}
221 %   would typeset a different word depending the type of column this
222 %   code is executed. Using it like this is probably pointless, but
223 %   you can imagine applications like writing something into the
224 %   nearest margin, etc.
226 %   As this feature needs at least two \LaTeX{} runs to produce correct
227 %   results and as it adds to the processing complexity it is only
228 %   made available if one add the option \texttt{colaction} when
229 %   loading the package.
231 % \end{multicols}
233 % \RLmulticolcolumns
235 % \begin{multicols}{3}[\section*{Preface to version 1.7
236 %                         (right to left support)}]
237 %    The 1.7 release adds support for languages that are typeset
238 %    right-to-left. For those languages the order of the columns on the page
239 %    also need to be reversed---something that wasn't supported before. This
240 %    paragraph demonstrates the result (as it is typeset as if we are writing
241 %    in a left-to-right language---so restart reading the rightmost column
242 %    first if you started with this column).
243 % \end{multicols}
245 % \LRmulticolcolumns
247 % \begin{multicols}{3}
248 %    Right-to-left typesetting will only reverse the column orders. Any
249 %    other support needed will have to be provided by other means,
250 %    e.g., using appropriate fonts and reversing the writing directions
251 %    within the columns. As footnotes are typeset in full measure the
252 %    footnote rule needs to be redefined as if they are below a single
253 %    column, i.e., using |\textwidth| not |\columnwidth|. For example:
254 %\begin{verbatim}
255 %\renewcommand \footnoterule{%
256 %  \kern-3pt\hbox to\textwidth
257 %    {\hskip .6\textwidth
258 %     \hrulefill }%
259 %  \kern2.6pt}
260 %\end{verbatim}
261 % \end{multicols}
264 % \begin{multicols}{3}[\section*{Preface to version 1.5 + 1.6}]
265 %   \hbadness=10000
266 %   The 1.5 release contains two major changes: \mc{} will now
267 %   support up to 10 columns and two more tuning possibilities have
268 %   been added to the balancing routine. The balancing routine now
269 %   checks the badness
270 %   of the resulting columns and rejects solutions that are larger
271 %   than a certain threshold.
272 %   At the same time \mc{} has been upgraded to run under \LaTeXe{}.
274 %   Later changes to 1.5 include |\columnbreak| and |multicols*|.
276 %   For version 1.6 micro-spacing around the boxes produced by \mc{}
277 %   has been improved to allow for baseline-grid typesetting.
278 % \end{multicols}
281 % \setcounter{collectmore}{2}
282 % \begin{multicols}{3}[\section{Introduction}]
283 %   \hbadness=10000
284 %   Switching between two-column and one-column layout is possible in
285 %   \LaTeX{}, but every use of |\twocolumn| or |\onecolumn|
286 %   starts a new page. Moreover, the last page of two-column output
287 %   isn't balanced and this often results in an empty, or nearly
288 %   empty, right column. When I started to write macros for {\sf
289 %   doc.sty} (see ``The {\tt doc}--Option'', \TUB\
290 %   volume 10~\#2, pp.~245--273) I thought that it would be nice to
291 %   place the index
292 %   on the same page as the bibliography. And balancing the last page
293 %   would not only look better, it also would save space; provided of
294 %   course that it is also possible to start the next article on the
295 %   same page. Rewriting the index environment was comparatively easy,
296 %   but the next goal, designing an environment which takes care of
297 %   footnotes, floats, etc., was a harder task. It took me a whole
298 %   weekend\footnote{I started with the algorithm given in the \TeX
299 %   book on page 417. Without this help a weekend would not have been
300 %   enough. (This remark was made in the documentation of the initial
301 %    release, since then several hundreds more hours went into
302 %    improving the original code.)} to get together the few lines of
303 %    code below and there is
304 %   still a good chance that I missed something after all.
306 %   Try it and, hopefully, enjoy it; and {\em please\/} direct bug
307 %   reports and suggestions back to Mainz.
308 % \end{multicols}
311 % \setcounter{collectmore}{0}
312 % \begin{multicols}{3}[\section{The User Interface}]
313 %   \hbadness=10000
314 %   To use the environment one simply says\\*[2mm]
315 %     \hspace*{2mm}|\begin{multicols}{|\meta{number}|}|
316 %     \hspace*{12mm}\meta{multicolumn text}\\
317 %     \hspace*{2mm}|\end{multicols}|\\[2mm]
318 %   where \meta{number} is the required number of columns and
319 %^^A\meta{multicolumn text}
320 %   $\langle${\it multi\-column text\/}$\rangle$ may contain arbitrary
321 %   \LaTeX{} commands, except that floats and marginpars are not
322 %   allowed in the current implementation\footnote{This is dictated by
323 %   lack of time.  To implement floats one has to reimplement the
324 %   whole \LaTeX{} output routine.}.
326 % \enlargethispage{-1\baselineskip}
328 % \DescribeMacro\premulticols
329 % As its first action, the {\sf multicols} environment measures the
330 % current page to determine whether there is enough room for some
331 % portion of multicolumn output. This is controlled by the
332 % \meta{dimen} variable |\premulticols| which can be changed by
333 % the user with ordinary \LaTeX{} commands.
334 % \DescribeMacro\multicolsep
335 % If the space is less than |\premulticols|, a new page is
336 % started.  Otherwise, a |\vskip| of |\multicolsep| is
337 % added.\footnote{Actually the added space may be less because we use
338 % \cs{addvspace} (see the \LaTeX{} manual for further
339 % information about this command).}
341 % \DescribeMacro\postmulticols
342 % When the end of the \mc{} environment is encountered, an
343 % analogous mechanism is employed, but now we test whether there is a
344 % space larger than |\postmulticols| available. Again we add
345 % |\multicolsep| or start a new page.
347 % It is often convenient to spread some text over all columns, just
348 % before the multicolumn output, without any page break in between. To
349 % achieve this the \mc{} environment has an optional second
350 % argument which can be used for this purpose. For example, the text
351 % you are now reading was started with
352 % \begin{verbatim}
353 % \begin{multicols}{3}
354 %   [\section{The User
355 %             Interface}] ...
356 %\end{verbatim}
357 % If such text is unusually long (or short) the value of
358 % |\premulticols| might need adjusting to prevent a bad page
359 % break.  We therefore provide a third argument which can be used to
360 % overwrite the default value of |\premulticols| just for this
361 % occasion. So if you want to combine some longer single column text
362 % with a multicols environment you could write
363 % \begin{verbatim}
364 % \begin{multicols}{3}
365 %     [\section{Index}
366 %      This index contains ...]
367 %     [6cm]
368 %  ...
369 %\end{verbatim}
372 % \DescribeMacro\columnsep
373 % The space between columns is controlled by the length parameter
374 % |\columnsep|. The width for the individual columns is automatically
375 % calculated from this parameter and the current |\linewidth|. In this
376 % article a value of \textsf{\the\columnsep} was used.
379 % \DescribeMacro\columnseprule
380 % Separation of columns with vertical rules is achieved by setting the
381 % parameter |\columnseprule| to some positive value.  In this
382 % article a value of {\sf.4pt} was used.
384 % \DescribeMacro\columnseprulecolor
385 % The color of the rules separating the columns can be specified through
386 % |\columnseprulecolor|. The default value is |\normalcolor|.
388 % \DescribeMacro\multicolbaselineskip
389 % Since narrow columns tend to need adjustments in interline spacing
390 % we also provide a \meta{skip} parameter called
391 % |\multicolbaselineskip| which is added to the
392 % |\baselineskip| parameter inside the \mc{}
393 % environment.  Please use this parameter with care or leave it alone;
394 % it is intended only for package file designers since even small
395 % changes might produce totally unexpected changes to your document.
398 %    \subsection{Balancing columns}
401 % Besides the previously mentioned parameters, some others are
402 % provided to influence the layout of the columns generated.
404 % Paragraphing in \TeX{} is controlled by several parameters. One of
405 % the most important is called |\tolerance|: this controls the
406 % allowed `looseness' (i.e.\ the amount of blank space between words).
407 % Its default value is 200 (the \LaTeX{} |\fussy|) which is too
408 % small for narrow columns. On the other hand the |\sloppy|
409 % declaration (which sets |\tolerance| to $10000=\infty$) is too
410 % large, allowing really bad spacing.\footnote{Look at the next
411 % paragraph, it was set with the \cs{sloppy} declaration.}
413 % \begin{sloppypar}
414 % \DescribeMacro\multicoltolerance \DescribeMacro\multicolpretolerance
415 %  We therefore use a |\multicoltolerance| parameter for the
416 % |\tolerance| value inside the \mc{} environment.  Its default value
417 % is 9999 which is less than infinity but `bad' enough for most
418 % paragraphs in a multicolumn environment. Changing its value should
419 % be done outside the \mc{} environment.  Since |\tolerance| is set
420 % to |\multicoltolerance| at the beginning of every {\sf multicols}
421 % environment one can locally overwrite this default by assigning
422 % \verb*+\tolerance = +\meta{desired value}. There also exists a
423 % |\multicolpretolerance| parameter holding the value for
424 % |\pretolerance| within a \mc{} environment. Both parameters are
425 % usually used only by package designers.
426 % \end{sloppypar}
428 % Generation of multicolumn output can be divided into two parts.  In
429 % the first part we are collecting material for a page, shipping it
430 % out, collecting material for the next page, and so on.  As a second
431 % step, balancing will be done when the end of the \mc{} environment
432 % is reached.
433 % In the first step \TeX{} might consider more material whilst
434 % finding the final column content than it actually uses when shipping out the
435 % page. This might cause a problem if a footnote is encountered in
436 % the part of the input considered, but not used, on the current page.
437 % In this case the footnote might show up on the current page, while the
438 % footnotemark corresponding to this footnote might be set on the next
439 % one.\footnote{The reason behind this behavior is the asynchronous
440 %               character of the \TeX{} {\it page\_builder}.
441 %               However, this
442 %               could be avoided by defining very complicated output
443 %               routines which don't use \TeX{} primitives like
444 %               \cs{insert} but do everything by hand.
445 %               This is clearly beyond the scope of a weekend problem.}
446 % Therefore the \mc{} environment gives a warning
447 % message\footnote{This message will be generated even if there are no
448 % footnotes in this part of the text.} whenever it is unable to use
449 % all the material considered so far.
451 % If you don't use footnotes too often the chances of something
452 % actually going wrong are very slim, but if this happens you can help
453 % \TeX{} by using a |\pagebreak| command in the final document.
454 % Another way to influence the behavior of \TeX{} in this respect is
455 % given by the counter variable `{\sf collectmore}'. If you use the
456 % |\setcounter| declaration to set this counter to \meta{number},
457 % \TeX{} will consider \meta{number} more (or less) lines before
458 % making its final decision. So a value of $-1$ may solve all your
459 % problems at the cost of slightly less optimal columns.
462 % In the second step (balancing columns) we have other bells and
463 % whistles. First of all you can say |\raggedcolumns| if you
464 % don't want the bottom lines to be aligned.
465 % The default is |\flushcolumns|, so \TeX{} will normally try to
466 % make both
467 % the top and bottom baselines of all columns align.
469 % Additionally you can set another counter, the `{\sf unbalance}'
470 % counter, to some positive \meta{number}. This will make all but the
471 % right-most column \meta{number} of lines longer than they would
472 % normally have been. `Lines' in this context refer to normal text
473 % lines (i.e.\ one |\baselineskip| apart); thus, if your columns
474 % contain displays,
475 % for example, you may need a higher \meta{number}
476 % to shift something from one column into another.
478 % Unlike `{\sf collectmore},' the `{\sf unbalance}' counter is reset
479 % to zero at the end of the environment so it only applies to one
480 % \mc{} environment.
482 % The two methods may be combined but I suggest using these features
483 % only when fine tuning important publications.
485 % Two more general tuning possibilities were added with version~1.5.
486 % \TeX{} allows to measure the badness of a column in terms of an
487 % integer value, where 0 means optimal and any higher value means a
488 % certain amount of extra white space. 10000 is considered to be
489 % infinitely bad (\TeX{} does not distinguish any further). In addition
490 % the special value 100000 means overfull (i.e., the column contains
491 % more text than could possibly fit into it).
493 % The new release now measures every generated column and ignores
494 % solutions where at least one column has a badness being larger than
495 % the value of the counter {\sf columnbadness}. The default value for
496 % this counter is 10000, thus \TeX{} will accept all solutions except
497 % those being overfull.
498 % By setting the counter to a smaller value you can force the algorithm
499 % to search for solutions that do not have columns with a lot of white
500 % space.
502 % However, if the setting is too low, the algorithm may not find any
503 % acceptable solution at all and will then finally choose the extreme
504 % solution of placing all text into the first column.
506 % Often, when columns are balanced, it is impossible to find a solution
507 % that distributes the text evenly over all columns. If that is the case
508 % the last column usually has less text than the others. In the earlier
509 % releases this text was stretched to produce a column with the same
510 % height as all others, sometimes resulting in really ugly looking
511 % columns.
513 % In the new release this stretching is only done if the badness of
514 % the final column is not larger than the value of the counter
515 % {\sf finalcolumnbadness}. The default setting is 9999, thus preventing
516 % the stretching for all columns that \TeX{} would consider infinitely
517 % bad. In that case the final column is allowed to run short which gives
518 % a much better result.
520 % And there are two more parameters of some experimental nature, one
521 % called |\multicolovershoot| the other |\multicolundershoot|.  They
522 % control the amount of space a column within the \mc{} environment is
523 % allowed to be ``too full'' or ``too short'' without affecting the
524 % column badness. They are set to 0pt and 2pt, respectively.
526 % Finally, when doing the balancing at the end, columns may become
527 % higher than the remaining available space. In that case the
528 % algorithm aborts and instead generates a normal page. However, if the
529 % amount is not too large, e.g., a line or so, then it might be better to
530 % keep everything on the same page instead of starting a new page with
531 % just one line after balancing. So the parameter
532 % |\maxbalancingoverflow| governs this process: only when the excess
533 % gets larger than its value balancing is aborted.
535 % \subsection{Not balancing the columns}
537 % Although this package was written to solve the problem of balancing
538 % columns, I got repeated requests to provide a version where all
539 % white space is automatically placed in the last column or
540 % columns. Since version v1.5q this now exists: if you use
541 % \texttt{multicols*} instead of the usual environment the columns on
542 % the last page are not  balanced. Of course, this environment only
543 % works on top-level, e.g., inside a box one has to balance to
544 % determine a column height in absence of a fixed value.
547 % \subsection{Manually breaking columns}
549 % Another request often voiced was: ``How do I tell \LaTeX{} that it
550 % should break the first column after this particular line?''. The
551 % |\pagebreak| command (which works with the two-column option of
552 % \LaTeX{}) is of no use here since it would end the collection phase
553 % of \mc{} and thus all columns on that page. So with version 1.5u
554 % the |\columnbreak| command was added. If used within a paragraph it
555 % marks the end of the current line as the desired breakpoint. You can
556 % observe its effect on
557 % the previous page where three lines of text have been artificially
558 % forced into the second column  (resulting in some white
559 % space between paragraphs in the first column).
561 % \subsection{Floats inside a \mc{} environment}
563 % Within the \mc{} environment the usual star float commands are
564 % available but their function is somewhat different as in the
565 % two-column mode of standard \LaTeX. Stared floats, e.g., {\tt
566 % figure*}, denote page wide floats that are handled in a similar
567 % fashion as normal floats outside the \mc{} environment. However,
568 % they will never show up on the page where they are encountered. In
569 % other words, one can influence their placement by specifying a
570 % combination of {\tt t}, {\tt b}, and/or {\tt p} in their optional
571 % argument, but {\tt h} doesn't work because the first possible place
572 % is the top of the next page. One should also note, that this means
573 % that their placement behavior is determined by the values of
574 % |\topfraction|, etc.\ rather than by |\dbl...|.
577 % \subsection{Support for right-to-left typesetting}
579 %    In right-to-left typesetting the order of the columns on the page
580 %    also need to be reversed, i.e., the first column has to appear on the far
581 %    right and the last column on the left. This is supported through the
582 %    commands |\RLmulticolcolumns| (switching to right-to-left typesetting)
583 %    and |\LRmulticolcolumns| (switching to left-to-right typesetting) the
584 %    latter being the default.
586 % \subsection{Warnings}
588 % Under certain circumstances the use of the \mc{} environment may
589 % result in some
590 % warnings from \TeX{} or \LaTeX{}. Here is a list
591 % of the important ones and the possible cause:
592 % \begin{description}
594 % \item[] {\hspace*{-\labelsep}\tt Underfull \string\hbox\space
595 %  (badness ...)}
597 %  As the columns are often very narrow \TeX{} wasn't able to find a
598 %  good way to break the paragraph. Underfull denotes a loose line but
599 %  as long as the badness value is below $10000$ the result is probably
600 %  acceptable.
602 % \item[]
603 % {\hspace*{-\labelsep}\tt Underfull \string\vbox\space ...  while
604 %  \string\output\space is active}
606 %  If a column contains a character with an unusual depth, for
607 %  example a `(', in the bottom line then this message may show up. It
608 %  usually has no significance as long as the value is not more than a
609 %  few points.
611 % \item[] {\hspace*{-\labelsep}\tt LaTeX Warning: I moved some lines
612 %  to the next page}
614 %  As mentioned above, \mc{} sometimes screws up the footnote
615 %  numbering. As a precaution, whenever there is a footnote on a
616 %  page where \mc{} had to leave a remainder for the following
617 %  page this warning appears. Check the footnote numbering on this
618 %  page. If it turns out that it is wrong, you have to manually break
619 %  the page using |\newpage| or |\pagebreak[..]|.
621 % \item[] {\hspace*{-\labelsep}\tt Floats and marginpars not allowed
622 %  inside `multicols' environment!}
624 %  This message appears if you try to use the |\marginpar| command or
625 %  an unstarred version of the {\sf figure} or {\sf table} environment.
626 %  Such floats will disappear!
628 % \item[] {\hspace*{-\labelsep}\tt Very deep columns!
629 %          Grid alignment might be broken}
631 % This message can only appear if the option \texttt{grid} was
632 %    chosen. In that case it will show up if a column has a very large
633 %    depth so that \mc{} is unable to back up to its baseline. This
634 %    is only relevant if one tries to produce a document where all
635 %    text lines are aligned at an invisible grid, something that
636 %    requires careful adjustment of many parameters and macros, e.g.,
637 %    heading definitions.
639 % \end{description}
642 % \subsection{Tracing the output}
644 % To understand the reasoning behind the decisions \TeX{} makes when
645 % processing a \mc{} environment, a tracing mechanism is provided.
646 % If you set the counter `\texttt{tracingmulticols}'
647 % to a positive \meta{number} you then
648 % will get some tracing information on the terminal and in the
649 % transcript file:
650 % \begin{description}
651 % \item[$\meta{number}=1$.]  \TeX{} will now tell you, whenever it
652 %    enters or leaves a \mc{} environment, the number of columns it
653 %    is working on and its decision about starting a new page before
654 %    or after the environment.
655 % \item[$\meta{number}=2$.]
656 %    In this case you also get information from the balancing routine:
657 %    the heights tried for the left and right-most columns,
658 %    information about shrinking if the |\raggedcolumns|
659 %    declaration is in force and the value of the `{\sf unbalance}'
660 %    counter if positive.
661 % \item[$\meta{number}= 3$.]  Setting \meta{number}\pagebreak[2] to
662 %    this value will additionally trace the mark handling
663 %    algorithm. It will show what marks are found, what marks are
664 %    considered, etc. To fully understand this information you will
665 %    probably have to read carefully trough the implementation.
666 % \item[$\meta{number}\geq 4$.]  Setting \meta{number}\pagebreak[2] to
667 %    such a high value will additionally place an |\hrule| into your
668 %    output, separating the part of text which had already been
669 %    considered on the previous page from the rest.  Clearly this
670 %    setting should {\em not\/} be used for the final output.  It will
671 %    also activate even more debugging code for mark handling.
672 % \end{description}
675 % \end{multicols}
677 % \begin{multicols}{3}[\section{Prefaces to older versions}
678 %                      \subsection{Preface to version 1.4}]
679 %   \hbadness=10000
680 %   Beside fixing some bugs as mentioned in the {\sf multicol.bug} file
681 %   this new release enhances the \mc{} environment by allowing for
682 %   balancing in arbitrary contexts. It is now, for example, possible
683 %   to balance text within a \mc{} or a {\sf minipage} as shown in
684 %   \ref{tab:newcmds} where a {\sf multicols} environment within a
685 %   {\sf quote} environment was used. It is now even possible to nest
686 %   \mc{} environments.
688 %   The only restriction to such inner \mc{} environments (nested, or
689 %   within \TeX's internal vertical mode) is that such variants will
690 %   produce a box with the balanced material in it, so that they can
691 %   not be broken across pages or columns.
693 %   Additionally I rewrote the algorithm for balancing so that it will
694 %   now produce slightly better results.
696 %   I updated the source documentation but like to apologize in
697 %   advance for some `left over' parts that slipped through the
698 %   revision.
700 %   A note to people who like to improve the balancing algorithm of
701 %   \mc{}: The balancing routine is now placed into a single macro
702 %   which is called |\balance@columns|. This means that one can easily
703 %   try different balancing routines by rewriting this macro. The
704 %   interface for it is explained in table \ref{tab:balance}. There are
705 %   several improvements possible, one can think of integrating the
706 %   |\badness| function of \TeX3, define a faster algorithm for finding
707 %   the right column height, etc. If somebody thinks he/she has an
708 %   enhancement I would be pleased to learn about it. But please obey
709 %   the copyright notice and don't change {\sf multicol.dtx} directly!
710 %   \begin{table*}
711 %    \begin{quote}
712 %    \begin{multicols}{2}
713 %     \raggedcolumns
714 %     The macro |\balance@columns| that contains the code for balancing
715 %     gathered material is a macro without parameters. It assumes that
716 %     the material for balancing is stored in the box |\mult@box| which
717 %     is a |\vbox|. It also ``knows'' about all parameters set up by the
718 %     \mc{} environment, like |\col@number|, etc. It can also assume
719 %     that |\@colroom| is the still available space on the current page.
721 %     When it finishes it must return the individual columns in boxes
722 %     suitable for further processing with |\page@sofar|. This means
723 %     that the left column should be stored in box register
724 %     |\mult@gfirstbox|, the next
725 %     in register |\mult@firstbox|${}+2$, \ldots,
726 %     only the last one as an exception in
727 %     register |\mult@grightbox|. Furthermore it has to set up
728 %     the two macros
729 %     |\kept@firstmark| and |\kept@botmark| to hold the values for the
730 %     first and bottom mark as found in the individual columns. There
731 %     are some helper functions defined in section \ref{sec:v14} which
732 %     may be used for this. Getting the marks right ``by hand'' is
733 %     non-trivial and it may pay off to first take a look at the
734 %     documentation and implementation of |\balance@columns| below
735 %     before trying anew.
736 %    \end{multicols}
737 %    \end{quote}
738 %    \vspace*{-3ex}
739 %    \vspace*{-0ex}
740 %    \caption{Interface description for \cs{balance@columns}}
741 %    \label{tab:balance}
742 %   \end{table*}
743 % \end{multicols}
745 % \begin{multicols}{3}[\subsection{Preface to version 1.2}]
746 %   \hbadness=10000
747 %   After the article about the \mc{} environment was published in
748 %   \TUB\ 10\#3, I got numerous requests for these macros. However, I
749 %   also got a changed version of my style file, together with a
750 %   letter asking me if I would include the changes to get better
751 %   paragraphing results in the case of narrow lines. The main
752 %   differences to my original style option were additional parameters
753 %   (like |\multicoladjdemerits| to be used for |\adjdemerits|, etc.)
754 %   which would influence the line breaking algorithm.
756 %   But actually resetting such parameters to zero or even worse to a
757 %   negative value won't give better line breaks inside the \mc{}
758 %   environment. \TeX{}s line breaking algorithm will only look at
759 %   those possible line breaks which can be reached without a badness
760 %   higher than the current value of |\tolerance| (or |\pretolerance|
761 %   in the first pass). If this isn't possible, then, as a last
762 %   resort, \TeX{} will produce overfull boxes. All those (and only
763 %   those) possible break points will be considered and finally the
764 %   sequence which results in the fewest demerits will be chosen. This
765 %   means that a value of $-1000$ for |\adjdemerits| instructs \TeX{}
766 %   to prefer visibly incompatible lines instead of producing better
767 %   line breaks.
769 %   However, with \TeX{} 3.0 it is possible to get decent line breaks
770 %   even in small columns by setting |\emergencystretch| to an
771 %   appropriate value. I implemented a version which is capable of
772 %   running both in the old and the new \TeX{} (actually it will
773 %   simply ignore the new feature if it is not available). The
774 %   calculation of |\emergencystretch| is probably incorrect. I
775 %   made a few tests but of course one has to have much more experience
776 %   with the new possibilities to achieve the maximum quality.
778 %   Version 1.1a had a nice `feature': the penalty for using the
779 %   forbidden floats was their ultimate removal from \LaTeX{}s
780 %   |\@freelist| so that after a few |\marginpar|s inside the \mc{}
781 %   environment floats where disabled forever.  (Thanks to Chris
782 %   Rowley for pointing this out.) I removed this misbehaviour and at
783 %   the same time decided to allow at least floats spanning all
784 %   columns, e.g., generated by the |figure*| environment.  You can
785 %   see the new functionality in table~\ref{tab:newcmds} which was
786 %   inserted at this very point.
787 %   \begin{table*}
788 %    \small
789 %    \setlength{\multicolsep}{0pt}
790 %    \begin{quote}
791 %     \begin{multicols}{2}
792 %      |\setemergencystretch|: This is a hook for people who like
793 %      to play around. It is supposed to set the
794 %      |\emergencystretch| \meta{dimen} register provided in the
795 %      new \TeX{} 3.0. The first argument is the number of columns and
796 %      the second one is the current |\hsize|. At the moment the
797 %      default definition is $4\mbox{\tt pt} \times |#1|$, i.e.\ the
798 %      |\hsize| isn't used at all. But maybe there are better
799 %      formulae.
801 %      \setlength{\emergencystretch}{20pt} |\set@floatcmds|: This is
802 %      the hook for the experts who like to implement a full float
803 %      mechanism for the \mc{} environment. The |@| in the name
804 %      should signal that this might not be easy.
805 %    \end{multicols}
806 %   \end{quote}
807 %   \vspace*{-1ex}
808 %   \vspace*{-0ex}
809 %   \caption[]{The new commands of {\sf multicol.sty} version 1.2.
810 %            Both commands might be removed if good solutions to these
811 %            open problems are found. I hope that these commands will
812 %            prevent that nearly identical style files derived from
813 %            this one are floating around.}
814 %   \label{tab:newcmds}
815 %   \end{table*}
816 %   However single column floats are still forbidden and I don't think
817 %   I will have time to tackle this problem in the near future. As an
818 %   advice for all who want to try: wait for \TeX{} 3.0. It has a few
819 %   features which will make life much easier in multi-column
820 %   surroundings. Nevertheless we are working here at the edge of
821 %   \TeX{}s capabilities, really perfect solutions would need a
822 %   different approach than it was done in \TeX{}s page builder.
824 %   The text below is nearly unchanged, I only added documentation at
825 %   places where new code was added.
826 % \end{multicols}
828 % \changes{v1.5l}{1996/01/13}{Try hard to explain unresolved reference
829 %                that happens if \cs{OnlyDescription} is used}
831 % \StopEventually{\PrintIndex \PrintChanges
832 %   \ifx\Finale\relax
833 %    \typeout{**********************************}
834 %    \typeout{* Info: Typesetting this document with
835 %                     \protect\OnlyDescription\space will}
836 %    \typeout{* Info: result in one unresolved
837 %                     reference to `sec:v14'.}
838 %    \typeout{* Info: --- tough, it's just not there in this case!}
839 %    \typeout{**********************************}
840 %   \fi
841 %  }
844 % \begin{multicols}{2}[\section{The Implementation}
845 %         We are now switching to two-column output to show the
846 %         abilities of this environment (and bad layout decisions).
847 %      \subsection{The documentation driver file}
848 %         ][10\baselineskip]
850 %   \hbadness=10000
853 % The next bit of code contains the documentation driver file for
854 % \TeX{}, i.e., the file that will produce the documentation you are
855 % currently reading. It will be extracted from this file by the {\tt
856 % docstrip} program.
857 % Since this is the first code in this file one can produce the
858 % documentation
859 % simply by running \LaTeX{} on the \texttt{.dtx} file.
860 %    \begin{macrocode}
861 %<*driver>
862 \documentclass{ltxdoc}
863 %    \end{macrocode}
864 %    We use the \texttt{balancingshow} option when loading \mc{} so
865 %    that full tracing is produced. This has to be done before the
866 %    \texttt{doc} package is loaded, since \texttt{doc} otherwise
867 %    requires \mc{} without any options.
868 %    \begin{macrocode}
869 \usepackage{multicol}[1999/05/25]
870 \usepackage{doc}
871 %    \end{macrocode}
872 %    First we set up the page layout suitable for
873 %    this article.
874 %    \begin{macrocode}
875 \setlength{\textwidth}{39pc}
876 \setlength{\textheight}{54pc}
877 \setlength{\parindent}{1em}
878 \setlength{\parskip}{0pt plus 1pt}
879 \setlength{\oddsidemargin}{0pc}
880 \setlength{\marginparwidth}{0pc}
881 \setlength{\topmargin}{-2.5pc}
882 \setlength{\headsep}{20pt}
883 \setlength{\columnsep}{1.5pc}
884 %    \end{macrocode}
885 %    We want a rule between columns.
886 %    \begin{macrocode}
887 \setlength\columnseprule{.4pt}
888 %    \end{macrocode}
889 %    We also want to ensure that a new \mc{} environment finds enough
890 %    space at the bottom of the page.
891 %    \begin{macrocode}
892 \setlength\premulticols{6\baselineskip}
893 %    \end{macrocode}
894 %    When balancing columns we disregard solutions that
895 %    are too bad. Also, if the last column is too bad
896 %    we typeset it without stretch.
897 %    \begin{macrocode}
898 \setcounter{columnbadness}{7000}
899 \setcounter{finalcolumnbadness}{7000}
900 %    \end{macrocode}
901 %    The index is supposed to come out in four columns.
902 %    And we don't show macro names in the margin.
903 %    \begin{macrocode}
904 \setcounter{IndexColumns}{4}
905 \let\DescribeMacro\SpecialUsageIndex
906 \let\DescribeEnv\SpecialEnvIndex
907 \renewcommand\PrintMacroName[1]{}
908 \CodelineIndex
909 %\DisableCrossrefs           % Partial index
910 \RecordChanges               % Change log
911 %    \end{macrocode}
912 %    Line numbers are very small for this article.
913 %    \begin{macrocode}
914 \renewcommand{\theCodelineNo}
915   {\scriptsize\rm\arabic{CodelineNo}}
916 \settowidth\MacroIndent{\scriptsize\rm 00\ }
918 \begin{document}
919   \typeout
920    {****************************************
921  ^^J* Expect some Under- and overfull boxes.
922  ^^J****************************************}
923    \DocInput{multicol.dtx}
924 \end{document}
925 %</driver>
926 %    \end{macrocode}
929 % \end{multicols}
931 % \begin{multicols}{2}[\subsection{Identification and
932 %                      option processing}]
935 % We start by identifying the package. Since it makes use of features
936 % only available in \LaTeXe{} we ensure that this format is available.
937 % (Now this is done earlier in the file.)
938 %    \begin{macrocode}
939 %<*package>
940 % \NeedsTeXFormat{LaTeX2e}
941 % \ProvidesPackage{multicol}[..../../..
942 %    v... multicolumn formatting]
943 %    \end{macrocode}
945 %^^A \subsection{Option processing}
947 %    Next we declare options supported by \mc{}. Two-column mode
948 %    and \mc{} do not work together so we warn about possible
949 %    problems. However, since you can revert to |\onecolumn|
950 %    in which case \mc{} does work, we don't make this an error.
951 %    \begin{macrocode}
952 \DeclareOption{twocolumn}
953    {\PackageWarning{multicol}{May not work
954              with the twocolumn option}}
955 %    \end{macrocode}
956 %    Tracing is done using a counter. However
957 %    it is also possible to invoke the tracing
958 %    using the options declared below.
959 %    \begin{macrocode}
960 \newcount\c@tracingmulticols
961 \DeclareOption{errorshow}
962     {\c@tracingmulticols\z@}
963 \DeclareOption{infoshow}
964     {\c@tracingmulticols\@ne}
965 \DeclareOption{balancingshow}
966     {\c@tracingmulticols\tw@}
967 \DeclareOption{markshow}
968     {\c@tracingmulticols\thr@@}
969 \DeclareOption{debugshow}
970     {\c@tracingmulticols5\relax}
971 %    \end{macrocode}
972 %    The next option is intended for typesetting on a |\baselineskip|
973 %    grid. Right now it doesn't do anything other than warning if it
974 %    thinks that the grid got lost.
975 % \changes{v1.6a}{2003/03/15}{New option grid}
976 %    \begin{macrocode}
977 \let\mc@gridwarn\maxdimen
978 \DeclareOption{grid}{\def\mc@gridwarn{\maxdepth}}
979 %    \end{macrocode}
981 % \changes{v1.8e}{2014/04/23}{Support \cs{docolaction}}
982 %    Next option enables the |\docolaction| command. As this changes
983 %   the \texttt{.aux} file content this is not automatically enabled.
984 %    \begin{macrocode}
985 \DeclareOption{colaction}{%
986   \def\mc@col@status@write{%
987          \protected@write\@auxout{}%
988               {\string\mc@col@status
989               {\ifmc@firstcol 1\else 2\fi}}%
990          \mc@firstcolfalse}%
991   \def\mc@lastcol@status@write{%
992          \protected@write\@auxout{}%
993               {\string\mc@col@status{3}}}%
995 \let\mc@col@status@write\relax
996 \let\mc@lastcol@status@write\relax
997 %    \end{macrocode}
999 %    \begin{macrocode}
1000 \ProcessOptions
1001 %    \end{macrocode}
1004 % \end{multicols}
1006 % \begin{multicols}{2}[\subsection{Starting and
1007 %                      Ending the \mc{} Environment}]
1009 % \begin{macro}{\multicols}
1010 %    As mentioned before, the \mc{} environment has one mandatory
1011 %    argument (the number of columns) and up to two optional ones.  We
1012 %    start by reading the number of columns into the |\col@number|
1013 %    register.
1014 %    \begin{macrocode}
1015 \def\multicols#1{\col@number#1\relax
1016 %    \end{macrocode}
1017 %    If the user forgot the argument, \TeX{} will complain about a
1018 %    missing number at this point. The error recovery mechanism will
1019 %    then use zero, which isn't a good choice in this case. So we
1020 %    should now test whether everything is okay. The minimum is two
1021 %    columns at the moment.
1022 % \changes{v1.3b}{1990/10/09}{Minimum of two columns}
1023 %    \begin{macrocode}
1024   \ifnum\col@number<\tw@
1025      \PackageWarning{multicol}%
1026       {Using `\number\col@number'
1027        columns doesn't seem a good idea.^^J
1028        I therefore use two columns instead}%
1029      \col@number\tw@ \fi
1030 %    \end{macrocode}
1031 %    We have only enough box registers for ten columns, so we need to
1032 %    check that the user hasn't asked for more.
1033 % \changes{v1.4k}{1992/06/27}{Maximum of 5 columns (temp)}
1034 % \changes{v1.5a}{1992/11/04}{Allow 10 columns again}
1035 %    \begin{macrocode}
1036   \ifnum\col@number>10
1037      \PackageError{multicol}%
1038       {Too many columns}%
1039       {Current implementation doesn't
1040        support more than 10 columns.%
1041        \MessageBreak
1042        I therefore use 10 columns instead}%
1043      \col@number10 \fi
1044 %    \end{macrocode}
1045 %    Within the environment we need a special version of the
1046 %    kernel |\@footnotetext| command since the original sets the
1047 %    the |\hsize| to |\columnwidth| which is not correct in the
1048 %    multicol environment. Here |\columnwidth| refers to the width of
1049 %    the individual column and the footnote should be in |\textwidth|.
1050 %    Since |\@footnotetext| has a different definition inside a
1051 %    minipage environment we do not redefine it directly. Instead we
1052 %    locally set |\columnwidth| to |\textwidth| and call the original
1053 %    (current) definition stored in |\orig@footnotetext|.
1054 % \changes{v1.5p}{1997/12/14}{Redefinition of \cs{@footnotetext}
1055 %                           only within env pr/2689.}
1056 % \changes{v1.5r}{1998/08/17}{Use \cs{@footnotetext} but with
1057 %                             local change to \cs{columnwidth}.}
1058 % \changes{v1.5w}{1999/10/21}{Make \cs{@footnotetext} long to allow
1059 %                             multi-paragraph footnotes.}
1060 %    If the \mc{} environment is nested inside another \mc{}
1061 %    environment then the redefinition has already happened. So be
1062 %    better test for this situation. Otherwise, we will get a \TeX{}
1063 %    stack overflow as this would generate a self-referencing definition.
1064 % \changes{v1.6e}{2004/02/14}{Avoid self-referencing definition of
1065 %    \cs{@footnotetext} (pr/3618)}.
1066 %    \begin{macrocode}
1067      \ifx\@footnotetext\mult@footnotetext\else
1068        \let\orig@footnotetext\@footnotetext
1069        \let\@footnotetext\mult@footnotetext
1070      \fi
1071 %    \end{macrocode}
1072 %    Now we can safely look for the optional arguments.
1073 %    \begin{macrocode}
1074   \@ifnextchar[\mult@cols{\mult@cols[]}}
1075 %    \end{macrocode}
1076 % \end{macro}
1080 % \begin{macro}{\mult@footnotetext}
1082 %    \begin{macrocode}
1083 \long\def\mult@footnotetext#1{\begingroup
1084          \columnwidth\textwidth
1085          \orig@footnotetext{#1}\endgroup}
1086 %    \end{macrocode}
1087 % \end{macro}
1089 % \begin{macro}{\mult@cols}
1090 %    The |\mult@cols| macro grabs the first optional argument
1091 %    (if any) and looks for the second one.
1092 %    \begin{macrocode}
1093 \def\mult@cols[#1]{\@ifnextchar[%
1094 %    \end{macrocode}
1095 %    This argument should be a \meta{dimen} denoting the minimum free
1096 %    space needed on the current page to start the environment. If the
1097 %    user didn't supply one, we use |\premulticols| as a
1098 %    default.
1099 %    \begin{macrocode}
1100   {\mult@@cols{#1}}%
1101   {\mult@@cols{#1}[\premulticols]}}
1102 %    \end{macrocode}
1103 % \end{macro}
1106 % \begin{macro}{\mult@@cols}
1107 %    After removing all arguments from the input we are able
1108 %    to start with |\mult@@cols|.
1109 %    \begin{macrocode}
1110 \def\mult@@cols#1[#2]{%
1111 %    \end{macrocode}
1112 %    First thing we do is to decide whether or not this is an
1113 %    unbounded multicols environment, i.e. one that may split across
1114 %    pages, or one that has to be typeset into a box. If we are in
1115 %    \TeX's ``inner'' mode (e.g., inside a box already) then we have a
1116 %    boxed version of multicols therefore we set the |@boxedmulticols|
1117 %    switch to true.  The \mc{} should start in vertical mode. If we
1118 %    are not already there we now force it with |\par| since otherwise
1119 %    the test for ``inner'' mode wouldn't show if we are in a box.
1120 % \changes{v1.4f}{1992/04/28}{\cs{par} added to allow for correct inner test}
1121 %    \begin{macrocode}
1122   \par
1123   \ifinner \@boxedmulticolstrue
1124 %    \end{macrocode}
1125 %    Otherwise we check |\doublecol@number|. This counter is zero
1126 %    outside a multicols environment but positive inside (this happens
1127 %    a little later on). In the second case we need to process the
1128 %    current multicols also in ``boxed mode'' and so change the switch
1129 %    accordingly.
1130 %    \begin{macrocode}
1131   \else
1132     \ifnum \doublecol@number>\z@
1133        \@boxedmulticolstrue
1134     \fi
1135   \fi
1136 %    \end{macrocode}
1137 %    Then we look to see if statistics are requested:
1138 %    \begin{macrocode}
1139   \mult@info\z@
1140       {Starting environment with
1141        \the\col@number\space columns%
1142 %    \end{macrocode}
1143 %    In boxed mode we add some more info.
1144 % \changes{v1.4f}{1992/04/28}{\cs{on@line} added to tracing info}
1145 %    \begin{macrocode}
1146         \if@boxedmulticols\MessageBreak
1147            (boxed mode)\fi
1148       }%
1149 %    \end{macrocode}
1150 %    Then we measure the current page to see whether a useful portion
1151 %    of the multicolumn environment can be typeset.  This routine
1152 %    might start a new page.
1153 % \changes{v1.4a}{1992/02/14}{Forgotten braces added}
1154 %    \begin{macrocode}
1155    \enough@room{#2}%
1156 %    \end{macrocode}
1157 %    Now we output the first argument and produce vertical space
1158 %    above the columns. (Note that this argument corresponds to the
1159 %    first optional argument of the {\sf multicols} environment.)
1160 %    For many releases this argument was typeset in a group to get
1161 %    a similar effect as |\twocolumn[..]| where the argument is
1162 %    also implicitly surrounded by braces. However, this conflicts
1163 %    with local changes done by things like sectioning commands (which
1164 %    account for the majority of commands used in that argument)
1165 %    messing up vertical spacing etc.\ later in the document so that
1166 %    from version v1.5q on this argument is again typeset at the outer
1167 %    level.
1168 % \changes{v1.4e}{1992/03/16}{Typeset optional arg inside group}
1169 % \changes{v1.5q}{1998/01/19}{And removed the group again six years later}
1170 %    \begin{macrocode}
1171    #1\par\addvspace\multicolsep
1172 %    \end{macrocode}
1173 %    When the last line of a paragraph had a positive depth then this
1174 %    depth normally taken into account by the baselineskip calculation
1175 %    for the next line. However, the columns produced by a following
1176 %    \texttt{multicol} are rigid and thus the distance from the
1177 %    baseline of a previous text line to the first line in a
1178 %    \texttt{multicol} would differ depending on the depth of the
1179 %    previous line. To account for this we add a negative space unless
1180 %    the depth is \texttt{-1000pt} which signals something special to
1181 %    \TeX and is not supposed to be a real depth.
1182 % \changes{v1.5z1}{2003/02/17}{Add a kern to cancel potential depth of
1183 %    previous line}
1184 %    \begin{macrocode}
1185    \ifdim \prevdepth = -\@m\p@
1186    \else
1187 %    \end{macrocode}
1188 %    The actual generation of this corrective space is a little bit
1189 %    more complicated as it doesn't make sense to always back up to
1190 %    the previous baseline (in case an object with a very large depth
1191 %    was placed there, e.g., a centered tabular). So we only back up
1192 %    to the extend that we are within the |\baselineskip| grid. We
1193 %    know that the box produced by \mc{} has |\topskip| at its top so
1194 %    that also needs to be taken into account.
1195 % \changes{v1.6a}{2003/03/15}{Adjust spacing}
1196 %    \begin{macrocode}
1197      \@tempcnta\prevdepth
1198      \@tempcntb\baselineskip
1199      \divide\@tempcnta\@tempcntb
1200      \advance\@tempcnta\@ne
1201      \dimen@\prevdepth
1202      \advance\dimen@ -\@tempcnta\baselineskip
1203      \advance\dimen@ \topskip
1204      \kern-\dimen@
1205    \fi
1206 %    \end{macrocode}
1207 %    We start a new grouping level to hide all subsequent changes
1208 %    (done in |\prepare@multicols| for example).
1209 %    \begin{macrocode}
1210    \begingroup
1211      \prepare@multicols
1212 %    \end{macrocode}
1213 %    If we are in boxed mode we now open a box to typeset all material
1214 %    from the multicols body into it, otherwise we simply go ahead.
1215 % \changes{v1.4g}{1992/05/07}{\cs{global} was probably wrong but at least
1216 %                           unnecessary}
1217 %    \begin{macrocode}
1218      \if@boxedmulticols
1219        \setbox\mult@box\vbox\bgroup
1220 %    \end{macrocode}
1222 % \changes{v1.8c}{2013/11/03}{Add \cs{color@setgroup} to prevent color leak}
1223 %    \begin{macrocode}
1224                             \color@setgroup
1225 %    \end{macrocode}
1226 % \changes{v1.5?}{1994/?/?}{Penalty moved to later point}
1227 %    We may have to reset some parameters at this point,
1228 %    perhaps |\@parboxrestore|
1229 %    would be the right action but I leave it for the moment.
1230 % \changes{v1.4l}{1992/08/17}{\cs{@totalleftmargin} now in
1231 %                             \cs{prepare@multicols}}
1232 %    \begin{macrocode}
1233      \fi
1234 %    \end{macrocode}
1235 %    We finish by suppressing initial spaces.
1236 %    \begin{macrocode}
1237      \ignorespaces}
1238 %    \end{macrocode}
1239 % \end{macro}
1241 %  \begin{macro}{\if@boxedmulticols}
1242 %    Here is the switch and the box for ``boxed'' multicols code.
1243 %    \begin{macrocode}
1244 \newif\if@boxedmulticols
1245 \@boxedmulticolsfalse
1246 \newbox\mult@box
1247 %    \end{macrocode}
1248 %  \end{macro}
1250 % \begin{macro}{\enough@room}
1251 % \changes{v1.0c}{1989/05/12}{Penalty 0 added to empty the contribution
1252 %                           list.}
1253 %    The |\enough@room| macro used
1254 %    above isn't perfect but works reasonably well in this context. We
1255 %    measure the free space on the current page by subtracting
1256 %    |\pagetotal| from |\pagegoal|. This isn't entirely
1257 %    correct since it doesn't take the `shrinking' (i.e.\
1258 %    |\pageshrink|) into account.  The `recent contribution list'
1259 %    might be nonempty so we start with |\par| and an explicit
1260 %    |\penalty|.\footnote{See the documentation of
1261 %    \cs{endmulticols} for further details.}
1262 %    Actually, we use |\addpenalty| to ensure that a following
1263 %    |\addvspace| will `see' the vertical space that might be
1264 %    present.
1265 %    The use of |\addpenalty| will have the effect that all items from
1266 %    the recent contributions will be moved to the main vertical list
1267 %    and the |\pagetotal| value will be updated correctly. However,
1268 %    the penalty will be placed in front of any dangling glue item
1269 %    with the result that the main vertical list may already be
1270 %    overfull even if \TeX{} is not invoking the output routine.
1271 % \changes{v1.3b}{1990/10/09}{Do \cs{penalty} with \cs{addpenalty}}
1272 % \changes{v1.4e}{1992/03/16}{But ignore \cs{@nobreak} in \cs{addpenalty}}
1273 %    \begin{macrocode}
1274 \def\enough@room#1{%
1275 %    \end{macrocode}
1276 %    Measuring makes only sense when we are not in ``boxed mode'' so
1277 %    the routine does nothing if the switch is true.
1278 %    \begin{macrocode}
1279    \if@boxedmulticols\else
1280    \par
1281 %    \end{macrocode}
1282 %    \label{mac:enoughroom}
1283 %    To empty the contribution list the first release contained a
1284 %    penalty zero but this had the result that |\addvspace| couldn't
1285 %    detect preceding glue. So this was changed to |\addpenalty|. But
1286 %    this turned out to be not enough as |\addpenalty| will not add a
1287 %    penalty when |@nobreak| is true. Therefore we force this switch
1288 %    locally to false. As a result there may be a break between
1289 %    preceding text and the start of a multicols environment, but this
1290 %    seems acceptable since there is the optional argument for exactly
1291 %    this reason.
1292 %    \begin{macrocode}
1293    \bgroup\@nobreakfalse\addpenalty\z@\egroup
1294    \page@free \pagegoal
1295    \advance \page@free -\pagetotal
1296 %    \end{macrocode}
1297 %    To be able to output the value we need to assign it to a register
1298 %    first since it might be a register (default) in which case we
1299 %    need to use |\the| or it might be a plain value in which case
1300 %    |\the| would be wrong.
1301 % \changes{v1.5e}{1994/05/26}{Assign arg to skip register to be able
1302 %                             to output value}
1303 %    \begin{macrocode}
1304      \@tempskipa#1\relax
1305 %    \end{macrocode}
1306 %    Now we test whether tracing information is required:
1307 %    \begin{macrocode}
1308    \mult@info\z@
1309        {Current page:\MessageBreak
1310         height=%
1311         \the\pagegoal: used \the\pagetotal
1312         \space -> free=\the\page@free
1313         \MessageBreak
1314         needed \the\@tempskipa
1315               \space(for #1)}%
1316 %    \end{macrocode}
1317 %    Our last action is to force a page break if there isn't enough
1318 %    room left.
1319 %    \begin{macrocode}
1320    \ifdim \page@free <#1\newpage \fi
1321   \fi}
1322 %    \end{macrocode}
1323 % \end{macro}
1325 % \begin{macro}{\prepare@multicols}
1326 %    When preparing for multicolumn output several things must
1327 %    be done.
1328 %    \begin{macrocode}
1329 \def\prepare@multicols{%
1330 %    \end{macrocode}
1331 %    We start saving the current |\@totalleftmargin| and then
1332 %    resetting the |\parshape| in case we are inside some list
1333 %    environment. The correct indentation for the \mc{} environment in
1334 %    such a case will be produced by moving the result to the right by
1335 %    |\multicol@leftmargin| later on. If we would use the value of of
1336 %    |\@totalleftmargin| directly then lists inside the \mc{}
1337 %    environment could cause a shift of the output.
1338 % \changes{v1.4l}{1992/08/17}{saved \cs{@totalleftmargin}}
1339 %    \begin{macrocode}
1340   \multicol@leftmargin\@totalleftmargin
1341   \@totalleftmargin\z@
1342   \parshape\z@
1343 %    \end{macrocode}
1344 %    We also set the register |\doublecol@number| for later use.  This
1345 %    register should contain $2\times |\col@number|$.  This is also an
1346 %    indicator that we are within a \mc{} environment as mentioned
1347 %    above.
1348 % \changes{v1.5a}{1992/11/04}{Add offset to \cs{doublecolnumber}}
1349 %    \begin{macrocode}
1350   \doublecol@number\col@number
1351   \multiply\doublecol@number\tw@
1352   \advance\doublecol@number\mult@rightbox
1353 %    \end{macrocode}
1355 %    \begin{macrocode}
1356   \if@boxedmulticols
1357     \let\l@kept@firstmark\kept@firstmark
1358     \let\l@kept@botmark\kept@botmark
1359     \global\let\kept@firstmark\@empty
1360     \global\let\kept@botmark\@empty
1361   \else
1362 %    \end{macrocode}
1363 %    We add an empty box to the main vertical list to ensure that we
1364 %    catch any insertions (held over or inserted at the top of the
1365 %    page). Otherwise it might happen that the |\eject| is discarded
1366 %    without calling the output routine. Inside the output routine we
1367 %    remove this box again.  Again this code applies only if we are on
1368 %    the main vertical list and not within a box.
1369 %    However, it is not enough to turn off interline spacing, we also
1370 %    have to clear |\topskip| before adding this box, since |\topskip|
1371 %    is always inserted before the first box on a page which would
1372 %    leave us with an extra space of |\topskip| if \mc{} start on a
1373 %    fresh sheet.
1374 % \changes{v1.3c}{1991/03/03}{\cs{null} inserted and removed in output}
1375 % \changes{v1.4a}{1992/02/11}{Conditional code for boxed mode added.}
1376 % \changes{v1.4o}{1992/11/22}{\cs{topskip} locally zeroed.}
1377 %    \begin{macrocode}
1378     \nointerlineskip {\topskip\z@\null}%
1379     \output{%
1380       \global\setbox\partial@page\vbox
1381         {%
1382 %    \end{macrocode}
1383 %    Now we have to make sure that we catch one special situation which
1384 %    may result in loss of text! If the user has a huge amount of
1385 %    vertical material within the first optional argument that is larger
1386 %    then |\premulticols| and we are near the bottom of the page then it
1387 %    can happen that not the |\eject| is triggering this special output
1388 %    routine but rather the overfull main vertical list.  In that case
1389 %    we get another breakpoint through the |\eject| penalty. As a result
1390 %    this special output routine would be called twice and the contents
1391 %    of |\partial@page|, i.e.\ the material before the \mc{}
1392 %    environment gets lost. There are several solutions to avoid this
1393 %    problem, but for now we will simply detect this and inform the user
1394 %    that he/she has to enlarge the |\premulticols| by using a suitable
1395 %    value for the second argument.
1396 % \changes{v1.4a}{1992/02/11}{Checking for text losses.}
1397 %    \begin{macrocode}
1398 %<*check>
1399          \ifvoid\partial@page\else
1400            \PackageError{multicol}%
1401             {Error saving partial page}%
1402             {The part of the page before
1403              the multicols environment was
1404              nearly full with^^Jthe result
1405              that starting the environment
1406              will produce an overfull
1407              page.  Some^^Jtext may be lost!
1408              Please increase \premulticols
1409              either generally or for this%
1410              ^^Jenvironment by specifying a
1411              suitable value in the second
1412              optional argument to^^Jthe
1413              multicols environment.}
1414            \unvbox\partial@page
1415            \box\last@line
1416          \fi
1417 %</check>
1418          \unvbox\@cclv
1419          \global\setbox\last@line\lastbox
1420         }%
1421 %    \end{macrocode}
1422 %    Finally we need to record the marks that are present within the
1423 %    |\partial@page| so that we can construct correct first and bottom
1424 %    marks later on. This is done by the following code.
1425 % \changes{v1.4a}{1992/02/14}{kept marks initiated}
1426 %    \begin{macrocode}
1427            \prep@keptmarks
1428 %    \end{macrocode}
1429 %    Finally we have to initialize |\kept@topmark| which should
1430 %    ideally be initialized with the mark that is current on ``top''
1431 %    of this page. Unfortunately we can't use |\topmark| because this
1432 %    register will not always contain what its name promises because
1433 %    \LaTeX{} sometimes calls the output routine for float
1434 %    management.\footnote{During such a call the \cs{botmark}
1435 %    gets globally copied to \cs{topmark} by the \TeX{}
1436 %    program.} Therefore we use the second best solution by
1437 %    initializing it with |\firstmark|. In fact, for our purpose this
1438 %    doesn't matter as we use |\kept@topmark| only to initialize
1439 %    |\firstmark| and |\botmark| of a following page if we don't find
1440 %    any marks on the current one.
1441 % \changes{v1.4i}{1992/06/18}{\cs{kept@topmark} initialized.}
1442 %    \begin{macrocode}
1443            \global\let\kept@topmark\firstmark
1444           }\eject
1445 %    \end{macrocode}
1446 %    The next thing to do is to assign a new value to |\vsize|.
1447 %    \LaTeX{} maintains the free room on the page (i.e.\ the page
1448 %    height without the space for already contributed floats) in the
1449 %    register |\@colroom|. We must subtract the height of
1450 %    |\partial@page| to put the actual free room into this
1451 %    variable.
1452 %    \begin{macrocode}
1453     \advance\@colroom-\ht\partial@page
1454 %    \end{macrocode}
1455 %    Then we have to calculate the |\vsize| value to use during column
1456 %    assembly. |\set@mult@vsize| takes an argument which allows to
1457 %    make the setting local (|\relax|) or global (|\global|). The
1458 %    latter variant is used inside the output routine below. At this
1459 %    point here we have to make a local change to |\vsize| because we
1460 %    want to get the original value for |\vsize| restored in case
1461 %    this \mc{} environment ends on the same page where it has started.
1462 % \changes{v1.4p}{1992/11/26}{Use different \cs{vsize} setting}
1463 % \changes{v1.4p}{1992/11/26}{Code moved to \cs{set@mult@vsize}}
1464 %    \begin{macrocode}
1465     \set@mult@vsize\relax
1466 %    \end{macrocode}
1467 %    Now we switch to a new |\output| routine which will be used
1468 %    to put the gathered column material together.
1469 %    \begin{macrocode}
1470     \output{\multi@column@out}%
1471 %    \end{macrocode}
1472 %    Finally we handle the footnote insertions. We have to multiply
1473 %    the magnification factor and the extra skip by the number of
1474 %    columns since each footnote reduces the space for every column
1475 %    (remember that we have pagewide footnotes).  If, on the other
1476 %    hand, footnotes are typeset at the very end of the document, our
1477 %    scheme still works since |\count\footins| is zero then, so it
1478 %    will not change.
1479 %    To allow even further customization the setting of the |\footins|
1480 %    parameters is done in a separate macro.
1481 % \changes{v1.5?}{1994/?/?}{Use \cs{init@mult@footins}}
1482 %    \begin{macrocode}
1483     \init@mult@footins
1484 %    \end{macrocode}
1485 %    For the same reason (pagewide footnotes), the \meta{dimen}
1486 %    register controlling the maximum space used for footnotes isn't
1487 %    changed.  Having done this, we must reinsert all the footnotes
1488 %    which are already present (i.e.\ those encountered when the
1489 %    material saved in |\partial@page| was first processed). This
1490 %    will reduce the free space (i.e.\ |\pagetotal|) by the
1491 %    appropriate amount since we have changed the magnification
1492 %    factor, etc.\ above.
1493 %    \begin{macrocode}
1494     \reinsert@footnotes
1495 %    \end{macrocode}
1496 %    All the code above was only necessary for the unrestricted \mc{}
1497 %    version, i.e.\ the one that allows page breaks. If we are within
1498 %    a box there is no point in setting up special output routines or
1499 %    |\vsize|, etc.
1500 %    \begin{macrocode}
1501   \fi
1502 %    \end{macrocode}
1503 %    But now we are coming to code that is necessary in all cases.  We
1504 %    assign new values to |\vbadness|, |\hbadness| and |\tolerance|
1505 %    since it's rather hard for \TeX{} to produce `good' paragraphs
1506 %    within narrow columns.
1507 % \changes{v1.2a}{1990/02/05}{\cs{vbadness} 10001 now.}
1508 %    \begin{macrocode}
1509   \vbadness\@Mi \hbadness5000
1510   \tolerance\multicoltolerance
1511 %    \end{macrocode}
1512 %    Since nearly always the first pass will fail we ignore it
1513 %    completely telling \TeX{} to hyphenate directly.  In fact, we now
1514 %    use another register to keep the value for the multicol
1515 %    pre-tolerance, so that a designer may allow to use
1516 %    |\pretolerance|.
1517 % \changes{v1.2a}{1990/02/05}{\cs{pretolerance} -1 because it nearly never
1518 %                            succeeds.}
1519 % \changes{v1.4e}{1992/03/20}{Using}
1520 %    \begin{macrocode}
1521   \pretolerance\multicolpretolerance
1522 %    \end{macrocode}
1523 %    For use with the new \TeX{} we set |\emergencystretch| to
1524 %    $|\col@number| \times 4pt$. However this is only a guess
1525 %    so at the moment this is done in a macro
1526 %    |\setemergencystretch| which gets the current |\hsize|
1527 %    and the number of columns as arguments. Therefore users are able
1528 %    to figure out their own formula.
1529 % \changes{v1.2a}{1990/02/05}{\cs{setemergencystretch} added.}
1530 %    \begin{macrocode}
1531   \setemergencystretch\col@number\hsize
1532 %    \end{macrocode}
1533 %    Another hook to allow people adding their own extensions without
1534 %    making a new package is |\set@floatcmds| which handles any
1535 %    redefinitions of \LaTeX{}s internal float commands to work with
1536 %    the \mc{} environment. At the moment it is only used to redefine
1537 %    |\@dblfloat| and |\end@dblfloat|.
1538 % \changes{v1.2a}{1990/02/05}{\cs{set@floatcmds} added.}
1539 %    \begin{macrocode}
1540   \set@floatcmds
1541 %    \end{macrocode}
1542 %    Additionally, we advance |\baselineskip| by
1543 %    |\multicolbaselineskip| to allow corrections for narrow
1544 %    columns.
1545 %    \begin{macrocode}
1546   \advance\baselineskip\multicolbaselineskip
1547 %    \end{macrocode}
1548 % \changes{v1.0e}{1989/06/21}{\cs{textwidth} changed to \cs{linewidth}.}
1549 % \changes{v1.0e}{1989/06/21}{So this file will
1550 %                           work with the `twocolumn' command.}
1551 %    The |\hsize| of the columns is given by the formula:
1552 %    \[
1553 %       { |\linewidth| - (|\col@number|-1)
1554 %                             \times
1555 %                             |\columnsep|
1556 %        \over
1557 %        |\col@number|}
1558 %    \]
1559 %    The formula above has changed from release to release. We now
1560 %    start with the current value of |\linewidth| so that the column
1561 %    width is properly calculated when we are inside a minipage or a
1562 %    list or some other environment.
1563 %    This will be achieved with:
1564 %    \begin{macrocode}
1565   \hsize\linewidth \advance\hsize\columnsep
1566   \advance\hsize-\col@number\columnsep
1567   \divide\hsize\col@number
1568 %    \end{macrocode}
1569 %    We also set |\linewidth| and |\columnwidth| to |\hsize| In the past
1570 %    |\columnwidth| was left unchanged. This is inconsistent,
1571 %    but |\columnwidth| is used only by floats (which
1572 %    aren't allowed in their current implementation) and by the
1573 %    |\footnote| macro. Since we want pagewide
1574 % footnotes\footnote{I'm not sure that I really want pagewide
1575 %                       footnotes. But balancing of the last page can
1576 %                       only be achieved with this approach or with a
1577 %                       multi-path algorithm which is complicated and
1578 %                       slow. But it's a challenge to everybody to
1579 %                       prove me wrong!  Another possibility is to
1580 %                       reimplement a small part of the {\it
1581 %                       fire\_up\/} procedure in \TeX{} (the program).
1582 %                       I think that this is the best solution if you
1583 %                       are interested in complex page makeup, but it
1584 %                       has the disadvantage that the resulting
1585 %                       program cannot be called \TeX{} thereafter.}
1586 %    this simple trick saved us from rewriting the |\footnote|
1587 %    macros. However, some applications referred to |\columnwidth| as
1588 %    the ``width of the current column'' to typeset displays
1589 %    (the \texttt{amsmath} package, for example) and to allow the use
1590 %    of such applications together with \texttt{multicol} this is now
1591 %    changed.
1593 %    Before we change |\linewidth| to the new value we record its old
1594 %    value in some register called |\full@width|. This value is
1595 %    used later on when we package all columns together.
1596 % \changes{v1.0e}{1989/06/21}{Setting of \cs{columnwidth} removed.}
1597 % \changes{v1.5o}{1997/11/16}{Setting of \cs{columnwidth} added again
1598 %                           pr/2664.}
1599 %    \begin{macrocode}
1600   \full@width\linewidth
1601   \linewidth\hsize
1602   \columnwidth\hsize
1604 %    \end{macrocode}
1605 % \end{macro}
1607 %  \begin{macro}{\init@mult@footins}
1608 %    This macro is used to set up the parameters associated
1609 %    with footnote floats. It can be redefined by applications that
1610 %    require different amount of spaces when typesetting footnotes.
1611 %    \begin{macrocode}
1612 \def\init@mult@footins{%
1613     \multiply\count\footins\col@number
1614     \multiply\skip \footins\col@number
1616 %    \end{macrocode}
1617 % \end{macro}
1619 %  \begin{macro}{\set@mult@vsize}
1621 %    Since we have to set |\col@umber| columns on one page,
1622 %    each with a height of |\@colroom|, we have to assign
1623 %    $
1624 %      |\vsize|  = |\col@number| \times |\@colroom|
1625 %    $
1626 %    in order to collect enough material before entering the
1627 %    |\output| routine again. In fact we have to add another
1628 %    $
1629 %       (|\col@number|-1) \times (|\baselineskip|-|\topskip|)
1630 %    $
1631 %    if you think about it.
1632 % \changes{v1.4p}{1992/11/26}{Macro added.}
1633 %    \begin{macrocode}
1634 \def\set@mult@vsize#1{%
1635     \vsize\@colroom
1636     \@tempdima\baselineskip
1637     \advance\@tempdima-\topskip
1638     \advance\vsize\@tempdima
1639     \vsize\col@number\vsize
1640     \advance\vsize-\@tempdima
1641 %    \end{macrocode}
1642 %    But this might not be enough since we use |\vsplit| later to
1643 %    extract the columns from the gathered material. Therefore we add
1644 %    some `extra lines,' one for each column plus a corrective action
1645 %    depending on the value of the `\texttt{collectmore}' counter.
1646 %    The final value is assigned globally if |#1| is |\global| because
1647 %    we want to use this macro later inside the output routine too.
1648 % \changes{v1.6c}{2003/04/08}{Collect one line per column more}
1649 %    \begin{macrocode}
1650     \advance\vsize\col@number\baselineskip
1651     #1\advance\vsize
1652         \c@collectmore\baselineskip}
1653 %    \end{macrocode}
1654 %  \end{macro}
1657 %  \begin{macro}{\multicol@leftmargin}
1658 %    Here is the dimen register we need for saving away the outer
1659 %    value of |\@totalleftmargin|.
1660 %    \begin{macrocode}
1661 \newdimen\multicol@leftmargin
1662 %    \end{macrocode}
1663 %  \end{macro}
1665 % \begin{macro}{\endmulticols}
1666 %    When the end of the \mc{} environment is sensed we have to
1667 %    balance the gathered material. Depending on whether or not we are
1668 %    inside a boxed multicol different things must happen. But first
1669 %    we end the current paragraph with a |\par| command.
1670 %    \begin{macrocode}
1671 \def\endmulticols{\par
1672   \if@boxedmulticols
1673 %    \end{macrocode}
1674 %    In boxed mode we have to close the box in which we have gathered
1675 %    all material for the columns. But before we do this we need to
1676 %    remove any space at the end of the box as we don't want to use
1677 %    this in balancing. Because of the |\color@endgroup| this can't be
1678 %    done later in |\balance@columns| as the color command will hide
1679 %    it. 
1680 % \changes{v1.8c}{2013/11/03}{Add \cs{color@endgroup} to prevent color leak}
1681 % \changes{v1.8f}{2014/06/19}{Discard spaces before adding \cs{color@endgroup}}
1682 %    \begin{macrocode}
1683     \remove@discardable@items\color@endgroup\egroup
1684 %    \end{macrocode}
1685 %    Now we call |\balance@columns| the routine that balances material
1686 %    stored in the box |\mult@box|.
1687 % \changes{v1.5?}{1994/?/?}{Splitting off zero box moved to
1688 %                           \cs{balance@columns}}
1689 %    \begin{macrocode}
1690     \balance@columns
1691 %    \end{macrocode}
1692 %    After balancing the result has to be returned by the command
1693 %    |\page@sofar|. But before we do this we reinsert any marks found
1694 %    in box |\mult@box|.
1695 %    \begin{macrocode}
1696     \return@nonemptymark{first}%
1697                  \kept@firstmark
1698     \return@nonemptymark{bot}%
1699                   \kept@botmark
1700     \page@sofar
1701 %    \end{macrocode}
1703 %    \begin{macrocode}
1704     \global\let\kept@firstmark
1705                \l@kept@firstmark
1706     \global\let\kept@botmark
1707             \l@kept@botmark
1708 %<*marktrace>
1709     \mult@info\tw@
1710       {Restore kept marks to\MessageBreak
1711        first: \meaning\kept@firstmark
1712        \MessageBreak bot\space\space:
1713                      \meaning\kept@botmark }%
1714 %</marktrace>
1715 %    \end{macrocode}
1716 %    This finishes the code for the ``boxed'' case.
1717 %    \begin{macrocode}
1718   \else
1719 %    \end{macrocode}
1720 %    If there was a |\columnbreak| on the very last line all material
1721 %    will have been moved to the |\colbreak@box|. Thus the the galley
1722 %    will be empty and no output routine gets called so that the text
1723 %    is lost. To avoid this problem (though unlikely) we check if the
1724 %    current galley is empty and the |\colbreak@box| contains text and
1725 %    if so return that to the galley. If the galley is non-empty any
1726 %    material in  |\colbreak@box| is added in the output routine since
1727 %    it needs to be put in front.
1728 % \changes{v1.6d}{2003/04/17}{Catch problem with \cs{columnbreak} in
1729 %    last line}
1730 %    \begin{macrocode}
1731     \ifdim\pagegoal=\maxdimen
1732       \ifvoid\colbreak@box\else
1733         \mult@info\@ne{Re-adding forced
1734                  break(s) for splitting}%
1735         \unvbox\colbreak@box\fi
1736     \fi
1737 %    \end{macrocode}
1738 %    If we are in an unrestricted \mc{} environment we end the current
1739 %    paragraph above with |\par| but this isn't sufficient since \TeX{}s
1740 %    {\it page\_builder} will not totally empty the contribution
1741 %    list.\footnote{This once caused a puzzling bug where some of the
1742 %    material was balanced twice, resulting in some overprints.  The
1743 %    reason was the \cs{eject} which was placed at the end of
1744 %    the contribution list. Then the {\it page\_builder} was called
1745 %    (an explicit \cs{penalty} will empty the contribution
1746 %    list), but the line with the \cs{eject} didn't fit onto
1747 %    the current page.  It was then reconsidered after the output
1748 %    routine had ended, causing a second break after one line.}
1749 %    Therefore we must also add an explicit |\penalty|.  Now the
1750 %    contribution list will be emptied and, if its material doesn't
1751 %    all fit onto the current page then the output routine will be
1752 %    called before we change it.
1753 % \changes{v1.3b}{1990/10/09}{Do \cs{penalty} with \cs{addpenalty}}
1754 % \changes{v1.4e}{1992/03/16}{But ignore \cs{@nobreak} in \cs{addpenalty}}
1755 % \changes{v1.5c}{1993/04/18}{Again use \cs{penalty}}
1756 %    At this point we need to use |\penalty| not |\addpenalty| to
1757 %    ensure that a) the recent contributions are emptied and b) that
1758 %    the very last item on the main vertical list is a valid break
1759 %    point so that \TeX{} breaks the page in case it is overfull.
1760 %    \begin{macrocode}
1761    \penalty\z@
1762 %    \end{macrocode}
1763 %    Now it's safe to change the output routine in order to balance
1764 %    the columns.
1765 %    \begin{macrocode}
1766    \output{\balance@columns@out}%
1767    \eject
1768 %    \end{macrocode}
1769 %    If the \mc{} environment body was completely empty or if a
1770 %    multi-page \mc{} just ends at a page boundary we have the unusual
1771 %    case that the |\eject| will have no effect (since the main
1772 %    vertical list is empty)---thus no output routine is called at
1773 %    all. As a result the material preceding the \mc{} (stored in
1774 %    |\partial@page| will get lost if we don't put this back by hand.
1775 % \changes{v1.4m}{1992/09/04}{Check \cs{partial@page} being emptied}
1776 %    \begin{macrocode}
1777     \ifvbox\partial@page
1778          \unvbox\partial@page\fi
1779 %    \end{macrocode}
1780 %    After the output routine has acted we restore
1781 %    the kept marks to their initial value.
1782 %    \begin{macrocode}
1783      \global\let\kept@firstmark\@empty
1784      \global\let\kept@botmark\@empty
1785 %<*marktrace>
1786      \mult@info\tw@
1787        {Make kept marks empty}%
1788 %</marktrace>
1789   \fi
1790 %    \end{macrocode}
1791 %    The output routine above will take care of the |\vsize| and
1792 %    reinsert the balanced columns, etc. But it can't reinsert the
1793 %    |\footnotes| because we first have to restore the
1794 %    |\footins| parameter since we are returning to one column
1795 %    mode. This will be done in the next line of code; we simply close
1796 %    the group started in |\multicols|.
1798 %    To fix an obscure bug which is the result of the current
1799 %    definition of the |\begin| \ldots\ |\end| macros, we check that
1800 %    we are still (logically speaking) in the \mc{} environment. If,
1801 %    for example, we forget to close some environment inside the
1802 %    \mc{} environment, the following |\endgroup| would be
1803 %    incorrectly considered to be the closing of this environment.
1804 % \changes{v1.3c}{1991/03/14}{Check closing env.}
1805 %    \begin{macrocode}
1806   \@checkend{multicols}%
1807   \endgroup
1808 %    \end{macrocode}
1809 %    We also set the `{\sf unbalance}' counter to its default. This is
1810 %    done globally since \LaTeX{} counters are always changed this
1811 %    way.\footnote{Actually, we are still in a group started by the
1812 %    \cs{begin} macro, so \cs{global} must be used
1813 %    anyway.}
1814 %    \begin{macrocode}
1815   \global\c@unbalance\z@
1816 %    \end{macrocode}
1817 %    Now it's time to return any footnotes if we are in unrestricted
1818 %    mode:
1819 %    \begin{macrocode}
1820   \if@boxedmulticols\else
1821     \reinsert@footnotes
1822 %    \end{macrocode}
1823 %    We also take a look at the amount of free space on the current
1824 %    page to see if it's time for a page break.  The vertical space
1825 %    added thereafter will vanish if |\enough@room| starts a new
1826 %    page.
1828 %    But there is one catch. If the |\end{multicols}| is at the top of
1829 %    which can happen if there is a break point just before it (such
1830 %    as end ending environment) which was chosen. In that case we
1831 %    would do the next page using the internal |\vsize| for multicol
1832 %    collection which is a disaster. So we better catch this
1833 %    case. Fortunately we can detect it by looking at |\pagegoal|.
1834 % \changes{v1.5x}{2000/05/05}{Detect and fix problem if a multicols
1835 %    ends at the top of a page}
1836 %    \begin{macrocode}
1837     \ifdim \pagegoal=\maxdimen
1838       \global\vsize\@colroom
1839     \else
1840       \enough@room\postmulticols
1841     \fi
1842   \fi
1843   \addvspace\multicolsep
1844 %    \end{macrocode}
1845 %    There is one more thing to do: the balanced result of the
1846 %   environment is supposed to have a |\prevdepth| of zero as we
1847 %   backed up by its real prevdepth within |\page@sofar|. However if
1848 %   the balancing happened in the output routine then \TeX{} reverts
1849 %   to the |\prevdepth| that was current before the OR once the OR has
1850 %   finished. In short |\prevdepth| is something you can't set
1851 %   globally it is alway local to the current list being built. Thus
1852 %   we need to set it back to zero here to avoid incorrect spacing.
1853 % \changes{v1.8h}{2014/09/12}{Set \cs{prevdepdth} for current vlist
1854 %   when returning from multicols environment}
1855 %    \begin{macrocode}
1856  \prevdepth\z@
1857 %    \end{macrocode}
1858 %    If statistics are required we finally report that we have
1859 %    finished everything.
1860 %    \begin{macrocode}
1861   \mult@info\z@
1862      {Ending environment
1863              \if@boxedmulticols
1864                 \space(boxed mode)\fi
1865               }}
1866 %    \end{macrocode}
1867 % \end{macro}
1870 % \begin{macro}{\c@unbalance}
1871 % \SpecialMainIndex{\c@collectmore}
1872 % \SpecialMainIndex{\col@number}
1873 % \SpecialMainIndex{\doublecol@number}
1874 % \SpecialMainIndex{\premulticols}
1875 % \SpecialMainIndex{\multicoltolerance}
1876 % \SpecialMainIndex{\multicolpretolerance}
1877 % \SpecialMainIndex{\page@free}
1878 % \SpecialMainIndex{\premulticols}
1879 % \SpecialMainIndex{\postmulticols}
1880 % \SpecialMainIndex{\multicolsep}
1881 % \SpecialMainIndex{\multicolbaselineskip}
1882 % \SpecialMainIndex{\partial@page}
1883 %    Let us end this section by allocating all the registers used so
1884 %    far.
1885 %    \begin{macrocode}
1886 \newcount\c@unbalance
1887 \newcount\c@collectmore
1888 %    \end{macrocode}
1889 %    In the new \LaTeX{} release |\col@number| is already allocated by
1890 %    the kernel, so we don't allocate it again.
1891 %    \begin{macrocode}
1892 %\newcount\col@number
1893 \newcount\doublecol@number
1894 \newcount\multicoltolerance
1895 \newcount\multicolpretolerance
1896 \newdimen\full@width
1897 \newdimen\page@free
1898 \newdimen\premulticols
1899 \newdimen\postmulticols
1900 \newskip\multicolsep
1901 \newskip\multicolbaselineskip
1902 \newbox\partial@page
1903 \newbox\last@line
1904 %    \end{macrocode}
1905 %    And here are their default values:
1906 %    \begin{macrocode}
1907 \c@unbalance   = 0
1908 \c@collectmore = 0
1909 %    \end{macrocode}
1910 %    To allow checking whether some macro is used within the \mc{}
1911 %    environment the counter |\col@number| gets a default of |1|
1912 %    outside the the environment.
1913 % \changes{v1.3d}{1991/10/23}{\cs{col@number} set to one}
1914 %    \begin{macrocode}
1915 \col@number = 1
1916 \multicoltolerance = 9999
1917 \multicolpretolerance = -1
1918 \premulticols = 50pt
1919 \postmulticols= 20pt
1920 \multicolsep = 12pt plus 4pt minus 3pt
1921 \multicolbaselineskip=0pt
1922 %    \end{macrocode}
1923 % \end{macro}
1925 % \end{multicols}
1927 % \begin{multicols}{2}[\subsection{The output routines}]
1929 % We first start with some simple macros. When typesetting the page we
1930 % save the columns either in the box registers 0, 2, 4,\ldots\
1931 % (locally) or 1, 3, 5,\ldots\ (globally). This is \PlainTeX{} policy
1932 % to avoid an overflow of the save stack.
1934 % \begin{macro}{\process@cols}
1935 %    Therefore we define a |\process@cols| macro to help us in
1936 %    using these registers in the output routines below. It has two
1937 %    arguments: the first one is a number; the second one is the
1938 %    processing information.  It loops starting with |\count@=#1|
1939 %    (|\count@| is a scratch register defined in \PlainTeX),
1940 %    processes argument |#2|, adds two to |\count@|,
1941 %    processes argument |#2| again, etc.\ until |\count@| is
1942 %    higher than |\doublecol@number|.  It might be easier to
1943 %    understand it through an example, so we define it now and
1944 %    explain its usage afterwards.
1945 %    \begin{macrocode}
1946 \def\process@cols#1#2{\count@#1\relax
1947      \loop
1948 %<*debug>
1949      \typeout{Looking at box \the\count@}
1950 %</debug>
1951       #2%
1952      \advance\count@\tw@
1953      \ifnum\count@<\doublecol@number
1954    \repeat}
1955 %    \end{macrocode}
1956 % \end{macro}
1959 % \begin{macro}{\page@sofar}
1960 %    We now define |\page@sofar| to give an example of the
1961 %    |\process@cols| macro. |\page@sofar| should output everything
1962 %    prepared by the balancing routine |\balance@columns|.
1963 %    \begin{macrocode}
1964 \def\page@sofar{%
1965 %    \end{macrocode}
1966 %    |\balance@columns| prepares its output in the even numbered
1967 %    scratch box registers.
1968 %    Now we output the columns gathered assuming that they are saved
1969 %    in the box registers 2 (left column), 4 (second column), \ldots\
1970 %    However, the last column (i.e.\ the right-most) should be saved in
1971 %    box register 0.\footnote{You will see the reason for this numbering
1972 %                             when we look at the output routines
1973 %                             \cs{multi@column@out} and
1974 %                             \cs{balance@columns@out}.}
1975 %    First we ensure that the columns have equal width. We use
1976 %    |\process@cols| for this purpose, starting with
1977 %    $|\count@|=|\mult@rightbox|$. Therefore |\count@| loops through
1978 %    |\mult@rightbox|, $|\mult@rightbox| + 2$,\ldots
1979 %                                  (to |\doublecol@number|).
1980 % \changes{v1.5a}{1992/11/04}{New box mechanism}
1981 %    \begin{macrocode}
1982    \process@cols\mult@rightbox
1983 %    \end{macrocode}
1984 %    We have to check if the box in question is void, because the
1985 %    operation |\wd|\meta{number} on a void box will \emph{not} change
1986 %    its dimension (sigh).
1987 % \changes{v1.5h}{1994/08/26}{Check for void boxes}
1988 % \changes{v1.5i}{1994/10/02}{But don't remove original code.}
1989 %    \begin{macrocode}
1990        {\ifvoid\count@
1991           \setbox\count@\hbox to\hsize{}%
1992         \else
1993           \wd\count@\hsize
1994         \fi}%
1995 %    \end{macrocode}
1996 %    Now we give some tracing information.
1997 % \changes{v1.4l}{1992/08/17}{use \cs{multicol@leftmargin} instead of
1998 %                           \cs{@totalleftmargin}}
1999 % \changes{v1.6b}{2003/03/15}{Different info display}
2000 %    \begin{macrocode}
2001    \count@\col@number \advance\count@\m@ne
2002    \mult@info\z@
2003     {Column spec: \the\full@width\space = indent
2004                   + columns + sep =\MessageBreak
2005         \the\multicol@leftmargin\space
2006         + \the\col@number\space
2007         x \the\hsize\space
2008         + \the\count@\space
2009         x \the\columnsep
2010      }%
2011 %    \end{macrocode}
2012 %    At this point we should always be in vertical mode.
2013 %    \begin{macrocode}
2014 \ifvmode\else\errmessage{Multicol Error}\fi
2015 %    \end{macrocode}
2016 %    Now we put all columns together in an |\hbox| of width
2017 %    |\full@width| (shifting it by |\multicol@leftmargin| to the right
2018 %    so that it will be placed correctly if we are within a list
2019 %    environment)
2020 %    and separating the columns with a rule if desired.
2021 % \changes{v1.5a}{1992/11/04}{New box mechanism}
2022 % \changes{v1.5z}{2000/07/10}{Ensure that column rule has always
2023 %                             \cs{normalcolor}}
2024 % \changes{v1.6f}{2006/09/19}{Make the color of the rule a hook}
2025 % \changes{v1.4l}{1992/08/17}{use \cs{multicol@leftmargin} instead of
2026 %                           \cs{@totalleftmargin}}
2028 %    The box containing the columns has  a large height and thus will
2029 %    always result in using |\lineskip| if the normal |\baselineskip|
2030 %    calculations are used. We therefore better cancel that process.
2031 % \changes{v1.5z1}{2003/02/17}{Suppress interline glue at this point}
2032 %    \begin{macrocode}
2033    \nointerlineskip
2034 %    \end{macrocode}
2035 %    As mentioned earlier we want to have the reference point of the
2036 %    box we put on the page being at the baseline of the last line of
2037 %    the columns but we also want to ensure that the box has no depth
2038 %    so that any following skip is automatically starting from that
2039 %    baseline.
2040 %    We achieve this by recording the depths of all columns and then
2041 %    finally backing up by the maximum. (perhaps a simpler method
2042 %    would be to assemble the box in a register and set the depth of
2043 %    that box to zero (not checked).
2045 %    We need a global scratch register for this; using standard \TeX{}
2046 %    conventions we choose |\dimen2| and initialize it with the depth
2047 %    of the character ``p'' since that is one of the depths that
2048 %    compete for the maximum.
2049 % \changes{v1.6a}{2003/03/15}{Preparing for adjusting \cs{prevdepth}}
2050 %    \begin{macrocode}
2051    \setbox\z@\hbox{p}\global\dimen\tw@\dp\z@
2052    \moveright\multicol@leftmargin
2053     \hbox to\full@width{%
2054 %    \end{macrocode}
2055 %    If the document is written in a language that is typeset right-to-left
2056 %    then, of course, the multicol columns should be also typeset
2057 %    right-to-left. To support this we call |\mc@align@columns| which
2058 %    with execute different code depending on the typesetting direction.
2059 % \changes{v1.7b}{2011/12/18}{RL language support fixed}
2060 %    \begin{macrocode}
2061        \mc@align@columns
2062 %    \end{macrocode}
2063 %    The depths of the columns depend on their last lines. To ensure
2064 %    that we will always get a similar look as far as the rules are
2065 %    concerned we force the depth to be at least the depth of a
2066 %    letter~`p' (which is what we set |\dimen2| to above).
2067 %    \begin{macrocode}
2068        \rlap{\phantom p}%
2069     }%
2070 %    \end{macrocode}
2071 %    The processed material might consist of a last line with a
2072 %    descender in which case the |\prevdepth| will be
2073 %    non-zero. However, this material is getting reformatted now so
2074 %    that this value is likely to be wrong. We therefore normalize the
2075 %    situation by pretending that the depth is zero. However, if |\page@sofar|
2076 %   is being called inside the OR then setting |\prevdepth| here has
2077 %   no longlasting effect, we therefore have to repeat this once we
2078 %   return to the main vertical list. Here we set it only for those
2079 %   cases where the command is used within a list and then followed by
2080 %   something else.
2081 % \changes{v1.8g}{2014/08/24}{Resetting \cs{prevdepth} in the right place}
2082 %    \begin{macrocode}
2083    \prevdepth\z@
2084 %    \end{macrocode}
2085 %    Now after typesetting the box we back up to its baseline by using
2086 %    the value stored in |\dimen2| (which will hold the largest depth
2087 %    found on any column).
2088 % \changes{v1.8g}{2003/03/15}{Now adjusting \cs{prevdepth}}
2089 %    \begin{macrocode}
2090  \kern-\dimen\tw@
2091 %    \end{macrocode}
2092 %    However, in case one of the columns was unusually deep \TeX{} may
2093 %    have tried some corrective actions in which case backing up by
2094 %    the saved value will not bring us back to the baseline. A good
2095 %    indication for this is a depth of |\maxdepth| though it is not an
2096 %    absolute proof. If the option \texttt{grid} is used
2097 %    |\mc@gridwarn| will expand to this, otherwise to |\maxdimen| in
2098 %    which case this warning will not show up.
2099 % \changes{v1.8g}{2014/08/24}{Warn if value is exceeded not when equal}
2100 %    \begin{macrocode}
2101  \ifdim\dimen\tw@ > \mc@gridwarn
2102    \PackageWarning{multicol}%
2103      {Very deep columns!\MessageBreak
2104       Grid alignment might be broken}%
2105  \fi
2107 %    \end{macrocode}
2108 % \end{macro}
2110 % \begin{macro}{\columnseprulecolor}
2111 % \changes{v1.6f}{2006/09/19}{Make the color of the rule a hook}
2112 %    By default the vertical rule between columns will be in |\normalcolor|.
2113 %    \begin{macrocode}
2114 \def\columnseprulecolor{\normalcolor}
2115 %    \end{macrocode}
2116 % \end{macro}
2118 % \begin{macro}{\reinsert@footnotes}
2119 %    Before we tackle the bigger output routines we define just one
2120 %    more macro which will help us to find our way through the
2121 %    mysteries later. |\reinsert@footnotes| will do what its name
2122 %    indicates: it reinserts the footnotes present in
2123 %    |\footinbox| so that they will be reprocessed by \TeX{}'s
2124 %    {\it page\_builder}.
2126 %    Instead of actually reinserting the footnotes we insert an empty
2127 %    footnote. This will trigger insertion mechanism as well and since
2128 %    the old footnotes are still in their box and we are on a fresh page
2129 %    |\skip| |footins| should be correctly taken into account.
2130 % \changes{v1.3c}{1990/03/03}{\cs{unbox}ing avoided.}
2131 %    \begin{macrocode}
2132 \def\reinsert@footnotes{\ifvoid\footins\else
2133          \insert\footins{}\fi}
2134 %    \end{macrocode}
2135 % \end{macro}
2138 % \begin{macro}{\vfilmaxdepth}
2139 %    This curious definition is used as the space at the bottom of a
2140 %   column if we implement |\raggedcolumns|. Normlly one only appends
2141 %   |\vfill| in that case but this is actually wrong for columns that
2142 %   are more or less full: by adding a glue at the bottom such a
2143 %   column doesn't have any depth any more but without it the material
2144 %   would be allowed a depth of |\maxdepth|. So we allow shrinking by
2145 %   that amount. This only makes a difference if the box would
2146 %   otherwise become overfull and shrinking never exceeds the
2147 %   specified value, so we should be fine. 
2148 % \changes{v1.8h}{2014/09/12}{Macro added  (pr/4395)}
2149 % \changes{v1.8j}{2015/03/07}{Use only `0.0001fil' for stretching}
2150 %    \begin{macrocode}
2151 \def\vfilmaxdepth{\vskip \z@ \@plus .0001fil 
2152                            \@minus \maxdepth}
2153 %    \end{macrocode}
2154 % \end{macro}
2157 % \begin{macro}{\multi@column@out}
2158 %    Now we can't postpone the difficulties any longer.  The
2159 %    |\multi@column@out| routine will be called in two situations.
2160 %    Either the page is full (i.e., we have collected enough material
2161 %    to generate all the required columns) or a float or marginpar or
2162 %    a |\clearpage| is
2163 %    sensed.  In the latter case the |\outputpenalty| is less
2164 %    than $-10000$, otherwise the penalty which triggered the output
2165 %    routine is higher.  Therefore it's easy to distinguish both
2166 %    cases: we simply test this register.
2167 % \changes{v1.5c}{1993/04/18}{Support \cs{clearpage}}
2168 %    \begin{macrocode}
2169 \def\multi@column@out{%
2170    \ifnum\outputpenalty <-\@M
2171 %    \end{macrocode}
2172 %    If this was a |\clearpage|, a float or a marginpar we call
2173 %    |\speci@ls|
2174 %    \begin{macrocode}
2175     \speci@ls \else
2176 %    \end{macrocode}
2177 %    otherwise we construct the final page.
2178 % \changes{v1.5u}{1999/05/25}{Support \cs{columnbreak}}
2179 % \changes{v1.5v}{1999/07/18}{Added debug statements for
2180 %                             column break support}
2181 %    For the next block of code see comments in section~\ref{sec:colbreak}.
2182 %    \begin{macrocode}
2183     \ifvoid\colbreak@box\else
2184       \mult@info\@ne{Re-adding forced
2185                 break(s) for splitting}%
2186       \setbox\@cclv\vbox{%
2187        \unvbox\colbreak@box
2188        \penalty-\@Mv
2189        \unvbox\@cclv}%
2190     \fi
2191 %    \end{macrocode}
2192 %    Let us now consider the
2193 %    normal case. We have to |\vsplit| the columns from the
2194 %    accumulated material in box 255.  Therefore we first assign
2195 %    appropriate values to |\splittopskip| and |\splitmaxdepth|.
2196 %    \begin{macrocode}
2197    \splittopskip\topskip
2198    \splitmaxdepth\maxdepth
2199 %    \end{macrocode}
2200 %    We also need to restrict |\boxmaxdepth| so that re-boxing is not
2201 %    generating boxes with arbitrary depth.   
2202 % \changes{v1.8j}{2015/03/07}{Set \cs{boxmaxdepth}}
2203 %    \begin{macrocode}
2204    \boxmaxdepth\maxdepth
2205 %    \end{macrocode}
2206 %    Then we calculate the current column height (in |\dimen@|).
2207 %    Note that the height of |\partial@page| is already
2208 %    subtracted from |\@colroom| so we can use its value as a
2209 %    starter.
2210 %    \begin{macrocode}
2211    \dimen@\@colroom
2212 %    \end{macrocode}
2213 %    But we must also subtract the space occupied by footnotes on the
2214 %    current page. Note that we first have to reset the skip register
2215 %    to its normal value.
2216 %    Again, the actual action is carried out in a utility macro, so that
2217 %    other applications can modify it.
2218 % \changes{v1.5?}{1994/?/?}{Use \cs{leave@mult@footins}}
2219 %    \begin{macrocode}
2220    \divide\skip\footins\col@number
2221    \ifvoid\footins \else
2222       \leave@mult@footins
2223    \fi
2224 %    \end{macrocode}
2225 %    And there is one more adjustment that we have to make: if the
2226 %    user has issue a |\enlargethispage| command then the height the
2227 %    |\@kludgeins| box will be the negation of the size by which the
2228 %    page should be enlarged. If the star form of this command has
2229 %    been used then we also need to shrink the resulting column. As we
2230 %    don't know whether or not shrinking is already generally
2231 %    requested with save the current value of |\ifshr@king| and
2232 %    restore it afterwards.
2233 % \changes{v1.8a}{2011/12/20}{Support for \cs{enlargethispage}}
2234 %    \begin{macrocode}
2235    \let\ifshr@kingsaved\ifshr@king
2236    \ifvbox \@kludgeins
2237      \advance \dimen@ -\ht\@kludgeins
2238 %    \end{macrocode}
2239 %    The star form of  |\enlargethispage| makes the width of the box
2240 %    greater than zero (sneaky isn't it?).
2241 %    \begin{macrocode}
2242      \ifdim \wd\@kludgeins>\z@
2243         \shr@nkingtrue
2244      \fi
2245    \fi
2246 %    \end{macrocode}
2247 %    Now we are able to |\vsplit| off all but the last column.
2248 %    Recall that these columns should be saved in the box registers 2,
2249 %    4,\ldots\ (plus offset).
2250 % \changes{v1.5a}{1992/11/04}{New box mechanism}
2251 %    \begin{macrocode}
2252    \process@cols\mult@gfirstbox{%
2253         \setbox\count@
2254             \vsplit\@cclv to\dimen@
2255 %    \end{macrocode}
2256 %    After splitting we update the kept marks.
2257 %    \begin{macrocode}
2258             \set@keptmarks
2259 %    \end{macrocode}
2260 %    If |\raggedcolumns| is in force we add a |vfill| at the bottom by
2261 %    unboxing the split box.
2262 %    But we need to unbox anyway to ensure that at the end of the box
2263 %    we do not have unwanted space. This can sneak in in certain
2264 %    situations, for example, if two lists follow each other and we
2265 %    break between them. While sich space is usually zero it still has
2266 %    an effect because it hides depth of the last line in the column
2267 %    and that will result in incorrect placement.
2268 % \changes{v1.3c}{1990/03/03}{\cs{unbox}ing avoided.}
2269 % \changes{v1.8b}{2013/08/28}{And 20odd years later conclude that
2270 %         this was wrong and unboxing is always needed.}
2271 % \changes{v1.8b}{2013/08/28}{Remove discardable items at the
2272 %                             end of split boxes}
2273 % \changes{v1.8h}{2014/09/12}{Use \cs{vfilmaxdepth}}
2274 % \changes{v1.8k}{2015/03/22}{\cs{remove@discardable@items} removed}
2275 %    \begin{macrocode}
2276             \setbox\count@
2277                  \vbox to\dimen@
2278                   {\unvbox\count@
2279                    \ifshr@nking\vfilmaxdepth\fi}%
2280            }%
2281 %    \end{macrocode}
2282 %    Then the last column follows.
2283 % \changes{v1.5a}{1992/11/04}{New box mechanism}
2284 % \changes{v1.8b}{2013/08/28}{Remove discardable items at the
2285 %                             end of split boxes}
2286 % \changes{v1.8h}{2014/09/12}{Use \cs{vfilmaxdepth}}
2287 % \changes{v1.8k}{2015/03/22}{\cs{remove@discardable@items} removed}
2288 %    \begin{macrocode}
2289    \setbox\mult@rightbox
2290        \vsplit\@cclv to\dimen@
2291    \set@keptmarks
2292    \setbox\mult@rightbox\vbox to\dimen@
2293           {\unvbox\mult@rightbox
2294            \ifshr@nking\vfilmaxdepth\fi}%
2295 %    \end{macrocode}
2296 %    Now that we are done with the boxes, we restored the current
2297 %    setting for shrinking in case it got changed:
2298 %    \begin{macrocode}
2299    \let\ifshr@king\ifshr@kingsaved
2300 %    \end{macrocode}
2301 %    Having done this we hope that box 255 is emptied. If not, we
2302 %    reinsert its contents.
2303 % \changes{v1.8a}{2011/12/20}{Only re-add output penalty if it was
2304 %    explicitly set}
2305 %    \begin{macrocode}
2306    \ifvoid\@cclv \else
2307        \unvbox\@cclv
2308        \ifnum\outputpenalty=\@M
2309        \else
2310           \penalty\outputpenalty
2311        \fi
2312 %    \end{macrocode}
2313 %    In this case a footnote that happens to fall into the leftover
2314 %    bit will be typeset on the wrong page. Therefore we warn the user
2315 %    if the current page contains footnotes. The older versions of
2316 %    \mc{} produced this warning regardless of whether or not
2317 %    footnotes were present, resulting in many unnecessary warnings.
2318 % \changes{v1.3c}{1991/02/17}{Check if footnotes are actually present
2319 %                           before issuing a warning.}
2320 %    \begin{macrocode}
2321        \ifvoid\footins\else
2322          \PackageWarning{multicol}%
2323           {I moved some lines to
2324            the next page.\MessageBreak
2325            Footnotes on page
2326            \thepage\space might be wrong}%
2327        \fi
2328 %    \end{macrocode}
2329 %    If the `{\sf tracingmulticols}' counter is 4 or higher we also
2330 %    add a rule.
2331 %    \begin{macrocode}
2332        \ifnum \c@tracingmulticols>\thr@@
2333                     \hrule\allowbreak \fi
2334    \fi
2335 %    \end{macrocode}
2336 %    To get a correct marks for the current page we have to (locally)
2337 %    redefine |\firstmark| and |\botmark|.
2338 %    If |\kept@firstmark| is non-empty then |\kept@botmark| must be
2339 %    non-empty too so we can use their values. Otherwise we use the
2340 %    value of |\kept@topmark| which was first initialized when we
2341 %    gathered the |\partical@page| and later on was updated to the
2342 %    |\botmark| for the preceding page.
2344 % \changes{v1.4a}{1992/02/14}{\cs{botmark} set to \cs{splitbotmark}}
2345 %    \begin{macrocode}
2346    \ifx\@empty\kept@firstmark
2347       \let\firstmark\kept@topmark
2348       \let\botmark\kept@topmark
2349    \else
2350       \let\firstmark\kept@firstmark
2351       \let\botmark\kept@botmark
2352    \fi
2353 %    \end{macrocode}
2354 %    We also initalize |\topmark| with |\kept@topmark|. This will make
2355 %    this mark okay for all middle pages of the \mc{} environment.
2356 % \changes{v1.5d}{1993/09/15}{reinit \cs{topmark}}
2357 %    \begin{macrocode}
2358    \let\topmark\kept@topmark
2359 %<*marktrace>
2360    \mult@info\tw@
2361         {Use kept top mark:\MessageBreak
2362           \meaning\kept@topmark
2363          \MessageBreak
2364          Use kept first mark:\MessageBreak
2365           \meaning\kept@firstmark
2366         \MessageBreak
2367          Use kept bot mark:\MessageBreak
2368           \meaning\kept@botmark
2369         \MessageBreak
2370          Produce first mark:\MessageBreak
2371           \meaning\firstmark
2372         \MessageBreak
2373         Produce bot mark:\MessageBreak
2374           \meaning\botmark
2375          \@gobbletwo}%
2376 %</marktrace>
2377 %    \end{macrocode}
2378 %    With a little more effort we could have done better. If we had,
2379 %    for example, recorded the shrinkage of the material in
2380 %    |\partial@page| it would be now possible to try higher
2381 %    values for |\dimen@| (i.e.\ the column height) to overcome
2382 %    the problem with the nonempty box 255. But this would make the
2383 %    code even more complex so I skipped it in the current
2384 %    implementation.
2386 %    Now we use \LaTeX{}'s standard output
2387 %    mechanism.\footnote{This will produce a lot of overhead since both
2388 %                       output routines are held in memory. The correct
2389 %                       solution would be to redesign the whole output
2390 %                       routine used in \LaTeX.}
2391 %    Admittedly this is a funny way to do it.
2393 %    \begin{macrocode}
2394    \setbox\@cclv\vbox{\unvbox\partial@page
2395                       \page@sofar}%
2396 %    \end{macrocode}
2397 %    The macro |\@makecol| adds all floats assigned for the current
2398 %    page to this page.  |\@outputpage| ships out the resulting box.
2399 %    Note that it is just possible that such floats are present even
2400 %    if we do not allow any inside a \mc{} environment.
2401 %    \begin{macrocode}
2402    \@makecol\@outputpage
2403 %    \end{macrocode}
2404 %    After the page is shipped out we have to prepare the kept marks
2405 %    for the following page. |\kept@firstmark| and |\kept@botmark|
2406 %    reinitialized by setting them to |\@empty|.  The value of
2407 %    |\botmark| is then assigned to |\kept@topmark|.
2408 % \changes{v1.4g}{1992/06/03}{Only change \cs{kept@topmark} if
2409 %                            \cs{kept@botmark} non-empty}
2410 % \changes{v1.4i}{1992/06/18}{Set \cs{kept@topmark} to \cs{botmark}}
2411 %    \begin{macrocode}
2412      \global\let\kept@topmark\botmark
2413      \global\let\kept@firstmark\@empty
2414      \global\let\kept@botmark\@empty
2415 %<*marktrace>
2416      \mult@info\tw@
2417         {(Re)Init top mark:\MessageBreak
2418          \meaning\kept@topmark
2419          \@gobbletwo}%
2420 %</marktrace>
2421 %    \end{macrocode}
2422 %    Now we reset |\@colroom| to |\@colht| which is \LaTeX's
2423 %    saved value of |\textheight|.
2424 %    We also have to reset the recorded position of the last
2425 %   |\marginpar| as well as the recorded size of intext floats 
2426 %    as we are now on a new page.
2427 % \changes{v1.8d}{2014/04/23}{Reset \cs{@mparbottom} after page finishes}
2428 % \changes{v1.8n}{2015/08/19}{Reset \cs{@textfloatsheight} after page finishes}
2429 %    \begin{macrocode}
2430    \global\@colroom\@colht
2431    \global \@mparbottom \z@
2432    \global \@textfloatsheight \z@
2433 %    \end{macrocode}
2434 %    Then we process deferred floats waiting for their chance to be
2435 %    placed on the next page.
2436 %    \begin{macrocode}
2437    \process@deferreds
2438    \@whilesw\if@fcolmade\fi{\@outputpage
2439       \global\@colroom\@colht
2440       \process@deferreds}%
2441 %    \end{macrocode}
2442 %    If the user is interested in statistics we inform him about the
2443 %    amount of space reserved for floats.
2444 %    \begin{macrocode}
2445    \mult@info\@ne
2446      {Colroom:\MessageBreak
2447       \the\@colht\space
2448               after float space removed
2449               = \the\@colroom \@gobble}%
2450 %    \end{macrocode}
2451 %    Having done all this we must prepare to tackle the next page.
2452 %    Therefore we assign a new value to |\vsize|.  New, because
2453 %    |\partial@page| is now empty and |\@colroom| might be
2454 %    reduced by the space reserved for floats.
2455 % \changes{v1.4p}{1992/11/26}{Use different \cs{vsize} setting}
2456 %    \begin{macrocode}
2457     \set@mult@vsize \global
2458 %    \end{macrocode}
2459 %    The |\footins| skip register will be adjusted when the output
2460 %    group is closed.
2461 % \changes{v1.3c}{1991/03/03}{Unnecessary code removed}
2462 %    \begin{macrocode}
2463   \fi}
2464 %    \end{macrocode}
2465 % \end{macro}
2469 % \begin{macro}{\leave@mult@footins}
2470 %    This macro is used to subtract the amount of space
2471 %    occupied by footnotes for the current space from the
2472 %    space available for the current column. The space current column
2473 %    is stored in |\dimen@|. See above for the description of the default
2474 %    action.
2475 % \changes{v1.5?}{1994/?/?}{Macro added}
2476 %    \begin{macrocode}
2477 \def\leave@mult@footins{%
2478    \advance\dimen@-\skip\footins
2479    \advance\dimen@-\ht\footins
2481 %    \end{macrocode}
2482 % \end{macro}
2486 % \begin{macro}{\speci@ls}
2487 %    We left out two macros: |\process@deferreds| and
2488 %    |\speci@ls|.
2489 % \changes{v1.5c}{1993/04/18}{Support \cs{clearpage}}
2490 %    \begin{macrocode}
2491 \def\speci@ls{%
2492  \ifnum\outputpenalty <-\@Mi
2493 %    \end{macrocode}
2494 %    If the document ends in the middle of a multicols environment, e.g.,
2495 %    if the user forgot the |\end{multicols}|, \TeX{} adds a very
2496 %    negative penalty to the end of the galley which is intended to signal
2497 %    the output routine that it is time to prepare for shipping out
2498 %    everything remaining. Since inside multicols the output routine of
2499 %    \LaTeX{} is disabled sometimes we better check for this case: if we
2500 %    find a very negative penalty we produce an error message and run
2501 %    the default output routine for this case.
2502 % \changes{v1.5s}{1998/09/10}{check for \cs{stop} penalty pr/2873}
2503 %    \begin{macrocode}
2504   \ifnum \outputpenalty<-\@MM
2505    \PackageError{multicol}{Document end
2506            inside multicols environment}\@ehd
2507    \@specialoutput
2508   \else
2509 %    \end{macrocode}
2510 % \changes{v1.5u}{1999/05/25}{Support \cs{columnbreak}}
2511 % \changes{v1.5v}{1999/07/18}{Added debug statements for
2512 %                             column break support}
2513 %    For the next block of code see comments in section~\ref{sec:colbreak}.
2514 %    \begin{macrocode}
2515      \ifnum\outputpenalty = -\@Mv
2516          \mult@info\@ne{Forced column
2517                         break seen}%
2518          \global\advance\vsize-\pagetotal
2519          \global\setbox\colbreak@box
2520            \vbox{%
2521               \ifvoid\colbreak@box
2522               \else
2523                 \unvbox\colbreak@box
2524                 \penalty-\@Mv
2525               \fi
2526 %    \end{macrocode}
2527 %    As this is the place of a forced break we now remove vertical
2528 %   white space just in front of it (or some of it at least) as it is
2529 %   quite likely that the break is not exactly in the right place,
2530 %   e.g., after a display environment (if LaTeX would break here by
2531 %   its own it would break before the space following the display).
2533 %   Thus we rebox box 255 once (using |\maxdepth| and calling
2534 %   |\remove@discardable@items| inside). The depth of 255 will then
2535 %   give us the depth the box would have had if it would have been a
2536 %   natural break. We then unbox 255 to get it into the
2537 %   |\colbreak@box| and then back up by this depth. This will position
2538 %   the bottom of the box at its natural baseline which is useful for
2539 %   balancing later on.
2540 % \changes{v1.8k}{2015/03/21}{Remove discarable items just before a
2541 %   forced break}
2542 %    \begin{macrocode}
2543               \boxmaxdepth\maxdepth
2544               \setbox\@cclv\vbox{%
2545                  \unvbox\@cclv
2546                  \remove@discardable@items}%
2547               \dimen@\dp\@cclv
2548               \unvbox\@cclv
2549               \kern-\dimen@
2550          }%
2551          \reinsert@footnotes
2552      \else
2553 %    \end{macrocode}
2554 %    If we encounter a float or a marginpar in the current
2555 %    implementation we simply warn the user that this is not allowed.
2556 %    Then we reinsert the page and its footnotes.
2557 %    \begin{macrocode}
2558         \PackageWarningNoLine{multicol}%
2559            {Floats and marginpars not
2560             allowed inside `multicols'
2561             environment!}%
2562         \unvbox\@cclv\reinsert@footnotes
2563 %    \end{macrocode}
2564 %    Additionally we empty the |\@currlist| to avoid later error
2565 %    messages when the \LaTeX{} output routine is again in force.
2566 %    But first we have to place the boxes back onto the
2567 %    |\@freelist|. (|\@elt|s default is |\relax| so
2568 %    this is possible with |\xdef|.)
2569 % \changes{v1.2a}{1990/02/05}{Float boxes freed.}
2570 %    \begin{macrocode}
2571        \xdef\@freelist{\@freelist\@currlist}%
2572        \gdef\@currlist{}%
2573      \fi
2574   \fi
2575 %    \end{macrocode}
2576 %    If the penalty is $-10001$ it will come from a |\clearpage| and
2577 %    we will execute |\@doclearpage| to get rid of any deferred
2578 %    floats.
2579 %    \begin{macrocode}
2580  \else \@doclearpage \fi
2582 %    \end{macrocode}
2583 % \end{macro}
2585 % \begin{macro}{\process@deferreds}
2586 %    |\process@deferreds| is a simplified version of \LaTeX{}'s
2587 %    |\@startpage|.  We first call the macro
2588 %    |\@floatplacement| to save the current user parameters in
2589 %    internal registers.  Then we start a new group and save the
2590 %    |\@deferlist| temporarily in the macro |\@tempb|.
2591 %    \begin{macrocode}
2592 \def\process@deferreds{%
2593    \@floatplacement
2594    \@tryfcolumn\@deferlist
2595    \if@fcolmade\else
2596      \begingroup
2597     \let\@tempb\@deferlist
2598 %    \end{macrocode}
2599 %    Our next action is to (globally) empty |\@deferlist| and
2600 %    assign a new meaning to |\@elt|.  Here |\@scolelt| is a
2601 %    macro that looks at the boxes in a list to decide whether they
2602 %    should be placed on the next page (i.e.\ on |\@toplist| or
2603 %    |\@botlist|) or should wait for further processing.
2604 %    \begin{macrocode}
2605       \gdef\@deferlist{}%
2606       \let\@elt\@scolelt
2607 %    \end{macrocode}
2608 %    Now we call |\@tempb| which has the form
2609 %    \begin{center}
2610 %      |\@elt|\meta{box register}|\@elt|^^A
2611 %                        \meta{box register}\ldots{}
2612 %    \end{center}
2613 %    So |\@elt| (i.e.\ |\@scolelt|) will distribute the
2614 %    boxes to the three lists.
2615 %    \begin{macrocode}
2616         \@tempb \endgroup
2617    \fi}
2618 %    \end{macrocode}
2619 % \end{macro}
2623 % \begin{macro}{ifshr@nking}
2624 % \begin{macro}{\raggedcolumns}
2625 % \begin{macro}{\flushcolumns}
2626 % \changes{v1.1a}{1989/09/20}{\cs{flushedcolumns} renamed to \cs{flushcolumns}.}
2627 %    The |\raggedcolumns| and |\flushcolumns|
2628 %    declarations are defined with the help of a new |\if...|
2629 %    macro.
2630 %    \begin{macrocode}
2631 \newif\ifshr@nking
2632 %    \end{macrocode}
2633 %    The actual definitions are simple: we just switch to {\sf true}
2634 %    or {\sf false} depending on the desired action. To avoid extra
2635 %    spaces in the output we enclose these changes in
2636 %    |\@bsphack|\ldots{}\allowbreak|\@esphack|.
2637 %    \begin{macrocode}
2638 \def\raggedcolumns{%
2639    \@bsphack\shr@nkingtrue\@esphack}
2640 \def\flushcolumns{%
2641    \@bsphack\shr@nkingfalse\@esphack}
2642 %    \end{macrocode}
2643 % \end{macro}
2644 % \end{macro}
2645 % \end{macro}
2648 % \begin{macro}{\balance@columns@out}
2649 %    Now for the last part of the show: the column balancing output
2650 %    routine.  Since this code is called with an explicit penalty
2651 %    (|\eject|) there is no need to check for something special (eg
2652 %    floats).  We start by balancing the material gathered.
2653 %    \begin{macrocode}
2654 \def\balance@columns@out{%
2655 %    \end{macrocode}
2656 %    For this we need to put the contents of box 255 into |\mult@box|.
2657 % \changes{v1.5u}{1999/05/25}{Support \cs{columnbreak}}
2658 % \changes{v1.5v}{1999/07/18}{Added debug statements for column break
2659 %   support} For the next block of code see also comments in
2660 %   section~\ref{sec:colbreak}.  All forced breaks except the last are
2661 %   inside |\colbreak@box| so all we have to do is to concatenate this
2662 %   box with box |\@cclv| and put a penalty inbetween. Here we test if
2663 %   |\colbreak@box| is void so that the message is only generated if
2664 %   we really add forced breaks and the penalty.
2665 % \changes{v1.8k}{2015/03/21}{Use \cs{@Mv} and not \cs{break} in case
2666 %   this forced break is not used on this page}
2667 %    \begin{macrocode}
2668    \setbox\mult@box\vbox{%
2669        \ifvoid\colbreak@box\else
2670          \unvbox\colbreak@box
2671          \penalty-\@Mv
2672          \mult@info\@ne{Re-adding
2673            forced break(s) in balancing}%
2674        \fi
2675        \unvbox\@cclv
2676 %    \end{macrocode}
2677 %    The last column again is a forced break, so here we discard white
2678 %   space as well as that is normally unwanted.
2679 % \changes{v1.8k}{2015/03/21}{Add \cs{remove@discardable@items} at the
2680 %   end of the last column when balancing.}
2681 %    \begin{macrocode}
2682        \remove@discardable@items
2683    }%
2684    \balance@columns
2685 %    \end{macrocode}
2686 %    If during balancing the columns got too long the flag
2687 %    |\iftoo@bad| is set to true.
2688 % \changes{v1.8a}{2011/12/20}{Balancing concept improved}
2689 %    \begin{macrocode}
2690    \iftoo@bad
2691      \mult@info\@ne
2692         {Balancing failed ...
2693          cut a normal page}%
2694 %    \end{macrocode}
2695 %    In that case we put the material back in box 255 so that we can
2696 %    cut a normal page. The curious set of
2697 %    |\vskip|s we add is necessary to  cancel out the |\splittopskip|
2698 %    that got added for balancing.
2699 %    \begin{macrocode}
2700      \setbox\@cclv\vbox
2701          {\vskip\topskip
2702           \vskip-\splittopskip
2703           \unvbox\mult@box}%
2704 %    \end{macrocode}
2705 %    We then call the standard multicol output routine which will
2706 %    produce a normal page for us (remember we are still within the
2707 %    OR so some part of the code in |\multi@column@out| is actually not
2708 %    doing anything---perhaps this should be cleaned up at some point).
2709 %    This also means that if there was an |\enlargethispage| present
2710 %    it will apply to this page as |\multi@column@out| will look at
2711 %    the status of |\@kludgeins|.
2712 %    \begin{macrocode}
2713      \multi@column@out
2714 %    \end{macrocode}
2715 %    Because balancing made the columns too long we are sure that there
2716 %    will be some material remaining which was put back onto the main
2717 %    vertical list by |\multi@column@out|. This will also put the
2718 %    explicit |\eject| penalty back so the current
2719 %    |\balance@columns@out| output routine will be called again (so we
2720 %    better do not add another penalty or else the OR will be called
2721 %    twice and we may get scrambled results).
2722 % \changes{v1.8k}{2015/03/21}{No additional penalty here}
2723 %    \begin{macrocode}
2724    \else
2725 %    \end{macrocode}
2726 %    If the balancing went ok, we are in the position
2727 %    to apply |\page@sofar|.  But first we have to set |\vsize| to a
2728 %    value suitable for one column output.
2729 %    \begin{macrocode}
2730      \global\vsize\@colroom
2731      \global\advance\vsize\ht\partial@page
2732 %    \end{macrocode}
2733 %    We also have to look at |\@kludgeins| and generate a new
2734 %    |\insert| in case there was one present due to an
2735 %    |\enlargethispage| command.
2736 % \changes{v1.8a}{2011/12/20}{Support for \cs{enlargethispage}}
2737 %    \begin{macrocode}
2738      \ifvbox\@kludgeins\insert\@kludgeins
2739                         {\unvbox\@kludgeins}\fi
2740 %    \end{macrocode}
2741 %    Then we |\unvbox| the |\partial@page| (which may be void if we
2742 %    are not processing the first page of this \mc{} environment.
2743 %    \begin{macrocode}
2744      \unvbox\partial@page
2745 %    \end{macrocode}
2746 %    Then we return the first and bottom mark and the gathered
2747 %    material to the main vertical list.
2748 %    \begin{macrocode}
2749      \return@nonemptymark{first}\kept@firstmark
2750      \return@nonemptymark{bot}\kept@botmark
2751      \page@sofar
2752 %    \end{macrocode}
2753 %    We need to add a penalty at this point which allows to break at
2754 %    this point since calling the output routine may have removed the
2755 %    only permissible break point thereby ``glueing'' any following
2756 %    skip to the balanced box. In case there are any weird settings
2757 %    for |\multicolsep| etc. this could produce funny results.
2758 %  \changes{v1.5c}{1993/04/18}{added penalty at output routine exit}
2759 %    \begin{macrocode}
2760      \penalty\z@
2761   \fi
2763 %    \end{macrocode}
2764 %    As we already know, reinserting of footnotes will be done in the
2765 %    macro |\endmulticols|.
2766 % \end{macro}
2769 %  \begin{macro}{\balance@columns}
2770 %    This macro now does the actual balancing.
2771 %    \begin{macrocode}
2772 \def\balance@columns{%
2773 %    \end{macrocode}
2774 %    We start by setting the kept marks by updating them with any
2775 %    marks from this box. This has to be done \emph{before} we add a
2776 %    penalty of $-10000$ to the top of the box, otherwise only an
2777 %    empty box will be considered.
2778 % \changes{v1.5h}{1994/08/26}{Get kept marks first}
2779 %    \begin{macrocode}
2780    \get@keptmarks\mult@box
2781 %    \end{macrocode}
2782 %    We then continue by resetting trying to remove any discardable
2783 %    stuff at the end of |\mult@box|. This is rather experimental.  We
2784 %    also add a forced break point at the very beginning, so that we
2785 %    can split the box to height zero later on, thereby adding a known
2786 %    |\splittopskip| glue at the beginning.
2787 % \changes{v1.8k}{2015/03/21}{\cs{remove@discardable@items} removed}
2788 %    \begin{macrocode}
2789    \setbox\mult@box\vbox{%
2790         \penalty-\@M
2791         \unvbox\mult@box
2792         }%
2793 %    \end{macrocode}
2794 %    Then follow values assignments to get the |\vsplit|ting right.
2795 %    We use the natural part of |\topskip| as the natural part for
2796 %    |\splittopskip| and allow for a bit of undershoot and overshoot
2797 %    by adding some stretch and shrink.
2798 % \changes{v1.5?}{1994/?/?}{Allow columns to come out a bit long or short}
2799 %    \begin{macrocode}
2800    \@tempdima\topskip
2801    \splittopskip\@tempdima
2802        \@plus\multicolundershoot
2803        \@minus\multicolovershoot
2804    \splitmaxdepth\maxdepth
2805 %    \end{macrocode}
2806 %   We also have to set |\boxmaxdepth| which normally allows to
2807 %   build boxes with arbitrary depth, but as we are building text
2808 %   columns we really want to restrict the depth. This is necessary as
2809 %   we sometimes rebox the boxes generated by |\vsplit| and then the
2810 %   restriction posed by |\splitmaxdepth|  gets lost.
2811 % \changes{v1.8h}{2014/09/12}{All column boxes should obey
2812 %   \cs{maxdepth}  (pr/4395)}
2813 %    \begin{macrocode}
2814    \boxmaxdepth\maxdepth
2815 %    \end{macrocode}
2816 %    The next step is a bit tricky: when \TeX{} assembles material in
2817 %    a box, the first line isn't preceded by interline glue, i.e.
2818 %    there is no parameter like |\boxtopskip| in \TeX{}. This means
2819 %    that the baseline of the first line in our box is at some
2820 %    unpredictable point depending on the height of the largest
2821 %    character in this line. But of course we want all columns to
2822 %    align properly at the baselines of their first lines. For this
2823 %    reason we have opened |\mult@box| with a |\penalty| {\sf -10000}.
2824 %    This will now allow us to split off from |\mult@box| a tiny bit
2825 %    (in fact nothing since the first possible break-point is the
2826 %    first item in the box). The result is that |\splittopskip| is
2827 %    inserted at the top of |\mult@box| which is exactly what we like
2828 %    to achieve.
2829 % \changes{v1.5?}{1994/?/?}{Do splitting to zero here}
2830 %    \begin{macrocode}
2831    \setbox\@tempboxa\vsplit\mult@box to\z@
2832 %    \end{macrocode}
2833 %    Next we try to find a suitable starting point for the calculation
2834 %    of the column height.  It should be less than the height finally
2835 %    chosen, but large enough to reach this final value in only a few
2836 %    iterations.  The formula which is now implemented will try to
2837 %    start with the nearest value which is a multiple of
2838 %    |\baselineskip|. The coding is slightly tricky in \TeX{} and
2839 %    there are perhaps better ways \ldots
2840 % \changes{v1.4d}{1992/03/04}{New algorithm for start height}
2841 %    \begin{macrocode}
2842    \@tempdima\ht\mult@box
2843    \advance\@tempdima\dp\mult@box
2844    \divide\@tempdima\col@number
2845 %    \end{macrocode}
2846 %    The code above sets |\@tempdima| to the length of a column if we
2847 %    simply divide the whole box into equal pieces. To get to the next
2848 %    lower multiple of |\baselineskip| we convert this dimen to a
2849 %    number (the number of scaled points) then divide this by
2850 %    |\baselineskip| (also in scaled points) and then multiply this
2851 %    result with |\baselineskip| assigning the result to |\dimen@|.
2852 %    This makes |\dimen@| $\leq$ to |\@tempdimena|.
2853 %    \begin{macrocode}
2854    \count@\@tempdima
2855    \divide\count@\baselineskip
2856    \dimen@\count@\baselineskip
2857 %    \end{macrocode}
2858 %    Next step is to correct our result by taking into account the
2859 %    difference between |\topskip| and |\baselineskip|. We start by
2860 %    adding |\topskip|; if this makes the result too large then we
2861 %    have to subtract one |\baselineskip|.
2862 %    \begin{macrocode}
2863    \advance\dimen@\topskip
2864    \ifdim \dimen@ >\@tempdima
2865      \advance\dimen@-\baselineskip
2866    \fi
2867 %    \end{macrocode}
2868 %    At the user's request we start with a higher value (or lower, but
2869 %    this usually only increases the number of tries).
2870 %    \begin{macrocode}
2871    \advance\dimen@\c@unbalance\baselineskip
2872 %    \end{macrocode}
2873 %    We type out statistics if we were asked to do so.
2874 % \changes{v1.4f}{1992/04/28}{\cs{on@line} added to tracing info}
2875 %    \begin{macrocode}
2876    \mult@info\@ne
2877       {Balance columns\on@line:
2878         \ifnum\c@unbalance=\z@\else
2879        (off balance=\number\c@unbalance)\fi
2880       \@gobbletwo}%
2881 %    \end{macrocode}
2882 %    But we don't allow nonsense values for a start.
2883 %    \begin{macrocode}
2884    \ifnum\dimen@<\topskip
2885      \mult@info\@ne
2886        {Start value
2887           \the\dimen@  \space ->
2888           \the\topskip \space (corrected)}%
2889      \dimen@\topskip
2890    \fi
2891 %    \end{macrocode}
2892 %    Now we try to find the final column height.  We start by setting
2893 %    |\vbadness| to infinity (i.e.\ $10000$) to suppress
2894 %    underfull box reports while we are trying to find an acceptable
2895 %    solution.  We do not need to do it in a group since at the end of
2896 %    the output routine everything will be restored. The setting of
2897 %    the final columns will nearly always produce underfull boxes with
2898 %    badness $10000$ so there is no point in warning the user about
2899 %    it.
2900 % \changes{v1.2a}{1990/02/05}{Group around main loop removed.}
2901 %    \begin{macrocode}
2902    \vbadness\@M
2903 %    \end{macrocode}
2904 %    We also allow for overfull boxes while we trying to split the
2905 %    columns. They can easily happen if we have objects with unusual depth. 
2906 % \changes{v1.8h}{2014/09/12}{Do not report overfull}
2907 %    \begin{macrocode}
2908    \vfuzz \maxdimen
2909 %    \end{macrocode}
2910 %    The variable |\last@try| will hold the dimension used in the
2911 %    previous trial splitting. We initialize it with a negative value.
2912 % \changes{v1.5?}{1994/?/?}{Initialize \cs{last@try}}
2913 %    \begin{macrocode}
2914    \last@try-\p@
2915    \loop
2916 %    \end{macrocode}
2917 %    In order not to clutter up \TeX{}'s valuable main memory with
2918 %    things that are no longer needed, we empty all globally used box
2919 %    registers. This is necessary if we return to this point after an
2920 %    unsuccessful trial.  We use |\process@cols| for this purpose,
2921 %    starting with |\mult@grightbox|.  Note the extra braces around
2922 %    this macro call.  They are needed since \PlainTeX{}'s
2923 %    |\loop|\ldots{}\allowbreak|\repeat| mechanism cannot be nested on
2924 %    the same level of grouping.
2925 % \changes{v1.5a}{1992/11/04}{New box mechanism}
2926 %    \begin{macrocode}
2927     {\process@cols\mult@grightbox
2928            {\global\setbox\count@
2929                    \box\voidb@x}}%
2930 %    \end{macrocode}
2931 %    The contents of box |\mult@box| are now copied globally to
2932 %    box~|\mult@grightbox|.  (This will be the right-most column, as
2933 %    we shall see later.)
2934 %    \begin{macrocode}
2935     \global\setbox\mult@grightbox
2936            \copy\mult@box
2937 %    \end{macrocode}
2938 %    We start with the assumption that the trial will be successful.
2939 %    If we end up with a solution that is too bad we set
2940 %    |too@bad| to \texttt{true}. We also assume that all forced breaks
2941 %    (if any) will be used during balancing. If this is not the case
2942 %    we record this in |forcedbreak@leftover|.
2943 % \changes{v1.5b}{1992/11/05}{New badness mechanism}
2944 % \changes{v1.8k}{2015/03/21}{Init \cs{ifforcedbreak@leftover}}
2945 %    \begin{macrocode}
2946 %<*badness>
2947    \too@badfalse
2948    \forcedbreak@leftoverfalse
2949 %</badness>
2950 %    \end{macrocode}
2951 %    Using |\vsplit| we extract the other columns from box register
2952 %    |\mult@grightbox|.  This leaves box register |\mult@box|
2953 %    untouched so that we can start over again if this trial was
2954 %    unsuccessful.
2955 %    \begin{macrocode}
2956    {\process@cols\mult@firstbox{%
2957          \global\setbox\count@
2958          \vsplit\mult@grightbox to\dimen@
2959 %    \end{macrocode}
2960 %    After splitting we need to ensure that there isn't any space at
2961 %    the bottom, so we rebox once more.
2962 % \changes{v1.8b}{2013/08/28}{Remove discardable items at the
2963 %                             end of split boxes}
2964 % \changes{v1.8k}{2015/03/21}{Do not use \cs{remove@discardable@items}
2965 %    here}
2966 %    \begin{macrocode}
2967          \global\setbox\count@
2968                  \vbox to\dimen@
2969                   {\unvbox\count@}%
2970 %    \end{macrocode}
2971 %    After every split we check the badness of the resulting column,
2972 %    normally the amount of extra white in the column.
2973 %    \begin{macrocode}
2974 %<*badness>
2975          \ifnum\c@tracingmulticols>\@ne
2976            \@tempcnta\count@
2977            \advance\@tempcnta-\mult@grightbox
2978            \divide\@tempcnta \tw@
2979            \message{^^JColumn
2980               \number\@tempcnta\space
2981                badness: \the\badness\space}%
2982          \fi
2983 %    \end{macrocode}
2984 %    If this badness is larger than the allowed column badness
2985 %    we reject this solution by setting |too@bad| to \texttt{true}.
2986 %    \begin{macrocode}
2987          \ifnum\badness>\c@columnbadness
2988            \ifnum\c@tracingmulticols>\@ne
2989              \message{too bad
2990                   (>\the\c@columnbadness)}%
2991            \fi
2992            \too@badtrue
2993          \fi
2994 %</badness>
2995                         }}%
2996 %    \end{macrocode}
2997 %    There is one subtle point here: while all other constructed boxes
2998 %    have a depth that is determined by |\splitmaxdepth| and/or
2999 %   |\boxmaxdepth| the last box
3000 %    will get a natural depth disregarding the original setting and
3001 %    the value of |\splitmaxdepth| or |\boxmaxdepth|. This means that
3002 %    we may end up with a very large depth in box |\mult@grightbox|
3003 %    which would
3004 %    make the result of the testing incorrect. So we change the value
3005 %    by unboxing the box into itself.
3006 %    \begin{macrocode}
3007    \global\setbox\mult@grightbox
3008       \vbox{\unvbox\mult@grightbox}%
3009 %    \end{macrocode}
3010 %    We also save a copy |\mult@firstbox| at its ``natural'' size
3011 %    for later use.
3012 %    \begin{macrocode}
3013    \setbox\mult@nat@firstbox
3014       \vbox{\unvcopy\mult@firstbox}%
3015 %    \end{macrocode}
3016 %    After |\process@cols| has done its job we have the following
3017 %    situation:
3018 %    \begin{center}
3019 %      \begin{tabular}{r@{$\:\:\longleftarrow\:\:$}l}
3020 %        box |\mult@rightbox| & all material \\
3021 %        box |\mult@gfirstbox| & first column \\
3022 %        box |\mult@gfirstbox|${}+2$ & second column \\
3023 %        \multicolumn{1}{c}{$\vdots$} &
3024 %        \multicolumn{1}{c}{$\vdots$} \\
3025 %        box |\mult@grightbox| & last column
3026 %      \end{tabular}
3027 %    \end{center}
3028 %    We report the height of the first column, in brackets
3029 %    the natural size is given.
3030 % \changes{v1.5?}{1994/?/?}{Show natural size}
3031 %    \begin{macrocode}
3032     \ifnum\c@tracingmulticols>\@ne
3033        \message{^^JFirst column
3034            = \the\dimen@\space
3035            (\the\ht\mult@nat@firstbox)}\fi
3036 %    \end{macrocode}
3037 %    If |\raggedcolumns| is in force older releases of this file also
3038 %    shrank the first column to its natural height at this point.
3039 %    This was done so that the first column doesn't run short compared
3040 %    to later columns but it is actually producing incorrect results
3041 %    (overprinting of text) in boundary cases, so since version v1.5q
3042 %    |\raggedcolumns| means allows for all columns to run slightly short.
3043 % \changes{v1.5q}{1998/01/19}{Do not reset \cs{mult@firstbox} (pr2739)}
3044 %    \begin{macrocode}
3045 %    \ifshr@nking
3046 %      \global\setbox\mult@firstbox
3047 %             \copy\mult@nat@firstbox
3048 %    \fi
3049 %    \end{macrocode}
3050 %    Then we give information about the last column.\footnote{With
3051 %    \TeX{} version 3.141 it is now possible to use \LaTeX's
3052 %    \cs{newlinechar} in the \cs{message} command, but
3053 %    people with older \TeX{} versions will now get
3054 %    \texttt{\string^\string^J} instead of a new line on the screen.}
3055 % \changes{v1.4a}{1992/02/12}{Changed to proper \cs{endlinechar} in\cs{message}}
3056 %    \begin{macrocode}
3057     \ifnum\c@tracingmulticols>\@ne
3058       \message{<> last column =
3059                \the\ht\mult@grightbox^^J}%
3060 %    \end{macrocode}
3061 %    Some tracing code that we don't compile into the production version
3062 %    unless asked for. It will produce huge listings of the boxes
3063 %    involved in balancing in the transcript file.
3064 % \changes{v1.6f}{2004/07/03}{need to use \cs{mult@grightbox} in the loop}
3065 %    \begin{macrocode}
3066 %<*debug>
3067       \ifnum\c@tracingmulticols>4
3068          {\showoutput
3069           \batchmode
3070           \process@cols\mult@grightbox
3071            {\showbox\count@}}%
3072           \errorstopmode
3073       \fi
3074 %</debug>
3075      \fi
3076 %    \end{macrocode}
3077 %    We check whether our trial was successful.  The test used is very
3078 %    simple: we merely compare the first and the last column.  Thus
3079 %    the intermediate columns may be longer than the first if
3080 %    |\raggedcolumns| is used.  If the right-most column is
3081 %    longer than the first then we start over with a larger value for
3082 %    |\dimen@|.
3083 % \changes{v1.3c}{1991/03/03}{\cs{global}\cs{advance} left over from older code}
3084 %    \begin{macrocode}
3085     \ifdim\ht\mult@grightbox >\dimen@
3086 %    \end{macrocode}
3087 %    If the height of the last box is too large we mark this trial as
3088 %    unsuccessful.
3089 % \changes{v1.5v}{1999/07/18}{Added tracing statements for
3090 %                             trial unsuccessful}
3091 %    \begin{macrocode}
3092 %<*badness>
3093       \too@badtrue
3094       \ifnum\c@tracingmulticols>\@ne
3095          \typeout{Rejected: last
3096                  column too large!}%
3097       \fi
3098     \else
3099 %    \end{macrocode}
3100 % \changes{v1.5v}{1999/07/18}{Check last column if it contains forced
3101 %    break and reject trial if that is the case}
3103 %    To ensure that there isn't a forced break in the last column we
3104 %    try to split off a box of size |\maxdimen| from |\mult@grightbox|
3105 %    (or rather from a copy of it). This should result in a void box
3106 %    after the split, unless there was a forced break somewhere within
3107 %    the column in which case the material after the break would have
3108 %    stayed in the box.
3109 %    \begin{macrocode}
3110       \setbox\@tempboxa
3111            \copy\mult@grightbox
3112       \setbox\z@\vsplit\@tempboxa to\maxdimen
3113       \ifvoid\@tempboxa
3114 %    \end{macrocode}
3115 %    Thus if |\@tempboxa| is void we  have a valid solution.
3116 %    In this case we take a closer
3117 %    look at the last column to decide if this column should be made
3118 %    as long as all other columns or if it should be allowed to be
3119 %    shorter.
3120 %    For this we first have to rebox the column into a box of the
3121 %    appropriate height. If tracing is enabled we then display the
3122 %    badness for this box.
3123 %    \begin{macrocode}
3124         \global\setbox\mult@grightbox
3125            \vbox to\dimen@
3126               {\unvbox\mult@grightbox}%
3127         \ifnum\c@tracingmulticols>\@ne
3128           \message{Final badness:
3129                    \the\badness}%
3130         \fi
3131 %    \end{macrocode}
3132 %    We then compare this badness with the allowed badness for the final
3133 %    column. If it does not exceed this value we use the box, otherwise
3134 %    we rebox it once more and add some glue at the bottom.
3135 % \changes{v1.8h}{2014/09/12}{Use \cs{vfilmaxdepth}}
3136 % \changes{v1.8j}{2015/03/07}{Use \cs{vfil} in this case}
3137 %    \begin{macrocode}
3138         \ifnum\badness>\c@finalcolumnbadness
3139           \global\setbox\mult@grightbox
3140            \vbox to\dimen@
3141               {\unvbox\mult@grightbox\vfil}%
3142            \ifnum\c@tracingmulticols>\@ne
3143              \message{ setting natural
3144               (> \the\c@finalcolumnbadness)}%
3145            \fi
3146         \fi
3147 %    \end{macrocode}
3148 %    If |\@tempboxa| above was not void our trial was unsuccessful and
3149 %    we report this fact and try again.
3150 % \changes{v1.6f}{2004/07/03}{\texttt{/colbreak} guard in the wrong position}
3151 %    \begin{macrocode}
3152       \else
3153 %    \end{macrocode}
3154 %    If we have unprocessed forced breaks we normally reiterate with a
3155 %    larger column size to fit them in eventually. However, if there
3156 %    are simply too many of them (e.g., 3 forced breaks but only 2
3157 %    columns to balance) then this will never succeed and and we would
3158 %    continue growing the columns until we hit the largest possible
3159 %    column size. So in addition we check how big the column size is
3160 %    compared to available room and if we exceed this by
3161 %    |\maxbalancingoverflow| we give up and instead of balancing cut
3162 %    another normal page. To be indicate this case we set
3163 %    |forcedbreak@leftover| to true.
3164 % \changes{v1.8k}{2015/03/21}{Watch out for columns growing too far in
3165 %    case of forced breaks}
3166 % \changes{v1.8l}{2015/03/25}{Added additional tracing if column overflows}
3167 %    \begin{macrocode}
3168        \@tempdima\@colroom
3169        \advance\@tempdima \maxbalancingoverflow
3170        \ifdim \dimen@ < \@tempdima
3171         \too@badtrue
3172          \ifnum\c@tracingmulticols>\@ne
3173            \typeout{Rejected: unprocessed
3174              forced break(s) in last column!}%
3175          \fi
3176        \else
3177          \forcedbreak@leftovertrue
3178          \ifnum\c@tracingmulticols>\@ne
3179           \typeout{Failed: columns too large
3180             with unprocessed forced break(s)!}%
3181          \fi
3182        \fi
3183       \fi
3184     \fi
3185 %    \end{macrocode}
3186 %    If the natural height of the first box is smaller than the
3187 %    current trial size but is larger than the previous trial size it
3188 %    is likely that we have missed a potentially better
3189 %    solution. (This could have happened if for some reason our first
3190 %    trial size was too high.) In that case we dismiss this trial and
3191 %    restart using the natural height for the next trial.
3192 %    \begin{macrocode}
3193     \ifdim\ht\mult@nat@firstbox<\dimen@
3194       \ifdim\ht\mult@nat@firstbox>\last@try
3195         \too@badtrue
3196         \ifnum\c@tracingmulticols>\@ne
3197            \typeout{Retry: using natural
3198                     height of first column!}%
3199         \fi
3200         \dimen@\ht\mult@nat@firstbox
3201         \last@try\dimen@
3202         \advance\dimen@-\p@
3203       \fi
3204     \fi
3205 %    \end{macrocode}
3206 %    Finally the switch |too@bad| is tested. If it was made true
3207 %    either earlier on or due to a rightmost column being too large
3208 %    we try again with a slightly larger value for |\dimen@|.
3209 %    \begin{macrocode}
3210     \iftoo@bad
3211 %</badness>
3212       \advance\dimen@\p@
3213     \repeat
3214 %    \end{macrocode} 
3215 %    If we come out of the loop with the switch |forcedbreak@leftover|
3216 %    set to true then balancing has failed and we should cut a normal
3217 %    page. We indicate this below with |\too@badtrue| when any of the
3218 %    columns get too high, so we set this flag here too in order to
3219 %    get the same processing logic.\footnote{Should get cleaned up as
3220 %    we now have two different routes to reach this part of the
3221 %    processing.}
3222 % \changes{v1.8k}{2015/03/21}{}
3223 %    \begin{macrocode}
3224     \ifforcedbreak@leftover
3225        \too@badtrue
3226     \else
3227 %    \end{macrocode}
3228 %    At that point |\dimen@| holds the height that was determined by
3229 %    the balancing loop.
3230 %    If that height for the columns turns out to be larger
3231 %    than the available space (which is |\@colroom|) we squeeze the
3232 %    columns into the space assuming that they will have enough
3233 %    shrinkability to allow this.\footnote{This might be wrong, since
3234 %    the shrinkability that accounts for the amount of material might
3235 %    be present only in some columns. But it is better to try then to
3236 %    give up directly.}
3237 %    However, this squeezing should only be done if we are balancing
3238 %    columns on the main galley and \emph{not} if we are building a
3239 %    boxed multicol (in the latter case the current |\@colroom| is
3240 %    irrelevant since the produced box might be moved anywhere at a
3241 %    later stage).
3242 % \changes{v1.3c}{1991/03/03}{Limit column height to \cs{@colroom}}
3243 % \changes{v1.5q}{1998/01/19}{Removed setting \cs{dimen@} (pr2739)}
3244 % \changes{v1.5y}{2000/06/10}{Limit column height only in unrestricted
3245 %    mode (pr/3212)}
3246 %    \begin{macrocode}
3247      \if@boxedmulticols\else
3248        \ifdim\dimen@>\@colroom
3249          \dimen@\@colroom
3250        \fi
3251      \fi
3252 %    \end{macrocode}
3253 %    Then we move the contents of the odd-numbered box registers to
3254 %    the even-numbered ones, shrinking them if requested.
3255 %    We have to use |\vbox| not |\vtop| (as it was done in
3256 %    the first versions) since otherwise the resulting boxes will have
3257 %    no height (\TB\/ page 81). This would mean that extra
3258 %    |\topskip|  is added when the boxes are returned to the
3259 %    page-builder via |\page@sofar|.
3260 % \changes{v1.3a}{1990/05/20}{Changed \cs{vtop} to \cs{vbox}.}
3261 %    \begin{macrocode}
3262      \process@cols\mult@rightbox
3263          {\@tempcnta\count@
3264           \advance\@tempcnta\@ne
3265 %    \end{macrocode}
3266 %    when putting the final column together we want overfull
3267 %    information:
3268 %    \begin{macrocode}
3269           \vfuzz\z@
3270           \setbox\count@\vbox to\dimen@
3271              {%
3272 %    \end{macrocode}
3274 % \changes{v1.8h}{2014/09/12}{Use \cs{vfilmaxdepth}}
3275 %    \begin{macrocode}
3276               \vskip \z@
3277                 \@plus-\multicolundershoot
3278                 \@minus-\multicolovershoot
3279               \unvbox\@tempcnta
3280               \ifshr@nking\vfilmaxdepth\fi
3281              }%
3282 %    \end{macrocode}
3283 %    If the resulting box is overfull there was too much material to
3284 %    fit into the available space. The question though is how much? If
3285 %    it wasn't more than |\maxbalancingoverflow| we accept it still to
3286 %    avoid getting very little material for the next page (which we
3287 %    would then have difficulties to balance).
3288 % \changes{v1.8a}{2011/12/20}{Balancing concept improved}
3289 %    \begin{macrocode}
3290           \ifnum\badness>\@M
3291             \vfuzz\maxdimen % no overfull warning
3292             \setbox\@tempboxa \vbox to\dimen@
3293                  {\vskip-\maxbalancingoverflow
3294                   \unvcopy\count@}%
3295             \ifnum\badness>\@M
3296               \mult@info\@ne
3297                 {Balanced column more than
3298                   \the\maxbalancingoverflow\space
3299                   too large}%
3300 %    \end{macrocode}
3301 %    Fail the balancing attempt:
3302 %    \begin{macrocode}
3303               \too@badtrue
3304             \else
3305 %    \end{macrocode}
3306 %    Otherwise report that there is a problem but within the accepted
3307 %    boundary.
3308 %    \begin{macrocode}
3309               \mult@info\@ne
3310                 {Balanced column
3311                  too large, but less than
3312                  \the\maxbalancingoverflow}%
3313             \fi
3314           \fi
3315          }%
3316 %    \end{macrocode}
3317 %    Finally end the |\ifforcedbreak@leftover| conditional.
3318 % \changes{v1.8k}{2015/03/21}{Finish the new conditional}
3319 %    \begin{macrocode}
3320    \fi
3322 %    \end{macrocode}
3323 %  \end{macro}
3326 % \begin{macro}{\maxbalancingoverflow}
3327 %    Amount that balancing is allowed to overflow the available column
3328 %    space. We default to 12pt which means about one line in most
3329 %    layouts.
3330 % \changes{v1.8a}{2011/12/20}{\cs{maxbalancingoverflow} parameter added}
3331 %    \begin{macrocode}
3332 \newdimen\maxbalancingoverflow
3333 \maxbalancingoverflow=12pt
3334 %    \end{macrocode}
3335 %  \end{macro}
3337 % \end{multicols}
3339 % \begin{multicols}{2}[\subsection{The box allocations}]
3341 % \begin{macro}{\mult@rightbox}
3342 % \begin{macro}{\mult@grightbox}
3343 % \begin{macro}{\mult@firstbox}
3344 % \begin{macro}{\mult@gfirstbox}
3345 %    Early releases of these macros used the first box registers
3346 %    0, 2, 4,\ldots\ for global boxes and 1, 3, 5,\ldots\ for the
3347 %    corresponding local boxes. (You might still find some traces
3348 %    of this setup in the documentation, sigh.) This produced a problem
3349 %    at the moment we had more than 5 columns because then officially
3350 %    allocated boxes were overwritten by the algorithm.
3351 %    The new release now uses private box registers
3352 %    \begin{macrocode}
3353 \newbox\mult@rightbox
3354 \newbox\mult@grightbox
3355 \newbox\mult@gfirstbox
3356 \newbox\mult@firstbox
3357 \newbox\@tempa\newbox\@tempa
3358 \newbox\@tempa\newbox\@tempa
3359 \newbox\@tempa\newbox\@tempa
3360 \newbox\@tempa\newbox\@tempa
3361 \newbox\@tempa\newbox\@tempa
3362 \newbox\@tempa\newbox\@tempa
3363 \newbox\@tempa\newbox\@tempa
3364 \newbox\@tempa\newbox\@tempa
3365 \newbox\@tempa
3366 \let\@tempa\relax
3367 %    \end{macrocode}
3368 % \end{macro}
3369 % \end{macro}
3370 % \end{macro}
3371 % \end{macro}
3374 % \end{multicols}
3377 % \begin{multicols}{2}[\section{New macros and hacks for version 1.2}]
3379 % \begin{macro}{\emergencystretch}
3380 % \begin{macro}{\setemergencystretch}
3381 %    If we don't use \TeX{} 3.0 |\emergencystretch| is undefined
3382 %    so in this case we simply add it as an unused \meta{dimen}
3383 %    register.
3384 % \changes{v1.4j}{1992/06/25}{Setting of \cs{emergencystretch} on top
3385 %                  removed.}
3386 %    \begin{macrocode}
3387 \@ifundefined{emergencystretch}
3388      {\newdimen\emergencystretch}{}
3389 %    \end{macrocode}
3390 % \changes{v1.2a}{1990/02/05}{Macro added.}
3391 %    My tests showed that the following formula worked pretty well.
3392 %    Nevertheless the |\setemergencystretch| macro also gets
3393 %    |\hsize| as second argument to enable the user to try
3394 %    different formulae.
3395 %    \begin{macrocode}
3396 \def\setemergencystretch#1#2{%
3397    \emergencystretch 4pt
3398    \multiply\emergencystretch#1}
3399 %    \end{macrocode}
3400 % \end{macro}
3401 % \end{macro}
3404 % \begin{macro}{\set@floatcmds}
3405 % \changes{v1.2a}{1990/02/05}{Macro added.}
3406 % \changes{v1.5g}{1994/06/07}{Updated since floats have changed}
3407 % \changes{v1.5j}{1994/06/07}{Updated since floats have changed again}
3408 % \changes{v1.5l}{1995/10/19}{Added \cs{@largefloatcheck}}
3409 % \changes{v1.6g}{2006/02/23}{Added \cs{@minipagefalse}}
3410 % \changes{v1.6h}{2008/12/05}{Use \cs{@endfloatbox} to better support
3411 %   the modifications done by the float package}
3412 %    Even if this should be used as a hook we use a |@| in the
3413 %    name since it is more for experts.
3414 %    \begin{macrocode}
3415 \def\set@floatcmds{%
3416  \let\@dblfloat\@dbflt
3417  \def\end@dblfloat{\@endfloatbox
3418    \@largefloatcheck
3419    \outer@nobreak
3420 %    \end{macrocode}
3421 %    This is cheap (deferring the floats until after the current page)
3422 %    but any other solution would go deep into \LaTeX's output
3423 %    routine and I don't like to work on it until I know which parts
3424 %    of the output routine have to be reimplemented anyway for
3425 %    \LaTeX3.
3426 %    \begin{macrocode}
3427    \ifnum\@floatpenalty<\z@
3428 %    \end{macrocode}
3429 %    We have to add the float to the |\@deferlist| because we assume
3430 %    that outside the \mc{} environment we are in one column mode.
3431 %    This is not entirely correct, I already used the \mc{}
3432 %    environment inside of \LaTeX{}s |\twocolumn| declaration but it
3433 %    will do for most applications.
3434 %    \begin{macrocode}
3435      \@cons\@deferlist\@currbox
3436    \fi
3437    \ifnum\@floatpenalty=-\@Mii
3438      \@Esphack
3439    \fi}}
3440 %    \end{macrocode}
3441 % \end{macro}
3443 % \end{multicols}
3445 % \begin{multicols}{2}[\subsection{Maintaining the mark registers}]
3446 % \label{sec:v14}
3448 % This section contains the routines that set the marks so that they
3449 % will be handled correctly. They have been introduced with version~1.4.
3451 %  \begin{macro}{\kept@topmark}
3452 % \changes{v1.4h}{1992/06/04}{Init to double brace pair}
3453 %  \begin{macro}{\kept@firstmark}
3454 %  \begin{macro}{\kept@botmark}
3455 %    First thing we do is to reserve three macro names to hold the
3456 %    replacement text for \TeX's primitives |\firstmark|, |\botmark| and
3457 %    |\topmark|. We initialize the first two to be empty and
3458 %    |\kept@topmark| to contain  two empty pair of braces. This is
3459 %    necessary since |\kept@topmark| is supposed to contain the last
3460 %    mark from a preceding page and in \LaTeX{} any ``real'' mark must
3461 %    contain two parts representing left and right mark information.
3462 %    \begin{macrocode}
3463 \def\kept@topmark{{}{}}
3464 \let\kept@firstmark\@empty
3465 \let\kept@botmark\@empty
3466 %    \end{macrocode}
3467 %  \end{macro}
3468 %  \end{macro}
3469 %  \end{macro}
3472 %  \begin{macro}{\return@nonemptymark}
3473 %    Sometimes we want to return the value of a ``kept'' mark into a
3474 %    |\mark| node on the main vertical list. This is done by the
3475 %    function |\return@nonemptymark|. As the name suggests it only acts
3476 %    if the replacement text of the kept mark is non-empty. This is done
3477 %    to avoid adding an empty mark when no mark was actually present. If
3478 %    we would nevertheless add such a mark it would be regarded as a
3479 %    valid |\firstmark| later on.
3480 %    \begin{macrocode}
3481 \def\return@nonemptymark#1#2{%
3482   \ifx#2\@empty
3483   \else
3484 %    \end{macrocode}
3485 %    For debugging purposes we take a look at the value of the kept mark
3486 %    that we are about to return. This code will get stripped out for
3487 %    production.
3488 %    \begin{macrocode}
3489 %<*marktrace>
3490     \mult@info\tw@
3491       {Returned #1 mark:\MessageBreak
3492        \meaning#2}%
3493 %      \nobreak
3494 %    \fi
3495 %</marktrace>
3496 %    \end{macrocode}
3497 %    Since the contents of the mark may be arbitrary \LaTeX{} code we
3498 %    better make sure that it doesn't get expanded any further. (Some
3499 %    expansion have been done already during the execution of
3500 %    |\markright| or |\markboth|.) We therefore use the usual mechanism
3501 %    of a toks register to prohibit expansion.\footnote{Due to the
3502 %    current definition of \cs{markright} etc.\ it wouldn't
3503 %    help to define the \cs{protect} command to prohibit
3504 %    expansion as any \cs{protect} has already vanished due to
3505 %    earlier expansions.}
3506 % \changes{v1.4n}{1992/09/10}{Make marks robust}
3507 % \changes{v1.5t}{1999/03/22}{re-add \cs{mark} command which was commented out
3508 %       by mistake at some point in 1998 (pr/2978)}
3509 %    \begin{macrocode}
3510     \toks@\expandafter{#2}%
3511     \mark{\the\toks@}%
3512 %    \end{macrocode}
3513 %    We don't want any breakpoint between such a returned mark and the
3514 %    following material (which is usually just the box where the mark
3515 %    came from).
3516 %    \begin{macrocode}
3517     \nobreak
3518   \fi}
3519 %    \end{macrocode}
3520 %  \end{macro}
3523 %  \begin{macro}{\get@keptmarks}
3524 %    If we have some material in a box register we may want to get the
3525 %    first and the last mark out of this box. This can be done with
3526 %    |\get@keptmarks| which takes one argument: the box register number
3527 %    or its nick name defined by |\newbox|.
3528 %    \begin{macrocode}
3529 \def\get@keptmarks#1{%
3530 %    \end{macrocode}
3531 %    For debugging purposes we take a look at the current dimensions
3532 %    of the box since in earlier versions of the code I made some
3533 %    mistakes in this area.
3534 %    \begin{macrocode}
3535 %<*debug>
3536       \typeout{Mark box #1 before:
3537                ht \the\ht#1, dp \the\dp#1}%
3538 %</debug>
3539 %    \end{macrocode}
3540 %    Now we open a new group an locally copy the box to itself. As a
3541 %    result any operation, i.e.\ |\vsplit|, will only have a local
3542 %    effect. Without this trick the box content would get lost up to
3543 %    the level where the last assignment to the box register was done.
3544 %    \begin{macrocode}
3545   \begingroup
3546    \vbadness\@M
3547    \setbox#1\copy#1%
3548 %    \end{macrocode}
3549 %    Now we split the box to the maximal possible dimension. This
3550 %    should split off the full contents of the box so that effectively
3551 %    everything is split off. As a result |\splitfirstmark| and
3552 %    |\splitbotmark| will contain the first and last mark in the box
3553 %    respectively.
3554 %    \begin{macrocode}
3555    \setbox#1\vsplit#1to\maxdimen
3556 %    \end{macrocode}
3557 %    Therefore we can now set the kept marks which is a global
3558 %    operation and afterwards close the group. This will restore the
3559 %    original box contents.
3560 %    \begin{macrocode}
3561    \set@keptmarks
3562  \endgroup
3563 %    \end{macrocode}
3564 %    For debugging we take again a look at the box dimension which
3565 %    shouldn't have changed.
3566 %    \begin{macrocode}
3567 %<*debug>
3568     \typeout{Mark box #1 \space after:
3569              ht \the\ht#1, dp \the\dp#1}%
3570 %</debug>
3572 %    \end{macrocode}
3573 %  \end{macro}
3576 %  \begin{macro}{\set@keptmarks}
3577 %    The macro |\set@keptmarks| is responsible for setting
3578 %    |\kept@firstmark| and |\kept@botmark|, by checking the current
3579 %    values for |\splitfirstmark| and |\splitbotmark|.
3580 %    \begin{macrocode}
3581 \def\set@keptmarks{%
3582 %    \end{macrocode}
3583 %    If |\kept@firstmark| is empty we assume that it isn't set. This
3584 %    is strictly speaking not correct as we loose the ability to have
3585 %    marks that are explicitly empty, but for standard \LaTeX{}
3586 %    application it is sufficient. If it is non-empty we don't change
3587 %    the value---within the output routines it will then be restored
3588 %    to |\@empty|.
3589 %    \begin{macrocode}
3590    \ifx\kept@firstmark\@empty
3591 %    \end{macrocode}
3592 %    We now put the contents of |\splitfirstmark| into
3593 %    |\kept@firstmark|. In the case that there wasn't any mark at all
3594 %    |\kept@firstmark| will not change by that operation.
3595 %    \begin{macrocode}
3596      \expandafter\gdef\expandafter
3597         \kept@firstmark
3598         \expandafter{\splitfirstmark}%
3599 %    \end{macrocode}
3600 %    When debugging we show the assignment but only when something
3601 %    actually happened.
3602 %    \begin{macrocode}
3603 %<*marktrace>
3604      \ifx\kept@firstmark\@empty\else
3605        \mult@info\tw@
3606          {Set kept first mark:\MessageBreak
3607           \meaning\kept@firstmark%
3608           \@gobbletwo}%
3609      \fi
3610 %</marktrace>
3611    \fi
3612 %    \end{macrocode}
3613 %    We always try to set the bottom mark to the |\splitbotmark| but
3614 %    of course only when there has been a |\splitbotmark| at all.
3615 %    Again, we assume that an empty |\splitbotmark| means that the
3616 %    split off box part didn't contain any marks at all.
3617 %    \begin{macrocode}
3618    \expandafter\def\expandafter\@tempa
3619       \expandafter{\splitbotmark}%
3620    \ifx\@tempa\@empty\else
3621       \global\let\kept@botmark\@tempa
3622 %<*marktrace>
3623       \mult@info\tw@
3624         {Set kept bot mark:\MessageBreak
3625          \meaning\kept@botmark%
3626          \@gobbletwo}%
3627 %</marktrace>
3628    \fi}%
3629 %    \end{macrocode}
3630 %  \end{macro}
3633 %  \begin{macro}{\prep@keptmarks}
3634 %    The |\prep@keptmarks| function is used to initialize the kept
3635 %    marks from the contents of  |\partial@page|, i.e.\ the box that
3636 %    holds everything from the top of the current page prior to
3637 %    starting the \mc{} environment. However, such a box is only
3638 %    available if we are not producing a boxed \mc{}.
3639 %    \begin{macrocode}
3640 \def\prep@keptmarks{%
3641    \if@boxedmulticols \else
3642      \get@keptmarks\partial@page
3643    \fi}
3644 %    \end{macrocode}
3645 %  \end{macro}
3648 %  \begin{macro}{\remove@discardable@items}
3649 %    There are situations when we may have some space at the end of a
3650 %    column and this macro here will attempt to get rid of it. The
3651 %    typical \LaTeX{} sequence is a series of selfcanceling glues so
3652 %    if we remove them recursively we are usually fine.
3654 %    Special care is needed with handling |\vspace*| as that
3655 %    corresponds to |\penalty10000|, |\vskip <skip>|, followed by
3656 %    |\vskip 0pt|. If we see this sequence going backwards in the the
3657 %    vertical list we assume that this is a ``desired'' space. We
3658 %    therefore stop the recursion and reinsert the spaces.
3660 %    As the multicol code sometimes add an explicit penalty at the end
3661 %    of a column we first attempt to remove it in case it is there.
3662 % \changes{v1.8m}{2015/03/31}{Another rewrite of
3663 %     \cs{remove@discardable@items} hopefully okay now}
3664 %    \begin{macrocode}
3665 \skip0=0pt
3666 \edef\the@zero@skip{\the\skip0}
3667 \def\remove@discardable@items{%
3668      \unpenalty
3669 %    \end{macrocode}
3670 %    Save a previous skip (if there) and then remove it, we can't
3671 %    really tell the difference between no skip an a skip of zero but
3672 %    that's life.
3673 %    \begin{macrocode}
3674      \edef\@tempa{\the\lastskip}%
3675 %\typeout{s1=\@tempa}%
3676      \unskip
3677 %    \end{macrocode}
3678 %    If it was a zero skip (or none) we save the next previous skip
3679 %    (if any).
3680 %    \begin{macrocode}
3681      \ifx\@tempa\the@zero@skip
3682        \edef\@tempb{\the\lastskip}%
3683 %\typeout{s2=\@tempb}%
3684 %    \end{macrocode}
3685 %    If this one again was zero (or more likely not there in the first
3686 %    place) we stop.
3687 %    \begin{macrocode}
3688        \ifx\@tempb\the@zero@skip
3689        \else
3690 %    \end{macrocode}
3691 %    Otherwise we remove this ``real'' skip. Then we look if it was
3692 %    preceeded by a penalty of 10000 (i.e., a |\nobreak|)
3693 %    \begin{macrocode}
3694          \unskip
3695 %\typeout{p=\lastpenalty}%
3696          \ifnum \lastpenalty=\@M
3697 %    \end{macrocode}
3698 %    If so this was a |\vspace*| or something equivalent to
3699 %    it. Therefore we reintroduce the skips and stop. Otherwise we
3700 %    recurse.
3701 %    \begin{macrocode}
3702            \vskip\@tempb\vskip\@tempa\relax
3703          \else 
3704            \remove@discardable@items
3705          \fi
3706        \fi
3707      \else
3708 %    \end{macrocode}
3709 %    If the first skip was a non-zero skip we recurse as well.
3710 %    \begin{macrocode}
3711        \remove@discardable@items
3712      \fi
3714 %    \end{macrocode}
3715 %  \end{macro}
3717 %    \begin{macrocode}
3718 %<*badness>
3719 \newif\iftoo@bad
3720 \def\too@badtrue{\global\let\iftoo@bad\iftrue}
3721 \def\too@badfalse{\global\let\iftoo@bad\iffalse}
3722 %    \end{macrocode}
3723 %    
3724 % \changes{v1.8k}{2015/03/21}{The new switch}
3725 %    \begin{macrocode}
3726 \newif\ifforcedbreak@leftover
3727 %    \end{macrocode}
3729 % \begin{macro}{\c@columnbadness}
3730 % \begin{macro}{\c@finalcolumnbadness}
3731 %    \begin{macrocode}
3732 \newcount\c@columnbadness
3733 \c@columnbadness=10000
3734 \newcount\c@finalcolumnbadness
3735 \c@finalcolumnbadness=9999
3737 \newdimen\last@try
3739 %    \end{macrocode}
3741 % \changes{v1.5z1}{2003/02/17}{Change wrong default for
3742 %    \cs{multicolovershoot} to zero (pr/3465).}
3743 %    \begin{macrocode}
3744 \newdimen\multicolovershoot
3745 \newdimen\multicolundershoot
3746 \multicolovershoot=0pt
3747 \multicolundershoot=2pt
3748 \newbox\mult@nat@firstbox
3749 %</badness>
3750 %    \end{macrocode}
3751 % \end{macro}
3752 % \end{macro}
3754 %  \begin{macro}{\mult@info}
3755 %    A helper for producing info messages
3756 %    \begin{macrocode}
3757 \def\mult@info#1#2{%
3758   \ifnum\c@tracingmulticols>#1%
3759    \GenericWarning
3760        {(multicol)\@spaces\@spaces}%
3761        {Package multicol: #2}%
3762   \fi
3764 %    \end{macrocode}
3765 %  \end{macro}
3767 % \end{multicols}
3770 % \begin{multicols}{2}[\section{Fixing the
3771 %                        \cs{columnwidth}}]
3773 %  \begin{macro}{\@footnotetext}
3774 % \changes{v1.5o}{1997/11/16}{Redefinition added pr/2664.}
3775 % \changes{v1.5r}{1998/08/17}{Use \cs{@footnotetext} but with
3776 %                             local change to \cs{columnwidth}.}
3777 %  \begin{macro}{\mult@footnotetext}
3778 % \changes{v1.5r}{1998/08/17}{Macro removed again.}
3779 %    If we store the current column width in |\columnwidth| we have
3780 %    to redefine the internal |\@footnotetext| macro to use |\textwidth|
3781 %    for the width of the footnotes rather than using the original
3782 %    definition.
3784 %    Starting with version v1.5r this is now done in a way that the original
3785 %    definition is still used, except that locally |\columnwidth| is set to
3786 %    |\textwidth|.
3788 %    This solves two problems: first redefinitions of |\@footnotetext|
3789 %    done by a class will correctly survive and second if multicols is
3790 %    used inside a minipage environment the special definition of
3791 %    |\@footnotetext| in that environment will be picked up and not the
3792 %    one for the main galley (the latter would result in all footnotes
3793 %    getting lost in that case).
3795 %    See the definition of the |\multicols| command further up for the exact
3796 %    code.
3797 %  \end{macro}
3798 %  \end{macro}
3799 % \end{multicols}
3802 % \begin{multicols*}{2}[\section{Further extensions}]
3804 % This section does contain code for extensions added to this package
3805 % over time. Not all of them may be active, some might sit dormant and
3806 % wait for being activated in some later release.
3808 % \subsection{Not balancing the columns}
3810 %  This is fairly trivial to implement. we just have to disable the
3811 %  balancing output routine and replace it by the one that ships out
3812 %  the other pages.
3814 %  \begin{macro}{\multicols*}
3815 % \changes{v1.5q}{1998/01/19}{Macro added}
3816 %  The code for this environment was suggested by Matthias Clasen.
3817 %    \begin{macrocode}
3818 %<*nobalance>
3819  \@namedef{multicols*}{%
3820 %    \end{macrocode}
3821 %    If we are not on the main galley, i.e., inside a box of some
3822 %    sort, that approach will not work since we don't have a vertical
3823 %    size for the box so we better warn that we balance anyway.
3824 %    \begin{macrocode}
3825    \ifinner
3826      \PackageWarning{multicol}%
3827        {multicols* inside a box does
3828         not make sense.\MessageBreak
3829         Going to balance anyway}%
3830    \else
3831      \let\balance@columns@out
3832          \multi@column@out
3833    \fi
3834    \begin{multicols}
3836 %    \end{macrocode}
3837 %  \end{macro}
3839 %  \begin{macro}{\endmulticols*}
3840 %    When ending the environment we simply end the inner
3841 %    \texttt{multicols} environment, except that we better also stick
3842 %    in some stretchable vertical glue so that the last column still
3843 %    containing text is not vertically stretched out. 
3845 %    We do this as follows: first we cancel out |\lastskip| if it was
3846 %    positive (in case of a negative glue we assume that it was
3847 %    deliberate, for a deliberate positive glue one needs to use
3848 %    |\vspace*|). We can't simply use |\remove@discardable@items| here
3849 %    as this only works inside boxes but we are here on the main
3850 %    vertical list.
3852 %    Then we back up by |\prevdepth| but not more than |\boxmaxdepth|
3853 %    so that a baseline of the last box is now at the bottom. This way
3854 %    the material will align properly in case something like |\vfill|
3855 %    spreads it out after all.
3856 %    Finally we append |\vfil| to put white space at the bottom of the
3857 %    column, but we only do this if we aren't anyway doing |\raggedcolumns|.
3858 % \changes{v1.5q}{1998/01/19}{Macro added}
3859 % \changes{v1.8h}{2014/09/12}{Use \cs{vfilmaxdepth}}
3860 % \changes{v1.8i}{2014/10/28}{Add \cs{null} to hide the final fill and only add
3861 %                             vertical space if not doing \cs{raggedcolumns}}
3862 % \changes{v1.8j}{2015/03/07}{Redesign the whole approach.}
3863 % \changes{v1.8k}{2015/03/21}{And a bit more redesign because of the
3864 %    change in \cs{remove@discardable@items}}
3865 %    \begin{macrocode}
3866 \@namedef{endmulticols*}{%
3867    \ifdim\lastskip>\z@ \vskip-\lastskip \fi
3868    \ifdim \prevdepth>\z@
3869      \vskip-\ifdim\prevdepth>\boxmaxdepth 
3870                   \boxmaxdepth
3871             \else \prevdepth \fi
3872    \fi
3873    \ifshr@nking\else
3874      \vfil
3875    \fi
3876    \end{multicols}}
3877 %</nobalance>
3878 %    \end{macrocode}
3879 %  \end{macro}
3882 % \subsection{Manual column breaking} \label{sec:colbreak}
3884 % The problem with manual page breaks within \mc{} is the fact that
3885 % during collection of material for all columns a page-forcing penalty
3886 % (i.e. -10000 or higher) would stop the collecting pass which is not
3887 % quite what is desired. On the other hand, using a penalty like -9999
3888 % would mean that there would be occasions where the |\vsplit|ing
3889 % operations within \mc{} would ignore that penalty and still choose a
3890 % different break point.
3892 % For this reason the current implementation
3893 % uses a completely different approach. In a nutshell it extends the \LaTeX{}
3894 % output routine handling by introducing an additional penalty flag
3895 % (i.e., a penalty which is forcing but higher than -10000 so that the
3896 % output routine can look at this value and thus knows why it has been
3897 % called).
3899 % Inside the output routine we test for this value and if it appears
3900 % we do two things: save the galley up to this point in a special box
3901 % for later use and reduce the |\vsize| by the height of the material
3902 % seen. This way the forcing penalty is now hidden in that box and we
3903 % can restart the collection process for the remaining
3904 % columns. (This is done in |\speci@ls| above.)
3906 % In the output routines that do the |\vsplit|ting either for
3907 % balancing or for a full page we simply combine box~255 with the
3908 % saved box thus getting a single box for  splitting which now
3909 % contains forcing breaks in the right positions.
3912 %  \begin{macro}{\columnbreak}
3913 % \changes{v1.5u}{1999/05/25}{Macro added}
3914 %    |\columnbreak| is modelled after |\pagebreak| except that we
3915 %    generate a penalty -10005.
3916 %    \begin{macrocode}
3917 \mathchardef\@Mv=10005
3918 \def\columnbreak{%
3919 %    \end{macrocode}
3920 %    We have to ensure that it is only used within a \mc{}
3921 %    environment since if that penalty would be seen by the unmodified
3922 %    \LaTeX{} output routine strange things would happen.
3923 %    \begin{macrocode}
3924  \ifnum\col@number<\tw@
3925   \PackageError{multicol}%
3926    {\noexpand\columnbreak outside multicols}%
3927    {This command can only be used within
3928     a multicols or multicols* environment.}%
3929  \else
3930   \ifvmode
3931     \penalty -\@Mv\relax
3932   \else
3933     \@bsphack
3934     \vadjust{\penalty -\@Mv\relax}%
3935     \@esphack
3936   \fi
3937  \fi}
3938 %    \end{macrocode}
3939 %  \end{macro}
3942 %  \begin{macro}{\colbreak@box}
3943 % \changes{v1.5u}{1999/05/25}{Macro added}
3944 %    Need a box to collect the galley up to the column break.
3945 %    \begin{macrocode}
3946 \newbox\colbreak@box
3947 %</package>
3948 %    \end{macrocode}
3949 %  \end{macro}
3952 % \subsection{Supporting right-to-left languages} \label{sec:RL}
3955 % \changes{v1.7a}{2010/10/24}{RL language support added}
3956 % \changes{v1.7b}{2011/12/18}{RL language support fixed}
3958 %  \begin{macro}{\LR@column@boxes}
3959 %    |\LR@column@boxes| is called when we are assembling the columns for left
3960 %    to right typesetting. When we start we are inside an |\hbox| of
3961 %    full width.
3962 %    Left to right typesetting is fairly easy, we basically output
3963 %    each column box intermixed with vertical rules and proper
3964 %    spacing. As this happens inside a box of a defined width the
3965 %    rules and the columns automatically get into the right positions.
3966 %    \begin{macrocode}
3967 \def\LR@column@boxes{%
3968 %    \end{macrocode}
3969 %    We loop through the columns with |\process@cols|
3970 %    \begin{macrocode}
3971      \process@cols\mult@gfirstbox{%
3972 %    \end{macrocode}
3973 %    If the depth of the current box is larger than the maximum found
3974 %    so far in |\dimen2| we update that register for later use.
3975 % \changes{v1.6a}{2003/03/15}{Preparing for adjusting \cs{prevdepth}}
3976 %    \begin{macrocode}
3977        \ifdim\dp\count@>\dimen\tw@
3978          \global\dimen\tw@\dp\count@ \fi
3979 %    \end{macrocode}
3980 %    If the \texttt{colaction} option is given we write out status
3981 %    information about the current column, otherwise the next command
3982 %    does nothing.
3983 % \changes{v1.8e}{2014/04/23}{Support \cs{docolaction}}
3984 %    \begin{macrocode}
3985        \mc@col@status@write
3986 %    \end{macrocode}
3987 %    The typeset box followed by the column rule material
3988 %    \begin{macrocode}
3989        \box\count@
3990        \hss{\columnseprulecolor\vrule
3991               \@width\columnseprule}\hss}%
3992 %    \end{macrocode}
3993 %    As you will have noticed, we started with box register
3994 %    |\mult@gfirstbox|  (i.e.\
3995 %    the left column). So this time |\count@| looped through 2,
3996 %    4,\ldots\ (plus the appropriate offset).
3997 %    Finally we add box |\mult@rightbox| and we are done.
3998 % \changes{v1.5a}{1992/11/04}{New box mechanism}
3999 % \changes{v1.6a}{2003/03/15}{Preparing for adjusting \cs{prevdepth}}
4000 %    Again we may have to update |\dimen\tw@|.
4001 %    \begin{macrocode}
4002      \ifdim\dp\mult@rightbox>\dimen\tw@
4003        \global\dimen\tw@\dp\mult@rightbox \fi
4004 %    \end{macrocode}
4005 %    If the \texttt{colaction} option is given we write out status
4006 %    information about the last column, otherwise the next command
4007 %    does nothing.
4008 % \changes{v1.8e}{2014/04/23}{Support \cs{docolaction}}
4009 %    \begin{macrocode}
4010      \mc@lastcol@status@write
4011      \box\mult@rightbox
4013 %    \end{macrocode}
4014 %  \end{macro}
4016 %  \begin{macro}{\RL@column@boxes}
4017 %    Assembling the boxes for right to left typesetting is far more
4018 %    complicated. When I first tried to build a solution for this my
4019 %    thinking was that all that is necessary to do is to reverse the
4020 %    order of the columns. But such an approach produces a subtle bug:
4021 %    If we work this way then the first column put on the page will be
4022 %    the last column of the text to read. and this means that the
4023 %    order in which \TeX{} executes write statements or assembles mark
4024 %    material will not happen in the order of the textual flow. So if,
4025 %    for example each column contains a section command then these
4026 %    sections will appear in reverse order in the table of content.
4028 %    For this reason some amount of gymnastics is needed to add the
4029 %    columns in their natural flow.
4030 %    \begin{macrocode}
4031 \def\RL@column@boxes{%
4032 %    \end{macrocode}
4033 %    First step is to put all rules in the right place (without adding
4034 %    the comes which are instead represented by a space of |\hsize|.
4035 %    \begin{macrocode}
4036      \process@cols\mult@gfirstbox{%
4037        \hskip\hsize
4038        \hss{\columnseprulecolor\vrule
4039               \@width\columnseprule}\hss
4040      }%
4041      \hskip\hsize
4042 %    \end{macrocode}
4043 %    At this point in the code our typesetting reference point is at
4044 %    the right end of the rightmost column (or rather where that column
4045 %    should appear).
4047 %    We are now typesetting all columns by first backing up by their
4048 %    width (which is |\hsize|) then typesetting the box and then
4049 %    backing up again, but this time further, i.e., also across the
4050 %    column separation. That will then enable us to typeset the next
4051 %    column using the same approach until we are done with all but the
4052 %    final column.
4053 %    \begin{macrocode}
4054      \process@cols\mult@gfirstbox{%
4055        \ifdim\dp\count@>\dimen\tw@
4056          \global\dimen\tw@\dp\count@ \fi
4057        \hskip-\hsize
4058 %    \end{macrocode}
4060 % \changes{v1.8e}{2014/04/23}{Support \cs{docolaction}}
4061 %    \begin{macrocode}
4062        \mc@col@status@write
4063        \box\count@
4064        \hskip-\hsize
4065        \hskip-\columnsep
4066      }%
4067 %    \end{macrocode}
4068 %    The approach for the final column is similar only that we do not
4069 %    have to back up over any column gap.
4070 %    \begin{macrocode}
4071      \ifdim\dp\mult@rightbox>\dimen\tw@
4072        \global\dimen\tw@\dp\mult@rightbox \fi
4073      \hskip-\hsize
4074 %    \end{macrocode}
4076 % \changes{v1.8e}{2014/04/23}{Support \cs{docolaction}}
4077 %    \begin{macrocode}
4078      \mc@lastcol@status@write
4079      \box\mult@rightbox
4080      \hskip-\hsize
4081 %    \end{macrocode}
4082 %    However we do have to move the reference point to its right
4083 %    place: to make the rules appear at the expected places, we should
4084 %    get the typesetting position to the far right again. As we at the
4085 %    moment at the far left we skip to the far right like this:
4086 %    \begin{macrocode}
4087      \hskip\full@width
4089 %    \end{macrocode}
4090 %  \end{macro}
4092 %  \begin{macro}{\RLmulticolcolumns}
4093 %  \begin{macro}{\LRmulticolcolumns}
4094 %  \begin{macro}{\mc@align@columns}
4095 %    Macros to switch between left-right and right-left typesetting. In LR
4096 %    typesetting the |\LR@column@boxes| is used to combine
4097 %    the columns. When typesetting right to left the |\RL@column@boxes|
4098 %    is used instead.
4099 %    \begin{macrocode}
4100 \newcommand\RLmulticolcolumns
4101     {\let\mc@align@columns
4102          \RL@column@boxes}
4103 \newcommand\LRmulticolcolumns
4104     {\let\mc@align@columns
4105       \LR@column@boxes}
4106 %    \end{macrocode}
4107 %    The default is left-to-right:
4108 %    \begin{macrocode}
4109 \LRmulticolcolumns
4110 %    \end{macrocode}
4111 %  \end{macro}
4112 %  \end{macro}
4113 %  \end{macro}
4116 % \subsection{Supporting \texttt{\textbackslash docolaction}}
4118 % \changes{v1.8e}{2014/04/23}{Support \cs{docolaction}}
4120 %   Whenever we want to do something that depends on the current
4121 %   column we execute \verb=\docolaction=. This command takes one
4122 %   optional and three mandatory arguments. The mandatory ones denote
4123 %   what to do if this is a ``left'', ``middle'', or ``right'' column
4124 %   and the optional one is simply there to say what to do if we don't
4125 %   know (default is to use the ``left'' column action in that case).
4127 %  \begin{macro}{\mc@col@check@num}
4128 %   We use one counter \verb=\mc@col@check@num= to generate us unique
4129 %   label names. Each time we execute \verb=\docolaction= we increment
4130 %   this counter to get a new name.
4131 %    \begin{macrocode}
4132 \newcount\mc@col@check@num
4133 %    \end{macrocode}
4134 %  \end{macro}
4136 %   The generated ``labels'' are named
4137 %\begin{verbatim}
4138 %\mc@col-\the\mc@col@check@num
4139 %\end{verbatim}
4140 %   and they hold as values the
4141 %   numbers 1, 2, or 3 denoting the current column type.
4143 %  \begin{macro}{\docolaction}
4145 %    \begin{macrocode}
4146 \newcommand\docolaction[4][1]{%
4147  \ifx\mc@col@status@write\relax
4148      \PackageError{multicol}%
4149       {Option 'colaction' not selected}%
4150       {\string\docolaction\space
4151        requires the use of the 'colaction'
4152        option on the package}%
4153  \fi
4154  \global\advance\mc@col@check@num\@ne
4155  \edef\mc@col@type{\expandafter\ifx
4156    \csname mc@col-\the\mc@col@check@num
4157    \endcsname\relax
4158                    0\else
4159    \csname mc@col-\the\mc@col@check@num
4160    \endcsname
4161                     \fi}%
4162 %    \end{macrocode}
4163 %    We prefix with 0 so that an unknown label (that returns
4164 %   \verb=\relax=) will result in case 0
4165 %    \begin{macrocode}
4166  \ifcase \mc@col@type\relax
4167 %    \end{macrocode}
4168 %    If column is unknown we use the default action or the action
4169 %   denoted by the optional argument (so that arg can take the value
4170 %   1, 2, 3).
4171 %    \begin{macrocode}
4172      \ifcase #1\or #2\or#3\or#4\fi
4173   \or
4174 %    \end{macrocode}
4175 %    Otherwise we know (or think we know) that this is a first, middle,
4176 %   or last column:
4177 %    \begin{macrocode}
4178      #2%  % 1 First col
4179   \or
4180      #3%  % 2 any middle col
4181   \or
4182      #4%  % 3 last col
4183   \else
4184     \ERROR
4185   \fi
4186 %    \end{macrocode}
4187 %    But how does the column number get associated with our label? We
4188 %   do do this by writing another line into the aux file at this point:
4189 %    \begin{macrocode}
4190   \edef\next{\write\@auxout
4191      {\string\mc@set@col@status
4192       {mc@col-\the\mc@col@check@num}%
4193       {\mc@col@type}}}%
4194   \next
4196 %    \end{macrocode}
4197 %  \end{macro}
4199 %   Because of extra data writing to the aux file the aux file will
4200 %   now contain something like the following after the document is
4201 %   processed the first time:
4202 %\begin{verbatim}
4203 %\relax
4204 %\mc@col@status{1}
4205 %\mc@set@col@status{lcol-1}{0}
4206 %\mc@col@status{2}
4207 %\mc@set@col@status{lcol-2}{0}
4208 %\mc@col@status{3}
4209 %\mc@set@col@status{lcol-3}{0}
4210 %\mc@col@status{1}
4211 %\mc@col@status{2}
4212 %\mc@col@status{3}
4213 %\mc@set@col@status{lcol-4}{0}
4214 %\end{verbatim}
4215 %   The \verb=\mc@col@status= line denotes the column type and has been
4216 %   written out just before corresponding the column box was placed
4217 %   onto the page.
4218 %   The\verb=\mc@set@col@status= lines have been written out as part
4219 %   of shipping the column boxes out, e.g.,
4220 %   \verb=\mc@set@col@status{lcol-1}{0}= was therefore somewhere within
4221 %   the first column as it appears between \verb=\mc@col@status{1}=
4222 %   and  \verb=\mc@col@status{2}=
4223 %   The second argument in that line is the value used in the previous
4224 %   run (or zero if there was no previous run. We can use this to
4225 %   determine if a rerun is necessary.
4227 %   Thus with this knowledge we can set things up to get the labels
4228 %   working.
4231 %  \begin{macro}{\mc@col@status}
4233 %   When the aux file is read in \verb=\mc@col@status= is used to set
4234 %   \verb=\mc@curr@col@status=:
4235 %    \begin{macrocode}
4236 \def\mc@col@status#1{%
4237     \gdef\mc@curr@col@status{#1}}
4238 %    \end{macrocode}
4239 %  \end{macro}
4243 %  \begin{macro}{\mc@set@col@status}
4245 %   And when \verb=\mc@set@col@status= is executed we can simply set
4246 %   up the label by associating it with the \verb=\mc@curr@col@status=
4247 %   and ignore the second argument:
4248 %    \begin{macrocode}
4249 \def\mc@set@col@status#1#2{%
4250   \global\expandafter\let\csname #1\endcsname
4251                          \mc@curr@col@status}
4252 %    \end{macrocode}
4253 %   The above definition is being used when the \texttt{.aux} file is
4254 %   read in at the beginning. At the end we need a different
4255 %   definition to test if another typesetting run is needed. There we
4256 %   compare the value used in the current run (stored in the second
4257 %   argument) with the value used on the next run. If those two values
4258 %   differ we set \verb=@tempswa= to false which will trigger the
4259 %   ``Label(s) may have changed'' warning.
4260 %    \begin{macrocode}
4261 \AtEndDocument{\def\mc@set@col@status#1#2{%
4262      \ifnum #2=\mc@curr@col@status\else
4263        \@tempswatrue
4264      \fi}%
4266 %    \end{macrocode}
4267 %  \end{macro}
4270 %  \begin{macro}{mc@firstcol}
4271 %   Finally, as part of determining in which column we are, we used a
4272 %   switch inside |\mc@col@status@write| to determine if we are in the
4273 %   first column or not.
4274 %  \begin{macrocode}
4275 \newif\ifmc@firstcol
4276 \mc@firstcoltrue
4277 %    \end{macrocode}
4278 %  \end{macro}
4279 % \end{multicols*}
4281 % \Finale
4283 \endinput