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'.
20 % \iffalse This is a METACOMMENT
22 %% Package `multicol' to use with LaTeX2e
23 %% Copyright 1989-2016 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
87 \ProvidesFile{multicol.dtx}
89 %<package>\NeedsTeXFormat{LaTeX2e}[1997/12/01]
90 %<package>\ProvidesPackage{multicol}
91 %<driver> \ProvidesFile{multicol.drv}
93 % \ProvidesFile{multicol.dtx}
94 [2017/04/11 v1.8q multicolumn formatting (FMi)]
99 % \changes{v1.5n}{1997/06/05}{Applied improvement of documentation,
100 % kindly done by Robin Fairbairns.}
101 % \changes{v1.4h}{1992/06/04}{Added mark tracing with
102 % tracingmulticols$\ge2$}
103 % \changes{v1.4a}{1992/02/11}{Added support for multicol in inner mode}
104 % \changes{v1.0d}{1989/05/17}{All lines shortened to 72 or less.}
105 % \changes{v1.0e}{1989/06/21}{Redefinition of description env. to use
106 % \cs{descriptionmargin}\quotechar=5pt
108 % \changes{v1.0f}{1989/07/11}{Changed \cs{z@} to 0pt in redefinition of
110 % \changes{v1.1a}{1989/09/20}{\cs{multicolssep} changed to \cs{multicolsep}.}
112 % \def\description{\list{}{\labelwidth 0pt \leftmargin\descriptionmargin
113 % \itemindent-\leftmargin \let\makelabel\descriptionlabel}}
114 % \newdimen\descriptionmargin \descriptionmargin=5pt
116 % \DoNotIndex{\@M,\@Mi,\@bsphack,\@cclv,\@colht,\@currlist,\@deferlist}
117 % \DoNotIndex{\@elt,\@esphack,\@floatplacement}
118 % \DoNotIndex{\@ifundefined,\@ifnextchar,\@makecol}
119 % \DoNotIndex{\@ne,\@outputpage,\@scolelt,\@spaces,\@tempb,\@tempcnta}
120 % \DoNotIndex{\@width}
121 % \DoNotIndex{\addvspace,\advance,\allowbreak}
122 % \DoNotIndex{\baselineskip,\begingroup,\box,\columnsep,\copy,\count}
123 % \DoNotIndex{\count@,\def,\dimen@,\divide,\docdate}
124 % \DoNotIndex{\edef,\eject,\egroup,\else,\endgroup,\endinput}
125 % \DoNotIndex{\fi,\fileversion,\filedate}
126 % \DoNotIndex{\gdef,\global}
127 % \DoNotIndex{\hbox,\hfil,\hrule,\ht,\hss}
128 % \DoNotIndex{\ifdim,\ifnum,\ifvoid,\ignorespaces,\insert,\immediate}
129 % \DoNotIndex{\let,\loop}
130 % \DoNotIndex{\maxdepth,\message,\multiply}
131 % \DoNotIndex{\newbox,\newcount,\newdimen,\newskip,\number,\newpage}
132 % \DoNotIndex{\outputpenalty,\p@,\penalty}
133 % \DoNotIndex{\relax,\repeat,\setbox,\skip,\space,\splitmaxdepth}
134 % \DoNotIndex{\splittopskip,\string,\sixt@@n}
135 % \DoNotIndex{\the,\thepage,\thr@@,\topskip,\tw@,\typeout}
136 % \DoNotIndex{\unvbox,\vbox,\vfill,\vsplit,\voidb@x,\vrule}
137 % \DoNotIndex{\write,\wd}
141 % \newcommand{\mc}{{\sf multicols}}
142 % \newcommand{\TUB}{{\sl TUGboat\/}}
143 % \newcommand{\TB}{{\sl\TeX book\/}}
146 % \setcounter{StandardModuleDepth}{2}
147 % \setcounter{collectmore}{3}
149 % \GetFileInfo{multicol.dtx}
150 % \title{An environment for multicolumn output\thanks{This file
151 % has version number \fileversion, last
152 % revised \filedate.}%
153 % \thanks{Note: This package is released under terms which affect
154 % its use in commercial applications. Please see the details at
155 % the top of the source file.}}
156 % \author{Frank Mittelbach\\
157 % {\rm Email:} see top of the source file}
158 % \date{Printed \today}
160 % \MaintainedByLaTeXTeam{tools}
164 % This article describes the use and the implementation of the \mc{}
165 % environment. This environment allows switching between
166 % one and multicolumn format on the same page. Footnotes are handled
167 % correctly (for the most part), but will be placed at the bottom of
168 % the page and not under each column. \LaTeX{}'s float mechanism,
169 % however, is partly disabled in this implementation. At the
170 % moment only page-wide floats (i.e., star-forms) can be used within
171 % the scope of the environment.
174 % \begin{multicols}{3}[\section*{Preface to version 1.8}]
175 % The 1.8 release improves on the balancing approach. If due to a
176 % limited number of break points (e.g., due to large objects) the
177 % balanced columns exceed the available vertical space, then
178 % balancing is canceled and a normal page is produced first. Some
179 % overflow is allowed (controlled by the parameter
180 % |\maxbalancingoverflow| which defaults to 12pt). This ensures
181 % that we only cut a normal page if we get enough material carried
184 % Also added was support for |\enlargethispage|. This means it is
185 % now possible to request a page to be artificially enlarged or
186 % shortened. Note that if you enlarge pages by more than one line
187 % you may have to increase the {\sf collectmore} counter value to
188 % ensure that enough material is being picked up.
190 % This command was used on the second page of this manual to shorten
191 % it by one line, in order to get rid of a number of widow lines on
192 % the following pages.
195 % Finally, version 1.8 adds the command |\docolaction| to help with
196 % more complicated actions that depend on the current column. This
197 % command expects 3 arguments: code that is executed if we are in
198 % the ``first'' column, code to execute if we end up in any
199 % ``middle'' column (if there are more than two) and finally code to
200 % execute if we are in the ``last'' column. Thus
202 % \docolaction{first}
205 % would typeset a different word depending the type of column this
206 % code is executed. Using it like this is probably pointless, but
207 % you can imagine applications like writing something into the
208 % nearest margin, etc.
210 % As this feature needs at least two \LaTeX{} runs to produce correct
211 % results and as it adds to the processing complexity it is only
212 % made available if one add the option \texttt{colaction} when
213 % loading the package.
218 % \begin{multicols}{3}[\section*{Preface to version 1.7
219 % (right to left support)}]
220 % The 1.7 release adds support for languages that are typeset
221 % right-to-left. For those languages the order of the columns on the page
222 % also need to be reversed---something that wasn't supported before. The next
223 % paragraph demonstrates the result (as it is typeset as if we are writing
224 % in a left-to-right language--- so read the rightmost column
225 % first). The change is initialized via
226 % |\RLmulticolcolumns| and returning to left-right (default)
227 % is done via |\LRmulticolcolumns|.
232 % \begin{multicols}{3}
233 % Right-to-left typesetting will only reverse the column orders. Any
234 % other support needed will have to be provided by other means,
235 % e.g., using appropriate fonts and reversing the writing directions
236 % within the columns. As footnotes are typeset in full measure the
237 % footnote rule needs to be redefined as if they are below a single
238 % column, i.e., using |\textwidth| not |\columnwidth|. For example:
240 %\renewcommand \footnoterule{%
241 % \kern-3pt\hbox to\textwidth
242 % {\hskip .6\textwidth
250 % \begin{multicols}{3}[\section*{Preface to version 1.5 + 1.6}]
252 % The 1.5 release contains two major changes: \mc{} will now
253 % support up to 10 columns and two more tuning possibilities have
254 % been added to the balancing routine. The balancing routine now
256 % of the resulting columns and rejects solutions that are larger
257 % than a certain threshold.
258 % At the same time \mc{} has been upgraded to run under \LaTeXe{}.
260 % Later changes to 1.5 include |\columnbreak| and |multicols*|.
262 % For version 1.6 micro-spacing around the boxes produced by \mc{}
263 % has been improved to allow for baseline-grid typesetting.
267 % \setcounter{collectmore}{2}
268 % \begin{multicols}{3}[\section{Introduction}]
270 % Switching between two-column and one-column layout is possible in
271 % \LaTeX{}, but every use of |\twocolumn| or |\onecolumn|
272 % starts a new page. Moreover, the last page of two-column output
273 % isn't balanced and this often results in an empty, or nearly
274 % empty, right column. When I started to write macros for {\sf
275 % doc.sty} (see ``The {\tt doc}--Option'', \TUB\
276 % volume 10~\#2, pp.~245--273) I thought that it would be nice to
278 % on the same page as the bibliography. And balancing the last page
279 % would not only look better, it also would save space; provided of
280 % course that it is also possible to start the next article on the
281 % same page. Rewriting the index environment was comparatively easy,
282 % but the next goal, designing an environment which takes care of
283 % footnotes, floats, etc., was a harder task. It took me a whole
284 % weekend\footnote{I started with the algorithm given in the \TeX
285 % book on page 417. Without this help a weekend would not have been
286 % enough. (This remark was made in the documentation of the initial
287 % release, since then several hundreds more hours went into
288 % improving the original code.)} to get together the few lines of
289 % code below and there is
290 % still a good chance that I missed something after all.
292 % Try it and, hopefully, enjoy it; and {\em please\/} direct bug
293 % reports and suggestions back to Mainz.
297 % \setcounter{collectmore}{0}
298 % \begin{multicols}{3}[\section{The User Interface}]
300 % To use the environment one simply says\\*[2mm]
301 % \hspace*{2mm}|\begin{multicols}{|\meta{number}|}|
302 % \hspace*{12mm}\meta{multicolumn text}\\
303 % \hspace*{2mm}|\end{multicols}|\\[2mm]
304 % where \meta{number} is the required number of columns and
305 %^^A\meta{multicolumn text}
306 % $\langle${\it multi\-column text\/}$\rangle$ may contain arbitrary
307 % \LaTeX{} commands, except that floats and marginpars are not
308 % allowed in the current implementation\footnote{This is dictated by
309 % lack of time. To implement floats one has to reimplement the
310 % whole \LaTeX{} output routine.}.
312 % \enlargethispage{-1\baselineskip}
314 % \DescribeMacro\premulticols
315 % As its first action, the {\sf multicols} environment measures the
316 % current page to determine whether there is enough room for some
317 % portion of multicolumn output. This is controlled by the
318 % \meta{dimen} variable |\premulticols| which can be changed by
319 % the user with ordinary \LaTeX{} commands.
320 % \DescribeMacro\multicolsep
321 % If the space is less than |\premulticols|, a new page is
322 % started. Otherwise, a |\vskip| of |\multicolsep| is
323 % added.\footnote{Actually the added space may be less because we use
324 % \cs{addvspace} (see the \LaTeX{} manual for further
325 % information about this command).}
327 % \DescribeMacro\postmulticols
328 % When the end of the \mc{} environment is encountered, an
329 % analogous mechanism is employed, but now we test whether there is a
330 % space larger than |\postmulticols| available. Again we add
331 % |\multicolsep| or start a new page.
333 % It is often convenient to spread some text over all columns, just
334 % before the multicolumn output, without any page break in between. To
335 % achieve this the \mc{} environment has an optional second
336 % argument which can be used for this purpose. For example, the text
337 % you are now reading was started with
339 % \begin{multicols}{3}
343 % If such text is unusually long (or short) the value of
344 % |\premulticols| might need adjusting to prevent a bad page
345 % break. We therefore provide a third argument which can be used to
346 % overwrite the default value of |\premulticols| just for this
347 % occasion. So if you want to combine some longer single column text
348 % with a multicols environment you could write
350 % \begin{multicols}{3}
352 % This index contains ...]
358 % \DescribeMacro\columnsep
359 % The space between columns is controlled by the length parameter
360 % |\columnsep|. The width for the individual columns is automatically
361 % calculated from this parameter and the current |\linewidth|. In this
362 % article a value of \textsf{\the\columnsep} was used.
365 % \DescribeMacro\columnseprule
366 % Separation of columns with vertical rules is achieved by setting the
367 % parameter |\columnseprule| to some positive value. In this
368 % article a value of {\sf.4pt} was used.
370 % \DescribeMacro\columnseprulecolor
371 % The color of the rules separating the columns can be specified through
372 % |\columnseprulecolor|. The default value is |\normalcolor|.
374 % \DescribeMacro\multicolbaselineskip
375 % Since narrow columns tend to need adjustments in interline spacing
376 % we also provide a \meta{skip} parameter called
377 % |\multicolbaselineskip| which is added to the
378 % |\baselineskip| parameter inside the \mc{}
379 % environment. Please use this parameter with care or leave it alone;
380 % it is intended only for package file designers since even small
381 % changes might produce totally unexpected changes to your document.
384 % \subsection{Balancing columns}
387 % Besides the previously mentioned parameters, some others are
388 % provided to influence the layout of the columns generated.
390 % Paragraphing in \TeX{} is controlled by several parameters. One of
391 % the most important is called |\tolerance|: this controls the
392 % allowed `looseness' (i.e.\ the amount of blank space between words).
393 % Its default value is 200 (the \LaTeX{} |\fussy|) which is too
394 % small for narrow columns. On the other hand the |\sloppy|
395 % declaration (which sets |\tolerance| to $10000=\infty$) is too
396 % large, allowing really bad spacing.\footnote{Look at the next
397 % paragraph, it was set with the \cs{sloppy} declaration.}
400 % \DescribeMacro\multicoltolerance \DescribeMacro\multicolpretolerance
401 % We therefore use a |\multicoltolerance| parameter for the
402 % |\tolerance| value inside the \mc{} environment. Its default value
403 % is 9999 which is less than infinity but `bad' enough for most
404 % paragraphs in a multicolumn environment. Changing its value should
405 % be done outside the \mc{} environment. Since |\tolerance| is set
406 % to |\multicoltolerance| at the beginning of every {\sf multicols}
407 % environment one can locally overwrite this default by assigning
408 % \verb*+\tolerance = +\meta{desired value}. There also exists a
409 % |\multicolpretolerance| parameter holding the value for
410 % |\pretolerance| within a \mc{} environment. Both parameters are
411 % usually used only by package designers.
414 % Generation of multicolumn output can be divided into two parts. In
415 % the first part we are collecting material for a page, shipping it
416 % out, collecting material for the next page, and so on. As a second
417 % step, balancing will be done when the end of the \mc{} environment
419 % In the first step \TeX{} might consider more material whilst
420 % finding the final column content than it actually uses when shipping out the
421 % page. This might cause a problem if a footnote is encountered in
422 % the part of the input considered, but not used, on the current page.
423 % In this case the footnote might show up on the current page, while the
424 % footnotemark corresponding to this footnote might be set on the next
425 % one.\footnote{The reason behind this behavior is the asynchronous
426 % character of the \TeX{} {\it page\_builder}.
428 % could be avoided by defining very complicated output
429 % routines which don't use \TeX{} primitives like
430 % \cs{insert} but do everything by hand.
431 % This is clearly beyond the scope of a weekend problem.}
432 % Therefore the \mc{} environment gives a warning
433 % message\footnote{This message will be generated even if there are no
434 % footnotes in this part of the text.} whenever it is unable to use
435 % all the material considered so far.
437 % If you don't use footnotes too often the chances of something
438 % actually going wrong are very slim, but if this happens you can help
439 % \TeX{} by using a |\pagebreak| command in the final document.
440 % Another way to influence the behavior of \TeX{} in this respect is
441 % given by the counter variable `{\sf collectmore}'. If you use the
442 % |\setcounter| declaration to set this counter to \meta{number},
443 % \TeX{} will consider \meta{number} more (or less) lines before
444 % making its final decision. So a value of $-1$ may solve all your
445 % problems at the cost of slightly less optimal columns.
448 % In the second step (balancing columns) we have other bells and
449 % whistles. First of all you can say |\raggedcolumns| if you
450 % don't want the bottom lines to be aligned.
451 % The default is |\flushcolumns|, so \TeX{} will normally try to
453 % the top and bottom baselines of all columns align.
455 % Additionally you can set another counter, the `{\sf unbalance}'
456 % counter, to some positive \meta{number}. This will make all but the
457 % right-most column \meta{number} of lines longer than they would
458 % normally have been. `Lines' in this context refer to normal text
459 % lines (i.e.\ one |\baselineskip| apart); thus, if your columns
461 % for example, you may need a higher \meta{number}
462 % to shift something from one column into another.
464 % Unlike `{\sf collectmore},' the `{\sf unbalance}' counter is reset
465 % to zero at the end of the environment so it only applies to one
468 % The two methods may be combined but I suggest using these features
469 % only when fine tuning important publications.
471 % Two more general tuning possibilities were added with version~1.5.
472 % \TeX{} allows to measure the badness of a column in terms of an
473 % integer value, where 0 means optimal and any higher value means a
474 % certain amount of extra white space. 10000 is considered to be
475 % infinitely bad (\TeX{} does not distinguish any further). In addition
476 % the special value 100000 means overfull (i.e., the column contains
477 % more text than could possibly fit into it).
479 % The new release now measures every generated column and ignores
480 % solutions where at least one column has a badness being larger than
481 % the value of the counter {\sf columnbadness}. The default value for
482 % this counter is 10000, thus \TeX{} will accept all solutions except
483 % those being overfull.
484 % By setting the counter to a smaller value you can force the algorithm
485 % to search for solutions that do not have columns with a lot of white
488 % However, if the setting is too low, the algorithm may not find any
489 % acceptable solution at all and will then finally choose the extreme
490 % solution of placing all text into the first column.
492 % Often, when columns are balanced, it is impossible to find a solution
493 % that distributes the text evenly over all columns. If that is the case
494 % the last column usually has less text than the others. In the earlier
495 % releases this text was stretched to produce a column with the same
496 % height as all others, sometimes resulting in really ugly looking
499 % In the new release this stretching is only done if the badness of
500 % the final column is not larger than the value of the counter
501 % {\sf finalcolumnbadness}. The default setting is 9999, thus preventing
502 % the stretching for all columns that \TeX{} would consider infinitely
503 % bad. In that case the final column is allowed to run short which gives
504 % a much better result.
506 % And there are two more parameters of some experimental nature, one
507 % called |\multicolovershoot| the other |\multicolundershoot|. They
508 % control the amount of space a column within the \mc{} environment is
509 % allowed to be ``too full'' or ``too short'' without affecting the
510 % column badness. They are set to 0pt and 2pt, respectively.
512 % Finally, when doing the balancing at the end, columns may become
513 % higher than the remaining available space. In that case the
514 % algorithm aborts and instead generates a normal page. However, if the
515 % amount is not too large, e.g., a line or so, then it might be better to
516 % keep everything on the same page instead of starting a new page with
517 % just one line after balancing. So the parameter
518 % |\maxbalancingoverflow| governs this process: only when the excess
519 % gets larger than its value balancing is aborted.
521 % \subsection{Not balancing the columns}
523 % Although this package was written to solve the problem of balancing
524 % columns, I got repeated requests to provide a version where all
525 % white space is automatically placed in the last column or
526 % columns. Since version v1.5q this now exists: if you use
527 % \texttt{multicols*} instead of the usual environment the columns on
528 % the last page are not balanced. Of course, this environment only
529 % works on top-level, e.g., inside a box one has to balance to
530 % determine a column height in absence of a fixed value.
533 % \subsection{Manually breaking columns}
535 % Another request often voiced was: ``How do I tell \LaTeX{} that it
536 % should break the first column after this particular line?''. The
537 % |\pagebreak| command (which works with the two-column option of
538 % \LaTeX{}) is of no use here since it would end the collection phase
539 % of \mc{} and thus all columns on that page. So with version 1.5u
540 % the |\columnbreak| command was added. If used within a paragraph it
541 % marks the end of the current line as the desired breakpoint. You can
542 % observe its effect on
543 % the previous page where three lines of text have been artificially
544 % forced into the second column (resulting in some white
545 % space between paragraphs in the first column).
547 % \subsection{Floats inside a \mc{} environment}
549 % Within the \mc{} environment the usual star float commands are
550 % available but their function is somewhat different as in the
551 % two-column mode of standard \LaTeX. Stared floats, e.g., {\tt
552 % figure*}, denote page wide floats that are handled in a similar
553 % fashion as normal floats outside the \mc{} environment. However,
554 % they will never show up on the page where they are encountered. In
555 % other words, one can influence their placement by specifying a
556 % combination of {\tt t}, {\tt b}, and/or {\tt p} in their optional
557 % argument, but {\tt h} doesn't work because the first possible place
558 % is the top of the next page. One should also note, that this means
559 % that their placement behavior is determined by the values of
560 % |\topfraction|, etc.\ rather than by |\dbl...|.
563 % \subsection{Support for right-to-left typesetting}
565 % In right-to-left typesetting the order of the columns on the page
566 % also need to be reversed, i.e., the first column has to appear on the far
567 % right and the last column on the left. This is supported through the
568 % commands |\RLmulticolcolumns| (switching to right-to-left typesetting)
569 % and |\LRmulticolcolumns| (switching to left-to-right typesetting) the
570 % latter being the default.
572 % \subsection{Warnings}
574 % Under certain circumstances the use of the \mc{} environment may
576 % warnings from \TeX{} or \LaTeX{}. Here is a list
577 % of the important ones and the possible cause:
578 % \begin{description}
580 % \item[] {\hspace*{-\labelsep}\tt Underfull \string\hbox\space
583 % As the columns are often very narrow \TeX{} wasn't able to find a
584 % good way to break the paragraph. Underfull denotes a loose line but
585 % as long as the badness value is below $10000$ the result is probably
589 % {\hspace*{-\labelsep}\tt Underfull \string\vbox\space ... while
590 % \string\output\space is active}
592 % If a column contains a character with an unusual depth, for
593 % example a `(', in the bottom line then this message may show up. It
594 % usually has no significance as long as the value is not more than a
597 % \item[] {\hspace*{-\labelsep}\tt LaTeX Warning: I moved some lines
600 % As mentioned above, \mc{} sometimes screws up the footnote
601 % numbering. As a precaution, whenever there is a footnote on a
602 % page where \mc{} had to leave a remainder for the following
603 % page this warning appears. Check the footnote numbering on this
604 % page. If it turns out that it is wrong, you have to manually break
605 % the page using |\newpage| or |\pagebreak[..]|.
607 % \item[] {\hspace*{-\labelsep}\tt Floats and marginpars not allowed
608 % inside `multicols' environment!}
610 % This message appears if you try to use the |\marginpar| command or
611 % an unstarred version of the {\sf figure} or {\sf table} environment.
612 % Such floats will disappear!
614 % \item[] {\hspace*{-\labelsep}\tt Very deep columns!
615 % Grid alignment might be broken}
617 % This message can only appear if the option \texttt{grid} was
618 % chosen. In that case it will show up if a column has a very large
619 % depth so that \mc{} is unable to back up to its baseline. This
620 % is only relevant if one tries to produce a document where all
621 % text lines are aligned at an invisible grid, something that
622 % requires careful adjustment of many parameters and macros, e.g.,
623 % heading definitions.
628 % \subsection{Tracing the output}
630 % To understand the reasoning behind the decisions \TeX{} makes when
631 % processing a \mc{} environment, a tracing mechanism is provided.
632 % If you set the counter `\texttt{tracingmulticols}'
633 % to a positive \meta{number} you then
634 % will get some tracing information on the terminal and in the
636 % \begin{description}
637 % \item[$\meta{number}=1$.] \TeX{} will now tell you, whenever it
638 % enters or leaves a \mc{} environment, the number of columns it
639 % is working on and its decision about starting a new page before
640 % or after the environment.
641 % \item[$\meta{number}=2$.]
642 % In this case you also get information from the balancing routine:
643 % the heights tried for the left and right-most columns,
644 % information about shrinking if the |\raggedcolumns|
645 % declaration is in force and the value of the `{\sf unbalance}'
646 % counter if positive.
647 % \item[$\meta{number}= 3$.] Setting \meta{number}\pagebreak[2] to
648 % this value will additionally trace the mark handling
649 % algorithm. It will show what marks are found, what marks are
650 % considered, etc. To fully understand this information you will
651 % probably have to read carefully trough the implementation.
652 % \item[$\meta{number}\geq 4$.] Setting \meta{number}\pagebreak[2] to
653 % such a high value will additionally place an |\hrule| into your
654 % output, separating the part of text which had already been
655 % considered on the previous page from the rest. Clearly this
656 % setting should {\em not\/} be used for the final output. It will
657 % also activate even more debugging code for mark handling.
663 % \begin{multicols}{3}[\section{Prefaces to older versions}
664 % \subsection{Preface to version 1.4}]
666 % Beside fixing some bugs as mentioned in the {\sf multicol.bug} file
667 % this new release enhances the \mc{} environment by allowing for
668 % balancing in arbitrary contexts. It is now, for example, possible
669 % to balance text within a \mc{} or a {\sf minipage} as shown in
670 % \ref{tab:newcmds} where a {\sf multicols} environment within a
671 % {\sf quote} environment was used. It is now even possible to nest
672 % \mc{} environments.
674 % The only restriction to such inner \mc{} environments (nested, or
675 % within \TeX's internal vertical mode) is that such variants will
676 % produce a box with the balanced material in it, so that they can
677 % not be broken across pages or columns.
679 % Additionally I rewrote the algorithm for balancing so that it will
680 % now produce slightly better results.
682 % I updated the source documentation but like to apologize in
683 % advance for some `left over' parts that slipped through the
686 % A note to people who like to improve the balancing algorithm of
687 % \mc{}: The balancing routine is now placed into a single macro
688 % which is called |\balance@columns|. This means that one can easily
689 % try different balancing routines by rewriting this macro. The
690 % interface for it is explained in table \ref{tab:balance}. There are
691 % several improvements possible, one can think of integrating the
692 % |\badness| function of \TeX3, define a faster algorithm for finding
693 % the right column height, etc. If somebody thinks he/she has an
694 % enhancement I would be pleased to learn about it. But please obey
695 % the copyright notice and don't change {\sf multicol.dtx} directly!
698 % \begin{multicols}{2}
700 % The macro |\balance@columns| that contains the code for balancing
701 % gathered material is a macro without parameters. It assumes that
702 % the material for balancing is stored in the box |\mult@box| which
703 % is a |\vbox|. It also ``knows'' about all parameters set up by the
704 % \mc{} environment, like |\col@number|, etc. It can also assume
705 % that |\@colroom| is the still available space on the current page.
707 % When it finishes it must return the individual columns in boxes
708 % suitable for further processing with |\page@sofar|. This means
709 % that the left column should be stored in box register
710 % |\mult@gfirstbox|, the next
711 % in register |\mult@firstbox|${}+2$, \ldots,
712 % only the last one as an exception in
713 % register |\mult@grightbox|. Furthermore it has to set up
715 % |\kept@firstmark| and |\kept@botmark| to hold the values for the
716 % first and bottom mark as found in the individual columns. There
717 % are some helper functions defined in section \ref{sec:v14} which
718 % may be used for this. Getting the marks right ``by hand'' is
719 % non-trivial and it may pay off to first take a look at the
720 % documentation and implementation of |\balance@columns| below
721 % before trying anew.
726 % \caption{Interface description for \cs{balance@columns}}
727 % \label{tab:balance}
731 % \begin{multicols}{3}[\subsection{Preface to version 1.2}]
733 % After the article about the \mc{} environment was published in
734 % \TUB\ 10\#3, I got numerous requests for these macros. However, I
735 % also got a changed version of my style file, together with a
736 % letter asking me if I would include the changes to get better
737 % paragraphing results in the case of narrow lines. The main
738 % differences to my original style option were additional parameters
739 % (like |\multicoladjdemerits| to be used for |\adjdemerits|, etc.)
740 % which would influence the line breaking algorithm.
742 % But actually resetting such parameters to zero or even worse to a
743 % negative value won't give better line breaks inside the \mc{}
744 % environment. \TeX{}s line breaking algorithm will only look at
745 % those possible line breaks which can be reached without a badness
746 % higher than the current value of |\tolerance| (or |\pretolerance|
747 % in the first pass). If this isn't possible, then, as a last
748 % resort, \TeX{} will produce overfull boxes. All those (and only
749 % those) possible break points will be considered and finally the
750 % sequence which results in the fewest demerits will be chosen. This
751 % means that a value of $-1000$ for |\adjdemerits| instructs \TeX{}
752 % to prefer visibly incompatible lines instead of producing better
755 % However, with \TeX{} 3.0 it is possible to get decent line breaks
756 % even in small columns by setting |\emergencystretch| to an
757 % appropriate value. I implemented a version which is capable of
758 % running both in the old and the new \TeX{} (actually it will
759 % simply ignore the new feature if it is not available). The
760 % calculation of |\emergencystretch| is probably incorrect. I
761 % made a few tests but of course one has to have much more experience
762 % with the new possibilities to achieve the maximum quality.
764 % Version 1.1a had a nice `feature': the penalty for using the
765 % forbidden floats was their ultimate removal from \LaTeX{}s
766 % |\@freelist| so that after a few |\marginpar|s inside the \mc{}
767 % environment floats where disabled forever. (Thanks to Chris
768 % Rowley for pointing this out.) I removed this misbehaviour and at
769 % the same time decided to allow at least floats spanning all
770 % columns, e.g., generated by the |figure*| environment. You can
771 % see the new functionality in table~\ref{tab:newcmds} which was
772 % inserted at this very point.
775 % \setlength{\multicolsep}{0pt}
777 % \begin{multicols}{2}
778 % |\setemergencystretch|: This is a hook for people who like
779 % to play around. It is supposed to set the
780 % |\emergencystretch| \meta{dimen} register provided in the
781 % new \TeX{} 3.0. The first argument is the number of columns and
782 % the second one is the current |\hsize|. At the moment the
783 % default definition is $4\mbox{\tt pt} \times |#1|$, i.e.\ the
784 % |\hsize| isn't used at all. But maybe there are better
787 % \setlength{\emergencystretch}{20pt} |\set@floatcmds|: This is
788 % the hook for the experts who like to implement a full float
789 % mechanism for the \mc{} environment. The |@| in the name
790 % should signal that this might not be easy.
795 % \caption[]{The new commands of {\sf multicol.sty} version 1.2.
796 % Both commands might be removed if good solutions to these
797 % open problems are found. I hope that these commands will
798 % prevent that nearly identical style files derived from
799 % this one are floating around.}
800 % \label{tab:newcmds}
802 % However single column floats are still forbidden and I don't think
803 % I will have time to tackle this problem in the near future. As an
804 % advice for all who want to try: wait for \TeX{} 3.0. It has a few
805 % features which will make life much easier in multi-column
806 % surroundings. Nevertheless we are working here at the edge of
807 % \TeX{}s capabilities, really perfect solutions would need a
808 % different approach than it was done in \TeX{}s page builder.
810 % The text below is nearly unchanged, I only added documentation at
811 % places where new code was added.
814 % \changes{v1.5l}{1996/01/13}{Try hard to explain unresolved reference
815 % that happens if \cs{OnlyDescription} is used}
817 % \StopEventually{\PrintIndex \PrintChanges
819 % \typeout{**********************************}
820 % \typeout{* Info: Typesetting this document with
821 % \protect\OnlyDescription\space will}
822 % \typeout{* Info: result in one unresolved
823 % reference to `sec:v14'.}
824 % \typeout{* Info: --- tough, it's just not there in this case!}
825 % \typeout{**********************************}
830 % \begin{multicols}{2}[\section{The Implementation}
831 % We are now switching to two-column output to show the
832 % abilities of this environment (and bad layout decisions).
833 % \subsection{The documentation driver file}
839 % The next bit of code contains the documentation driver file for
840 % \TeX{}, i.e., the file that will produce the documentation you are
841 % currently reading. It will be extracted from this file by the {\tt
843 % Since this is the first code in this file one can produce the
845 % simply by running \LaTeX{} on the \texttt{.dtx} file.
848 \documentclass{ltxdoc}
850 % We use the \texttt{balancingshow} option when loading \mc{} so
851 % that full tracing is produced. This has to be done before the
852 % \texttt{doc} package is loaded, since \texttt{doc} otherwise
853 % requires \mc{} without any options.
855 \usepackage{multicol}[1999/05/25]
858 % First we set up the page layout suitable for
861 \setlength{\textwidth}{39pc}
862 \setlength{\textheight}{54pc}
863 \setlength{\parindent}{1em}
864 \setlength{\parskip}{0pt plus 1pt}
865 \setlength{\oddsidemargin}{0pc}
866 \setlength{\marginparwidth}{0pc}
867 \setlength{\topmargin}{-2.5pc}
868 \setlength{\headsep}{20pt}
869 \setlength{\columnsep}{1.5pc}
871 % We want a rule between columns.
873 \setlength\columnseprule{.4pt}
875 % We also want to ensure that a new \mc{} environment finds enough
876 % space at the bottom of the page.
878 \setlength\premulticols{6\baselineskip}
880 % When balancing columns we disregard solutions that
881 % are too bad. Also, if the last column is too bad
882 % we typeset it without stretch.
884 \setcounter{columnbadness}{7000}
885 \setcounter{finalcolumnbadness}{7000}
887 % The index is supposed to come out in four columns.
888 % And we don't show macro names in the margin.
890 \setcounter{IndexColumns}{4}
891 \let\DescribeMacro\SpecialUsageIndex
892 \let\DescribeEnv\SpecialEnvIndex
893 \renewcommand\PrintMacroName[1]{}
895 %\DisableCrossrefs % Partial index
896 \RecordChanges % Change log
898 % Line numbers are very small for this article.
900 \renewcommand{\theCodelineNo}
901 {\scriptsize\rm\arabic{CodelineNo}}
902 \settowidth\MacroIndent{\scriptsize\rm 00\ }
906 {****************************************
907 ^^J* Expect some Under- and overfull boxes.
908 ^^J****************************************}
909 \DocInput{multicol.dtx}
917 % \begin{multicols}{2}[\subsection{Identification and
918 % option processing}]
921 % We start by identifying the package. Since it makes use of features
922 % only available in \LaTeXe{} we ensure that this format is available.
923 % (Now this is done earlier in the file.)
926 % \NeedsTeXFormat{LaTeX2e}
927 % \ProvidesPackage{multicol}[..../../..
928 % v... multicolumn formatting]
931 %^^A \subsection{Option processing}
933 % Next we declare options supported by \mc{}. Two-column mode
934 % and \mc{} do not work together so we warn about possible
935 % problems. However, since you can revert to |\onecolumn|
936 % in which case \mc{} does work, we don't make this an error.
938 \DeclareOption{twocolumn}
939 {\PackageWarning{multicol}{May not work
940 with the twocolumn option}}
942 % Tracing is done using a counter. However
943 % it is also possible to invoke the tracing
944 % using the options declared below.
946 \newcount\c@tracingmulticols
947 \DeclareOption{errorshow}
948 {\c@tracingmulticols\z@}
949 \DeclareOption{infoshow}
950 {\c@tracingmulticols\@ne}
951 \DeclareOption{balancingshow}
952 {\c@tracingmulticols\tw@}
953 \DeclareOption{markshow}
954 {\c@tracingmulticols\thr@@}
955 \DeclareOption{debugshow}
956 {\c@tracingmulticols5\relax}
958 % The next option is intended for typesetting on a |\baselineskip|
959 % grid. Right now it doesn't do anything other than warning if it
960 % thinks that the grid got lost.
961 % \changes{v1.6a}{2003/03/15}{New option grid}
963 \let\mc@gridwarn\maxdimen
964 \DeclareOption{grid}{\def\mc@gridwarn{\maxdepth}}
967 % \changes{v1.8e}{2014/04/23}{Support \cs{docolaction}}
968 % Next option enables the |\docolaction| command. As this changes
969 % the \texttt{.aux} file content this is not automatically enabled.
971 \DeclareOption{colaction}{%
972 \def\mc@col@status@write{%
973 \protected@write\@auxout{}%
974 {\string\mc@col@status
975 {\ifmc@firstcol 1\else 2\fi}}%
977 \def\mc@lastcol@status@write{%
978 \protected@write\@auxout{}%
979 {\string\mc@col@status{3}}}%
981 \let\mc@col@status@write\relax
982 \let\mc@lastcol@status@write\relax
992 % \begin{multicols}{2}[\subsection{Starting and
993 % Ending the \mc{} Environment}]
995 % \begin{macro}{\multicols}
996 % As mentioned before, the \mc{} environment has one mandatory
997 % argument (the number of columns) and up to two optional ones. We
998 % start by reading the number of columns into the |\col@number|
1001 \def\multicols#1{\col@number#1\relax
1003 % If the user forgot the argument, \TeX{} will complain about a
1004 % missing number at this point. The error recovery mechanism will
1005 % then use zero, which isn't a good choice in this case. So we
1006 % should now test whether everything is okay. The minimum is two
1007 % columns at the moment.
1008 % \changes{v1.3b}{1990/10/09}{Minimum of two columns}
1010 \ifnum\col@number<\tw@
1011 \PackageWarning{multicol}%
1012 {Using `\number\col@number'
1013 columns doesn't seem a good idea.^^J
1014 I therefore use two columns instead}%
1017 % We have only enough box registers for ten columns, so we need to
1018 % check that the user hasn't asked for more.
1019 % \changes{v1.4k}{1992/06/27}{Maximum of 5 columns (temp)}
1020 % \changes{v1.5a}{1992/11/04}{Allow 10 columns again}
1022 \ifnum\col@number>10
1023 \PackageError{multicol}%
1025 {Current implementation doesn't
1026 support more than 10 columns.%
1028 I therefore use 10 columns instead}%
1031 % Within the environment we need a special version of the
1032 % kernel |\@footnotetext| command since the original sets the
1033 % the |\hsize| to |\columnwidth| which is not correct in the
1034 % multicol environment. Here |\columnwidth| refers to the width of
1035 % the individual column and the footnote should be in |\textwidth|.
1036 % Since |\@footnotetext| has a different definition inside a
1037 % minipage environment we do not redefine it directly. Instead we
1038 % locally set |\columnwidth| to |\textwidth| and call the original
1039 % (current) definition stored in |\orig@footnotetext|.
1040 % \changes{v1.5p}{1997/12/14}{Redefinition of \cs{@footnotetext}
1041 % only within env pr/2689.}
1042 % \changes{v1.5r}{1998/08/17}{Use \cs{@footnotetext} but with
1043 % local change to \cs{columnwidth}.}
1044 % \changes{v1.5w}{1999/10/21}{Make \cs{@footnotetext} long to allow
1045 % multi-paragraph footnotes.}
1046 % If the \mc{} environment is nested inside another \mc{}
1047 % environment then the redefinition has already happened. So be
1048 % better test for this situation. Otherwise, we will get a \TeX{}
1049 % stack overflow as this would generate a self-referencing definition.
1050 % \changes{v1.6e}{2004/02/14}{Avoid self-referencing definition of
1051 % \cs{@footnotetext} (pr/3618)}.
1053 \ifx\@footnotetext\mult@footnotetext\else
1054 \let\orig@footnotetext\@footnotetext
1055 \let\@footnotetext\mult@footnotetext
1058 % Now we can safely look for the optional arguments.
1060 \@ifnextchar[\mult@cols{\mult@cols[]}}
1066 % \begin{macro}{\mult@footnotetext}
1069 \long\def\mult@footnotetext#1{\begingroup
1070 \columnwidth\textwidth
1071 \orig@footnotetext{#1}\endgroup}
1075 % \begin{macro}{\mult@cols}
1076 % The |\mult@cols| macro grabs the first optional argument
1077 % (if any) and looks for the second one.
1079 \def\mult@cols[#1]{\@ifnextchar[%
1081 % This argument should be a \meta{dimen} denoting the minimum free
1082 % space needed on the current page to start the environment. If the
1083 % user didn't supply one, we use |\premulticols| as a
1087 {\mult@@cols{#1}[\premulticols]}}
1092 % \begin{macro}{\mult@@cols}
1093 % After removing all arguments from the input we are able
1094 % to start with |\mult@@cols|.
1096 \def\mult@@cols#1[#2]{%
1098 % First thing we do is to decide whether or not this is an
1099 % unbounded multicols environment, i.e. one that may split across
1100 % pages, or one that has to be typeset into a box. If we are in
1101 % \TeX's ``inner'' mode (e.g., inside a box already) then we have a
1102 % boxed version of multicols therefore we set the |@boxedmulticols|
1103 % switch to true. The \mc{} should start in vertical mode. If we
1104 % are not already there we now force it with |\par| since otherwise
1105 % the test for ``inner'' mode wouldn't show if we are in a box.
1106 % \changes{v1.4f}{1992/04/28}{\cs{par} added to allow for correct inner test}
1109 \ifinner \@boxedmulticolstrue
1111 % Otherwise we check |\doublecol@number|. This counter is zero
1112 % outside a multicols environment but positive inside (this happens
1113 % a little later on). In the second case we need to process the
1114 % current multicols also in ``boxed mode'' and so change the switch
1118 \ifnum \doublecol@number>\z@
1119 \@boxedmulticolstrue
1123 % Then we look to see if statistics are requested:
1126 {Starting environment with
1127 \the\col@number\space columns%
1129 % In boxed mode we add some more info.
1130 % \changes{v1.4f}{1992/04/28}{\cs{on@line} added to tracing info}
1132 \if@boxedmulticols\MessageBreak
1136 % Then we measure the current page to see whether a useful portion
1137 % of the multicolumn environment can be typeset. This routine
1138 % might start a new page.
1139 % \changes{v1.4a}{1992/02/14}{Forgotten braces added}
1143 % Now we output the first argument and produce vertical space
1144 % above the columns. (Note that this argument corresponds to the
1145 % first optional argument of the {\sf multicols} environment.)
1146 % For many releases this argument was typeset in a group to get
1147 % a similar effect as |\twocolumn[..]| where the argument is
1148 % also implicitly surrounded by braces. However, this conflicts
1149 % with local changes done by things like sectioning commands (which
1150 % account for the majority of commands used in that argument)
1151 % messing up vertical spacing etc.\ later in the document so that
1152 % from version v1.5q on this argument is again typeset at the outer
1154 % \changes{v1.4e}{1992/03/16}{Typeset optional arg inside group}
1155 % \changes{v1.5q}{1998/01/19}{And removed the group again six years later}
1157 #1\par\addvspace\multicolsep
1159 % When the last line of a paragraph had a positive depth then this
1160 % depth normally taken into account by the baselineskip calculation
1161 % for the next line. However, the columns produced by a following
1162 % \texttt{multicol} are rigid and thus the distance from the
1163 % baseline of a previous text line to the first line in a
1164 % \texttt{multicol} would differ depending on the depth of the
1165 % previous line. To account for this we add a negative space unless
1166 % the depth is \texttt{-1000pt} which signals something special to
1167 % \TeX and is not supposed to be a real depth.
1168 % \changes{v1.5z1}{2003/02/17}{Add a kern to cancel potential depth of
1171 \ifdim \prevdepth = -\@m\p@
1174 % The actual generation of this corrective space is a little bit
1175 % more complicated as it doesn't make sense to always back up to
1176 % the previous baseline (in case an object with a very large depth
1177 % was placed there, e.g., a centered tabular). So we only back up
1178 % to the extend that we are within the |\baselineskip| grid. We
1179 % know that the box produced by \mc{} has |\topskip| at its top so
1180 % that also needs to be taken into account.
1181 % \changes{v1.6a}{2003/03/15}{Adjust spacing}
1183 \@tempcnta\prevdepth
1184 \@tempcntb\baselineskip
1185 \divide\@tempcnta\@tempcntb
1186 \advance\@tempcnta\@ne
1188 \advance\dimen@ -\@tempcnta\baselineskip
1189 \advance\dimen@ \topskip
1193 % We start a new grouping level to hide all subsequent changes
1194 % (done in |\prepare@multicols| for example).
1199 % If we are in boxed mode we now open a box to typeset all material
1200 % from the multicols body into it, otherwise we simply go ahead.
1201 % \changes{v1.4g}{1992/05/07}{\cs{global} was probably wrong but at least
1205 \setbox\mult@box\vbox\bgroup
1208 % \changes{v1.8c}{2013/11/03}{Add \cs{color@setgroup} to prevent color leak}
1212 % \changes{v1.5?}{1994/?/?}{Penalty moved to later point}
1213 % We may have to reset some parameters at this point,
1214 % perhaps |\@parboxrestore|
1215 % would be the right action but I leave it for the moment.
1216 % \changes{v1.4l}{1992/08/17}{\cs{@totalleftmargin} now in
1217 % \cs{prepare@multicols}}
1221 % We finish by suppressing initial spaces.
1227 % \begin{macro}{\if@boxedmulticols}
1228 % Here is the switch and the box for ``boxed'' multicols code.
1230 \newif\if@boxedmulticols
1231 \@boxedmulticolsfalse
1236 % \begin{macro}{\enough@room}
1237 % \changes{v1.0c}{1989/05/12}{Penalty 0 added to empty the contribution
1239 % The |\enough@room| macro used
1240 % above isn't perfect but works reasonably well in this context. We
1241 % measure the free space on the current page by subtracting
1242 % |\pagetotal| from |\pagegoal|. This isn't entirely
1243 % correct since it doesn't take the `shrinking' (i.e.\
1244 % |\pageshrink|) into account. The `recent contribution list'
1245 % might be nonempty so we start with |\par| and an explicit
1246 % |\penalty|.\footnote{See the documentation of
1247 % \cs{endmulticols} for further details.}
1248 % Actually, we use |\addpenalty| to ensure that a following
1249 % |\addvspace| will `see' the vertical space that might be
1251 % The use of |\addpenalty| will have the effect that all items from
1252 % the recent contributions will be moved to the main vertical list
1253 % and the |\pagetotal| value will be updated correctly. However,
1254 % the penalty will be placed in front of any dangling glue item
1255 % with the result that the main vertical list may already be
1256 % overfull even if \TeX{} is not invoking the output routine.
1257 % \changes{v1.3b}{1990/10/09}{Do \cs{penalty} with \cs{addpenalty}}
1258 % \changes{v1.4e}{1992/03/16}{But ignore \cs{@nobreak} in \cs{addpenalty}}
1260 \def\enough@room#1{%
1262 % Measuring makes only sense when we are not in ``boxed mode'' so
1263 % the routine does nothing if the switch is true.
1265 \if@boxedmulticols\else
1268 % \label{mac:enoughroom}
1269 % To empty the contribution list the first release contained a
1270 % penalty zero but this had the result that |\addvspace| couldn't
1271 % detect preceding glue. So this was changed to |\addpenalty|. But
1272 % this turned out to be not enough as |\addpenalty| will not add a
1273 % penalty when |@nobreak| is true. Therefore we force this switch
1274 % locally to false. As a result there may be a break between
1275 % preceding text and the start of a multicols environment, but this
1276 % seems acceptable since there is the optional argument for exactly
1279 \bgroup\@nobreakfalse\addpenalty\z@\egroup
1280 \page@free \pagegoal
1281 \advance \page@free -\pagetotal
1283 % To be able to output the value we need to assign it to a register
1284 % first since it might be a register (default) in which case we
1285 % need to use |\the| or it might be a plain value in which case
1286 % |\the| would be wrong.
1287 % \changes{v1.5e}{1994/05/26}{Assign arg to skip register to be able
1292 % Now we test whether tracing information is required:
1295 {Current page:\MessageBreak
1297 \the\pagegoal: used \the\pagetotal
1298 \space -> free=\the\page@free
1300 needed \the\@tempskipa
1303 % Our last action is to force a page break if there isn't enough
1306 \ifdim \page@free <#1\newpage \fi
1311 % \begin{macro}{\prepare@multicols}
1312 % When preparing for multicolumn output several things must
1315 \def\prepare@multicols{%
1317 % We start saving the current |\@totalleftmargin| and then
1318 % resetting the |\parshape| in case we are inside some list
1319 % environment. The correct indentation for the \mc{} environment in
1320 % such a case will be produced by moving the result to the right by
1321 % |\multicol@leftmargin| later on. If we would use the value of of
1322 % |\@totalleftmargin| directly then lists inside the \mc{}
1323 % environment could cause a shift of the output.
1324 % \changes{v1.4l}{1992/08/17}{saved \cs{@totalleftmargin}}
1326 \multicol@leftmargin\@totalleftmargin
1327 \@totalleftmargin\z@
1330 % We also set the register |\doublecol@number| for later use. This
1331 % register should contain $2\times |\col@number|$. This is also an
1332 % indicator that we are within a \mc{} environment as mentioned
1334 % \changes{v1.5a}{1992/11/04}{Add offset to \cs{doublecolnumber}}
1336 \doublecol@number\col@number
1337 \multiply\doublecol@number\tw@
1338 \advance\doublecol@number\mult@rightbox
1343 \let\l@kept@firstmark\kept@firstmark
1344 \let\l@kept@botmark\kept@botmark
1345 \global\let\kept@firstmark\@empty
1346 \global\let\kept@botmark\@empty
1349 % We add an empty box to the main vertical list to ensure that we
1350 % catch any insertions (held over or inserted at the top of the
1351 % page). Otherwise it might happen that the |\eject| is discarded
1352 % without calling the output routine. Inside the output routine we
1353 % remove this box again. Again this code applies only if we are on
1354 % the main vertical list and not within a box.
1355 % However, it is not enough to turn off interline spacing, we also
1356 % have to clear |\topskip| before adding this box, since |\topskip|
1357 % is always inserted before the first box on a page which would
1358 % leave us with an extra space of |\topskip| if \mc{} start on a
1360 % \changes{v1.3c}{1991/03/03}{\cs{null} inserted and removed in output}
1361 % \changes{v1.4a}{1992/02/11}{Conditional code for boxed mode added.}
1362 % \changes{v1.4o}{1992/11/22}{\cs{topskip} locally zeroed.}
1364 \nointerlineskip {\topskip\z@\null}%
1366 \global\setbox\partial@page\vbox
1369 % Now we have to make sure that we catch one special situation which
1370 % may result in loss of text! If the user has a huge amount of
1371 % vertical material within the first optional argument that is larger
1372 % then |\premulticols| and we are near the bottom of the page then it
1373 % can happen that not the |\eject| is triggering this special output
1374 % routine but rather the overfull main vertical list. In that case
1375 % we get another breakpoint through the |\eject| penalty. As a result
1376 % this special output routine would be called twice and the contents
1377 % of |\partial@page|, i.e.\ the material before the \mc{}
1378 % environment gets lost. There are several solutions to avoid this
1379 % problem, but for now we will simply detect this and inform the user
1380 % that he/she has to enlarge the |\premulticols| by using a suitable
1381 % value for the second argument.
1382 % \changes{v1.4a}{1992/02/11}{Checking for text losses.}
1385 \ifvoid\partial@page\else
1386 \PackageError{multicol}%
1387 {Error saving partial page}%
1388 {The part of the page before
1389 the multicols environment was
1390 nearly full with^^Jthe result
1391 that starting the environment
1392 will produce an overfull
1393 page. Some^^Jtext may be lost!
1394 Please increase \premulticols
1395 either generally or for this%
1396 ^^Jenvironment by specifying a
1397 suitable value in the second
1398 optional argument to^^Jthe
1399 multicols environment.}
1400 \unvbox\partial@page
1405 \global\setbox\last@line\lastbox
1408 % Finally we need to record the marks that are present within the
1409 % |\partial@page| so that we can construct correct first and bottom
1410 % marks later on. This is done by the following code.
1411 % \changes{v1.4a}{1992/02/14}{kept marks initiated}
1415 % Finally we have to initialize |\kept@topmark| which should
1416 % ideally be initialized with the mark that is current on ``top''
1417 % of this page. Unfortunately we can't use |\topmark| because this
1418 % register will not always contain what its name promises because
1419 % \LaTeX{} sometimes calls the output routine for float
1420 % management.\footnote{During such a call the \cs{botmark}
1421 % gets globally copied to \cs{topmark} by the \TeX{}
1422 % program.} Therefore we use the second best solution by
1423 % initializing it with |\firstmark|. In fact, for our purpose this
1424 % doesn't matter as we use |\kept@topmark| only to initialize
1425 % |\firstmark| and |\botmark| of a following page if we don't find
1426 % any marks on the current one.
1427 % \changes{v1.4i}{1992/06/18}{\cs{kept@topmark} initialized.}
1429 \global\let\kept@topmark\firstmark
1432 % The next thing to do is to assign a new value to |\vsize|.
1433 % \LaTeX{} maintains the free room on the page (i.e.\ the page
1434 % height without the space for already contributed floats) in the
1435 % register |\@colroom|. We must subtract the height of
1436 % |\partial@page| to put the actual free room into this
1439 \advance\@colroom-\ht\partial@page
1441 % Then we have to calculate the |\vsize| value to use during column
1442 % assembly. |\set@mult@vsize| takes an argument which allows to
1443 % make the setting local (|\relax|) or global (|\global|). The
1444 % latter variant is used inside the output routine below. At this
1445 % point here we have to make a local change to |\vsize| because we
1446 % want to get the original value for |\vsize| restored in case
1447 % this \mc{} environment ends on the same page where it has started.
1448 % \changes{v1.4p}{1992/11/26}{Use different \cs{vsize} setting}
1449 % \changes{v1.4p}{1992/11/26}{Code moved to \cs{set@mult@vsize}}
1451 \set@mult@vsize\relax
1453 % Now we switch to a new |\output| routine which will be used
1454 % to put the gathered column material together.
1456 \output{\multi@column@out}%
1458 % Finally we handle the footnote insertions. We have to multiply
1459 % the magnification factor and the extra skip by the number of
1460 % columns since each footnote reduces the space for every column
1461 % (remember that we have pagewide footnotes). If, on the other
1462 % hand, footnotes are typeset at the very end of the document, our
1463 % scheme still works since |\count\footins| is zero then, so it
1465 % To allow even further customization the setting of the |\footins|
1466 % parameters is done in a separate macro.
1467 % \changes{v1.5?}{1994/?/?}{Use \cs{init@mult@footins}}
1471 % For the same reason (pagewide footnotes), the \meta{dimen}
1472 % register controlling the maximum space used for footnotes isn't
1473 % changed. Having done this, we must reinsert all the footnotes
1474 % which are already present (i.e.\ those encountered when the
1475 % material saved in |\partial@page| was first processed). This
1476 % will reduce the free space (i.e.\ |\pagetotal|) by the
1477 % appropriate amount since we have changed the magnification
1478 % factor, etc.\ above.
1482 % Inside \mc{} a |\clearpage| is fairly useless as we aren't supporting
1483 % floats. In fact, it can cause harm as it doesn't know about the
1484 % |\partial@page| and may therefore result in making columns too long.
1485 % So we change that to bahve like |\newpage| but also check if there
1486 % are any deferred floats. If so, perhaps the user tried to place them through
1487 % that |\clearpage| (but that needs to be done before starting the \mc{}
1489 % \changes{v1.8q}{2017/04/11}{Make \cs{clearpage} behave like \cs{newpage} (pr/4511)}
1492 \ifx\@deferlist\@empty\else
1493 \PackageError{multicol}%
1494 {Deferred floats not cleared}%
1495 {A \string\clearpage\space inside multicols acts like
1496 \string\newpage\space and doesn't clear floats.\MessageBreak
1497 Move it before the multicols environment if you need it.}%
1501 % All the code above was only necessary for the unrestricted \mc{}
1502 % version, i.e.\ the one that allows page breaks. If we are within
1503 % a box there is no point in setting up special output routines or
1508 % But now we are coming to code that is necessary in all cases. We
1509 % assign new values to |\vbadness|, |\hbadness| and |\tolerance|
1510 % since it's rather hard for \TeX{} to produce `good' paragraphs
1511 % within narrow columns.
1512 % \changes{v1.2a}{1990/02/05}{\cs{vbadness} 10001 now.}
1514 \vbadness\@Mi \hbadness5000
1515 \tolerance\multicoltolerance
1517 % Since nearly always the first pass will fail we ignore it
1518 % completely telling \TeX{} to hyphenate directly. In fact, we now
1519 % use another register to keep the value for the multicol
1520 % pre-tolerance, so that a designer may allow to use
1522 % \changes{v1.2a}{1990/02/05}{\cs{pretolerance} -1 because it nearly never
1524 % \changes{v1.4e}{1992/03/20}{Using}
1526 \pretolerance\multicolpretolerance
1528 % For use with the new \TeX{} we set |\emergencystretch| to
1529 % $|\col@number| \times 4pt$. However this is only a guess
1530 % so at the moment this is done in a macro
1531 % |\setemergencystretch| which gets the current |\hsize|
1532 % and the number of columns as arguments. Therefore users are able
1533 % to figure out their own formula.
1534 % \changes{v1.2a}{1990/02/05}{\cs{setemergencystretch} added.}
1536 \setemergencystretch\col@number\hsize
1538 % Another hook to allow people adding their own extensions without
1539 % making a new package is |\set@floatcmds| which handles any
1540 % redefinitions of \LaTeX{}s internal float commands to work with
1541 % the \mc{} environment. At the moment it is only used to redefine
1542 % |\@dblfloat| and |\end@dblfloat|.
1543 % \changes{v1.2a}{1990/02/05}{\cs{set@floatcmds} added.}
1547 % Additionally, we advance |\baselineskip| by
1548 % |\multicolbaselineskip| to allow corrections for narrow
1551 \advance\baselineskip\multicolbaselineskip
1553 % \changes{v1.0e}{1989/06/21}{\cs{textwidth} changed to \cs{linewidth}.}
1554 % \changes{v1.0e}{1989/06/21}{So this file will
1555 % work with the `twocolumn' command.}
1556 % The |\hsize| of the columns is given by the formula:
1558 % { |\linewidth| - (|\col@number|-1)
1564 % The formula above has changed from release to release. We now
1565 % start with the current value of |\linewidth| so that the column
1566 % width is properly calculated when we are inside a minipage or a
1567 % list or some other environment.
1568 % This will be achieved with:
1570 \hsize\linewidth \advance\hsize\columnsep
1571 \advance\hsize-\col@number\columnsep
1572 \divide\hsize\col@number
1574 % We also set |\linewidth| and |\columnwidth| to |\hsize| In the past
1575 % |\columnwidth| was left unchanged. This is inconsistent,
1576 % but |\columnwidth| is used only by floats (which
1577 % aren't allowed in their current implementation) and by the
1578 % |\footnote| macro. Since we want pagewide
1579 % footnotes\footnote{I'm not sure that I really want pagewide
1580 % footnotes. But balancing of the last page can
1581 % only be achieved with this approach or with a
1582 % multi-path algorithm which is complicated and
1583 % slow. But it's a challenge to everybody to
1584 % prove me wrong! Another possibility is to
1585 % reimplement a small part of the {\it
1586 % fire\_up\/} procedure in \TeX{} (the program).
1587 % I think that this is the best solution if you
1588 % are interested in complex page makeup, but it
1589 % has the disadvantage that the resulting
1590 % program cannot be called \TeX{} thereafter.}
1591 % this simple trick saved us from rewriting the |\footnote|
1592 % macros. However, some applications referred to |\columnwidth| as
1593 % the ``width of the current column'' to typeset displays
1594 % (the \texttt{amsmath} package, for example) and to allow the use
1595 % of such applications together with \texttt{multicol} this is now
1598 % Before we change |\linewidth| to the new value we record its old
1599 % value in some register called |\full@width|. This value is
1600 % used later on when we package all columns together.
1601 % \changes{v1.0e}{1989/06/21}{Setting of \cs{columnwidth} removed.}
1602 % \changes{v1.5o}{1997/11/16}{Setting of \cs{columnwidth} added again
1605 \full@width\linewidth
1612 % \begin{macro}{\init@mult@footins}
1613 % This macro is used to set up the parameters associated
1614 % with footnote floats. It can be redefined by applications that
1615 % require different amount of spaces when typesetting footnotes.
1617 \def\init@mult@footins{%
1618 \multiply\count\footins\col@number
1619 \multiply\skip \footins\col@number
1624 % \begin{macro}{\set@mult@vsize}
1626 % Since we have to set |\col@umber| columns on one page,
1627 % each with a height of |\@colroom|, we have to assign
1629 % |\vsize| = |\col@number| \times |\@colroom|
1631 % in order to collect enough material before entering the
1632 % |\output| routine again. In fact we have to add another
1634 % (|\col@number|-1) \times (|\baselineskip|-|\topskip|)
1636 % if you think about it.
1637 % \changes{v1.4p}{1992/11/26}{Macro added.}
1639 \def\set@mult@vsize#1{%
1641 \@tempdima\baselineskip
1642 \advance\@tempdima-\topskip
1643 \advance\vsize\@tempdima
1644 \vsize\col@number\vsize
1645 \advance\vsize-\@tempdima
1647 % But this might not be enough since we use |\vsplit| later to
1648 % extract the columns from the gathered material. Therefore we add
1649 % some `extra lines,' one for each column plus a corrective action
1650 % depending on the value of the `\texttt{collectmore}' counter.
1651 % The final value is assigned globally if |#1| is |\global| because
1652 % we want to use this macro later inside the output routine too.
1653 % \changes{v1.6c}{2003/04/08}{Collect one line per column more}
1655 \advance\vsize\col@number\baselineskip
1657 \c@collectmore\baselineskip}
1662 % \begin{macro}{\multicol@leftmargin}
1663 % Here is the dimen register we need for saving away the outer
1664 % value of |\@totalleftmargin|.
1666 \newdimen\multicol@leftmargin
1670 % \begin{macro}{\endmulticols}
1671 % When the end of the \mc{} environment is sensed we have to
1672 % balance the gathered material. Depending on whether or not we are
1673 % inside a boxed multicol different things must happen. But first
1674 % we end the current paragraph with a |\par| command.
1676 \def\endmulticols{\par
1679 % In boxed mode we have to close the box in which we have gathered
1680 % all material for the columns. But before we do this we need to
1681 % remove any space at the end of the box as we don't want to use
1682 % this in balancing. Because of the |\color@endgroup| this can't be
1683 % done later in |\balance@columns| as the color command will hide
1685 % \changes{v1.8c}{2013/11/03}{Add \cs{color@endgroup} to prevent color leak}
1686 % \changes{v1.8f}{2014/06/19}{Discard spaces before adding \cs{color@endgroup}}
1688 \remove@discardable@items\color@endgroup\egroup
1690 % Now we call |\balance@columns| the routine that balances material
1691 % stored in the box |\mult@box|.
1692 % \changes{v1.5?}{1994/?/?}{Splitting off zero box moved to
1693 % \cs{balance@columns}}
1697 % After balancing the result has to be returned by the command
1698 % |\page@sofar|. But before we do this we reinsert any marks found
1699 % in box |\mult@box|.
1701 \return@nonemptymark{first}%
1703 \return@nonemptymark{bot}%
1709 \global\let\kept@firstmark
1711 \global\let\kept@botmark
1715 {Restore kept marks to\MessageBreak
1716 first: \meaning\kept@firstmark
1717 \MessageBreak bot\space\space:
1718 \meaning\kept@botmark }%
1721 % This finishes the code for the ``boxed'' case.
1725 % If there was a |\columnbreak| on the very last line all material
1726 % will have been moved to the |\colbreak@box|. Thus the the galley
1727 % will be empty and no output routine gets called so that the text
1728 % is lost. To avoid this problem (though unlikely) we check if the
1729 % current galley is empty and the |\colbreak@box| contains text and
1730 % if so return that to the galley. If the galley is non-empty any
1731 % material in |\colbreak@box| is added in the output routine since
1732 % it needs to be put in front.
1733 % \changes{v1.6d}{2003/04/17}{Catch problem with \cs{columnbreak} in
1736 \ifdim\pagegoal=\maxdimen
1737 \ifvoid\colbreak@box\else
1738 \mult@info\@ne{Re-adding forced
1739 break(s) for splitting}%
1740 \unvbox\colbreak@box\fi
1743 % If we are in an unrestricted \mc{} environment we end the current
1744 % paragraph above with |\par| but this isn't sufficient since \TeX{}s
1745 % {\it page\_builder} will not totally empty the contribution
1746 % list.\footnote{This once caused a puzzling bug where some of the
1747 % material was balanced twice, resulting in some overprints. The
1748 % reason was the \cs{eject} which was placed at the end of
1749 % the contribution list. Then the {\it page\_builder} was called
1750 % (an explicit \cs{penalty} will empty the contribution
1751 % list), but the line with the \cs{eject} didn't fit onto
1752 % the current page. It was then reconsidered after the output
1753 % routine had ended, causing a second break after one line.}
1754 % Therefore we must also add an explicit |\penalty|. Now the
1755 % contribution list will be emptied and, if its material doesn't
1756 % all fit onto the current page then the output routine will be
1757 % called before we change it.
1758 % \changes{v1.3b}{1990/10/09}{Do \cs{penalty} with \cs{addpenalty}}
1759 % \changes{v1.4e}{1992/03/16}{But ignore \cs{@nobreak} in \cs{addpenalty}}
1760 % \changes{v1.5c}{1993/04/18}{Again use \cs{penalty}}
1761 % At this point we need to use |\penalty| not |\addpenalty| to
1762 % ensure that a) the recent contributions are emptied and b) that
1763 % the very last item on the main vertical list is a valid break
1764 % point so that \TeX{} breaks the page in case it is overfull.
1768 % Now it's safe to change the output routine in order to balance
1771 \output{\balance@columns@out}%
1774 % If the \mc{} environment body was completely empty or if a
1775 % multi-page \mc{} just ends at a page boundary we have the unusual
1776 % case that the |\eject| will have no effect (since the main
1777 % vertical list is empty)---thus no output routine is called at
1778 % all. As a result the material preceding the \mc{} (stored in
1779 % |\partial@page| will get lost if we don't put this back by hand.
1780 % \changes{v1.4m}{1992/09/04}{Check \cs{partial@page} being emptied}
1782 \ifvbox\partial@page
1783 \unvbox\partial@page\fi
1785 % After the output routine has acted we restore
1786 % the kept marks to their initial value.
1788 \global\let\kept@firstmark\@empty
1789 \global\let\kept@botmark\@empty
1792 {Make kept marks empty}%
1796 % The output routine above will take care of the |\vsize| and
1797 % reinsert the balanced columns, etc. But it can't reinsert the
1798 % |\footnotes| because we first have to restore the
1799 % |\footins| parameter since we are returning to one column
1800 % mode. This will be done in the next line of code; we simply close
1801 % the group started in |\multicols|.
1803 % To fix an obscure bug which is the result of the current
1804 % definition of the |\begin| \ldots\ |\end| macros, we check that
1805 % we are still (logically speaking) in the \mc{} environment. If,
1806 % for example, we forget to close some environment inside the
1807 % \mc{} environment, the following |\endgroup| would be
1808 % incorrectly considered to be the closing of this environment.
1809 % \changes{v1.3c}{1991/03/14}{Check closing env.}
1811 \@checkend{multicols}%
1814 % We also set the `{\sf unbalance}' counter to its default. This is
1815 % done globally since \LaTeX{} counters are always changed this
1816 % way.\footnote{Actually, we are still in a group started by the
1817 % \cs{begin} macro, so \cs{global} must be used
1820 \global\c@unbalance\z@
1822 % Now it's time to return any footnotes if we are in unrestricted
1825 \if@boxedmulticols\else
1828 % We also take a look at the amount of free space on the current
1829 % page to see if it's time for a page break. The vertical space
1830 % added thereafter will vanish if |\enough@room| starts a new
1833 % But there is one catch. If the |\end{multicols}| is at the top of
1834 % which can happen if there is a break point just before it (such
1835 % as end ending environment) which was chosen. In that case we
1836 % would do the next page using the internal |\vsize| for multicol
1837 % collection which is a disaster. So we better catch this
1838 % case. Fortunately we can detect it by looking at |\pagegoal|.
1839 % \changes{v1.5x}{2000/05/05}{Detect and fix problem if a multicols
1840 % ends at the top of a page}
1842 \ifdim \pagegoal=\maxdimen
1843 \global\vsize\@colroom
1845 \enough@room\postmulticols
1848 \addvspace\multicolsep
1850 % There is one more thing to do: the balanced result of the
1851 % environment is supposed to have a |\prevdepth| of zero as we
1852 % backed up by its real prevdepth within |\page@sofar|. However if
1853 % the balancing happened in the output routine then \TeX{} reverts
1854 % to the |\prevdepth| that was current before the OR once the OR has
1855 % finished. In short |\prevdepth| is something you can't set
1856 % globally it is alway local to the current list being built. Thus
1857 % we need to set it back to zero here to avoid incorrect spacing.
1858 % \changes{v1.8h}{2014/09/12}{Set \cs{prevdepdth} for current vlist
1859 % when returning from multicols environment}
1863 % If statistics are required we finally report that we have
1864 % finished everything.
1869 \space(boxed mode)\fi
1875 % \begin{macro}{\c@unbalance}
1876 % \SpecialMainIndex{\c@collectmore}
1877 % \SpecialMainIndex{\col@number}
1878 % \SpecialMainIndex{\doublecol@number}
1879 % \SpecialMainIndex{\premulticols}
1880 % \SpecialMainIndex{\multicoltolerance}
1881 % \SpecialMainIndex{\multicolpretolerance}
1882 % \SpecialMainIndex{\page@free}
1883 % \SpecialMainIndex{\premulticols}
1884 % \SpecialMainIndex{\postmulticols}
1885 % \SpecialMainIndex{\multicolsep}
1886 % \SpecialMainIndex{\multicolbaselineskip}
1887 % \SpecialMainIndex{\partial@page}
1888 % Let us end this section by allocating all the registers used so
1891 \newcount\c@unbalance
1892 \newcount\c@collectmore
1894 % In the new \LaTeX{} release |\col@number| is already allocated by
1895 % the kernel, so we don't allocate it again.
1897 %\newcount\col@number
1898 \newcount\doublecol@number
1899 \newcount\multicoltolerance
1900 \newcount\multicolpretolerance
1901 \newdimen\full@width
1903 \newdimen\premulticols
1904 \newdimen\postmulticols
1905 \newskip\multicolsep
1906 \newskip\multicolbaselineskip
1907 \newbox\partial@page
1910 % And here are their default values:
1915 % To allow checking whether some macro is used within the \mc{}
1916 % environment the counter |\col@number| gets a default of |1|
1917 % outside the the environment.
1918 % \changes{v1.3d}{1991/10/23}{\cs{col@number} set to one}
1919 % \changes{v1.8o}{2016/02/08}{\cs{col@number} already initialized in the
1920 % kernel, so not initializing it in the package
1921 % in case the document is in two-column (pr/4435)}
1924 \multicoltolerance = 9999
1925 \multicolpretolerance = -1
1926 \premulticols = 50pt
1927 \postmulticols= 20pt
1928 \multicolsep = 12pt plus 4pt minus 3pt
1929 \multicolbaselineskip=0pt
1935 % \begin{multicols}{2}[\subsection{The output routines}]
1937 % We first start with some simple macros. When typesetting the page we
1938 % save the columns either in the box registers 0, 2, 4,\ldots\
1939 % (locally) or 1, 3, 5,\ldots\ (globally). This is \PlainTeX{} policy
1940 % to avoid an overflow of the save stack.
1942 % \begin{macro}{\process@cols}
1943 % Therefore we define a |\process@cols| macro to help us in
1944 % using these registers in the output routines below. It has two
1945 % arguments: the first one is a number; the second one is the
1946 % processing information. It loops starting with |\count@=#1|
1947 % (|\count@| is a scratch register defined in \PlainTeX),
1948 % processes argument |#2|, adds two to |\count@|,
1949 % processes argument |#2| again, etc.\ until |\count@| is
1950 % higher than |\doublecol@number|. It might be easier to
1951 % understand it through an example, so we define it now and
1952 % explain its usage afterwards.
1954 \def\process@cols#1#2{\count@#1\relax
1957 \typeout{Looking at box \the\count@}
1961 \ifnum\count@<\doublecol@number
1967 % \begin{macro}{\page@sofar}
1968 % We now define |\page@sofar| to give an example of the
1969 % |\process@cols| macro. |\page@sofar| should output everything
1970 % prepared by the balancing routine |\balance@columns|.
1974 % |\balance@columns| prepares its output in the even numbered
1975 % scratch box registers.
1976 % Now we output the columns gathered assuming that they are saved
1977 % in the box registers 2 (left column), 4 (second column), \ldots\
1978 % However, the last column (i.e.\ the right-most) should be saved in
1979 % box register 0.\footnote{You will see the reason for this numbering
1980 % when we look at the output routines
1981 % \cs{multi@column@out} and
1982 % \cs{balance@columns@out}.}
1983 % First we ensure that the columns have equal width. We use
1984 % |\process@cols| for this purpose, starting with
1985 % $|\count@|=|\mult@rightbox|$. Therefore |\count@| loops through
1986 % |\mult@rightbox|, $|\mult@rightbox| + 2$,\ldots
1987 % (to |\doublecol@number|).
1988 % \changes{v1.5a}{1992/11/04}{New box mechanism}
1990 \process@cols\mult@rightbox
1992 % We have to check if the box in question is void, because the
1993 % operation |\wd|\meta{number} on a void box will \emph{not} change
1994 % its dimension (sigh).
1995 % \changes{v1.5h}{1994/08/26}{Check for void boxes}
1996 % \changes{v1.5i}{1994/10/02}{But don't remove original code.}
1999 \setbox\count@\hbox to\hsize{}%
2004 % Now we give some tracing information.
2005 % \changes{v1.4l}{1992/08/17}{use \cs{multicol@leftmargin} instead of
2006 % \cs{@totalleftmargin}}
2007 % \changes{v1.6b}{2003/03/15}{Different info display}
2009 \count@\col@number \advance\count@\m@ne
2011 {Column spec: \the\full@width\space = indent
2012 + columns + sep =\MessageBreak
2013 \the\multicol@leftmargin\space
2014 + \the\col@number\space
2020 % At this point we should always be in vertical mode.
2022 \ifvmode\else\errmessage{Multicol Error}\fi
2024 % Now we put all columns together in an |\hbox| of width
2025 % |\full@width| (shifting it by |\multicol@leftmargin| to the right
2026 % so that it will be placed correctly if we are within a list
2028 % and separating the columns with a rule if desired.
2029 % \changes{v1.5a}{1992/11/04}{New box mechanism}
2030 % \changes{v1.5z}{2000/07/10}{Ensure that column rule has always
2032 % \changes{v1.6f}{2006/09/19}{Make the color of the rule a hook}
2033 % \changes{v1.4l}{1992/08/17}{use \cs{multicol@leftmargin} instead of
2034 % \cs{@totalleftmargin}}
2036 % The box containing the columns has a large height and thus will
2037 % always result in using |\lineskip| if the normal |\baselineskip|
2038 % calculations are used. We therefore better cancel that process.
2039 % \changes{v1.5z1}{2003/02/17}{Suppress interline glue at this point}
2043 % As mentioned earlier we want to have the reference point of the
2044 % box we put on the page being at the baseline of the last line of
2045 % the columns but we also want to ensure that the box has no depth
2046 % so that any following skip is automatically starting from that
2048 % We achieve this by recording the depths of all columns and then
2049 % finally backing up by the maximum. (perhaps a simpler method
2050 % would be to assemble the box in a register and set the depth of
2051 % that box to zero (not checked).
2053 % We need a global scratch register for this; using standard \TeX{}
2054 % conventions we choose |\dimen2| and initialize it with the depth
2055 % of the character ``p'' since that is one of the depths that
2056 % compete for the maximum.
2057 % \changes{v1.6a}{2003/03/15}{Preparing for adjusting \cs{prevdepth}}
2059 \setbox\z@\hbox{p}\global\dimen\tw@\dp\z@
2060 \moveright\multicol@leftmargin
2061 \hbox to\full@width{%
2063 % If the document is written in a language that is typeset right-to-left
2064 % then, of course, the multicol columns should be also typeset
2065 % right-to-left. To support this we call |\mc@align@columns| which
2066 % with execute different code depending on the typesetting direction.
2067 % \changes{v1.7b}{2011/12/18}{RL language support fixed}
2071 % The depths of the columns depend on their last lines. To ensure
2072 % that we will always get a similar look as far as the rules are
2073 % concerned we force the depth to be at least the depth of a
2074 % letter~`p' (which is what we set |\dimen2| to above).
2079 % The processed material might consist of a last line with a
2080 % descender in which case the |\prevdepth| will be
2081 % non-zero. However, this material is getting reformatted now so
2082 % that this value is likely to be wrong. We therefore normalize the
2083 % situation by pretending that the depth is zero. However, if |\page@sofar|
2084 % is being called inside the OR then setting |\prevdepth| here has
2085 % no longlasting effect, we therefore have to repeat this once we
2086 % return to the main vertical list. Here we set it only for those
2087 % cases where the command is used within a list and then followed by
2089 % \changes{v1.8g}{2014/08/24}{Resetting \cs{prevdepth} in the right place}
2093 % Now after typesetting the box we back up to its baseline by using
2094 % the value stored in |\dimen2| (which will hold the largest depth
2095 % found on any column).
2096 % \changes{v1.8g}{2003/03/15}{Now adjusting \cs{prevdepth}}
2100 % However, in case one of the columns was unusually deep \TeX{} may
2101 % have tried some corrective actions in which case backing up by
2102 % the saved value will not bring us back to the baseline. A good
2103 % indication for this is a depth of |\maxdepth| though it is not an
2104 % absolute proof. If the option \texttt{grid} is used
2105 % |\mc@gridwarn| will expand to this, otherwise to |\maxdimen| in
2106 % which case this warning will not show up.
2107 % \changes{v1.8g}{2014/08/24}{Warn if value is exceeded not when equal}
2109 \ifdim\dimen\tw@ > \mc@gridwarn
2110 \PackageWarning{multicol}%
2111 {Very deep columns!\MessageBreak
2112 Grid alignment might be broken}%
2118 % \begin{macro}{\columnseprulecolor}
2119 % \changes{v1.6f}{2006/09/19}{Make the color of the rule a hook}
2120 % By default the vertical rule between columns will be in |\normalcolor|.
2122 \def\columnseprulecolor{\normalcolor}
2126 % \begin{macro}{\reinsert@footnotes}
2127 % Before we tackle the bigger output routines we define just one
2128 % more macro which will help us to find our way through the
2129 % mysteries later. |\reinsert@footnotes| will do what its name
2130 % indicates: it reinserts the footnotes present in
2131 % |\footinbox| so that they will be reprocessed by \TeX{}'s
2132 % {\it page\_builder}.
2134 % Instead of actually reinserting the footnotes we insert an empty
2135 % footnote. This will trigger insertion mechanism as well and since
2136 % the old footnotes are still in their box and we are on a fresh page
2137 % |\skip| |footins| should be correctly taken into account.
2138 % \changes{v1.3c}{1990/03/03}{\cs{unbox}ing avoided.}
2140 \def\reinsert@footnotes{\ifvoid\footins\else
2141 \insert\footins{}\fi}
2146 % \begin{macro}{\vfilmaxdepth}
2147 % This curious definition is used as the space at the bottom of a
2148 % column if we implement |\raggedcolumns|. Normlly one only appends
2149 % |\vfill| in that case but this is actually wrong for columns that
2150 % are more or less full: by adding a glue at the bottom such a
2151 % column doesn't have any depth any more but without it the material
2152 % would be allowed a depth of |\maxdepth|. So we allow shrinking by
2153 % that amount. This only makes a difference if the box would
2154 % otherwise become overfull and shrinking never exceeds the
2155 % specified value, so we should be fine.
2156 % \changes{v1.8h}{2014/09/12}{Macro added (pr/4395)}
2157 % \changes{v1.8j}{2015/03/07}{Use only `0.0001fil' for stretching}
2159 \def\vfilmaxdepth{\vskip \z@ \@plus .0001fil
2165 % \begin{macro}{\multi@column@out}
2166 % Now we can't postpone the difficulties any longer. The
2167 % |\multi@column@out| routine will be called in two situations.
2168 % Either the page is full (i.e., we have collected enough material
2169 % to generate all the required columns) or a float or marginpar or
2171 % sensed. In the latter case the |\outputpenalty| is less
2172 % than $-10000$, otherwise the penalty which triggered the output
2173 % routine is higher. Therefore it's easy to distinguish both
2174 % cases: we simply test this register.
2175 % \changes{v1.5c}{1993/04/18}{Support \cs{clearpage}}
2177 \def\multi@column@out{%
2178 \ifnum\outputpenalty <-\@M
2180 % If this was a |\clearpage|, a float or a marginpar we call
2185 % otherwise we construct the final page.
2186 % \changes{v1.5u}{1999/05/25}{Support \cs{columnbreak}}
2187 % \changes{v1.5v}{1999/07/18}{Added debug statements for
2188 % column break support}
2189 % For the next block of code see comments in section~\ref{sec:colbreak}.
2191 \ifvoid\colbreak@box\else
2192 \mult@info\@ne{Re-adding forced
2193 break(s) for splitting}%
2194 \setbox\@cclv\vbox{%
2195 \unvbox\colbreak@box
2200 % Let us now consider the
2201 % normal case. We have to |\vsplit| the columns from the
2202 % accumulated material in box 255. Therefore we first assign
2203 % appropriate values to |\splittopskip| and |\splitmaxdepth|.
2205 \splittopskip\topskip
2206 \splitmaxdepth\maxdepth
2208 % We also need to restrict |\boxmaxdepth| so that re-boxing is not
2209 % generating boxes with arbitrary depth.
2210 % \changes{v1.8j}{2015/03/07}{Set \cs{boxmaxdepth}}
2212 \boxmaxdepth\maxdepth
2214 % Then we calculate the current column height (in |\dimen@|).
2215 % Note that the height of |\partial@page| is already
2216 % subtracted from |\@colroom| so we can use its value as a
2221 % But we must also subtract the space occupied by footnotes on the
2222 % current page. Note that we first have to reset the skip register
2223 % to its normal value.
2224 % Again, the actual action is carried out in a utility macro, so that
2225 % other applications can modify it.
2226 % \changes{v1.5?}{1994/?/?}{Use \cs{leave@mult@footins}}
2228 \divide\skip\footins\col@number
2229 \ifvoid\footins \else
2233 % And there is one more adjustment that we have to make: if the
2234 % user has issue a |\enlargethispage| command then the height the
2235 % |\@kludgeins| box will be the negation of the size by which the
2236 % page should be enlarged. If the star form of this command has
2237 % been used then we also need to shrink the resulting column. As we
2238 % don't know whether or not shrinking is already generally
2239 % requested with save the current value of |\ifshr@king| and
2240 % restore it afterwards.
2241 % \changes{v1.8a}{2011/12/20}{Support for \cs{enlargethispage}}
2243 \let\ifshr@kingsaved\ifshr@king
2245 \advance \dimen@ -\ht\@kludgeins
2247 % The star form of |\enlargethispage| makes the width of the box
2248 % greater than zero (sneaky isn't it?).
2250 \ifdim \wd\@kludgeins>\z@
2255 % Now we are able to |\vsplit| off all but the last column.
2256 % Recall that these columns should be saved in the box registers 2,
2257 % 4,\ldots\ (plus offset).
2258 % \changes{v1.5a}{1992/11/04}{New box mechanism}
2260 \process@cols\mult@gfirstbox{%
2262 \vsplit\@cclv to\dimen@
2264 % After splitting we update the kept marks.
2268 % If |\raggedcolumns| is in force we add a |vfill| at the bottom by
2269 % unboxing the split box.
2270 % But we need to unbox anyway to ensure that at the end of the box
2271 % we do not have unwanted space. This can sneak in in certain
2272 % situations, for example, if two lists follow each other and we
2273 % break between them. While sich space is usually zero it still has
2274 % an effect because it hides depth of the last line in the column
2275 % and that will result in incorrect placement.
2276 % \changes{v1.3c}{1990/03/03}{\cs{unbox}ing avoided.}
2277 % \changes{v1.8b}{2013/08/28}{And 20odd years later conclude that
2278 % this was wrong and unboxing is always needed.}
2279 % \changes{v1.8b}{2013/08/28}{Remove discardable items at the
2280 % end of split boxes}
2281 % \changes{v1.8h}{2014/09/12}{Use \cs{vfilmaxdepth}}
2282 % \changes{v1.8k}{2015/03/22}{\cs{remove@discardable@items} removed}
2287 \ifshr@nking\vfilmaxdepth\fi}%
2290 % Then the last column follows.
2291 % \changes{v1.5a}{1992/11/04}{New box mechanism}
2292 % \changes{v1.8b}{2013/08/28}{Remove discardable items at the
2293 % end of split boxes}
2294 % \changes{v1.8h}{2014/09/12}{Use \cs{vfilmaxdepth}}
2295 % \changes{v1.8k}{2015/03/22}{\cs{remove@discardable@items} removed}
2297 \setbox\mult@rightbox
2298 \vsplit\@cclv to\dimen@
2300 \setbox\mult@rightbox\vbox to\dimen@
2301 {\unvbox\mult@rightbox
2302 \ifshr@nking\vfilmaxdepth\fi}%
2304 % Now that we are done with the boxes, we restored the current
2305 % setting for shrinking in case it got changed:
2307 \let\ifshr@king\ifshr@kingsaved
2309 % Having done this we hope that box 255 is emptied. If not, we
2310 % reinsert its contents.
2311 % \changes{v1.8a}{2011/12/20}{Only re-add output penalty if it was
2316 \ifnum\outputpenalty=\@M
2318 \penalty\outputpenalty
2321 % In this case a footnote that happens to fall into the leftover
2322 % bit will be typeset on the wrong page. Therefore we warn the user
2323 % if the current page contains footnotes. The older versions of
2324 % \mc{} produced this warning regardless of whether or not
2325 % footnotes were present, resulting in many unnecessary warnings.
2326 % \changes{v1.3c}{1991/02/17}{Check if footnotes are actually present
2327 % before issuing a warning.}
2329 \ifvoid\footins\else
2330 \PackageWarning{multicol}%
2331 {I moved some lines to
2332 the next page.\MessageBreak
2334 \thepage\space might be wrong}%
2337 % If the `{\sf tracingmulticols}' counter is 4 or higher we also
2340 \ifnum \c@tracingmulticols>\thr@@
2341 \hrule\allowbreak \fi
2344 % To get a correct marks for the current page we have to (locally)
2345 % redefine |\firstmark| and |\botmark|.
2346 % If |\kept@firstmark| is non-empty then |\kept@botmark| must be
2347 % non-empty too so we can use their values. Otherwise we use the
2348 % value of |\kept@topmark| which was first initialized when we
2349 % gathered the |\partical@page| and later on was updated to the
2350 % |\botmark| for the preceding page.
2352 % \changes{v1.4a}{1992/02/14}{\cs{botmark} set to \cs{splitbotmark}}
2354 \ifx\@empty\kept@firstmark
2355 \let\firstmark\kept@topmark
2356 \let\botmark\kept@topmark
2358 \let\firstmark\kept@firstmark
2359 \let\botmark\kept@botmark
2362 % We also initalize |\topmark| with |\kept@topmark|. This will make
2363 % this mark okay for all middle pages of the \mc{} environment.
2364 % \changes{v1.5d}{1993/09/15}{reinit \cs{topmark}}
2366 \let\topmark\kept@topmark
2369 {Use kept top mark:\MessageBreak
2370 \meaning\kept@topmark
2372 Use kept first mark:\MessageBreak
2373 \meaning\kept@firstmark
2375 Use kept bot mark:\MessageBreak
2376 \meaning\kept@botmark
2378 Produce first mark:\MessageBreak
2381 Produce bot mark:\MessageBreak
2386 % With a little more effort we could have done better. If we had,
2387 % for example, recorded the shrinkage of the material in
2388 % |\partial@page| it would be now possible to try higher
2389 % values for |\dimen@| (i.e.\ the column height) to overcome
2390 % the problem with the nonempty box 255. But this would make the
2391 % code even more complex so I skipped it in the current
2394 % Now we use \LaTeX{}'s standard output
2395 % mechanism.\footnote{This will produce a lot of overhead since both
2396 % output routines are held in memory. The correct
2397 % solution would be to redesign the whole output
2398 % routine used in \LaTeX.}
2399 % Admittedly this is a funny way to do it.
2401 % Within the OR |\boxmaxdepth| needs to be unrestricted so we set it back
2402 % now as it was changed above.
2403 % \changes{v1.8p}{2016/04/07}{Reset \cs{boxmaxdepth}}
2405 \boxmaxdepth\maxdimen
2406 \setbox\@cclv\vbox{\unvbox\partial@page
2409 % The macro |\@makecol| adds all floats assigned for the current
2410 % page to this page. |\@outputpage| ships out the resulting box.
2411 % Note that it is just possible that such floats are present even
2412 % if we do not allow any inside a \mc{} environment.
2414 \@makecol\@outputpage
2416 % After the page is shipped out we have to prepare the kept marks
2417 % for the following page. |\kept@firstmark| and |\kept@botmark|
2418 % reinitialized by setting them to |\@empty|. The value of
2419 % |\botmark| is then assigned to |\kept@topmark|.
2420 % \changes{v1.4g}{1992/06/03}{Only change \cs{kept@topmark} if
2421 % \cs{kept@botmark} non-empty}
2422 % \changes{v1.4i}{1992/06/18}{Set \cs{kept@topmark} to \cs{botmark}}
2424 \global\let\kept@topmark\botmark
2425 \global\let\kept@firstmark\@empty
2426 \global\let\kept@botmark\@empty
2429 {(Re)Init top mark:\MessageBreak
2430 \meaning\kept@topmark
2434 % Now we reset |\@colroom| to |\@colht| which is \LaTeX's
2435 % saved value of |\textheight|.
2436 % We also have to reset the recorded position of the last
2437 % |\marginpar| as well as the recorded size of intext floats
2438 % as we are now on a new page.
2439 % \changes{v1.8d}{2014/04/23}{Reset \cs{@mparbottom} after page finishes}
2440 % \changes{v1.8n}{2015/08/19}{Reset \cs{@textfloatsheight} after page finishes}
2442 \global\@colroom\@colht
2443 \global \@mparbottom \z@
2444 \global \@textfloatsheight \z@
2446 % Then we process deferred floats waiting for their chance to be
2447 % placed on the next page.
2450 \@whilesw\if@fcolmade\fi{\@outputpage
2451 \global\@colroom\@colht
2452 \process@deferreds}%
2454 % If the user is interested in statistics we inform him about the
2455 % amount of space reserved for floats.
2458 {Colroom:\MessageBreak
2460 after float space removed
2461 = \the\@colroom \@gobble}%
2463 % Having done all this we must prepare to tackle the next page.
2464 % Therefore we assign a new value to |\vsize|. New, because
2465 % |\partial@page| is now empty and |\@colroom| might be
2466 % reduced by the space reserved for floats.
2467 % \changes{v1.4p}{1992/11/26}{Use different \cs{vsize} setting}
2469 \set@mult@vsize \global
2471 % The |\footins| skip register will be adjusted when the output
2473 % \changes{v1.3c}{1991/03/03}{Unnecessary code removed}
2481 % \begin{macro}{\leave@mult@footins}
2482 % This macro is used to subtract the amount of space
2483 % occupied by footnotes for the current space from the
2484 % space available for the current column. The space current column
2485 % is stored in |\dimen@|. See above for the description of the default
2487 % \changes{v1.5?}{1994/?/?}{Macro added}
2489 \def\leave@mult@footins{%
2490 \advance\dimen@-\skip\footins
2491 \advance\dimen@-\ht\footins
2498 % \begin{macro}{\speci@ls}
2499 % We left out two macros: |\process@deferreds| and
2501 % \changes{v1.5c}{1993/04/18}{Support \cs{clearpage}}
2504 \ifnum\outputpenalty <-\@Mi
2506 % If the document ends in the middle of a multicols environment, e.g.,
2507 % if the user forgot the |\end{multicols}|, \TeX{} adds a very
2508 % negative penalty to the end of the galley which is intended to signal
2509 % the output routine that it is time to prepare for shipping out
2510 % everything remaining. Since inside multicols the output routine of
2511 % \LaTeX{} is disabled sometimes we better check for this case: if we
2512 % find a very negative penalty we produce an error message and run
2513 % the default output routine for this case.
2514 % \changes{v1.5s}{1998/09/10}{check for \cs{stop} penalty pr/2873}
2516 \ifnum \outputpenalty<-\@MM
2517 \PackageError{multicol}{Document end
2518 inside multicols environment}\@ehd
2522 % \changes{v1.5u}{1999/05/25}{Support \cs{columnbreak}}
2523 % \changes{v1.5v}{1999/07/18}{Added debug statements for
2524 % column break support}
2525 % For the next block of code see comments in section~\ref{sec:colbreak}.
2527 \ifnum\outputpenalty = -\@Mv
2528 \mult@info\@ne{Forced column
2530 \global\advance\vsize-\pagetotal
2531 \global\setbox\colbreak@box
2533 \ifvoid\colbreak@box
2535 \unvbox\colbreak@box
2539 % As this is the place of a forced break we now remove vertical
2540 % white space just in front of it (or some of it at least) as it is
2541 % quite likely that the break is not exactly in the right place,
2542 % e.g., after a display environment (if LaTeX would break here by
2543 % its own it would break before the space following the display).
2545 % Thus we rebox box 255 once (using |\maxdepth| and calling
2546 % |\remove@discardable@items| inside). The depth of 255 will then
2547 % give us the depth the box would have had if it would have been a
2548 % natural break. We then unbox 255 to get it into the
2549 % |\colbreak@box| and then back up by this depth. This will position
2550 % the bottom of the box at its natural baseline which is useful for
2551 % balancing later on.
2552 % \changes{v1.8k}{2015/03/21}{Remove discarable items just before a
2555 \boxmaxdepth\maxdepth
2556 \setbox\@cclv\vbox{%
2558 \remove@discardable@items}%
2566 % If we encounter a float or a marginpar in the current
2567 % implementation we simply warn the user that this is not allowed.
2568 % Then we reinsert the page and its footnotes.
2570 \PackageWarningNoLine{multicol}%
2571 {Floats and marginpars not
2572 allowed inside `multicols'
2574 \unvbox\@cclv\reinsert@footnotes
2576 % Additionally we empty the |\@currlist| to avoid later error
2577 % messages when the \LaTeX{} output routine is again in force.
2578 % But first we have to place the boxes back onto the
2579 % |\@freelist|. (|\@elt|s default is |\relax| so
2580 % this is possible with |\xdef|.)
2581 % \changes{v1.2a}{1990/02/05}{Float boxes freed.}
2583 \xdef\@freelist{\@freelist\@currlist}%
2588 % If the penalty is $-10001$ it will come from a |\clearpage| and
2589 % we will execute |\@doclearpage| to get rid of any deferred
2592 \else \@doclearpage \fi
2597 % \begin{macro}{\process@deferreds}
2598 % |\process@deferreds| is a simplified version of \LaTeX{}'s
2599 % |\@startpage|. We first call the macro
2600 % |\@floatplacement| to save the current user parameters in
2601 % internal registers. Then we start a new group and save the
2602 % |\@deferlist| temporarily in the macro |\@tempb|.
2604 \def\process@deferreds{%
2606 \@tryfcolumn\@deferlist
2609 \let\@tempb\@deferlist
2611 % Our next action is to (globally) empty |\@deferlist| and
2612 % assign a new meaning to |\@elt|. Here |\@scolelt| is a
2613 % macro that looks at the boxes in a list to decide whether they
2614 % should be placed on the next page (i.e.\ on |\@toplist| or
2615 % |\@botlist|) or should wait for further processing.
2620 % Now we call |\@tempb| which has the form
2622 % |\@elt|\meta{box register}|\@elt|^^A
2623 % \meta{box register}\ldots{}
2625 % So |\@elt| (i.e.\ |\@scolelt|) will distribute the
2626 % boxes to the three lists.
2635 % \begin{macro}{ifshr@nking}
2636 % \begin{macro}{\raggedcolumns}
2637 % \begin{macro}{\flushcolumns}
2638 % \changes{v1.1a}{1989/09/20}{\cs{flushedcolumns} renamed to \cs{flushcolumns}.}
2639 % The |\raggedcolumns| and |\flushcolumns|
2640 % declarations are defined with the help of a new |\if...|
2645 % The actual definitions are simple: we just switch to {\sf true}
2646 % or {\sf false} depending on the desired action. To avoid extra
2647 % spaces in the output we enclose these changes in
2648 % |\@bsphack|\ldots{}\allowbreak|\@esphack|.
2650 \def\raggedcolumns{%
2651 \@bsphack\shr@nkingtrue\@esphack}
2653 \@bsphack\shr@nkingfalse\@esphack}
2660 % \begin{macro}{\balance@columns@out}
2661 % Now for the last part of the show: the column balancing output
2662 % routine. Since this code is called with an explicit penalty
2663 % (|\eject|) there is no need to check for something special (eg
2664 % floats). We start by balancing the material gathered.
2666 \def\balance@columns@out{%
2668 % For this we need to put the contents of box 255 into |\mult@box|.
2669 % \changes{v1.5u}{1999/05/25}{Support \cs{columnbreak}}
2670 % \changes{v1.5v}{1999/07/18}{Added debug statements for column break
2671 % support} For the next block of code see also comments in
2672 % section~\ref{sec:colbreak}. All forced breaks except the last are
2673 % inside |\colbreak@box| so all we have to do is to concatenate this
2674 % box with box |\@cclv| and put a penalty inbetween. Here we test if
2675 % |\colbreak@box| is void so that the message is only generated if
2676 % we really add forced breaks and the penalty.
2677 % \changes{v1.8k}{2015/03/21}{Use \cs{@Mv} and not \cs{break} in case
2678 % this forced break is not used on this page}
2680 \setbox\mult@box\vbox{%
2681 \ifvoid\colbreak@box\else
2682 \unvbox\colbreak@box
2684 \mult@info\@ne{Re-adding
2685 forced break(s) in balancing}%
2689 % The last column again is a forced break, so here we discard white
2690 % space as well as that is normally unwanted.
2691 % \changes{v1.8k}{2015/03/21}{Add \cs{remove@discardable@items} at the
2692 % end of the last column when balancing.}
2694 \remove@discardable@items
2698 % If during balancing the columns got too long the flag
2699 % |\iftoo@bad| is set to true.
2700 % \changes{v1.8a}{2011/12/20}{Balancing concept improved}
2704 {Balancing failed ...
2707 % In that case we put the material back in box 255 so that we can
2708 % cut a normal page. The curious set of
2709 % |\vskip|s we add is necessary to cancel out the |\splittopskip|
2710 % that got added for balancing.
2714 \vskip-\splittopskip
2717 % We then call the standard multicol output routine which will
2718 % produce a normal page for us (remember we are still within the
2719 % OR so some part of the code in |\multi@column@out| is actually not
2720 % doing anything---perhaps this should be cleaned up at some point).
2721 % This also means that if there was an |\enlargethispage| present
2722 % it will apply to this page as |\multi@column@out| will look at
2723 % the status of |\@kludgeins|.
2727 % Because balancing made the columns too long we are sure that there
2728 % will be some material remaining which was put back onto the main
2729 % vertical list by |\multi@column@out|. This will also put the
2730 % explicit |\eject| penalty back so the current
2731 % |\balance@columns@out| output routine will be called again (so we
2732 % better do not add another penalty or else the OR will be called
2733 % twice and we may get scrambled results).
2734 % \changes{v1.8k}{2015/03/21}{No additional penalty here}
2738 % If the balancing went ok, we are in the position
2739 % to apply |\page@sofar|. But first we have to set |\vsize| to a
2740 % value suitable for one column output.
2742 \global\vsize\@colroom
2743 \global\advance\vsize\ht\partial@page
2745 % We also have to look at |\@kludgeins| and generate a new
2746 % |\insert| in case there was one present due to an
2747 % |\enlargethispage| command.
2748 % \changes{v1.8a}{2011/12/20}{Support for \cs{enlargethispage}}
2750 \ifvbox\@kludgeins\insert\@kludgeins
2751 {\unvbox\@kludgeins}\fi
2753 % Then we |\unvbox| the |\partial@page| (which may be void if we
2754 % are not processing the first page of this \mc{} environment.
2756 \unvbox\partial@page
2758 % Then we return the first and bottom mark and the gathered
2759 % material to the main vertical list.
2761 \return@nonemptymark{first}\kept@firstmark
2762 \return@nonemptymark{bot}\kept@botmark
2765 % We need to add a penalty at this point which allows to break at
2766 % this point since calling the output routine may have removed the
2767 % only permissible break point thereby ``glueing'' any following
2768 % skip to the balanced box. In case there are any weird settings
2769 % for |\multicolsep| etc. this could produce funny results.
2770 % \changes{v1.5c}{1993/04/18}{added penalty at output routine exit}
2776 % As we already know, reinserting of footnotes will be done in the
2777 % macro |\endmulticols|.
2781 % \begin{macro}{\balance@columns}
2782 % This macro now does the actual balancing.
2784 \def\balance@columns{%
2786 % We start by setting the kept marks by updating them with any
2787 % marks from this box. This has to be done \emph{before} we add a
2788 % penalty of $-10000$ to the top of the box, otherwise only an
2789 % empty box will be considered.
2790 % \changes{v1.5h}{1994/08/26}{Get kept marks first}
2792 \get@keptmarks\mult@box
2794 % We then continue by resetting trying to remove any discardable
2795 % stuff at the end of |\mult@box|. This is rather experimental. We
2796 % also add a forced break point at the very beginning, so that we
2797 % can split the box to height zero later on, thereby adding a known
2798 % |\splittopskip| glue at the beginning.
2799 % \changes{v1.8k}{2015/03/21}{\cs{remove@discardable@items} removed}
2801 \setbox\mult@box\vbox{%
2806 % Then follow values assignments to get the |\vsplit|ting right.
2807 % We use the natural part of |\topskip| as the natural part for
2808 % |\splittopskip| and allow for a bit of undershoot and overshoot
2809 % by adding some stretch and shrink.
2810 % \changes{v1.5?}{1994/?/?}{Allow columns to come out a bit long or short}
2813 \splittopskip\@tempdima
2814 \@plus\multicolundershoot
2815 \@minus\multicolovershoot
2816 \splitmaxdepth\maxdepth
2818 % We also have to set |\boxmaxdepth| which normally allows to
2819 % build boxes with arbitrary depth, but as we are building text
2820 % columns we really want to restrict the depth. This is necessary as
2821 % we sometimes rebox the boxes generated by |\vsplit| and then the
2822 % restriction posed by |\splitmaxdepth| gets lost.
2823 % \changes{v1.8h}{2014/09/12}{All column boxes should obey
2824 % \cs{maxdepth} (pr/4395)}
2826 \boxmaxdepth\maxdepth
2828 % The next step is a bit tricky: when \TeX{} assembles material in
2829 % a box, the first line isn't preceded by interline glue, i.e.
2830 % there is no parameter like |\boxtopskip| in \TeX{}. This means
2831 % that the baseline of the first line in our box is at some
2832 % unpredictable point depending on the height of the largest
2833 % character in this line. But of course we want all columns to
2834 % align properly at the baselines of their first lines. For this
2835 % reason we have opened |\mult@box| with a |\penalty| {\sf -10000}.
2836 % This will now allow us to split off from |\mult@box| a tiny bit
2837 % (in fact nothing since the first possible break-point is the
2838 % first item in the box). The result is that |\splittopskip| is
2839 % inserted at the top of |\mult@box| which is exactly what we like
2841 % \changes{v1.5?}{1994/?/?}{Do splitting to zero here}
2843 \setbox\@tempboxa\vsplit\mult@box to\z@
2845 % Next we try to find a suitable starting point for the calculation
2846 % of the column height. It should be less than the height finally
2847 % chosen, but large enough to reach this final value in only a few
2848 % iterations. The formula which is now implemented will try to
2849 % start with the nearest value which is a multiple of
2850 % |\baselineskip|. The coding is slightly tricky in \TeX{} and
2851 % there are perhaps better ways \ldots
2852 % \changes{v1.4d}{1992/03/04}{New algorithm for start height}
2854 \@tempdima\ht\mult@box
2855 \advance\@tempdima\dp\mult@box
2856 \divide\@tempdima\col@number
2858 % The code above sets |\@tempdima| to the length of a column if we
2859 % simply divide the whole box into equal pieces. To get to the next
2860 % lower multiple of |\baselineskip| we convert this dimen to a
2861 % number (the number of scaled points) then divide this by
2862 % |\baselineskip| (also in scaled points) and then multiply this
2863 % result with |\baselineskip| assigning the result to |\dimen@|.
2864 % This makes |\dimen@| $\leq$ to |\@tempdimena|.
2867 \divide\count@\baselineskip
2868 \dimen@\count@\baselineskip
2870 % Next step is to correct our result by taking into account the
2871 % difference between |\topskip| and |\baselineskip|. We start by
2872 % adding |\topskip|; if this makes the result too large then we
2873 % have to subtract one |\baselineskip|.
2875 \advance\dimen@\topskip
2876 \ifdim \dimen@ >\@tempdima
2877 \advance\dimen@-\baselineskip
2880 % At the user's request we start with a higher value (or lower, but
2881 % this usually only increases the number of tries).
2883 \advance\dimen@\c@unbalance\baselineskip
2885 % We type out statistics if we were asked to do so.
2886 % \changes{v1.4f}{1992/04/28}{\cs{on@line} added to tracing info}
2889 {Balance columns\on@line:
2890 \ifnum\c@unbalance=\z@\else
2891 (off balance=\number\c@unbalance)\fi
2894 % But we don't allow nonsense values for a start.
2896 \ifnum\dimen@<\topskip
2899 \the\dimen@ \space ->
2900 \the\topskip \space (corrected)}%
2904 % Now we try to find the final column height. We start by setting
2905 % |\vbadness| to infinity (i.e.\ $10000$) to suppress
2906 % underfull box reports while we are trying to find an acceptable
2907 % solution. We do not need to do it in a group since at the end of
2908 % the output routine everything will be restored. The setting of
2909 % the final columns will nearly always produce underfull boxes with
2910 % badness $10000$ so there is no point in warning the user about
2912 % \changes{v1.2a}{1990/02/05}{Group around main loop removed.}
2916 % We also allow for overfull boxes while we trying to split the
2917 % columns. They can easily happen if we have objects with unusual depth.
2918 % \changes{v1.8h}{2014/09/12}{Do not report overfull}
2922 % The variable |\last@try| will hold the dimension used in the
2923 % previous trial splitting. We initialize it with a negative value.
2924 % \changes{v1.5?}{1994/?/?}{Initialize \cs{last@try}}
2929 % In order not to clutter up \TeX{}'s valuable main memory with
2930 % things that are no longer needed, we empty all globally used box
2931 % registers. This is necessary if we return to this point after an
2932 % unsuccessful trial. We use |\process@cols| for this purpose,
2933 % starting with |\mult@grightbox|. Note the extra braces around
2934 % this macro call. They are needed since \PlainTeX{}'s
2935 % |\loop|\ldots{}\allowbreak|\repeat| mechanism cannot be nested on
2936 % the same level of grouping.
2937 % \changes{v1.5a}{1992/11/04}{New box mechanism}
2939 {\process@cols\mult@grightbox
2940 {\global\setbox\count@
2943 % The contents of box |\mult@box| are now copied globally to
2944 % box~|\mult@grightbox|. (This will be the right-most column, as
2945 % we shall see later.)
2947 \global\setbox\mult@grightbox
2950 % We start with the assumption that the trial will be successful.
2951 % If we end up with a solution that is too bad we set
2952 % |too@bad| to \texttt{true}. We also assume that all forced breaks
2953 % (if any) will be used during balancing. If this is not the case
2954 % we record this in |forcedbreak@leftover|.
2955 % \changes{v1.5b}{1992/11/05}{New badness mechanism}
2956 % \changes{v1.8k}{2015/03/21}{Init \cs{ifforcedbreak@leftover}}
2960 \forcedbreak@leftoverfalse
2963 % Using |\vsplit| we extract the other columns from box register
2964 % |\mult@grightbox|. This leaves box register |\mult@box|
2965 % untouched so that we can start over again if this trial was
2968 {\process@cols\mult@firstbox{%
2969 \global\setbox\count@
2970 \vsplit\mult@grightbox to\dimen@
2972 % After splitting we need to ensure that there isn't any space at
2973 % the bottom, so we rebox once more.
2974 % \changes{v1.8b}{2013/08/28}{Remove discardable items at the
2975 % end of split boxes}
2976 % \changes{v1.8k}{2015/03/21}{Do not use \cs{remove@discardable@items}
2979 \global\setbox\count@
2983 % After every split we check the badness of the resulting column,
2984 % normally the amount of extra white in the column.
2987 \ifnum\c@tracingmulticols>\@ne
2989 \advance\@tempcnta-\mult@grightbox
2990 \divide\@tempcnta \tw@
2992 \number\@tempcnta\space
2993 badness: \the\badness\space}%
2996 % If this badness is larger than the allowed column badness
2997 % we reject this solution by setting |too@bad| to \texttt{true}.
2999 \ifnum\badness>\c@columnbadness
3000 \ifnum\c@tracingmulticols>\@ne
3002 (>\the\c@columnbadness)}%
3009 % There is one subtle point here: while all other constructed boxes
3010 % have a depth that is determined by |\splitmaxdepth| and/or
3011 % |\boxmaxdepth| the last box
3012 % will get a natural depth disregarding the original setting and
3013 % the value of |\splitmaxdepth| or |\boxmaxdepth|. This means that
3014 % we may end up with a very large depth in box |\mult@grightbox|
3016 % make the result of the testing incorrect. So we change the value
3017 % by unboxing the box into itself.
3019 \global\setbox\mult@grightbox
3020 \vbox{\unvbox\mult@grightbox}%
3022 % We also save a copy |\mult@firstbox| at its ``natural'' size
3025 \setbox\mult@nat@firstbox
3026 \vbox{\unvcopy\mult@firstbox}%
3028 % After |\process@cols| has done its job we have the following
3031 % \begin{tabular}{r@{$\:\:\longleftarrow\:\:$}l}
3032 % box |\mult@rightbox| & all material \\
3033 % box |\mult@gfirstbox| & first column \\
3034 % box |\mult@gfirstbox|${}+2$ & second column \\
3035 % \multicolumn{1}{c}{$\vdots$} &
3036 % \multicolumn{1}{c}{$\vdots$} \\
3037 % box |\mult@grightbox| & last column
3040 % We report the height of the first column, in brackets
3041 % the natural size is given.
3042 % \changes{v1.5?}{1994/?/?}{Show natural size}
3044 \ifnum\c@tracingmulticols>\@ne
3045 \message{^^JFirst column
3047 (\the\ht\mult@nat@firstbox)}\fi
3049 % If |\raggedcolumns| is in force older releases of this file also
3050 % shrank the first column to its natural height at this point.
3051 % This was done so that the first column doesn't run short compared
3052 % to later columns but it is actually producing incorrect results
3053 % (overprinting of text) in boundary cases, so since version v1.5q
3054 % |\raggedcolumns| means allows for all columns to run slightly short.
3055 % \changes{v1.5q}{1998/01/19}{Do not reset \cs{mult@firstbox} (pr2739)}
3058 % \global\setbox\mult@firstbox
3059 % \copy\mult@nat@firstbox
3062 % Then we give information about the last column.\footnote{With
3063 % \TeX{} version 3.141 it is now possible to use \LaTeX's
3064 % \cs{newlinechar} in the \cs{message} command, but
3065 % people with older \TeX{} versions will now get
3066 % \texttt{\string^\string^J} instead of a new line on the screen.}
3067 % \changes{v1.4a}{1992/02/12}{Changed to proper \cs{endlinechar} in\cs{message}}
3069 \ifnum\c@tracingmulticols>\@ne
3070 \message{<> last column =
3071 \the\ht\mult@grightbox^^J}%
3073 % Some tracing code that we don't compile into the production version
3074 % unless asked for. It will produce huge listings of the boxes
3075 % involved in balancing in the transcript file.
3076 % \changes{v1.6f}{2004/07/03}{need to use \cs{mult@grightbox} in the loop}
3079 \ifnum\c@tracingmulticols>4
3082 \process@cols\mult@grightbox
3089 % We check whether our trial was successful. The test used is very
3090 % simple: we merely compare the first and the last column. Thus
3091 % the intermediate columns may be longer than the first if
3092 % |\raggedcolumns| is used. If the right-most column is
3093 % longer than the first then we start over with a larger value for
3095 % \changes{v1.3c}{1991/03/03}{\cs{global}\cs{advance} left over from older code}
3097 \ifdim\ht\mult@grightbox >\dimen@
3099 % If the height of the last box is too large we mark this trial as
3101 % \changes{v1.5v}{1999/07/18}{Added tracing statements for
3102 % trial unsuccessful}
3106 \ifnum\c@tracingmulticols>\@ne
3107 \typeout{Rejected: last
3112 % \changes{v1.5v}{1999/07/18}{Check last column if it contains forced
3113 % break and reject trial if that is the case}
3115 % To ensure that there isn't a forced break in the last column we
3116 % try to split off a box of size |\maxdimen| from |\mult@grightbox|
3117 % (or rather from a copy of it). This should result in a void box
3118 % after the split, unless there was a forced break somewhere within
3119 % the column in which case the material after the break would have
3120 % stayed in the box.
3123 \copy\mult@grightbox
3124 \setbox\z@\vsplit\@tempboxa to\maxdimen
3127 % Thus if |\@tempboxa| is void we have a valid solution.
3128 % In this case we take a closer
3129 % look at the last column to decide if this column should be made
3130 % as long as all other columns or if it should be allowed to be
3132 % For this we first have to rebox the column into a box of the
3133 % appropriate height. If tracing is enabled we then display the
3134 % badness for this box.
3136 \global\setbox\mult@grightbox
3138 {\unvbox\mult@grightbox}%
3139 \ifnum\c@tracingmulticols>\@ne
3140 \message{Final badness:
3144 % We then compare this badness with the allowed badness for the final
3145 % column. If it does not exceed this value we use the box, otherwise
3146 % we rebox it once more and add some glue at the bottom.
3147 % \changes{v1.8h}{2014/09/12}{Use \cs{vfilmaxdepth}}
3148 % \changes{v1.8j}{2015/03/07}{Use \cs{vfil} in this case}
3150 \ifnum\badness>\c@finalcolumnbadness
3151 \global\setbox\mult@grightbox
3153 {\unvbox\mult@grightbox\vfil}%
3154 \ifnum\c@tracingmulticols>\@ne
3155 \message{ setting natural
3156 (> \the\c@finalcolumnbadness)}%
3160 % If |\@tempboxa| above was not void our trial was unsuccessful and
3161 % we report this fact and try again.
3162 % \changes{v1.6f}{2004/07/03}{\texttt{/colbreak} guard in the wrong position}
3166 % If we have unprocessed forced breaks we normally reiterate with a
3167 % larger column size to fit them in eventually. However, if there
3168 % are simply too many of them (e.g., 3 forced breaks but only 2
3169 % columns to balance) then this will never succeed and and we would
3170 % continue growing the columns until we hit the largest possible
3171 % column size. So in addition we check how big the column size is
3172 % compared to available room and if we exceed this by
3173 % |\maxbalancingoverflow| we give up and instead of balancing cut
3174 % another normal page. To be indicate this case we set
3175 % |forcedbreak@leftover| to true.
3176 % \changes{v1.8k}{2015/03/21}{Watch out for columns growing too far in
3177 % case of forced breaks}
3178 % \changes{v1.8l}{2015/03/25}{Added additional tracing if column overflows}
3181 \advance\@tempdima \maxbalancingoverflow
3182 \ifdim \dimen@ < \@tempdima
3184 \ifnum\c@tracingmulticols>\@ne
3185 \typeout{Rejected: unprocessed
3186 forced break(s) in last column!}%
3189 \forcedbreak@leftovertrue
3190 \ifnum\c@tracingmulticols>\@ne
3191 \typeout{Failed: columns too large
3192 with unprocessed forced break(s)!}%
3198 % If the natural height of the first box is smaller than the
3199 % current trial size but is larger than the previous trial size it
3200 % is likely that we have missed a potentially better
3201 % solution. (This could have happened if for some reason our first
3202 % trial size was too high.) In that case we dismiss this trial and
3203 % restart using the natural height for the next trial.
3205 \ifdim\ht\mult@nat@firstbox<\dimen@
3206 \ifdim\ht\mult@nat@firstbox>\last@try
3208 \ifnum\c@tracingmulticols>\@ne
3209 \typeout{Retry: using natural
3210 height of first column!}%
3212 \dimen@\ht\mult@nat@firstbox
3218 % Finally the switch |too@bad| is tested. If it was made true
3219 % either earlier on or due to a rightmost column being too large
3220 % we try again with a slightly larger value for |\dimen@|.
3227 % If we come out of the loop with the switch |forcedbreak@leftover|
3228 % set to true then balancing has failed and we should cut a normal
3229 % page. We indicate this below with |\too@badtrue| when any of the
3230 % columns get too high, so we set this flag here too in order to
3231 % get the same processing logic.\footnote{Should get cleaned up as
3232 % we now have two different routes to reach this part of the
3234 % \changes{v1.8k}{2015/03/21}{}
3236 \ifforcedbreak@leftover
3240 % At that point |\dimen@| holds the height that was determined by
3241 % the balancing loop.
3242 % If that height for the columns turns out to be larger
3243 % than the available space (which is |\@colroom|) we squeeze the
3244 % columns into the space assuming that they will have enough
3245 % shrinkability to allow this.\footnote{This might be wrong, since
3246 % the shrinkability that accounts for the amount of material might
3247 % be present only in some columns. But it is better to try then to
3248 % give up directly.}
3249 % However, this squeezing should only be done if we are balancing
3250 % columns on the main galley and \emph{not} if we are building a
3251 % boxed multicol (in the latter case the current |\@colroom| is
3252 % irrelevant since the produced box might be moved anywhere at a
3254 % \changes{v1.3c}{1991/03/03}{Limit column height to \cs{@colroom}}
3255 % \changes{v1.5q}{1998/01/19}{Removed setting \cs{dimen@} (pr2739)}
3256 % \changes{v1.5y}{2000/06/10}{Limit column height only in unrestricted
3259 \if@boxedmulticols\else
3260 \ifdim\dimen@>\@colroom
3265 % Then we move the contents of the odd-numbered box registers to
3266 % the even-numbered ones, shrinking them if requested.
3267 % We have to use |\vbox| not |\vtop| (as it was done in
3268 % the first versions) since otherwise the resulting boxes will have
3269 % no height (\TB\/ page 81). This would mean that extra
3270 % |\topskip| is added when the boxes are returned to the
3271 % page-builder via |\page@sofar|.
3272 % \changes{v1.3a}{1990/05/20}{Changed \cs{vtop} to \cs{vbox}.}
3274 \process@cols\mult@rightbox
3276 \advance\@tempcnta\@ne
3278 % when putting the final column together we want overfull
3282 \setbox\count@\vbox to\dimen@
3286 % \changes{v1.8h}{2014/09/12}{Use \cs{vfilmaxdepth}}
3289 \@plus-\multicolundershoot
3290 \@minus-\multicolovershoot
3292 \ifshr@nking\vfilmaxdepth\fi
3295 % If the resulting box is overfull there was too much material to
3296 % fit into the available space. The question though is how much? If
3297 % it wasn't more than |\maxbalancingoverflow| we accept it still to
3298 % avoid getting very little material for the next page (which we
3299 % would then have difficulties to balance).
3300 % \changes{v1.8a}{2011/12/20}{Balancing concept improved}
3303 \vfuzz\maxdimen % no overfull warning
3304 \setbox\@tempboxa \vbox to\dimen@
3305 {\vskip-\maxbalancingoverflow
3309 {Balanced column more than
3310 \the\maxbalancingoverflow\space
3313 % Fail the balancing attempt:
3318 % Otherwise report that there is a problem but within the accepted
3323 too large, but less than
3324 \the\maxbalancingoverflow}%
3329 % Finally end the |\ifforcedbreak@leftover| conditional.
3330 % \changes{v1.8k}{2015/03/21}{Finish the new conditional}
3338 % \begin{macro}{\maxbalancingoverflow}
3339 % Amount that balancing is allowed to overflow the available column
3340 % space. We default to 12pt which means about one line in most
3342 % \changes{v1.8a}{2011/12/20}{\cs{maxbalancingoverflow} parameter added}
3344 \newdimen\maxbalancingoverflow
3345 \maxbalancingoverflow=12pt
3351 % \begin{multicols}{2}[\subsection{The box allocations}]
3353 % \begin{macro}{\mult@rightbox}
3354 % \begin{macro}{\mult@grightbox}
3355 % \begin{macro}{\mult@firstbox}
3356 % \begin{macro}{\mult@gfirstbox}
3357 % Early releases of these macros used the first box registers
3358 % 0, 2, 4,\ldots\ for global boxes and 1, 3, 5,\ldots\ for the
3359 % corresponding local boxes. (You might still find some traces
3360 % of this setup in the documentation, sigh.) This produced a problem
3361 % at the moment we had more than 5 columns because then officially
3362 % allocated boxes were overwritten by the algorithm.
3363 % The new release now uses private box registers
3365 \newbox\mult@rightbox
3366 \newbox\mult@grightbox
3367 \newbox\mult@gfirstbox
3368 \newbox\mult@firstbox
3369 \newbox\@tempa\newbox\@tempa
3370 \newbox\@tempa\newbox\@tempa
3371 \newbox\@tempa\newbox\@tempa
3372 \newbox\@tempa\newbox\@tempa
3373 \newbox\@tempa\newbox\@tempa
3374 \newbox\@tempa\newbox\@tempa
3375 \newbox\@tempa\newbox\@tempa
3376 \newbox\@tempa\newbox\@tempa
3389 % \begin{multicols}{2}[\section{New macros and hacks for version 1.2}]
3391 % \begin{macro}{\emergencystretch}
3392 % \begin{macro}{\setemergencystretch}
3393 % If we don't use \TeX{} 3.0 |\emergencystretch| is undefined
3394 % so in this case we simply add it as an unused \meta{dimen}
3396 % \changes{v1.4j}{1992/06/25}{Setting of \cs{emergencystretch} on top
3399 \@ifundefined{emergencystretch}
3400 {\newdimen\emergencystretch}{}
3402 % \changes{v1.2a}{1990/02/05}{Macro added.}
3403 % My tests showed that the following formula worked pretty well.
3404 % Nevertheless the |\setemergencystretch| macro also gets
3405 % |\hsize| as second argument to enable the user to try
3406 % different formulae.
3408 \def\setemergencystretch#1#2{%
3409 \emergencystretch 4pt
3410 \multiply\emergencystretch#1}
3416 % \begin{macro}{\set@floatcmds}
3417 % \changes{v1.2a}{1990/02/05}{Macro added.}
3418 % \changes{v1.5g}{1994/06/07}{Updated since floats have changed}
3419 % \changes{v1.5j}{1994/06/07}{Updated since floats have changed again}
3420 % \changes{v1.5l}{1995/10/19}{Added \cs{@largefloatcheck}}
3421 % \changes{v1.6g}{2006/02/23}{Added \cs{@minipagefalse}}
3422 % \changes{v1.6h}{2008/12/05}{Use \cs{@endfloatbox} to better support
3423 % the modifications done by the float package}
3424 % Even if this should be used as a hook we use a |@| in the
3425 % name since it is more for experts.
3427 \def\set@floatcmds{%
3428 \let\@dblfloat\@dbflt
3429 \def\end@dblfloat{\@endfloatbox
3433 % This is cheap (deferring the floats until after the current page)
3434 % but any other solution would go deep into \LaTeX's output
3435 % routine and I don't like to work on it until I know which parts
3436 % of the output routine have to be reimplemented anyway for
3439 \ifnum\@floatpenalty<\z@
3441 % We have to add the float to the |\@deferlist| because we assume
3442 % that outside the \mc{} environment we are in one column mode.
3443 % This is not entirely correct, I already used the \mc{}
3444 % environment inside of \LaTeX{}s |\twocolumn| declaration but it
3445 % will do for most applications.
3447 \@cons\@deferlist\@currbox
3449 \ifnum\@floatpenalty=-\@Mii
3457 % \begin{multicols}{2}[\subsection{Maintaining the mark registers}]
3460 % This section contains the routines that set the marks so that they
3461 % will be handled correctly. They have been introduced with version~1.4.
3463 % \begin{macro}{\kept@topmark}
3464 % \changes{v1.4h}{1992/06/04}{Init to double brace pair}
3465 % \begin{macro}{\kept@firstmark}
3466 % \begin{macro}{\kept@botmark}
3467 % First thing we do is to reserve three macro names to hold the
3468 % replacement text for \TeX's primitives |\firstmark|, |\botmark| and
3469 % |\topmark|. We initialize the first two to be empty and
3470 % |\kept@topmark| to contain two empty pair of braces. This is
3471 % necessary since |\kept@topmark| is supposed to contain the last
3472 % mark from a preceding page and in \LaTeX{} any ``real'' mark must
3473 % contain two parts representing left and right mark information.
3475 \def\kept@topmark{{}{}}
3476 \let\kept@firstmark\@empty
3477 \let\kept@botmark\@empty
3484 % \begin{macro}{\return@nonemptymark}
3485 % Sometimes we want to return the value of a ``kept'' mark into a
3486 % |\mark| node on the main vertical list. This is done by the
3487 % function |\return@nonemptymark|. As the name suggests it only acts
3488 % if the replacement text of the kept mark is non-empty. This is done
3489 % to avoid adding an empty mark when no mark was actually present. If
3490 % we would nevertheless add such a mark it would be regarded as a
3491 % valid |\firstmark| later on.
3493 \def\return@nonemptymark#1#2{%
3497 % For debugging purposes we take a look at the value of the kept mark
3498 % that we are about to return. This code will get stripped out for
3503 {Returned #1 mark:\MessageBreak
3509 % Since the contents of the mark may be arbitrary \LaTeX{} code we
3510 % better make sure that it doesn't get expanded any further. (Some
3511 % expansion have been done already during the execution of
3512 % |\markright| or |\markboth|.) We therefore use the usual mechanism
3513 % of a toks register to prohibit expansion.\footnote{Due to the
3514 % current definition of \cs{markright} etc.\ it wouldn't
3515 % help to define the \cs{protect} command to prohibit
3516 % expansion as any \cs{protect} has already vanished due to
3517 % earlier expansions.}
3518 % \changes{v1.4n}{1992/09/10}{Make marks robust}
3519 % \changes{v1.5t}{1999/03/22}{re-add \cs{mark} command which was commented out
3520 % by mistake at some point in 1998 (pr/2978)}
3522 \toks@\expandafter{#2}%
3525 % We don't want any breakpoint between such a returned mark and the
3526 % following material (which is usually just the box where the mark
3535 % \begin{macro}{\get@keptmarks}
3536 % If we have some material in a box register we may want to get the
3537 % first and the last mark out of this box. This can be done with
3538 % |\get@keptmarks| which takes one argument: the box register number
3539 % or its nick name defined by |\newbox|.
3541 \def\get@keptmarks#1{%
3543 % For debugging purposes we take a look at the current dimensions
3544 % of the box since in earlier versions of the code I made some
3545 % mistakes in this area.
3548 \typeout{Mark box #1 before:
3549 ht \the\ht#1, dp \the\dp#1}%
3552 % Now we open a new group an locally copy the box to itself. As a
3553 % result any operation, i.e.\ |\vsplit|, will only have a local
3554 % effect. Without this trick the box content would get lost up to
3555 % the level where the last assignment to the box register was done.
3561 % Now we split the box to the maximal possible dimension. This
3562 % should split off the full contents of the box so that effectively
3563 % everything is split off. As a result |\splitfirstmark| and
3564 % |\splitbotmark| will contain the first and last mark in the box
3567 \setbox#1\vsplit#1to\maxdimen
3569 % Therefore we can now set the kept marks which is a global
3570 % operation and afterwards close the group. This will restore the
3571 % original box contents.
3576 % For debugging we take again a look at the box dimension which
3577 % shouldn't have changed.
3580 \typeout{Mark box #1 \space after:
3581 ht \the\ht#1, dp \the\dp#1}%
3588 % \begin{macro}{\set@keptmarks}
3589 % The macro |\set@keptmarks| is responsible for setting
3590 % |\kept@firstmark| and |\kept@botmark|, by checking the current
3591 % values for |\splitfirstmark| and |\splitbotmark|.
3593 \def\set@keptmarks{%
3595 % If |\kept@firstmark| is empty we assume that it isn't set. This
3596 % is strictly speaking not correct as we loose the ability to have
3597 % marks that are explicitly empty, but for standard \LaTeX{}
3598 % application it is sufficient. If it is non-empty we don't change
3599 % the value---within the output routines it will then be restored
3602 \ifx\kept@firstmark\@empty
3604 % We now put the contents of |\splitfirstmark| into
3605 % |\kept@firstmark|. In the case that there wasn't any mark at all
3606 % |\kept@firstmark| will not change by that operation.
3608 \expandafter\gdef\expandafter
3610 \expandafter{\splitfirstmark}%
3612 % When debugging we show the assignment but only when something
3613 % actually happened.
3616 \ifx\kept@firstmark\@empty\else
3618 {Set kept first mark:\MessageBreak
3619 \meaning\kept@firstmark%
3625 % We always try to set the bottom mark to the |\splitbotmark| but
3626 % of course only when there has been a |\splitbotmark| at all.
3627 % Again, we assume that an empty |\splitbotmark| means that the
3628 % split off box part didn't contain any marks at all.
3630 \expandafter\def\expandafter\@tempa
3631 \expandafter{\splitbotmark}%
3632 \ifx\@tempa\@empty\else
3633 \global\let\kept@botmark\@tempa
3636 {Set kept bot mark:\MessageBreak
3637 \meaning\kept@botmark%
3645 % \begin{macro}{\prep@keptmarks}
3646 % The |\prep@keptmarks| function is used to initialize the kept
3647 % marks from the contents of |\partial@page|, i.e.\ the box that
3648 % holds everything from the top of the current page prior to
3649 % starting the \mc{} environment. However, such a box is only
3650 % available if we are not producing a boxed \mc{}.
3652 \def\prep@keptmarks{%
3653 \if@boxedmulticols \else
3654 \get@keptmarks\partial@page
3660 % \begin{macro}{\remove@discardable@items}
3661 % There are situations when we may have some space at the end of a
3662 % column and this macro here will attempt to get rid of it. The
3663 % typical \LaTeX{} sequence is a series of selfcanceling glues so
3664 % if we remove them recursively we are usually fine.
3666 % Special care is needed with handling |\vspace*| as that
3667 % corresponds to |\penalty10000|, |\vskip <skip>|, followed by
3668 % |\vskip 0pt|. If we see this sequence going backwards in the the
3669 % vertical list we assume that this is a ``desired'' space. We
3670 % therefore stop the recursion and reinsert the spaces.
3672 % As the multicol code sometimes add an explicit penalty at the end
3673 % of a column we first attempt to remove it in case it is there.
3674 % \changes{v1.8m}{2015/03/31}{Another rewrite of
3675 % \cs{remove@discardable@items} hopefully okay now}
3678 \edef\the@zero@skip{\the\skip0}
3679 \def\remove@discardable@items{%
3682 % Save a previous skip (if there) and then remove it, we can't
3683 % really tell the difference between no skip an a skip of zero but
3686 \edef\@tempa{\the\lastskip}%
3687 %\typeout{s1=\@tempa}%
3690 % If it was a zero skip (or none) we save the next previous skip
3693 \ifx\@tempa\the@zero@skip
3694 \edef\@tempb{\the\lastskip}%
3695 %\typeout{s2=\@tempb}%
3697 % If this one again was zero (or more likely not there in the first
3700 \ifx\@tempb\the@zero@skip
3703 % Otherwise we remove this ``real'' skip. Then we look if it was
3704 % preceeded by a penalty of 10000 (i.e., a |\nobreak|)
3707 %\typeout{p=\lastpenalty}%
3708 \ifnum \lastpenalty=\@M
3710 % If so this was a |\vspace*| or something equivalent to
3711 % it. Therefore we reintroduce the skips and stop. Otherwise we
3714 \vskip\@tempb\vskip\@tempa\relax
3716 \remove@discardable@items
3721 % If the first skip was a non-zero skip we recurse as well.
3723 \remove@discardable@items
3732 \def\too@badtrue{\global\let\iftoo@bad\iftrue}
3733 \def\too@badfalse{\global\let\iftoo@bad\iffalse}
3736 % \changes{v1.8k}{2015/03/21}{The new switch}
3738 \newif\ifforcedbreak@leftover
3741 % \begin{macro}{\c@columnbadness}
3742 % \begin{macro}{\c@finalcolumnbadness}
3744 \newcount\c@columnbadness
3745 \c@columnbadness=10000
3746 \newcount\c@finalcolumnbadness
3747 \c@finalcolumnbadness=9999
3753 % \changes{v1.5z1}{2003/02/17}{Change wrong default for
3754 % \cs{multicolovershoot} to zero (pr/3465).}
3756 \newdimen\multicolovershoot
3757 \newdimen\multicolundershoot
3758 \multicolovershoot=0pt
3759 \multicolundershoot=2pt
3760 \newbox\mult@nat@firstbox
3766 % \begin{macro}{\mult@info}
3767 % A helper for producing info messages
3769 \def\mult@info#1#2{%
3770 \ifnum\c@tracingmulticols>#1%
3772 {(multicol)\@spaces\@spaces}%
3773 {Package multicol: #2}%
3782 % \begin{multicols}{2}[\section{Fixing the
3783 % \cs{columnwidth}}]
3785 % \begin{macro}{\@footnotetext}
3786 % \changes{v1.5o}{1997/11/16}{Redefinition added pr/2664.}
3787 % \changes{v1.5r}{1998/08/17}{Use \cs{@footnotetext} but with
3788 % local change to \cs{columnwidth}.}
3789 % \begin{macro}{\mult@footnotetext}
3790 % \changes{v1.5r}{1998/08/17}{Macro removed again.}
3791 % If we store the current column width in |\columnwidth| we have
3792 % to redefine the internal |\@footnotetext| macro to use |\textwidth|
3793 % for the width of the footnotes rather than using the original
3796 % Starting with version v1.5r this is now done in a way that the original
3797 % definition is still used, except that locally |\columnwidth| is set to
3800 % This solves two problems: first redefinitions of |\@footnotetext|
3801 % done by a class will correctly survive and second if multicols is
3802 % used inside a minipage environment the special definition of
3803 % |\@footnotetext| in that environment will be picked up and not the
3804 % one for the main galley (the latter would result in all footnotes
3805 % getting lost in that case).
3807 % See the definition of the |\multicols| command further up for the exact
3814 % \begin{multicols*}{2}[\section{Further extensions}]
3816 % This section does contain code for extensions added to this package
3817 % over time. Not all of them may be active, some might sit dormant and
3818 % wait for being activated in some later release.
3820 % \subsection{Not balancing the columns}
3822 % This is fairly trivial to implement. we just have to disable the
3823 % balancing output routine and replace it by the one that ships out
3826 % \begin{macro}{\multicols*}
3827 % \changes{v1.5q}{1998/01/19}{Macro added}
3828 % The code for this environment was suggested by Matthias Clasen.
3831 \@namedef{multicols*}{%
3833 % If we are not on the main galley, i.e., inside a box of some
3834 % sort, that approach will not work since we don't have a vertical
3835 % size for the box so we better warn that we balance anyway.
3838 \PackageWarning{multicol}%
3839 {multicols* inside a box does
3840 not make sense.\MessageBreak
3841 Going to balance anyway}%
3843 \let\balance@columns@out
3851 % \begin{macro}{\endmulticols*}
3852 % When ending the environment we simply end the inner
3853 % \texttt{multicols} environment, except that we better also stick
3854 % in some stretchable vertical glue so that the last column still
3855 % containing text is not vertically stretched out.
3857 % We do this as follows: first we ensure that we are back in vertical mode
3858 % and then we cancel out |\lastskip| if it was
3859 % positive (in case of a negative glue we assume that it was
3860 % deliberate, for a deliberate positive glue one needs to use
3861 % |\vspace*|). We can't simply use |\remove@discardable@items| here
3862 % as this only works inside boxes but we are here on the main
3865 % Then we back up by |\prevdepth| but not more than |\boxmaxdepth|
3866 % so that a baseline of the last box is now at the bottom. This way
3867 % the material will align properly in case something like |\vfill|
3868 % spreads it out after all.
3869 % Finally we append |\vfil| to put white space at the bottom of the
3870 % column, but we only do this if we aren't anyway doing |\raggedcolumns|.
3871 % \changes{v1.5q}{1998/01/19}{Macro added}
3872 % \changes{v1.8h}{2014/09/12}{Use \cs{vfilmaxdepth}}
3873 % \changes{v1.8i}{2014/10/28}{Add \cs{null} to hide the final fill and only add
3874 % vertical space if not doing \cs{raggedcolumns}}
3875 % \changes{v1.8j}{2015/03/07}{Redesign the whole approach.}
3876 % \changes{v1.8k}{2015/03/21}{And a bit more redesign because of the
3877 % change in \cs{remove@discardable@items}}
3878 % \changes{v1.8o}{2016/02/08}{Ensure we are back in vmode before using
3879 % \cs{prevdepth} (pr/4448)}
3881 \@namedef{endmulticols*}{%
3883 \ifdim\lastskip>\z@ \vskip-\lastskip \fi
3884 \ifdim \prevdepth>\z@
3885 \vskip-\ifdim\prevdepth>\boxmaxdepth
3887 \else \prevdepth \fi
3898 % \subsection{Manual column breaking} \label{sec:colbreak}
3900 % The problem with manual page breaks within \mc{} is the fact that
3901 % during collection of material for all columns a page-forcing penalty
3902 % (i.e. -10000 or higher) would stop the collecting pass which is not
3903 % quite what is desired. On the other hand, using a penalty like -9999
3904 % would mean that there would be occasions where the |\vsplit|ing
3905 % operations within \mc{} would ignore that penalty and still choose a
3906 % different break point.
3908 % For this reason the current implementation
3909 % uses a completely different approach. In a nutshell it extends the \LaTeX{}
3910 % output routine handling by introducing an additional penalty flag
3911 % (i.e., a penalty which is forcing but higher than -10000 so that the
3912 % output routine can look at this value and thus knows why it has been
3915 % Inside the output routine we test for this value and if it appears
3916 % we do two things: save the galley up to this point in a special box
3917 % for later use and reduce the |\vsize| by the height of the material
3918 % seen. This way the forcing penalty is now hidden in that box and we
3919 % can restart the collection process for the remaining
3920 % columns. (This is done in |\speci@ls| above.)
3922 % In the output routines that do the |\vsplit|ting either for
3923 % balancing or for a full page we simply combine box~255 with the
3924 % saved box thus getting a single box for splitting which now
3925 % contains forcing breaks in the right positions.
3928 % \begin{macro}{\columnbreak}
3929 % \changes{v1.5u}{1999/05/25}{Macro added}
3930 % |\columnbreak| is modelled after |\pagebreak| except that we
3931 % generate a penalty -10005.
3933 \mathchardef\@Mv=10005
3936 % We have to ensure that it is only used within a \mc{}
3937 % environment since if that penalty would be seen by the unmodified
3938 % \LaTeX{} output routine strange things would happen.
3940 \ifnum\col@number<\tw@
3941 \PackageError{multicol}%
3942 {\noexpand\columnbreak outside multicols}%
3943 {This command can only be used within
3944 a multicols or multicols* environment.}%
3947 \penalty -\@Mv\relax
3950 \vadjust{\penalty -\@Mv\relax}%
3958 % \begin{macro}{\colbreak@box}
3959 % \changes{v1.5u}{1999/05/25}{Macro added}
3960 % Need a box to collect the galley up to the column break.
3962 \newbox\colbreak@box
3968 % \subsection{Supporting right-to-left languages} \label{sec:RL}
3971 % \changes{v1.7a}{2010/10/24}{RL language support added}
3972 % \changes{v1.7b}{2011/12/18}{RL language support fixed}
3974 % \begin{macro}{\LR@column@boxes}
3975 % |\LR@column@boxes| is called when we are assembling the columns for left
3976 % to right typesetting. When we start we are inside an |\hbox| of
3978 % Left to right typesetting is fairly easy, we basically output
3979 % each column box intermixed with vertical rules and proper
3980 % spacing. As this happens inside a box of a defined width the
3981 % rules and the columns automatically get into the right positions.
3983 \def\LR@column@boxes{%
3985 % We loop through the columns with |\process@cols|
3987 \process@cols\mult@gfirstbox{%
3989 % If the depth of the current box is larger than the maximum found
3990 % so far in |\dimen2| we update that register for later use.
3991 % \changes{v1.6a}{2003/03/15}{Preparing for adjusting \cs{prevdepth}}
3993 \ifdim\dp\count@>\dimen\tw@
3994 \global\dimen\tw@\dp\count@ \fi
3996 % If the \texttt{colaction} option is given we write out status
3997 % information about the current column, otherwise the next command
3999 % \changes{v1.8e}{2014/04/23}{Support \cs{docolaction}}
4001 \mc@col@status@write
4003 % The typeset box followed by the column rule material
4006 \hss{\columnseprulecolor\vrule
4007 \@width\columnseprule}\hss}%
4009 % As you will have noticed, we started with box register
4010 % |\mult@gfirstbox| (i.e.\
4011 % the left column). So this time |\count@| looped through 2,
4012 % 4,\ldots\ (plus the appropriate offset).
4013 % Finally we add box |\mult@rightbox| and we are done.
4014 % \changes{v1.5a}{1992/11/04}{New box mechanism}
4015 % \changes{v1.6a}{2003/03/15}{Preparing for adjusting \cs{prevdepth}}
4016 % Again we may have to update |\dimen\tw@|.
4018 \ifdim\dp\mult@rightbox>\dimen\tw@
4019 \global\dimen\tw@\dp\mult@rightbox \fi
4021 % If the \texttt{colaction} option is given we write out status
4022 % information about the last column, otherwise the next command
4024 % \changes{v1.8e}{2014/04/23}{Support \cs{docolaction}}
4026 \mc@lastcol@status@write
4032 % \begin{macro}{\RL@column@boxes}
4033 % Assembling the boxes for right to left typesetting is far more
4034 % complicated. When I first tried to build a solution for this my
4035 % thinking was that all that is necessary to do is to reverse the
4036 % order of the columns. But such an approach produces a subtle bug:
4037 % If we work this way then the first column put on the page will be
4038 % the last column of the text to read. and this means that the
4039 % order in which \TeX{} executes write statements or assembles mark
4040 % material will not happen in the order of the textual flow. So if,
4041 % for example each column contains a section command then these
4042 % sections will appear in reverse order in the table of content.
4044 % For this reason some amount of gymnastics is needed to add the
4045 % columns in their natural flow.
4047 \def\RL@column@boxes{%
4049 % First step is to put all rules in the right place (without adding
4050 % the comes which are instead represented by a space of |\hsize|.
4052 \process@cols\mult@gfirstbox{%
4054 \hss{\columnseprulecolor\vrule
4055 \@width\columnseprule}\hss
4059 % At this point in the code our typesetting reference point is at
4060 % the right end of the rightmost column (or rather where that column
4063 % We are now typesetting all columns by first backing up by their
4064 % width (which is |\hsize|) then typesetting the box and then
4065 % backing up again, but this time further, i.e., also across the
4066 % column separation. That will then enable us to typeset the next
4067 % column using the same approach until we are done with all but the
4070 \process@cols\mult@gfirstbox{%
4071 \ifdim\dp\count@>\dimen\tw@
4072 \global\dimen\tw@\dp\count@ \fi
4076 % \changes{v1.8e}{2014/04/23}{Support \cs{docolaction}}
4078 \mc@col@status@write
4084 % The approach for the final column is similar only that we do not
4085 % have to back up over any column gap.
4087 \ifdim\dp\mult@rightbox>\dimen\tw@
4088 \global\dimen\tw@\dp\mult@rightbox \fi
4092 % \changes{v1.8e}{2014/04/23}{Support \cs{docolaction}}
4094 \mc@lastcol@status@write
4098 % However we do have to move the reference point to its right
4099 % place: to make the rules appear at the expected places, we should
4100 % get the typesetting position to the far right again. As we at the
4101 % moment at the far left we skip to the far right like this:
4108 % \begin{macro}{\RLmulticolcolumns}
4109 % \begin{macro}{\LRmulticolcolumns}
4110 % \begin{macro}{\mc@align@columns}
4111 % Macros to switch between left-right and right-left typesetting. In LR
4112 % typesetting the |\LR@column@boxes| is used to combine
4113 % the columns. When typesetting right to left the |\RL@column@boxes|
4116 \newcommand\RLmulticolcolumns
4117 {\let\mc@align@columns
4119 \newcommand\LRmulticolcolumns
4120 {\let\mc@align@columns
4123 % The default is left-to-right:
4132 % \subsection{Supporting \texttt{\textbackslash docolaction}}
4134 % \changes{v1.8e}{2014/04/23}{Support \cs{docolaction}}
4136 % Whenever we want to do something that depends on the current
4137 % column we execute \verb=\docolaction=. This command takes one
4138 % optional and three mandatory arguments. The mandatory ones denote
4139 % what to do if this is a ``left'', ``middle'', or ``right'' column
4140 % and the optional one is simply there to say what to do if we don't
4141 % know (default is to use the ``left'' column action in that case).
4143 % \begin{macro}{\mc@col@check@num}
4144 % We use one counter \verb=\mc@col@check@num= to generate us unique
4145 % label names. Each time we execute \verb=\docolaction= we increment
4146 % this counter to get a new name.
4148 \newcount\mc@col@check@num
4152 % The generated ``labels'' are named
4154 %\mc@col-\the\mc@col@check@num
4156 % and they hold as values the
4157 % numbers 1, 2, or 3 denoting the current column type.
4159 % \begin{macro}{\docolaction}
4162 \newcommand\docolaction[4][1]{%
4163 \ifx\mc@col@status@write\relax
4164 \PackageError{multicol}%
4165 {Option 'colaction' not selected}%
4166 {\string\docolaction\space
4167 requires the use of the 'colaction'
4168 option on the package}%
4170 \global\advance\mc@col@check@num\@ne
4171 \edef\mc@col@type{\expandafter\ifx
4172 \csname mc@col-\the\mc@col@check@num
4175 \csname mc@col-\the\mc@col@check@num
4179 % We prefix with 0 so that an unknown label (that returns
4180 % \verb=\relax=) will result in case 0
4182 \ifcase \mc@col@type\relax
4184 % If column is unknown we use the default action or the action
4185 % denoted by the optional argument (so that arg can take the value
4188 \ifcase #1\or #2\or#3\or#4\fi
4191 % Otherwise we know (or think we know) that this is a first, middle,
4196 #3% % 2 any middle col
4203 % But how does the column number get associated with our label? We
4204 % do do this by writing another line into the aux file at this point:
4206 \edef\next{\write\@auxout
4207 {\string\mc@set@col@status
4208 {mc@col-\the\mc@col@check@num}%
4215 % Because of extra data writing to the aux file the aux file will
4216 % now contain something like the following after the document is
4217 % processed the first time:
4221 %\mc@set@col@status{lcol-1}{0}
4223 %\mc@set@col@status{lcol-2}{0}
4225 %\mc@set@col@status{lcol-3}{0}
4229 %\mc@set@col@status{lcol-4}{0}
4231 % The \verb=\mc@col@status= line denotes the column type and has been
4232 % written out just before corresponding the column box was placed
4234 % The\verb=\mc@set@col@status= lines have been written out as part
4235 % of shipping the column boxes out, e.g.,
4236 % \verb=\mc@set@col@status{lcol-1}{0}= was therefore somewhere within
4237 % the first column as it appears between \verb=\mc@col@status{1}=
4238 % and \verb=\mc@col@status{2}=
4239 % The second argument in that line is the value used in the previous
4240 % run (or zero if there was no previous run. We can use this to
4241 % determine if a rerun is necessary.
4243 % Thus with this knowledge we can set things up to get the labels
4247 % \begin{macro}{\mc@col@status}
4249 % When the aux file is read in \verb=\mc@col@status= is used to set
4250 % \verb=\mc@curr@col@status=:
4252 \def\mc@col@status#1{%
4253 \gdef\mc@curr@col@status{#1}}
4259 % \begin{macro}{\mc@set@col@status}
4261 % And when \verb=\mc@set@col@status= is executed we can simply set
4262 % up the label by associating it with the \verb=\mc@curr@col@status=
4263 % and ignore the second argument:
4265 \def\mc@set@col@status#1#2{%
4266 \global\expandafter\let\csname #1\endcsname
4267 \mc@curr@col@status}
4269 % The above definition is being used when the \texttt{.aux} file is
4270 % read in at the beginning. At the end we need a different
4271 % definition to test if another typesetting run is needed. There we
4272 % compare the value used in the current run (stored in the second
4273 % argument) with the value used on the next run. If those two values
4274 % differ we set \verb=@tempswa= to false which will trigger the
4275 % ``Label(s) may have changed'' warning.
4277 \AtEndDocument{\def\mc@set@col@status#1#2{%
4278 \ifnum #2=\mc@curr@col@status\else
4286 % \begin{macro}{mc@firstcol}
4287 % Finally, as part of determining in which column we are, we used a
4288 % switch inside |\mc@col@status@write| to determine if we are in the
4289 % first column or not.
4291 \newif\ifmc@firstcol