Debian Codegraph @

texmf-dist/source/latex/revtex4/ltxgrid.dtx

raw
1 % \iffalse ltxdoc klootch
2 % ltxgrid.dtx: package to change page grid, MVL.
3 % Copyright (c) 1999 Arthur Ogawa
4 %
5 % Disclaimer
6 % This file is distributed WITHOUT ANY WARRANTY;
7 % without even the implied warranty of
8 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9 % ReadMe
10 % For the documentation and more detailed instructions for
11 % installation, typeset this document with \LaTeX.
12 % \fi
13 % \GetFileInfo{ltxgrid.dtx}
14 %
15 % \iffalse ltxdoc klootch
16 %<*ltxgrid>
17 %%% @LaTeX-file{
18 %%% filename = "ltxgrid.dtx",
19 %%% version = "1.0d",
20 %%% date = "2020/09/30",
21 %%% author = "Arthur Ogawa (mailto:[email protected]),
22 %%% Phelype Oleinik (mailto:phelype.oleinik at latex-project.org),
23 %%% commissioned by the American Physical Society.
24 %%% ",
25 %%% copyright = "Copyright (C) 1999, 2000 Arthur Ogawa,
26 %%% distributed under the terms of the
27 %%% LaTeX Project Public License, see
28 %%% ftp://ctan.tug.org/macros/latex/base/lppl.txt
29 %%% ",
30 %%% address = "Arthur Ogawa,
31 %%% USA",
32 %%% telephone = "",
33 %%% FAX = "",
34 %%% email = "[email protected]",
35 %%% codetable = "ISO/ASCII",
36 %%% keywords = "latex, page grid, main vertical list",
37 %%% supported = "yes",
38 %%% abstract = "package to change page grid, MVL",
39 %%% }
40 %</ltxgrid>
41 % \fi
42 %
43 % \iffalse ltxdoc klootch
44 % The following references the \file{00readme.txt} file,
45 % which contains basic information about this package.
46 % The contents of this file are generated when
47 % you typeset the programmer's documentation.
48 % Search on "{filecontents*}{00readme.txt}" to locate it.
49 % \fi\input{00readme.txt}%
50 %
51 % \subsection{Bill of Materials}
52 %
53 % Following is a list of the files in this distribution arranged
54 % according to provenance.
55 %
56 % \subsubsection{Primary Source}%
57 % One single file generates all.
58 %\begin{verbatim}
59 %ltxgrid.dtx
60 %\end{verbatim}
61 %
62 % \subsubsection{Generated by \texttt{latex ltxgrid.dtx}}%
63 % Typesetting the source file under \LaTeX\
64 % generates the readme and the installer.
65 %\begin{verbatim}
66 %00readme.txt ltxgrid.ins
67 %\end{verbatim}
68 %
69 % \subsubsection{Generated by \texttt{tex ltxgrid.ins}}%
70 % Typesetting the installer generates
71 % the package files.
72 %\begin{verbatim}
73 %ltxgrid.sty
74 %\end{verbatim}
75 %
76 % \subsubsection{Documentation}%
77 % The following are the online documentation:
78 % \begin{verbatim}
79 %ltxgrid.pdf
80 % \end{verbatim}
81 %
82 % \subsubsection{Auxiliary}%
83 % The following are auxiliary files generated
84 % in the course of running \LaTeX:
85 % \begin{verbatim}
86 %ltxgrid.aux ltxgrid.idx ltxgrid.ind ltxgrid.log ltxgrid.toc
87 % \end{verbatim}
88 %
89 % \section{Code common to all modules}%
90 %
91 % The following may look a bit klootchy, but we
92 % want to require only one place in this file
93 % where the version number is stated,
94 % and we also want to ensure that the version
95 % number is embedded into every generated file.
96 %
97 % Now we declare that
98 % these files can only be used with \LaTeXe.
99 % An appropriate message is displayed if
100 % a different \TeX{} format is used.
101 % \begin{macrocode}
102 %<*doc|ltxgrid>
103 \NeedsTeXFormat{LaTeX2e}[1995/12/01]%
104 %</doc|ltxgrid>
105 % \end{macrocode}
106 % As desired, the following modules all
107 % take common version information:
108 % \begin{macrocode}
109 %<ltxgrid>\ProvidesFile{ltxgrid.sty}%
110 %<*doc>
111 \expandafter\ProvidesFile\expandafter{\jobname.dtx}%
112 %</doc>
113 % \end{macrocode}
114 %
115 % The following line contains, for once and for all,
116 % the version and date information.
117 % By various means, this information is reproduced
118 % consistently in all generated files and in the
119 % typeset documentation.
120 % \begin{macrocode}
121 %<*doc|ltxgrid>
122 [2020/09/30 1.0d page grid package]% \fileversion
123 %</doc|ltxgrid>
124 % \end{macrocode}
125 %
126 %
127 % \section{The driver module \texttt{doc}}
128 %
129 % This module, consisting of the present section,
130 % typesets the programmer's documentation,
131 % generating the \file{.ins} installer and \file{00readme.txt} as required.
132 %
133 % Because the only uncommented-out lines of code at the beginning of
134 % this file constitute the \file{doc} module itself,
135 % we can simply typeset the \file{.dtx} file directly,
136 % and there is thus rarely any need to
137 % generate the ``doc'' {\sc docstrip} module.
138 % Module delimiters are nonetheless required so that
139 % this code does not find its way into the other modules.
140 %
141 % The \enve{document} command concludes the typesetting run.
142 %
143 % \begin{macrocode}
144 %<*doc>
145 % \end{macrocode}
146 %
147 % \subsection{The Preamble}
148 % The programmers documentation is formatted
149 % with the \classname{ltxdoc} class with local customizations,
150 % and with the usual code line indexing.
151 % \begin{macrocode}
152 \documentclass{ltxdoc}
153 \RequirePackage{ltxdocext}%
154 \RequirePackage[colorlinks=true,linkcolor=blue]{hyperref}%
155 \makeatletter
156 \@ifundefined{package@font}{}%
157 {\expandafter\RequirePackage\expandafter{\csname package@font\endcsname}}
158 \makeatother
159 \CodelineIndex\EnableCrossrefs
160 % \end{macrocode}
161 %
162 % \subsubsection{Docstrip and info directives}
163 % We use so many {\sc docstrip} modules that we set the
164 % \texttt{StandardModuleDepth} counter to 1.
165 % \begin{macrocode}
166 \setcounter{StandardModuleDepth}{1}
167 % \end{macrocode}
168 % The following command retrieves the date and version information
169 % from this file.
170 % \begin{macrocode}
171 \expandafter\GetFileInfo\expandafter{\jobname.dtx}%
172 % \end{macrocode}
173 %
174 %
175 % \subsection{The installer file}
176 %
177 % The installer \file{ltxgrid.ins} appears here.
178 % If you have retrieved the standard distribution of this package,
179 % the installer file is already on your filesystem.
180 % If you are bootstrapping,
181 % the first typesetting of the \file{.dtx} file
182 % will cause the installer to be generated.
183 %
184 % The following modules are used to direct
185 % {\sc docstrip} in generating the external files:
186 % \begin{center}
187 % \begin{tabular}{lll}
188 % \textbf{Module}&\textbf{File}&\textbf{Description}\\
189 % doc &\file{ltxgrid.drv}&driver for programmer's documentation\\
190 % ltxgrid,ltxgrid-krn &\file{ltxgrid.sty}&this package\\
191 % ltxgrid-krn& &the portion of this package suitable for inclusion within another package
192 % \end{tabular}
193 % \end{center}
194 %
195 % \begin{macrocode}
196 \begin{filecontents}{ltxgrid.ins}
197 %% This file will generate documentation and runtime files
198 %% from ltxgrid.dtx when run through LaTeX or TeX.
199 \input docstrip
200 \preamble
201
202 This is a generated file;
203 altering it directly is inadvisable;
204 instead, modify the original source file.
205 See the URL in the file 00readme.txt.
206
207 Copyright notice.
208
209 These files are distributed
210 WITHOUT ANY WARRANTY; without even the implied warranty of
211 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
212
213 \endpreamble
214 \keepsilent
215 \generate{%
216 \file{ltxgrid.drv}{\from{ltxgrid.dtx}{doc}}%
217 \file{ltxgrid.sty}{%
218 \from{ltxgrid.dtx}{ltxgrid,ltxgrid-krn}%
219 }%
220 }%
221 \ifToplevel{
222 \Msg{***********************************************************}
223 \Msg{*}
224 \Msg{* To finish the installation, please move}
225 \Msg{* ltxgrid.sty}
226 \Msg{* into a directory searched by TeX;}
227 \Msg{* in a TDS-compliant installation:}
228 \Msg{* texmf/tex/macros/latex/ao/.}
229 \Msg{*}
230 \Msg{* To produce the documentation,
231 run ltxgrid.dtx through LaTeX.}
232 \Msg{*}
233 \Msg{* Happy TeXing}
234 \Msg{***********************************************************}
235 }
236 \endbatchfile
237 \end{filecontents}
238 % \end{macrocode}
239 % Note that, because all of the files generated by the installer
240 % are part of the standard distribution, it will
241 % be necessary to run the installer only when bootstrapping
242 % (or, of course, during development).
243 % Note, too, that it is rare to generate the \file{doc}
244 % module because it suffices to simply typeset the \file{.dtx} file itself.
245 %
246 % \subsection{The ``Read Me'' File}
247 % As promised above, here is the contents of the
248 % ``Read Me'' file. That file serves a double purpose,
249 % since it also constitutes the beginining of the
250 % programmer's documentation. What better thing, after
251 % all, to have appear at the beginning of the
252 % typeset documentation?
253 %
254 % A good discussion of how to write a ReadMe file can be found in
255 % Engst, Tonya, ``Writing a ReadMe File? Read This''
256 % \emph{MacTech} October 1998, p. 58.
257 %
258 % Note the appearance of the
259 % \cmd\StopEventually\ command, which marks the
260 % dividing line between the user documentation
261 % and the programmer documentation.
262 %
263 % The usual user will not be asked to
264 % do a full build, not to speak
265 % of the bootstrap.
266 % Instructions for carrying these processes
267 % begin the programmer's manual.
268 %
269 % \begin{macrocode}
270 \begin{filecontents*}{00readme.txt}
271 \title{%
272 A \LaTeX\ Package for changing the page grid and MVL%
273 \thanks{%
274 This file has version number \fileversion,
275 last revised \filedate.%
276 % For version number and date,
277 % search on "\fileversion" in the .dtx file,
278 % or see the end of the 00readme.txt file.
279 }%
280 }%
281
282 \author{%
283 Arthur Ogawa (\texttt{mailto:[email protected]}),
284 \fileversion\\Copyright (C) 1999, 2000 Arthur Ogawa
285 }%
286 \maketitle
287
288 This file embodies the \classname{ltxgrid} package,
289 the implementation and its user documentation.
290
291 The distribution point for this work is
292 \url{ftp://ftp.teleport.com/users/ogawa/macros/latex/contrib/supported/ltxgrid...},
293 which contains fully unpacked, prebuilt runtime files and documentation.
294
295 The \classname{ltxgrid} package was commissioned by the American Physical Society
296 and is distributed under the terms of the \LaTeX\ Project Public License,
297 the same license under which all the portions of \LaTeX\ itself is distributed.
298 Please see \url{http://ctan.tug.org/macros/latex/base/lppl.txt} for details.
299
300 To use this document class, you must have a working
301 \TeX\ installation equipped with \LaTeXe\
302 and possibly pdftex and Adobe Acrobat Reader or equivalent.
303
304 To install, retrieve the distribution,
305 unpack it into a directory on the target computer,
306 into a location in your filesystem where it will be found by \LaTeX;
307 in a TDS-compliant installation this would be:
308 \file{texmf/tex/macros/latex/ao/.}
309
310 To use, read the user documentation \file{ltxgrid.pdf}.
311
312 \tableofcontents
313
314 \section{Processing Instructions}
315
316 The package file \file{ltxgrid.sty}
317 is generated from this file, \file{ltxgrid.dtx},
318 using the {\sc docstrip} facility of \LaTeX
319 via |tex ltxgrid.ins|.
320 The typeset documentation that you are now reading is generated from
321 the same file by typesetting it with \LaTeX\ or pdftex
322 via |latex ltxgrid.dtx| or |pdflatex ltxgrid.dtx|.
323
324 \subsection{Build Instructions}
325
326 You may bootstrap this suite of files solely from \file{ltxgrid.dtx}.
327 Prepare by installing \LaTeXe\ (and either tex or pdftex) on your computer,
328 then carry out the following steps:
329 \begin{enumerate}
330 \item
331 Within an otherwise empty directory,
332 typeset \file{ltxgrid.dtx} with \LaTeX\ or pdflatex;
333 you will obtain the typeset documentation you are now reading,
334 along with
335 the installer \file{ltxgrid.ins},
336 and the file \file{00readme.txt}.
337
338 Note: you will have to run \LaTeX\ twice, then \file{makeindex}, then
339 \LaTeX\ again in order to obtain a valid index and table of contents.
340 \item
341 Now typeset \file{ltxgrid.ins},
342 thereby generating the package file \file{ltxgrid.sty}.
343 \item
344 Install \classname{ltxgrid.sty}
345 by moving it to a location
346 in your filesystem where they will be found by \LaTeX.
347 \end{enumerate}
348 \end{filecontents*}
349 % \end{macrocode}
350 %
351 % \subsection{The Document Body}
352 %
353 % Here is the document body, containing only a
354 % \cmd\DocInput\ directive---referring to this very file.
355 % This very cute self-reference is a common \classname{ltxdoc} idiom.
356 % \begin{macrocode}
357 \begin{document}%
358 \expandafter\DocInput\expandafter{\jobname.dtx}%
359 % ^^A\PrintChanges
360 \end{document}
361 % \end{macrocode}
362 %
363 % \begin{macrocode}
364 %</doc>
365 % \end{macrocode}
366 %
367 % \section{Using this package}
368 % Once this package is installed on your filesystem, you can employ it in
369 % adding functionality to \LaTeX\ by invoking it in your document or document class.
370 %
371 % \subsection{Invoking the package}
372 % In your document, you can simply call it up in your preamble:
373 % \begin{verbatim}
374 %\documentclass{book}%
375 %\usepackage{ltxgrid}%
376 %\begin{document}
377 %<your document here>
378 %\end{document}
379 % \end{verbatim}
380 % However, the preferred way is to invoke this package from within your
381 % customized document class:
382 % \begin{verbatim}
383 %\NeedsTeXFormat{LaTeX2e}[1995/12/01]%
384 %\ProvidesClass{myclass}%
385 %\LoadClass{book}%
386 %\RequirePackage{ltxgrid}%
387 %<class customization commands>
388 %\endinput
389 % \end{verbatim}
390 %
391 % Note that this package requires the features of the \classname{ltxutil} package,
392 % available at
393 % \url{ftp://ftp.teleport.com/users/ogawa/macros/latex/contrib/supported/ltxutil/}.
394 %
395 % Once loaded, the package gives you acccess to certain procedures,
396 % usually to be invoked by a \LaTeX\ command or environment, but not at the document level.
397 %
398 % \subsection{Changing the page grid}%
399 % This package provides two procedures, \cmd\onecolumngrid, \cmd\twocolumngrid,
400 % that change the page grid (it can be extended to more columns and to other page grids).
401 %
402 % They differ from standard \LaTeX's \cmd\onecolumn\ and \cmd\twocolumn\ commands in that
403 % they do not force a page break. Also, upon leaving a multiple-column grid, the columns are balanced.
404 % In other respects they work same.
405 %
406 % They differ from the grid-changing commands of Frank Mittelbach's \classname{multicol} package
407 % in that they allow floats of all types (single- and double column floats, that is) and
408 % preserve compatability with the \classname{longtable} package.
409 %
410 % These commands must be issued in vertical mode (conceivably via a \cmd\vadjust) such that
411 % they are ultimately present in the MVL, where they can do their work.
412 % Because they do not work in \LaTeX's left-right mode, they are unsuitable at the
413 % document level.
414 % Furthermore, packaging a grid command in a \cmd\vadjust, although possible, will probably
415 % not acheive satisfactory page layout.
416 %
417 % Page grid commands are not intended to be issued unnecessarily: only the first of
418 % two successive \cmd\onecolumngrid\ commands is effective; the second will be silently ignored.
419 %
420 % \DescribeMacro\onecolumngrid
421 % You command \LaTeX\ to return to the one-column grid with the
422 % \cmd\onecolumngrid\ command. If you are already in the one-column grid, this
423 % is a no-op. The one-column grid is considered special of all page grids, in that
424 % no portion of the page is held back (in \cmd\pagesofar); all items that might go
425 % on the current page (with the exception of floats and footnotes) are on the MVL.
426 %
427 % \DescribeMacro\twocolumngrid
428 % You command \LaTeX\ to return to the two-column grid with the
429 % \cmd\twocolumngrid\ command. If you are already in the two-column grid, this
430 % is a no-op.
431 %
432 % These two commands should be issued by a macro procedure that can ensure that
433 % \TeX\ is in outer vertical mode.
434 %
435 % \subsection{Changing the MVL}%
436 %
437 % This package also provides commands to modify the main vertical list (MVL) in a safe way.
438 % The scheme here is to structure, insofar possible, \TeX's MVL as follows:
439 %\begin{quotation}
440 %box or boxes\\
441 %penalty\\
442 %glue
443 %\end{quotation}
444 % This should be a familiar sequence. It is the prototype sequence for a vertical list,
445 % and is followed when \TeX\ breaks paragraphs into lines, and when \TeX\ generates
446 % a display math equation.
447 %
448 % If you (as a macro programmer) wish to modify the value of the penalty or glue item,
449 % you can use one of the MVL-altering commands to do so. Certain operations are implemented
450 % here; you can make up your own.
451 %
452 % Note that these commands must be issued in vertical mode, perhaps via a \cmd\vadjust\ or a \cmd\noalign.
453 % They can work directly if you are in inner mode (say within a parbox or a minipage).
454 %
455 % \DescribeMacro\removestuff
456 % You instruct \LaTeX\ to remove both the penalty and the glue item with this command.
457 %
458 % \DescribeMacro\addstuff
459 % You issue the \cmd\addstuff\arg{penalty}\arg{glue} command to add a penalty, glue, or both.
460 % If you do not wish to add one or the other, the corresponding argument should be nil.
461 % Note that the effect of \cmd\addstuff\ is to stack the penalties and glue items.
462 % Therefore, the lesser of the two penalties takes effect,
463 % and the two glue items add together.
464 %
465 % \cmd\addstuff\ is limited because once applied, it cannot be applied again with correct results.
466 %
467 % \DescribeMacro\replacestuff
468 % The \cmd\replacestuff\ command is syntactically the same as \cmd\addstuff, but works
469 % differently: the existing penalty and glue are replaced or modified.
470 %
471 % The specified penalty is not inserted if the existing penalty is greater than 10000
472 % (that is, in case of a \cmd\nobreak), otherwise, the lower (non-zero) of the two penalties is inserted.
473 %
474 % If the specified glue has a larger natural component than the existing glue, we replace the glue.
475 % However, if the specified glue's natural component is negative, then the existing glue's natural component is
476 % changed by that amount.
477 %
478 % \cmd\replacestuff\ can be applied mutiple times bceause it retains the list structure in the canonical form.
479 %
480 % Note that we treat two penalties specially (as does \TeX): a penalty of 10000 is considered
481 % a garbage value, to be replaced if found. This is the signal value that \TeX\ inserts on
482 % the MVL replacing the penalty that caused the page break (if the page break occurred at a penalty).
483 % Also, a penalty of zero is indistinguishable from no penalty at all, so it will always
484 % be replaced by the given value.
485 %
486 % Therefore, it is highly recommended to never set any of \TeX's penalty parameters to
487 % zero (a value of, say, 1, is practically the same), nor should a skip parameter be set to zero
488 % (instead, use, say, 1sp). Also, to prevent a pagebreak, do not use a penalty of 10000, use, say
489 % 10001 instead.
490 %
491 % You can define your own construct that modifies the MVL:
492 % Define a command, say, \cmd\myadjust, as follows:
493 %\begin{verbatim}
494 %\def\myadjust#1{\noexpand\do@main@vlist{\noexpand\@myadjust{#1}}\@tempa}%
495 %\end{verbatim}
496 % that is, \cmd\myadjust\ invokes \cmd\do@main@vlist, passing it the procedure name
497 % \cmd\@myadjust\ along with the arguments thereof pre-expanded.
498 % Next, define the procedure \cmd\@myadjust:
499 %\begin{verbatim}
500 %\def\@myadjust#1{<meddle with the MVL>}%
501 %\end{verbatim}
502 % when \cmd\@myadjust\ executes, you will be in the output routine (in inner vertical mode)
503 % and the MVL will be that very vertical list.
504 %
505 %
506 %
507 %
508 % \section{Compatability with \LaTeX's Required Packages}
509 % Certain packages, usually ones written by members of the
510 % \LaTeX\ Project itself, have been designated ``required'' and
511 % are distributed as part of standard \LaTeX.
512 % These packages have been placed in a priviledged position
513 % vis \'a vis the \LaTeX\ kernel in that they override the definitions of certain kernel macros.
514 %
515 % Compatability between \classname{ltxgrid} and these packages is complicated
516 % by a number of factors. First is that \classname{ltxgrid} alters the meaning of some of the same
517 % kernel macros as certain of the ``required'' packages.
518 % Second is that fact that certain of the ``required'' packages of \LaTeX\ are incompatible with
519 % each other.
520 %
521 % Examples of the first kind are the \classname{ftnright}, \classname{multicol}, and \classname{longtable}
522 % packages.
523 % The \classname{ltxgrid} package is not compatible with \classname{multicol},
524 % but if you are using \classname{ltxgrid}, you do not need to use \classname{ftnright} or \classname{multicol}
525 % anyway. The \classname{ltxgrid} package does however attempt to be compatible with \classname{longtable}.
526 %
527 % Among the ``required'' packages that are mutually incompatible are \classname{multicol} and \classname{longtable},
528 % the incompatibility arising because both packages replace \LaTeX's output routine:
529 % if one package is active, the other must not be so.
530 % This state of affairs has remained essentially unchanged since the introduction of the two as \LaTeX2.09 packages in the late 1980s.
531 %
532 % The reason that \classname{ltxgrid} can remain compatible with \classname{longtable} is due to the
533 % introduction of a more modern architecture, the ``output routine dispatcher'', which allows all macro packages access to the
534 % safe processing environment of the output routine, on an equal footing.
535 % The relevant portions of the \classname{longtable} package are reimplemented in \classname{ltxgrid}
536 % to take advantage of this mechanism.
537 %
538 % Timing is critical:
539 % the \classname{ltxgrid} package will be incompatible with any package that
540 % redefines any of the kernel macros that \classname{ltxgrid} patches---if that
541 % package is loaded \emph{after} \classname{ltxgrid}.
542 %
543 % Hereinafter follows some notes on specific \LaTeX\ packages.
544 %
545 % \subsection{ftnright}
546 % Frank Mittelbach's \classname{ftnright} package effects a change to \LaTeX's
547 % \cmd\twocolumn\ mode such that footnotes are set at the bottom of the right-hand
548 % column instead of at the foot of each of the two columns.
549 %
550 % Note that it overwrites three \LaTeX\ kernel macros: \cmd\@outputdblcol, \cmd\@startcolumn, and \cmd\@makecol.
551 % Fortunately none of the three are patched by \classname{ltxgrid}, so that compatability
552 % is not excluded on this basis.
553 %
554 % At the same time, it changes the meaning of \cmd\footnotesize, the macro that is automatically
555 % invoked when setting a document's footnote into type.
556 % One might well argue that it is an error for the meaning of \cmd\footnotesize\ to be determined by
557 % a package such as \classname{ftnright}, that indeed such a choice should be made in the
558 % document class, or in a file such as \file{bk10.clo}.
559 %
560 % To avoid being tripped up by this misfeature in \classname{ftnright}, it is only necessary to
561 % reassert our meaning for \cmd\footnotesize\ later on, after \classname{ftnright} has been loaded.
562 %
563 % Note that \classname{ftnright} inserts code that demands that \LaTeX's flag \cmd\if@twocolumn\
564 % is true, that is, it will complain if deployed in a \cmd\onecolumn\ document.
565 % It is therefore necessary for any other multicolumn package to assert that flag in order to
566 % avoid this package's complaint. It is an interesting question exactly why this package has
567 % this limitation. After all, a one-column page grid is just a degenerate case of the
568 % two column.
569 %
570 % \subsection{longtable}
571 % David Carlisle's \classname{longtable} package sets tables that can be so long as to break over pages.
572 % According to its author, it uses the same override of \LaTeX's output routine as
573 % Frank Mittelbach's \classname{multicol} package. By implication, then, it has a hard
574 % incompatability with the latter.
575 %
576 % The \classname{longtable} package also performs a check of whether the document is in
577 % \cmd\twocolumn\ mode, and declines to work if this is the case. It is not clear, however,
578 % that there is any true incompatability present if so. It's just that David did not see any reason
579 % anyone would want to set such long tables in a multicolumn document, hence the check.
580 %
581 % There does not appear to be any indication that \classname{longtable} would work less
582 % well under \classname{ltxgrid} than under standard \LaTeX's \cmd\twocolumn\ mode.
583 % Therefore, this \classname{ltxgrid} patches \classname{longtable} (if loaded) so as to provide
584 % compatability. In the course of which, \classname{longtable} becomes more robust
585 % (\classname{longtable} has mumerous bugs and incompatabilities of long standing,
586 % some of which are repaired by \classname{ltxgrid}).
587 %
588 % One problem remains, namely that, if a \env{longtable} environment breaks over columns
589 % and thereby inserts its special headers and footers at that break, and those columms are then
590 % balanced (due to a return to the one-column page grid), then those inserted rows
591 % will remain, and may no longer fall at the column break. This will, of course look
592 % wrong.
593 %
594 % The only way to fix this problem is to avoid doing column balancing in the way
595 % I have implemented here; such an enhancement to this package is possible.
596 %
597 % \subsection{multicol}
598 % Frank Mittelbach's \classname{multicol} package provides a page grid with many columns,
599 % albeit denies the placement of floats in individual columns.
600 %
601 % It esablishes its own \cmd\output\ routine, which is the reason it runs afoul of
602 % the \classname{longtable} package. On the other hand, \classname{ltxgrid} specifically
603 % allows for the case where a package installs its own \cmd\output\ routine, so
604 % there is no incompatability on that basis.
605 %
606 % Still, it is pointless to use \classname{multicol} if you are using \classname{ltxgrid},
607 % since both packages provide multicolumn page layouts.
608 % Therefore, \classname{multicol} is not supported by \classname{ltxgrid}.
609 %
610 % \subsection{ltxgrid}
611 % It has been pointed out that one of the disadvantages of adopting the \classname{ltxgrid} package is that
612 % it does alter the \LaTeX\ kernel.
613 % Any package that itself alters the \LaTeX\ kernel may be incompatible with \classname{ltxgrid}, and new packages
614 % (destined perhaps to become part of the successor to \LaTeXe) may break \classname{ltxgrid}.
615 %
616 % The consequence is that packages introduced in future, and future changes to \LaTeX\ may be incompatible
617 % with \classname{ltxgrid}.
618 % This is, of course, true.
619 % The development plan for \classname{ltxgrid} is that when such packages and \LaTeX\ kernel changes come about,
620 % the burden will be on \classname{ltxgrid} to change in a way that provides for continued compatability with
621 % those packages and \LaTeX\ kernel changes.
622 %
623 %
624 % \section{How \classname{ltxgrid} places footnotes}
625 %
626 % In conventional multicolumn layouts, a footnote will appear at the bottom of the column in which it is called out.
627 % The \classname{ltxgrid} package implements this conventional layout choice by default.
628 % However, other choices are possible (a la \classname{ftnright}, whose compatability with \classname{ltxgrid} has not been tested).
629 %
630 % One unusual feature of \classname{ltxgrid}'s default implementation must be mentioned, though,
631 % namely the case in a two-column page grid, where a footnote is followed by a temporary change to the one-column page grid
632 % (e.g., for a wide equation).
633 % In such a case, the material above the wide material is split into two columns, and a footnote whose callout
634 % appears in the right-hand column will nonetheless be set at the base of the left column.
635 %
636 % This arrangement was chosen because it ensures that the footnotes at the bottom of any page will appear in
637 % numerical order. It can be argued that this choice is ``incorrect'', but be that as it may,
638 % the \classname{ltxgrid} package does not foreclose on other arrangements for the footnotes.
639 % The package can be adapted to accomodate any page design desired.
640 %
641 % \section{Limitations in \classname{ltxgrid}'s default column balancing method}%
642 %
643 % In a multicolumn page grid, when encountering a page that is not completely full,
644 % it is customary to set the material in balanced columns (typically with the last column no longer than any of the others).
645 % Such a case also crops up when temporarily interrupting the multicolumn grid to set material on the full width of the page:
646 % the material on the page above the break is customarily set in balanced columns.
647 %
648 % An awkward case arises when we have already set one or more complete columns of type before encountering the need to
649 % balance columns. In this subset of cases, the default in \classname{ltxgrid} is to
650 % do an operation I call ``re-balancing'':
651 % the material on the page so far is pasted back together into a single column, and new, balanced column breaks are
652 % calculated.
653 %
654 % This scheme typically works fine, but it has a significant vulnerability:
655 % any discardable items trimmed at the original column break is lost, never to be retrieved.
656 % Consequently, after re-balancing, an element like, say, a section head can fail to have the correct amount of whitespace above.
657 %
658 % This problem is due to an unfortunate optimization in \TeX, wherein a certain class of nodes is trimmed from the
659 % top of main vertical list upon returning from the output routine:
660 % any penalty, glue, or leader node falls in to this class of discardable nodes,
661 % and trimming proceeds until a non-discardable node (such as a box, or rule) is encountered.
662 % It gets better: a third class of nodes is transparent to this trimming process;
663 % they are neither discarded nor do they halt the process of trimming:
664 % mark nodes and all whatsits fall into this class of transparent nodes;
665 % they are quietly passed over during trimming.
666 %
667 % An alternative approach for \TeX\ to take would have been,
668 % rather than discarding the node entirely, to simply mark it as discarded.
669 % (Implementors of NTS, please note!)
670 % Then, upon shipping out, such nodes would not make it into the DVI.
671 % \TeX's optimization, driven by the small computer architectures current when it was developed,
672 % does save mem, but at the cost of revisiting page breaks in a reliable way.
673 %
674 % FIXME: how to fix a column break in the above case? Widetext?
675 %
676 %\StopEventually{}
677 %
678 % \section{Implementation of package}
679 %
680 % Special acknowledgment: this package uses concepts pioneered
681 % and first realized by William Baxter (mailto:[email protected])
682 % in his SuperScript line of commercial typesetting tools, and
683 % which are used here with his permission. His thorough understanding
684 % of \TeX's output routine underpins the entire \classname{ltxgrid}
685 % package.
686 %
687 % \subsection{Beginning of the \file{ltxgrid} {\sc docstrip} module}
688 % Requires the underpinnings of the \classname{ltxkrnext} package.
689 % \begin{macrocode}
690 %<*ltxgrid>
691 \def\package@name{ltxgrid}%
692 \expandafter\PackageInfo\expandafter{\package@name}{%
693 Page grid for \protect\LaTeXe,
694 by A. Ogawa ([email protected])%
695 }%
696 \RequirePackage{ltxutil}%
697 %</ltxgrid>
698 % \end{macrocode}
699 %
700 % \subsection{Banner}%
701 % Credit where due.
702 % \begin{macrocode}
703 %<*ltxgrid-krn>
704 \typeout{%
705 ltxgrid: portions licensed from W. E. Baxter ([email protected])%
706 }%
707 % \end{macrocode}
708 %
709 % \subsection{Sundry}%
710 % Here are assorted macro definitions.
711 % \begin{macro}{\lineloop}
712 % The document-level command \cmd\lineloop\ sets numbered lines until the
713 % specified count is reached.
714 % This command is mainly used to construct test documents.
715 % \begin{macrocode}
716 \newcounter{linecount}
717 \def\lineloop#1{%
718 \loop
719 \ifnum\c@linecount<#1\relax
720 \global\advance\c@linecount\@ne
721 \par
722 \hb@xt@\hsize{%
723 \ifnum\c@linecount<100 0\fi\ifnum\c@linecount<10 0\fi\number\c@linecount
724 \vrule depth2.5\p@
725 \leaders\hrule\hfil
726 }%
727 \penalty\interlinepenalty
728 \repeat
729 }%
730 % \end{macrocode}
731 % \end{macro}
732 %
733 %
734 % \subsection{Mark Components}%
735 %
736 % Override LaTeX's mark macros to allow more components.
737 %
738 % We remain bound by the weakness of LaTeX's scheme in that
739 % one cannot emulate the action of \TeX\ whereby
740 % material with marks can be inserted in the middle of
741 % a vertical list such that the marks are reliably calculated.
742 % If we did that, \cmd\@themark\ would no longer be utilized.
743 %
744 % A more robust scheme involves placing all marks (component and value)
745 % into a list (using global scoping, i.e., \cmd\gdef),
746 % and using \cmd\@@mark to place an index on that list into the MVL.
747 % Then, e.g., \cmd\@@botmark signifies the place where that list is to be cut,
748 % and the \cmd\botmark\ of any component is
749 % the value of the last element of the cut
750 % list having the given component. The \cmd\firstmark\ and \cmd\topmark\
751 % can likewise be defined relative to \cmd\@@firstmark\ and \cmd\@@topmark,
752 % except in the latter case, we want the first following the cut instead of the last
753 % preceding the cut.
754 %
755 % The limitation of this scheme is its demands upon \TeX's mem.
756 % The list of marks would need to be trimmed back to, effectively,
757 % \cmd\topmark\ at the beginning of every page.
758 %
759 % This approach is not yet part of the extended LaTeX kernel.
760 %
761 % \begin{macro}{\@@mark}
762 % \begin{macro}{\@@topmark}
763 % \begin{macro}{\@@firstmark}
764 % \begin{macro}{\@@botmark}
765 % \begin{macro}{\@@splitfirstmark}
766 % \begin{macro}{\@@splitbotmark}
767 % Remember primitives under a new set of names.
768 % \begin{macrocode}
769 \let\@@mark\mark
770 \let\@@topmark\topmark
771 \let\@@firstmark\firstmark
772 \let\@@botmark\botmark
773 \let\@@splitfirstmark\splitfirstmark
774 \let\@@splitbotmark\splitbotmark
775 % \end{macrocode}
776 % \end{macro}
777 % \end{macro}
778 % \end{macro}
779 % \end{macro}
780 % \end{macro}
781 % \end{macro}
782 %
783 % \subsubsection{Procedures that expose the component data structure}%
784 % This portion of the code exposes the internal representation of
785 % the mark components. If we wish to add more components, we will have to revise
786 % these macro definitions:
787 % \cmd\@themark,
788 % \cmd\nul@mark,
789 % \cmd\set@mark@netw@,
790 % \cmd\set@marktw@,
791 % \cmd\set@markthr@@,
792 % \cmd\get@mark@@ne,
793 % \cmd\get@mark@tw@,
794 % \cmd\get@mark@thr@@,
795 % \cmd\get@mark@f@ur.
796 %
797 % \begin{macro}{\@themark}
798 %FIXME: is it safer to eliminate \cmd\@themark\ in favor of a message that evaluates \cmd\@@botmark?
799 %
800 % Note: these definitions expose the data structure of mark components.
801 % \begin{macrocode}
802 \def\@themark{{}{}{}{}}%
803 \def\nul@mark{{}{}{}{}\@@nul}%
804 % \end{macrocode}
805 % \end{macro}
806 %
807 % \begin{macro}{\set@mark@netw@}
808 % \begin{macro}{\set@marktw@}
809 % \begin{macro}{\set@markthr@@}
810 % These procedures insert the new value of a particular mark component into the given argument.
811 % They expose the data structure of mark components.
812 %
813 % \begin{macrocode}
814 \def\set@mark@netw@#1#2#3#4#5#6#7{\gdef#1{{#6}{#7}{#4}{#5}}\do@mark}%
815 \def\set@marktw@#1#2#3#4#5#6{\gdef#1{{#2}{#6}{#4}{#5}}\do@mark}%
816 \def\set@markthr@@#1#2#3#4#5#6{\gdef#1{{#2}{#3}{#6}{#5}}\do@mark}%
817 % \end{macrocode}
818 % \end{macro}
819 % \end{macro}
820 % \end{macro}
821 %
822 % \begin{macro}{\get@mark@@ne}
823 % \begin{macro}{\get@mark@tw@}
824 % \begin{macro}{\get@mark@thr@@}
825 % \begin{macro}{\get@mark@f@ur}
826 % These procedures retreive the value of a particular mark component.
827 % They expose the data structure of mark components.
828 % \begin{macrocode}
829 \def\get@mark@@ne#1#2#3#4#5\@@nul{#1}%
830 \def\get@mark@tw@#1#2#3#4#5\@@nul{#2}%
831 \def\get@mark@thr@@#1#2#3#4#5\@@nul{#3}%
832 \def\get@mark@f@ur#1#2#3#4#5\@@nul{#4}%
833 % \end{macrocode}
834 % \end{macro}
835 % \end{macro}
836 % \end{macro}
837 % \end{macro}
838 %
839 %
840 % \subsubsection{Procedures that do not expose the component data structure}%
841 %
842 % \begin{macro}{\mark@netw@}
843 % \begin{macro}{\marktw@}
844 % \begin{macro}{\markthr@@}
845 % These procedures insert the new value of a particular mark component into \cmd\@themark,
846 % then execute \cmd\do@mark.
847 % They constitute the implementation layer for mark components one, two, and three.
848 % An analogous procedure for component four could be defined; call it \cmd\markf@ur.
849 %
850 % \begin{macrocode}
851 \def\mark@netw@{\expandafter\set@mark@netw@\expandafter\@themark\@themark}%
852 \def\marktw@{\expandafter\set@marktw@\expandafter\@themark\@themark}%
853 \def\markthr@@{\expandafter\set@markthr@@\expandafter\@themark\@themark}%
854 % \end{macrocode}
855 % \end{macro}
856 % \end{macro}
857 % \end{macro}
858 %
859 % \begin{macro}{\do@mark}
860 % \begin{macro}{\do@@mark}
861 % Access procedures \cmd\mark (AKA \cmd\@@mark).
862 % The \cmd\do@mark\ procedure is used when a mark is being put down into the MVL;
863 % \cmd\do@@mark\ when this happens in the output routine.
864 % \begin{macrocode}
865 \def\do@mark{\do@@mark\@themark\nobreak@mark}%
866 \def\do@@mark#1{%
867 \begingroup
868 \let@mark
869 \@@mark{#1}%
870 \endgroup
871 }%
872 % \end{macrocode}
873 % \end{macro}
874 % \end{macro}
875 %
876 % \begin{macro}{\let@mark}
877 % \begin{macro}{\nobreak@mark}%
878 % The procedure that makes \cmd\csname s robust within a mark.
879 % Use \cmd\appdef\ and \cmd\robust@\ to extend the list.
880 % \begin{macrocode}
881 \def\let@mark{%
882 \let\protect\@unexpandable@protect
883 \let\label\relax
884 \let\index\relax
885 \let\glossary\relax
886 }%
887 \def\nobreak@mark{%
888 \@if@sw\if@nobreak\fi{\@ifvmode{\nobreak}{}}{}%
889 }%
890 % \end{macrocode}
891 % \end{macro}
892 % \end{macro}
893 %
894 %
895 % \subsubsection{Using mark components}%
896 %
897 % These procedures use the component mark mechanism to implement
898 % a mark component that remembers the current environment (used in page makeup)
899 % and the the two mark components left over from the original \LaTeX.
900 % The fourth component is presently unused.
901 %
902 % \begin{macro}{\mark@envir}
903 % The third mark component's access procedures.
904 % The \cmd\mark@envir\ and \cmd\bot@envir\ commands are a good model of how to write
905 % access procedures for a new mark component.
906 % \begin{macrocode}
907 \def\mark@envir{\markthr@@}%
908 \def\bot@envir{%
909 \expandafter\expandafter
910 \expandafter\get@mark@thr@@
911 \expandafter\@@botmark
912 \nul@mark
913 }%
914 % \end{macrocode}
915 % \end{macro}
916 %
917 % \begin{macro}{\markboth}
918 % \begin{macro}{\markright}
919 % \begin{macro}{\leftmark}
920 % \begin{macro}{\rightmark}
921 % Set procedures for legacy components.
922 % \begin{macrocode}
923 \def\markboth{\mark@netw@}%
924 \def\markright{\marktw@}%
925 % \end{macrocode}
926 %
927 % Retrieval procedures for legacy mark components.
928 % The procedure for retrieving the first component from \cmd\botmark\
929 % and the second component from \cmd\firstmark have names in \LaTeX;
930 % they are called, respectively, \cmd\leftmark\ and \cmd\rightmark.
931 %
932 % It is possible to retrieve the components of \cmd\topmark\
933 % as well: use \cmd\saved@@topmark.
934 % \begin{macrocode}
935 \def\leftmark{%
936 \expandafter\expandafter
937 \expandafter\get@mark@@ne
938 \expandafter\saved@@botmark
939 \nul@mark
940 }%
941 \def\rightmark{%
942 \expandafter\expandafter
943 \expandafter\get@mark@tw@
944 \expandafter\saved@@firstmark
945 \nul@mark
946 }%
947 % \end{macrocode}
948 % \end{macro}
949 % \end{macro}
950 % \end{macro}
951 % \end{macro}
952 %
953 %
954 %
955 % \subsection{Output Super-routine}%
956 %
957 % We want to change \LaTeX's output routine, but do not wish to remain vulnerable
958 % to interference from such ``required'' packages as
959 % \classname{multicol} (authored by Frank Mittelbach)
960 % and \classname{longtable} (authored by David P. Carlisle), which
961 % swap in their own output routines when the respective package is active.
962 %
963 % The better mechanism, used here, is due to William Baxter ([email protected]),
964 % who has allowed his several ideas to be used in this package.
965 %
966 % In what follows, we effectively wrap up the old \LaTeX\ output routine inside
967 % a new, more flexible ``super routine''. When the output routine is called,
968 % the ``super routine'' acts as a dispatcher. If the old routine is needed, it is called.
969 %
970 % If a package attempts to substitute in their own output routine, they will effectively
971 % be modifying a token register by the name of \cmd\output.
972 % The primitive \cmd\output\ is now known by a different name, which should no longer be
973 % necessary to use.
974 %
975 % Usage note: to make a visit to the output routine employing the dispatcher, enter
976 % with a value of \cmd\outputpenalty\ that corresponds to a macro. Defining as follows:
977 %\begin{verbatim}
978 %\@namedef{output@10000}{<your code here>}%
979 %\end{verbatim}
980 % by convention, your output routine should void out \cmd\box\cmd\@cclv.
981 %
982 % In rewriting \LaTeX's output dispatcher
983 % in a much simpler form, we also avoid the sin of multiple \cmd\shipout s
984 % within a single visit to the output routine.
985 %
986 % Conceptually, we divide visits to the output routine into two classes.
987 % The first involves natural page breaks
988 % (at a \cmd\newpage\ or when \cmd\pagetotal $>$ \cmd\pagegoal)
989 % and usually resulting in \cmd\box\cmd\@cclv\ either being shipped out or
990 % salted away (e.g., each column in a multicolumn layout).
991 % We might call this class the ``natural output routines''; the \cmd\outputpenalty\
992 % will never be less than $-10000$.
993 % Furthermore, we ensure that \cmd\holdinginserts\ is cleared when
994 % calling such routines.
995 %
996 % The other class involves a forced visit to the output routine
997 % via a large negative penalty ($< -10000$). They do not generally
998 % result in a \cmd\shipout\ of \cmd\box\cmd\@cclv: they may be dead cycles.
999 % We provide a mechanism (call it a ``one-off'' output routine) that allows
1000 % us to specify certain processing to be done when \TeX\ reaches
1001 % the current position on the page.
1002 %
1003 % One-off output routines themselves fall into two divisions, ones
1004 % that process \cmd\box\cmd\@cclv, and ones that work on the main vertical list (MVL).
1005 % The former are typified by changes to the page grid, perhaps
1006 % even column balancing.
1007 % The latter involve the insertion of penalties or glue and the processing of floats.
1008 %
1009 % The natural output routine is a single procedure. We have not introduced multiple
1010 % natural output routines based on the \cmd\outputpenalty\ because \TeX\ does not
1011 % support such a thing: \TeX\ sometimes lays down a penalty whose value is the sum
1012 % of other penalties. Because of this, we cannot depend on the value of \cmd\outputpenalty\
1013 % in such areas.
1014 %
1015 % We do introduce flexibility in the form of a mechanism for patching into the
1016 % natural output routine. Three hooks are offered, allowing a procedure
1017 % to prepare for the upcoming visit to the output routine,
1018 % access to \cmd\box\cmd\@cclv, and after shipping out (or otherwise
1019 % committing the material to the page).
1020 %
1021 % Environments, commands, and even packages can install their
1022 % own procedures into these hooks.
1023 % For instance, if the longtable package is loaded, it will install
1024 % its procedures, but those procedures will punt if the page break
1025 % being processed does not actually fall within a longtable environment.
1026 %
1027 % \begin{macro}{\primitive@output}
1028 % Here we remember the \TeX\ primitive \cmd\output\ and its value,
1029 % and then proceed to take over the \cmd\csname\ of \cmd\output,
1030 % making it a \cmd\toks\ register and installing the old value of
1031 % the output routine.
1032 % \begin{macrocode}
1033 \let\primitive@output\output
1034 % \end{macrocode}
1035 % \end{macro}
1036 %
1037 % \begin{macro}{\output}
1038 % Grab the tokens in \cmd\the\cmd\output\ (but without the extra set of braces).
1039 % The value of \cmd\toks@\ must remain untouched until loaded into the appropriate token
1040 % register; this is done a few lines below.
1041 % \begin{macrocode}
1042 \long\def\@tempa#1\@@nil{#1}%
1043 \toks@
1044 \expandafter\expandafter
1045 \expandafter{%
1046 \expandafter \@tempa
1047 \the\output
1048 \@@nil
1049 }%
1050 \newtoks\output
1051 \output\expandafter{\the\toks@}%
1052 % \end{macrocode}
1053 % \end{macro}
1054 %
1055 % \begin{macro}{\dispatch@output}
1056 % We now install our own output routine in place of the
1057 % old one, which is still available as \cmd\the\cmd\output.
1058 %
1059 % The output routine is simply the procedure \cmd\dispatch@output.
1060 % It either dispatches to a procedure based on a particular value of
1061 % \cmd\outputpenalty\ or it executes \cmd\the\cmd\output\ tokens.
1062 % \begin{macrocode}
1063 \primitive@output{\dispatch@output}%
1064 \def\dispatch@output{%
1065 \let\par\@@par
1066 \expandafter\let\expandafter\@tempa\csname output@\the\outputpenalty\endcsname
1067 \outputdebug@sw{%
1068 \saythe\badness
1069 \saythe\outputpenalty
1070 \saythe\holdinginserts
1071 \say\thepagegrid
1072 \saythe\pagegrid@col
1073 \saythe\pagegrid@cur
1074 %\say\bot@envir
1075 \saythe\insertpenalties
1076 %\say\@@topmark
1077 %\say\saved@@topmark
1078 %\say\@@firstmark
1079 %\say\saved@@firstmark
1080 \say\@@botmark
1081 %\say\saved@@botmark
1082 \saythe\pagegoal
1083 \saythe\pagetotal
1084 \saythe{\badness\@cclv}%
1085 \expandafter\@ifx\expandafter{\csname output@-\the\execute@message@pen\endcsname\@tempa}{%
1086 \say\@message@saved
1087 }{%
1088 \expandafter\say\csname output@\the\outputpenalty\endcsname
1089 }%
1090 \say\@toplist
1091 \say\@botlist
1092 \say\@dbltoplist
1093 \say\@deferlist
1094 {\tracingall\scrollmode
1095 \showbox\@cclv
1096 \showbox\@cclv@saved
1097 \showbox\pagesofar
1098 \showbox\footbox
1099 \showbox\footins@saved
1100 \showbox\footins
1101 \showlists
1102 }%
1103 }{}%
1104 \@ifnotrelax\@tempa{\@tempa}{\the\output}%
1105 }%
1106 \@ifxundefined{\outputdebug@sw}{%
1107 \@booleanfalse\outputdebug@sw
1108 }{}%
1109 % \end{macrocode}
1110 % \end{macro}
1111 %
1112 %
1113 % \subsection{Further thoughts about inserts}
1114 %
1115 % The only safe way to deal with inserts is to either set \cmd\holdininserts\ or
1116 % to commit to using whatever insert comes your way: you cannot change your mind
1117 % once you see a non-void \cmd\box\cmd\footins, say.
1118 %
1119 % Therefore all output routine processing must proceed with \cmd\holdinginserts\ set
1120 % until you are sure of the material to be committed to the page. At that point, you
1121 % can clear \cmd\holdinginserts, spew \cmd\box\cmd\@cclv, put down the appropriate penalty,
1122 % and exit, with the knowledge that \TeX\ will re-find the same pagebreak, this time
1123 % visiting the output routine with everything, including inserts, in their proper
1124 % place.
1125 % This technique applies to split elements (screens, longtable, index) as well as to
1126 % manufactured pages (float pages and clearpage pages).
1127 %
1128 % Therefore, the output routine must not make assumptions about whether \cmd\holdinginserts\
1129 % should be cleared; instead this must be left to the one-off output routines or the natural output routine.
1130 %
1131 % If we are manufacturing pages (``float page processing''), and if \cmd\pagegoal\ is not equal to
1132 % \cmd\vsize, then inserts are at hand, and our criterion should take into account the insert
1133 % material, even though we cannot measure its height based on the size of \cmd\box\cmd\footins\
1134 % (because \cmd\holdinginserts\ is set, you see).
1135 %
1136 % It would be better to take the complement of \cmd\floatpagefraction\ and use that
1137 % as a standard for the looseness of the page. Since \cmd\pagegoal\ reflects the inserted material,
1138 % the criterion becomes the difference of the aggregate height of the floats and the \cmd\pagegoal\
1139 % versus this "page looseness" standard.
1140 %
1141 % As a check, consider what happens if we bail out: \cmd\@deferlist\ has never been touched, so it
1142 % requires no attention. Also, \cmd\holdinginserts\ has never been cleared, so inserts require
1143 % no attention. So we only have to ensure that marks are preserved, which is already taken
1144 % care of by the message handler mechanism.
1145 %
1146 % If we are doing ordinary page cutting, then the scheme would be to detect whether we are within
1147 % a screen (or longtable as may be), do the adjustment to the page height, and return, but this time
1148 % with \cmd\holdinginserts\ cleared. Upon reentering the output routine, we may or may not be within
1149 % the screen environment, but we are now sure to have a final page break, and we can commit this
1150 % material (by shipping out or by saving it out as a full column).
1151 %
1152 % In the above, the first of the two visits to the output routine is a dead cycle and requires
1153 % propagation of marks, but nothing else.
1154 %
1155 % The natural output routine
1156 %
1157 % Here is the portion of the output routine that fields cases not handled by
1158 % the dispatcher.
1159 %
1160 % The default is to ship out a page and then look around for more material
1161 % that might constitute a ``float page''. However, because \cmd\holdinginserts\
1162 % is normally set, this output routine must first have a dead cycle and
1163 % come back again with \cmd\holdinginserts\ cleared.
1164 % Then, after shipping out, it puts down a message that
1165 % will manufacture zero or more float pages, finally terminating
1166 % with a procedure that commits floats to a new unfinished page.
1167 %
1168 % To accomodate special processing, we execute hooks whose name is based
1169 % on the value of the "envir" mark component. The default is "document",
1170 % ensured by an initial mark of that value; the associated procedures
1171 % are all nil. Any unknown envir value will "\cmd\relax\ out".
1172 %
1173 % The code \cmd\move@insert@sw\ tells whether we are on our first visit to
1174 % the output routine (with \cmd\holdinginserts\ still set), or our second
1175 % (with \cmd\holdinginserts\ cleared). The output routine will toggle the
1176 % setting.
1177 %
1178 % The commands \cmd\hold@insertions\ and \cmd\move@insertions\ respectively
1179 % clear and set the state of \cmd\move@insert@sw, so this procedure effectively
1180 % clears \cmd\holdinginserts\ just long enough to pick up the insertions.
1181 % Important: any output routine that clears \cmd\holdinginserts\
1182 % must guarentee that it is restored on the subsequent visit to the output routine.
1183 % Or, to put it another way, if an output routine detects that \cmd\holdinginserts\
1184 % is cleared, it should take it upon itself to restore it before exiting.
1185 %
1186 % The branch with \cmd\holdinginserts\ set is executed first; the other
1187 % branch follows on practically immediately thereafter. In the first branch,
1188 % we simply execute the appropriate hook and then execute a dead cycle.
1189 %
1190 % In the branch with \cmd\holdinginserts\ cleared, the procedure
1191 % builds up the current column, which is now complete, with \cmd\@makecol, then
1192 % dispatches to the shipout routine associated with the current page grid, \cmd\output@column@.
1193 % At the end, it triggers the execution of an output routine to prepare the next column (or page).
1194 %
1195 % \subsection{Natural output routine}%
1196 %
1197 % \begin{macro}{\output}
1198 % Here is what has become of the output routine of \LaTeX.
1199 % It is of necessity divided into phases, \cmd\output@holding\ is executed upon first encountering the natural page-breaking point, while inserts are being held.
1200 % The second phase, \cmd\output@moving, is set in motion by the first: here the same material (in most cases) will be processed with \cmd\holdinginserts\ cleared.
1201 %
1202 % \begin{macrocode}
1203 \output={\toggle@insert\output@holding\output@moving}%
1204 % \end{macrocode}
1205 %
1206 % The procedure \cmd\output@holding\
1207 % is our first cycle through the output routine; \cmd\holdinginserts\ is still set.
1208 % We give the current environment a heads up
1209 % (it is through this means that \classname{longtable} sets its running header and footer),
1210 % then we execute a dead cycle, which should propagate marks.
1211 %
1212 % One corner case that can crop up is the presence of a single unbreakable chunk whose size is larger
1213 % than \cmd\vsize.
1214 % Doing a dead cycle under such circumstances will not find the same breakpoint as this time
1215 % (remember we threw in a \cmd\mark\ node).
1216 % Instead, we attempt to remove the excess height of the material, so we can continue to propagate marks.
1217 %
1218 % The corner case is at hand if the natural size of \cmd\box\cmd\@cclv\ exceeds \cmd\pagegoal\ and
1219 % the contents cannot be shrunk to fit.
1220 %
1221 % \begin{macrocode}
1222 \def\output@holding{%
1223 \csname output@init@\bot@envir\endcsname
1224 %\vbadness\@M
1225 %\vfuzz\maxdimen
1226 \@if@exceed@pagegoal{\unvcopy\@cclv}{%
1227 \setbox\z@\vbox{\unvcopy\@cclv}%
1228 \outputdebug@sw{{\tracingall\scrollmode\showbox\z@}}{}%
1229 \dimen@\ht\@cclv\advance\dimen@-\ht\z@
1230 \dead@cycle@repair\dimen@
1231 }{%
1232 \dead@cycle
1233 }%
1234 }%
1235 \def\@if@exceed@pagegoal#1{%
1236 \begingroup
1237 \setbox\z@\vbox{#1}%
1238 \dimen@\ht\z@\advance\dimen@\dp\z@
1239 \outputdebug@sw{\saythe\dimen@}{}%
1240 \@ifdim{\dimen@>\pagegoal}{%
1241 \setbox\z@\vbox{\@@mark{}\unvbox\z@}%
1242 \splittopskip\topskip
1243 \splitmaxdepth\maxdepth
1244 \vbadness\@M
1245 \vfuzz\maxdimen
1246 \setbox\tw@\vsplit\z@ to\pagegoal
1247 \outputdebug@sw{{\tracingall\scrollmode\showbox\tw@\showbox\z@}}{}%
1248 \setbox\tw@\vbox{\unvbox\tw@}%
1249 \@ifdim{\ht\tw@=\z@}{%
1250 \ltxgrid@info{Found overly large chunk while preparing to move insertions. Attempting repairs}%
1251 \aftergroup\true@sw
1252 }{%
1253 \aftergroup\false@sw
1254 }%
1255 }{%
1256 \aftergroup\false@sw
1257 }%
1258 \endgroup
1259 }%
1260 % \end{macrocode}
1261 %
1262 % The procedure \cmd\output@moving\
1263 % is our second cycle through the output routine; \cmd\holdinginserts\ is now cleared,
1264 % and \cmd\insert s will have been split off into their respective box registers, like \cmd\footins.
1265 %
1266 % \begin{enumerate}
1267 % \item
1268 % Set the values of \cmd\topmark\ and \cmd\firstmark.
1269 % \item
1270 % If we got here because of a \cmd\clearpage\ command, remove the protection box that this mechanism has left on the MVL.
1271 % \item
1272 % If the contents of \cmd\box\cmd\@cclv\ are non-trivial, commit it to the current page or ship it out as the case may call for.
1273 % \item
1274 % If not, discard it (we are at the end of \cmd\clearpage\ processing).
1275 % \item
1276 % Set various values, including the available space for setting type on the next column (\cmd\@colroom).
1277 % \end{enumerate}
1278 %
1279 % The processing for a non-trivial \cmd\box\cmd\@cclv\ are:
1280 % \begin{enumerate}
1281 % \item
1282 % Execute the head procedure for the current environment.
1283 % \item
1284 % Make up a column and ship it out (or commit it to the current page) via a procedure keyed to the current page grid.
1285 % \item
1286 % Put down an interrupt for \cmd\do@startcolumn@pen: this will force a visit to the output routine for the
1287 % purpose of committing floats to the next column.
1288 % \item
1289 % Possibly put down an interrupt to continue \cmd\clearpage\ proccessing.
1290 % \item
1291 % Execute the tail procedure for the current environment.
1292 % \end{enumerate}
1293 %
1294 %
1295 % The processing for a trivial \cmd\box\cmd\@cclv\ are:
1296 % \begin{enumerate}
1297 % \item
1298 % Void out \cmd\box\cmd\@cclv\ and give appropriate warning messages and diagnostics.
1299 %% \item
1300 %% Put down the same interrupts as for the non-trivial case above.
1301 % \end{enumerate}
1302 %
1303 % \begin{macrocode}
1304 \def\output@moving{%
1305 \set@top@firstmark
1306 \@ifnum{\outputpenalty=\do@newpage@pen}{%
1307 \setbox\@cclv\vbox{%
1308 \unvbox\@cclv
1309 \setbox\z@\lastbox
1310 \@ifdim{\ht\z@=\ht\@protection@box}{\box\lastbox}{\unskip}%
1311 }%
1312 }{}%
1313 \@cclv@nontrivial@sw{%
1314 \csname output@prep@\bot@envir \endcsname
1315 \@makecol\csname output@column@\thepagegrid\endcsname
1316 \protect@penalty\do@startcolumn@pen
1317 \clearpage@sw{%
1318 \protect@penalty\do@endpage@pen
1319 }{}%
1320 \csname output@post@\bot@envir \endcsname
1321 }{%
1322 {\setbox\z@\box\@cclv}%
1323 }%
1324 \set@colroom
1325 \global\@mparbottom\z@
1326 \global\@textfloatsheight\z@ %FIXME: this legacy LaTeX variable is set, but never queried!
1327 }%
1328 % \end{macrocode}
1329 %
1330 % The procedure \cmd\@cclv@nontrivial@sw\ determines if this visit to \cmd\output@moving\
1331 % is a trivial one, which happens at the end of \cmd\clearpage\ processing and under some pathological circumstances.
1332 % It emits a Boolean, so it is syntactically like \cmd\true@sw, albeit does not execute solely via expansion.
1333 %
1334 % Note: the case where \cmd\box\cmd\@cclv\ is void comes up at the very beginning of the job, when
1335 % typesetting a (full-page-width) title block in a two-column layout.
1336 %
1337 % Note: the code that removes the last box and skip from the output is intended to detect the case
1338 % where the output has whatit nodes followed by topskip and a protection box.
1339 % This is what happens under normal circumstances at the end of \cmd\clearpage\ processing.
1340 % \begin{macrocode}
1341 \def\@cclv@nontrivial@sw{%
1342 \@ifx@empty\@toplist{%
1343 \@ifx@empty\@botlist{%
1344 \@ifvoid\footins{%
1345 \@ifvoid\@cclv{%
1346 \false@sw
1347 }{%
1348 \setbox\z@\vbox{\unvcopy\@cclv}%
1349 \@ifdim{\ht\z@=\topskip}{%
1350 \setbox\z@\vbox{%
1351 \unvbox\z@
1352 \setbox\z@\lastbox\dimen@\lastskip\unskip
1353 \@ifdim{\ht\z@=\ht\@protection@box}{%
1354 \advance\dimen@\ht\z@
1355 \@ifdim{\dimen@=\topskip}{%
1356 \aftergroup\true@sw
1357 }{%
1358 \aftergroup\false@sw
1359 }%
1360 }{%
1361 \aftergroup\false@sw
1362 }%
1363 }%
1364 {%
1365 \false@sw % Normal for \clearpage
1366 }{%
1367 \true@sw
1368 }%
1369 }{%
1370 \@ifdim{\ht\z@=\z@}{%
1371 \ltxgrid@info{Found trivial column. Discarding it}%
1372 \outputdebug@sw{{\tracingall\scrollmode\showbox\@cclv}}{}%
1373 \false@sw
1374 }{%
1375 \true@sw
1376 }%
1377 }%
1378 }%
1379 }{%
1380 \true@sw
1381 }%
1382 }{%
1383 \true@sw
1384 }%
1385 }{%
1386 \true@sw
1387 }%
1388 }%
1389 % \end{macrocode}
1390 %
1391 %
1392 % \end{macro}
1393 %
1394 % \begin{macro}{\protect@penalty}
1395 % The procedure \cmd\protect@penalty\ is the utility procedure for invoking a
1396 % one-off output routine. Such a routine can expect to find the protection box
1397 % above it in \cmd\box\cmd\@cclv: it should remove that box.
1398 %
1399 % Note that \cmd\execute@message\ does the same thing as \cmd\protect@penalty, but
1400 % in a slightly different way.
1401 %
1402 % We create a specially formulated box that will be universally used when a protection box is needed.
1403 % In this way, we can always recognize when \cmd\box\cmd\@cclv\ is trivial:
1404 % it will consist of whatsits followed by \cmd\topskip\ glue and the \cmd\@protection@box.
1405 % \begin{macrocode}
1406 \def\protect@penalty#1{\protection@box\penalty-#1\relax}%
1407 \newbox\@protection@box
1408 \setbox\@protection@box\vbox to1986sp{\vfil}%
1409 \def\protection@box{\nointerlineskip\copy\@protection@box}%
1410 % \end{macrocode}
1411 % \end{macro}
1412 %
1413 % \begin{macro}{\dead@cycle}
1414 % \begin{macro}{\dead@cycle@repair}
1415 % The procedure \cmd\dead@cycle\ is defined separately as a utility which can be used by
1416 % any output processing routine to emulate what takes place in the standard output routine.
1417 %
1418 % Here, we have entered the output routine with \cmd\holdinginserts\ enabled, which means that we
1419 % are not yet ready to ship out material, because the \cmd\insert\ registers are being held.
1420 % We want to clear \cmd\holdinginserts\ and come back here with the same page break as before, whereupon
1421 % we may properly proceed with page makeup.
1422 %
1423 % To do this, we
1424 % propagate marks, then spew the contents of \cmd\box\cmd\@cclv\ followed by the
1425 % original output penalty that landed us here (but only if it is not 10000,
1426 % the flag value for a pagebreak not at a penalty).
1427 %
1428 % However, the natural output routine should do this only if \cmd\box\cmd\@cclv\ is nontrivial.
1429 % A pathological case exists wherein a box of height greater than \cmd\textheight\ would cause an infinite loop involving the output routine.
1430 % The procedure \cmd\dead@cycle@repair, attempts to catch this case and avoid the loop.
1431 %
1432 % The test of the height of \cmd\box\cmd\@cclv\ is not the correct one, because this test will run afoul in
1433 % the case where \cmd\box\cmd\@cclv\ contains nothing but an \cmd\insert\ node. What to do?
1434 %
1435 % It is possible that the pathological case can be detected by looking at \cmd\pagetotal. If that quantity is
1436 % zero, then \cmd\box\cmd\@cclv\ really is trivial.
1437 %
1438 % In the procedure \cmd\dead@cycle@repair, if \cmd\box\cmd\@cclv\ is nontrivial, we execute \cmd\dead@cycle,
1439 % otherwise it contains nothing but a mark, so we dispense with propagating marks
1440 % and we simply spew out \cmd\box\cmd\@cclv\ without an accompanying mark.
1441 % This has the effect of failing to propagate marks, but this problem is preferrable to the infinite loop,
1442 % which in principle could crash even a robust operating system by filling up the file system.
1443 %
1444 % If a document has such a large chunk, it should be fixed, so we give a message in the log.
1445 %
1446 % You ask, ``In what way does this infinite loop come about?'' Good question!
1447 %
1448 % The setup is a chunk in the MVL that is taller than \cmd\textheight.
1449 % (Yes, it's that simple.)
1450 % As soon as the previous page ships out, the MVL will contain a mark (propagated from the previous page) followed
1451 % by that large chunk (call it the `big bad box', albeit does not need to be a single box).
1452 % The next visit to the output routine will be a natural page break, but
1453 % \TeX\ will select the juncture between the mark and the big bad box as the least-cost page break.
1454 % Unless the test in \cmd\dead@cycle\ is done, the cycle is perpetuated when the macro
1455 % reinserts the mark.
1456 %
1457 % The crux matter is achieving, in a robust way, the goal of going from a \cmd\holdinginserts\ state to one
1458 % where the insertions are moving.
1459 %
1460 % \begin{macrocode}
1461 \def\dead@cycle@repair#1{%
1462 \expandafter\do@@mark
1463 \expandafter{%
1464 \@@botmark
1465 }%
1466 \unvbox\@cclv
1467 \nointerlineskip
1468 \vbox to#1{\vss}%
1469 \@ifnum{\outputpenalty<\@M}{\penalty\outputpenalty}{}%
1470 }%
1471 \def\dead@cycle@repair@protected#1{%
1472 \expandafter\do@@mark
1473 \expandafter{%
1474 \@@botmark
1475 }%
1476 \begingroup
1477 \unvbox\@cclv
1478 \setbox\z@\lastbox % Remove protection box
1479 \nointerlineskip
1480 \advance#1-\ht\@protection@box
1481 \vbox to#1{\vss}%
1482 \protection@box % Reinsert protection box
1483 \@ifnum{\outputpenalty<\@M}{\penalty\outputpenalty}{}%
1484 \endgroup
1485 }%
1486 \def\dead@cycle{%
1487 \expandafter\do@@mark
1488 \expandafter{%
1489 \@@botmark
1490 }%
1491 \unvbox\@cclv
1492 \@ifnum{\outputpenalty<\@M}{\penalty\outputpenalty}{}%
1493 }%
1494 % \end{macrocode}
1495 % \end{macro}
1496 % \end{macro}
1497 %
1498 % \begin{macro}{\output@init@document}
1499 % \begin{macro}{\output@prep@document}
1500 % \begin{macro}{\output@post@document}
1501 % The default processing simply provides for insertion of held-over footnotes.
1502 % At a natural page break, we are either at the bottom of a column or at the bottom
1503 % of a page. In either case, the \cmd\output@init@\ processing adjusts for the height
1504 % of the held-over footnotes and bails out.
1505 % Upon our return, at \cmd\output@prep@\ time, the page break will accomodate the material;
1506 % it is now actually inserted by concatenating it with the contents of \cmd\footins.
1507 % The default processing for \cmd\output@post@\ is nil.
1508 % \begin{macrocode}
1509 \def\output@init@document{%
1510 \@ifvoid\footbox{}{%
1511 \global\advance\vsize-\ht\footbox
1512 \global\advance\vsize-\dp\footbox
1513 }%
1514 }%
1515 \def\output@prep@document{%
1516 \@ifvoid\footbox{}{%
1517 % {\tracingall\scrollmode\showbox\footbox\showbox\footins}%
1518 \setbox\footins\vbox{\unvbox\footbox\unvbox\footins}%
1519 }%
1520 }%
1521 \def\output@post@document{}%
1522 % \end{macrocode}
1523 % \end{macro}
1524 % \end{macro}
1525 % \end{macro}
1526 %
1527 % \begin{macro}{\@opcol}
1528 % The standard \LaTeX\ procedure \cmd\@opcol\ is now completely obsoleted.
1529 % \begin{macrocode}
1530 \let\@opcol\@undefined
1531 % \end{macrocode}
1532 % \end{macro}
1533 %
1534 % \begin{macro}{\@makecol}
1535 % The procedure \cmd\@makecol\ packages up a page along with all its insertions and floats.
1536 % Therefore it is essential that it be executed with \cmd\holdininserts\ cleared.
1537 %
1538 % Note that there is a corner case when in a multi-column grid, where the change back to
1539 % one-column grid occurs just after a complete page ships out. We want to detect when
1540 % \cmd\@cclv\ contains nothing but a \cmd\mark, but this is a \TeX\ impossibility.
1541 %
1542 % Note on \cmd\@kludgeins: we have removed this mechanism from \LaTeX, because the implementation
1543 % of \cmd\enlargethispage\ no longer requires it.
1544 % Here, for consistency sake, we remove \cmd\@makespecialcolbox.
1545 % \begin{macrocode}
1546 \def\@makecol{%
1547 \setbox\@outputbox\vbox{%
1548 \boxmaxdepth\@maxdepth
1549 \@tempdima\dp\@cclv
1550 \unvbox\@cclv
1551 \vskip-\@tempdima
1552 }%
1553 \xdef\@freelist{\@freelist\@midlist}\global\let\@midlist\@empty
1554 \@combinefloats
1555 \@combineinserts\@outputbox\footins
1556 %\@ifvbox\@kludgeins{%
1557 % \@makespecialcolbox
1558 %}{%
1559 \set@adj@colht\dimen@
1560 \count@\vbadness
1561 \vbadness\@M
1562 \setbox\@outputbox\vbox to\dimen@{%
1563 \@texttop
1564 \dimen@\dp\@outputbox
1565 \unvbox\@outputbox
1566 \vskip-\dimen@
1567 \@textbottom
1568 }%
1569 \vbadness\count@
1570 %}%
1571 \global\maxdepth\@maxdepth
1572 }%
1573 \let\@makespecialcolbox\@undefined
1574 % \end{macrocode}
1575 % \end{macro}
1576 %
1577 % \begin{macro}{\@combineinserts}
1578 % We split out the procedure to add the \cmd\footins\ insertions to the packaged-up page.
1579 % Any other non-trivial insertions should also be dealt with at this time.
1580 % \begin{macrocode}
1581 \def\@combineinserts#1#2{%
1582 \setbox#1\vbox{%
1583 \unvbox#1%
1584 % {\tracingall\scrollmode\showbox#2}%
1585 \vbox{%
1586 \@ifvoid#2{}{%
1587 \vskip\skip\footins
1588 \color@begingroup
1589 \normalcolor
1590 \footnoterule
1591 \nointerlineskip
1592 \box#2%
1593 \color@endgroup
1594 }{}%
1595 }%
1596 }%
1597 }%
1598 % \end{macrocode}
1599 % \end{macro}
1600 %
1601 % \begin{macro}{\@floatplacement}
1602 % In standard \LaTeX, someone (DPC?) makes the assumption that \cmd\@fpmin\ can be assigned
1603 % locally. This is no longer true now that we ship no more than one page per visit to the output routine.
1604 % We apply a bandaid.
1605 % \begin{macrocode}
1606 \appdef\@floatplacement{%
1607 \global\@fpmin\@fpmin
1608 }%
1609 % \end{macrocode}
1610 % \end{macro}
1611 %
1612 % \begin{macro}{\pagebreak@pen}
1613 % While we are in the way of registering certain penalty values,
1614 % let us register the smallest one that will force a visit to the output routine.
1615 % However, this penalty will not have an assciated macro: we wish to execute the
1616 % natural output routine instead.
1617 %
1618 % Note that this penalty is invoked by \cmd\clearpage\ and \cmd\newpage.
1619 % \begin{macrocode}
1620 \mathchardef\pagebreak@pen=\@M
1621 \expandafter\let\csname output@-\the\pagebreak@pen\endcsname\relax
1622 % \end{macrocode}
1623 % \end{macro}
1624 %
1625 %
1626 % \subsection{Float placement}%
1627 %
1628 % \begin{macro}{\do@startcolumn@pen}
1629 % The procedure \cmd\do@startcolumn@pen\ is executed as a one-off output routine
1630 % just after a page is shipped out (or, in a multicolumn page grid, a column is salted away).
1631 %
1632 % Its job is to either generate a ``float page'' (in reality a column) for shipping out,
1633 % or to commit deferred floats to the fresh column, concluding with a dead cycle.
1634 % In the former case, we accomodate split footnotes and other insertions (by comparing \cmd\vsize\ and \cmd\pagegoal):
1635 % the floats are spewed onto the page, whereupon \LaTeX's output routine will place the footnotes and ship out,
1636 % iterating the process once again.
1637 %
1638 % Note that when this procedure is invoked, \cmd\box\cmd\@cclv\ still has within it the protection box, so we
1639 % start by removing it. Note also that if there was a split insertion held over from the previous page, the
1640 % insert node will be present in \cmd\box\cmd\@cclv, \emph{prior to} the protection box. For this reason, we cannot
1641 % just throw away that box, as we might be tempted to do.
1642 %
1643 % FIXME: where else do we possibly inappropriately discard \cmd\box\cmd\@cclv?
1644 %
1645 % Note that, because a column or page page had previously just been completed,
1646 % we can assume that there is nothing of importance on the page,
1647 % and because no message is being passed, we can preserve marks in a simple way.
1648 %
1649 % A Note on terminology:
1650 % In a single-column page grid, you might expect that we would execute the procedure \cmd\do@startpage.
1651 % But this is not so.
1652 % \LaTeX\ has a confustion of long standing,
1653 % in which the procedures that handle full-page width floats in a two-column page grid all have in their names
1654 % the string `dbl', which erroneously suggests having something to do with ``double''. It does not:
1655 % when you see `dbl', think ``full page width''.
1656 % \begin{macrocode}
1657 \mathchardef\do@startcolumn@pen=10005
1658 \@namedef{output@-\the\do@startcolumn@pen}{\do@startcolumn}%
1659 \def\do@startcolumn{%
1660 \setbox\@cclv\vbox{\unvbox\@cclv\setbox\z@\lastbox\unskip}%
1661 \clearpage@sw{\@clearfloatplacement}{\@floatplacement}%
1662 \set@colroom
1663 \@booleanfalse\pfloat@avail@sw
1664 \begingroup
1665 \@colht\@colroom
1666 \@booleanfalse\float@avail@sw
1667 \@tryfcolumn\test@colfloat
1668 \float@avail@sw{\aftergroup\@booleantrue\aftergroup\pfloat@avail@sw}{}%
1669 \endgroup
1670 \fcolmade@sw{%
1671 \setbox\@cclv\vbox{\unvbox\@outputbox\unvbox\@cclv}%
1672 % \csname float@column@\thepagegrid\endcsname
1673 % \csname output@column@\thepagegrid\endcsname
1674 \outputpenalty-\pagebreak@pen % ask for a return visit, this time with insertions and all.
1675 \dead@cycle
1676 }{%
1677 \begingroup
1678 \let\@elt\@scolelt
1679 \let\reserved@b\@deferlist\global\let\@deferlist\@empty\reserved@b
1680 \endgroup
1681 \clearpage@sw{%
1682 \outputpenalty\@M
1683 }{%
1684 \outputpenalty\do@newpage@pen
1685 }%
1686 \dead@cycle
1687 }%
1688 \check@deferlist@stuck\do@startcolumn
1689 \set@vsize
1690 }%
1691 \def\@scolelt#1{\def\@currbox{#1}\@addtonextcol}%
1692 \def\test@colfloat#1{%
1693 \csname @floatselect@sw@\thepagegrid\endcsname#1{}{\@testtrue}%
1694 \@if@sw\if@test\fi{}{\aftergroup\@booleantrue\aftergroup\float@avail@sw}%
1695 }%
1696 % \end{macrocode}
1697 % \end{macro}
1698 %
1699 % \begin{macro}{\@addtonextcol}
1700 % We must adjust \cmd\@addtonextcol\ to take held-over inserts into account.
1701 % Now that all deferred floats are queued up together (in order), we must have a way of
1702 % differentiating them; this is done by the page grid-dependent procedure \cmd\@floatselect@sw@.
1703 % \begin{macrocode}
1704 \def\@addtonextcol{%
1705 \begingroup
1706 \@insertfalse
1707 \@setfloattypecounts
1708 \csname @floatselect@sw@\thepagegrid\endcsname\@currbox{%
1709 \@ifnum{\@fpstype=8 }{}{%
1710 \@ifnum{\@fpstype=24 }{}{%
1711 \@flsettextmin
1712 \@reqcolroom \ht\@currbox
1713 \advance \@reqcolroom \@textmin
1714 \advance \@reqcolroom \vsize % take into account split insertions
1715 \advance \@reqcolroom -\pagegoal
1716 \@ifdim{\@colroom>\@reqcolroom}{%
1717 \@flsetnum \@colnum
1718 \@ifnum{\@colnum>\z@}{%
1719 \@bitor\@currtype\@deferlist
1720 \@if@sw\if@test\fi{}{%
1721 \@addtotoporbot
1722 }%
1723 }{}%
1724 }{}%
1725 }%
1726 }%
1727 }{}%
1728 \@if@sw\if@insert\fi{}{%
1729 \@cons\@deferlist\@currbox
1730 }%
1731 \endgroup
1732 }%
1733 % \end{macrocode}
1734 % \end{macro}
1735 %
1736 % \begin{macro}{\do@startpage@pen}
1737 % \begin{macro}{\forcefloats@sw}
1738 % \begin{macro}{\@sdblcolelt}
1739 % \begin{macro}{\test@dblfloat}
1740 % \begin{macro}{\@if@notdblfloat}
1741 % Similar to \cmd\do@startcolumn,
1742 % the procedure \cmd\do@startpage\ starts up a new page (not column) in a multi-column page grid.
1743 % It is invoked after a page is shipped out in a multi-column page grid, and
1744 % it commits full-page-width floats to the fresh page, possibly resulting in a float page.
1745 % In implementation, it is similar to \cmd\do@startcolumn, except that
1746 % it commits effectively via \cmd\@addtodblcol\ instead of \cmd\@addtonextcol.
1747 % Note that this procedure will inevitably be followed by \cmd\do@startcolumn.
1748 %
1749 % Some details of the procedure:
1750 %
1751 % We begin by removing the protection box from \cmd\box\cmd\@cclv, then setting the values of the
1752 % float placement parameters appropriately, and resetting \cmd\@colht, \cmd\@colroom, and \cmd\vsize\ to base values.
1753 %
1754 % Next we attempt to compose a float page, a page consisting entirely of floats. If successful,
1755 % we ship out the float page and lay down an interrupt that will send us back here for another try.
1756 %
1757 % If no float page is formed, we attempt to commit full-page-width floats to the text page, and return with a dead cycle.
1758 % We are now ready to compose columns of text.
1759 %
1760 % Note that all floats (both column floats and full-page-width floats) move through a single queue.
1761 % To differentiate between the two, the width of the float is compared to \cmd\textwidth.
1762 % This comparison is encapsulated in the macro \cmd\@if@notdblfloat, which should be used whenever
1763 % such a determination must be made. This procedure returns a Boolean.
1764 % \begin{macrocode}
1765 \mathchardef\do@startpage@pen=10006
1766 \@namedef{output@-\the\do@startpage@pen}{\do@startpage}%
1767 \def\do@startpage{%
1768 \setbox\@cclv\vbox{\unvbox\@cclv\setbox\z@\lastbox\unskip}%
1769 \clearpage@sw{\@clearfloatplacement}{\@dblfloatplacement}%
1770 \set@colht
1771 \@booleanfalse\pfloat@avail@sw
1772 \begingroup
1773 \@booleanfalse\float@avail@sw
1774 \@tryfcolumn\test@dblfloat
1775 \float@avail@sw{\aftergroup\@booleantrue\aftergroup\pfloat@avail@sw}{}%
1776 \endgroup
1777 \fcolmade@sw{%
1778 \global\setbox\pagesofar\vbox{\unvbox\pagesofar\unvbox\@outputbox}%
1779 \@combinepage
1780 \@combinedblfloats
1781 \@outputpage
1782 \global\pagegrid@cur\@ne
1783 \protect@penalty\do@startpage@pen
1784 }{%
1785 \begingroup
1786 \@booleanfalse\float@avail@sw
1787 \let\@elt\@sdblcolelt
1788 \let\reserved@b\@deferlist\global\let\@deferlist\@empty\reserved@b
1789 \endgroup
1790 \@ifdim{\@colht=\textheight}{% No luck...
1791 \pfloat@avail@sw{% ...but a float *was* available!
1792 \forcefloats@sw{%
1793 \ltxgrid@warn{Forced dequeueing of floats stalled}%
1794 }{%
1795 \ltxgrid@warn{Dequeueing of floats stalled}%
1796 }%
1797 }{}%
1798 }{}%
1799 \outputpenalty\@M
1800 \dead@cycle
1801 }%
1802 \check@deferlist@stuck\do@startpage
1803 \set@colht
1804 %\set@colroom
1805 }%
1806 \def\@sdblcolelt#1{\def\@currbox{#1}\@addtodblcol}%
1807 \def\test@dblfloat#1{%
1808 \@if@notdblfloat{#1}{\@testtrue}{}%
1809 \@if@sw\if@test\fi{}{\aftergroup\@booleantrue\aftergroup\float@avail@sw}%
1810 }%
1811 \def\@if@notdblfloat#1{\@ifdim{\wd#1<\textwidth}}%
1812 \@booleanfalse\forcefloats@sw
1813 % \end{macrocode}
1814 % \end{macro}
1815 % \end{macro}
1816 % \end{macro}
1817 % \end{macro}
1818 % \end{macro}
1819 %
1820 % \begin{macro}{\@addtodblcol}
1821 %
1822 % The procedure \cmd\@addtodblcol\ is called into play at the beginning of each fresh page
1823 % and operates on each deferred float, in the hopes of placing one or more such floats
1824 % at the top of the current page.
1825 %
1826 % We alter the procedure of standard \LaTeX\ by putting failed floats into
1827 % \cmd\@deferlist\ instead of \cmd\@dbldeferlist. Having done so, we must have a means
1828 % of differentiating full-page-width floats from column-width floats.
1829 % We assume that the latter will always be narrower than \cmd\textwidth.
1830 %
1831 % In aid of detecting a stalled float flushing process, we set a Boolean if we encounter
1832 % a qualified full-page-width float here. Any that qualify but fail the rest of the tests
1833 % might still pass when reconsidered on an otherwise blank page.
1834 % \begin{macrocode}
1835 \def\@addtodblcol{%
1836 \begingroup
1837 \@if@notdblfloat{\@currbox}{%
1838 \false@sw
1839 }{%
1840 \@setfloattypecounts
1841 \@getfpsbit \tw@
1842 \@bitor \@currtype \@deferlist
1843 \@if@sw\if@test\fi{%
1844 \false@sw
1845 }{%
1846 \@ifodd\@tempcnta{%
1847 \aftergroup\@booleantrue\aftergroup\float@avail@sw
1848 \@flsetnum \@dbltopnum
1849 \@ifnum{\@dbltopnum>\z@}{%
1850 \@ifdim{\@dbltoproom>\ht\@currbox}{%
1851 \true@sw
1852 }{%
1853 \@ifnum{\@fpstype<\sixt@@n}{%
1854 \begingroup
1855 \advance \@dbltoproom \@textmin
1856 \@ifdim{\@dbltoproom>\ht\@currbox}{%
1857 \endgroup\true@sw
1858 }{%
1859 \endgroup\false@sw
1860 }%
1861 }{%
1862 \false@sw
1863 }%
1864 }%
1865 }{%
1866 \false@sw
1867 }%
1868 }{%
1869 \false@sw
1870 }%
1871 }%
1872 }%
1873 {%
1874 \@tempdima -\ht\@currbox
1875 \advance\@tempdima
1876 -\@ifx{\@dbltoplist\@empty}{\dbltextfloatsep}{\dblfloatsep}%
1877 \global \advance \@dbltoproom \@tempdima
1878 \global \advance \@colht \@tempdima
1879 \global \advance \@dbltopnum \m@ne
1880 \@cons \@dbltoplist \@currbox
1881 }{%
1882 \@cons \@deferlist \@currbox
1883 }%
1884 \endgroup
1885 }%
1886 % \end{macrocode}
1887 % \end{macro}
1888 %
1889 % \begin{macro}{\@tryfcolumn}
1890 % \begin{macro}{\@wtryfc}
1891 % \begin{macro}{\@xtryfc}
1892 % \begin{macro}{\@ztryfc}
1893 % Whenever a page is shipped out, \LaTeX\ automatically tries out a float column:
1894 % a page containing nothing but floats (and, as we have added here, split footnotes).
1895 %
1896 % The following four procedures employ certain macros to communicate between each other:
1897 %
1898 % \cmd\fcolmade@sw, a boolean, says whether we were successful in making a float column.
1899 %
1900 % \cmd\if@test, a \cmd\newif\ switch, says a float has failed some test.
1901 %
1902 % \cmd\@deferlist, is the input to the process, a list, of deferred floats.
1903 %
1904 % \cmd\@trylist, a list, stores the deferred floats to be tried out on the float column.
1905 %
1906 % \cmd\@failedlist, a list of floats that have failed the selection for the float column.
1907 %
1908 % \cmd\@flfail, a list of floats that have failed the second selection for the float column.
1909 %
1910 % \cmd\@flsucceed, a list, the floats that have been successfully placed on the float column.
1911 %
1912 % \cmd\@freelist, a list, receives any freed floats.
1913 %
1914 % \cmd\@colht, a dimen, the available space for the column, including column floats and insertions (footnotes).
1915 %
1916 % \cmd\@fpmin, a dimen, the required minimum height for the float column.
1917 %
1918 % \cmd\@outputbox, a box, the output of the process.
1919 %
1920 % \cmd\@fptop, \cmd\@fpsep, \cmd\@fpbot, glue, placed above, between, and below floats on the float column.
1921 %
1922 % \cmd\@currtype, a count, used temporarily for the float's bits.
1923 %
1924 % \cmd\@tempcnta, a count, used temporarily for the float's bits.
1925 %
1926 % In \cmd\@tryfcolumn, we alter the criterion for a float page, because if footnotes are present at this point
1927 % (presumably due to a split insertion) then \cmd\@fpmin is no longer the right threshold to apply.
1928 %
1929 % Note that we have changed \cmd\@tryfcolumn, \cmd\@xtryfc, and \cmd\@ztryfc\ syntactically so that the procedure
1930 % to test for the float's being a column float versus a full-page-width float is passed in as an
1931 % argument.
1932 %
1933 % \begin{macrocode}
1934 \def\@tryfcolumn#1{%
1935 \global\@booleanfalse\fcolmade@sw
1936 \@ifx@empty\@deferlist{}{%
1937 \global\let\@trylist\@deferlist
1938 \global\let\@failedlist\@empty
1939 \begingroup
1940 \dimen@\vsize\advance\dimen@-\pagegoal\@ifdim{\dimen@>\z@}{%
1941 \advance\@fpmin-\dimen@
1942 }{}%
1943 \def\@elt{\@xtryfc#1}\@trylist
1944 \endgroup
1945 \fcolmade@sw{%
1946 \global\setbox\@outputbox\vbox{\vskip \@fptop}%
1947 \let \@elt \@wtryfc \@flsucceed
1948 \global\setbox\@outputbox\vbox{\unvbox\@outputbox
1949 \unskip \vskip \@fpbot
1950 }%
1951 \let \@elt \relax
1952 \xdef\@deferlist{\@failedlist\@flfail}%
1953 \xdef\@freelist{\@freelist\@flsucceed}%
1954 }{}%
1955 }%
1956 }%
1957 \def\@wtryfc #1{%
1958 \global\setbox\@outputbox\vbox{\unvbox\@outputbox
1959 \box #1\vskip\@fpsep
1960 }%
1961 }%
1962 \def\@xtryfc#1#2{%
1963 \@next\reserved@a\@trylist{}{}% trim \@trylist. Ugly!
1964 \@currtype \count #2%
1965 \divide\@currtype\@xxxii\multiply\@currtype\@xxxii
1966 \@bitor \@currtype \@failedlist
1967 \@testfp #2%
1968 #1#2%
1969 \@ifdim{\ht #2>\@colht }{\@testtrue}{}%
1970 \@if@sw\if@test\fi{%
1971 \@cons\@failedlist #2%
1972 }{%
1973 \begingroup
1974 \gdef\@flsucceed{\@elt #2}%
1975 \global\let\@flfail\@empty
1976 \@tempdima\ht #2%
1977 \def \@elt {\@ztryfc#1}\@trylist
1978 \@ifdim{\@tempdima >\@fpmin}{%
1979 \global\@booleantrue\fcolmade@sw
1980 }{%
1981 \@cons\@failedlist #2%
1982 }%
1983 \endgroup
1984 \fcolmade@sw{%
1985 \let \@elt \@gobble
1986 }{}%
1987 }%
1988 }%
1989 \def\@ztryfc #1#2{%
1990 \@tempcnta \count#2%
1991 \divide\@tempcnta\@xxxii\multiply\@tempcnta\@xxxii
1992 \@bitor \@tempcnta {\@failedlist \@flfail}%
1993 \@testfp #2%
1994 #1#2%
1995 \@tempdimb\@tempdima
1996 \advance\@tempdimb \ht#2\advance\@tempdimb\@fpsep
1997 \@ifdim{\@tempdimb >\@colht}{%
1998 \@testtrue
1999 }{}%
2000 \@if@sw\if@test\fi{%
2001 \@cons\@flfail #2%
2002 }{%
2003 \@cons\@flsucceed #2%
2004 \@tempdima\@tempdimb
2005 }%
2006 }%
2007 % \end{macrocode}
2008 % \end{macro}
2009 % \end{macro}
2010 % \end{macro}
2011 % \end{macro}
2012 %
2013 %
2014 % \subsection{Clearing pages}%
2015 %
2016 % Clearing the page is an elaboration of ending the page: it entails flushing all floats.
2017 %
2018 % This package might make number of float flushing algorithms available,
2019 % a very simple one that does not try to produce excellent pages,
2020 % another that tries to make the best use of space,
2021 % and a more complex one that tries to balance columns.
2022 %
2023 % At the beginning of the page-clearing process, by definition all of the paragraph text involved is on the MVL and all floats have been encountered.
2024 % There may be material in \cmd\pagesofar, and (in a multi-column page grid) any number of columns of the page have been composed.
2025 % Also, there might be footnote material saved up in \cmd\footbox.
2026 %
2027 % Because we did not want to perform multiple \cmd\shipout s per visit to the output routine,
2028 % our multi-column page makeup will not compose multiple columns per visit.
2029 % This implementation detail may not require alteration, but it is not a limitation that is truly necessary:
2030 % it is only multiple \cmd\shipout s per visit that must be avoided.
2031 %
2032 % The crux matter is how to continue with flushing floats even after the material in the MVL is exhausted.
2033 % At that point, we must, upon completion of the output routine,
2034 % insert into the MVL an interrupt that triggers the next step in the processing.
2035 %
2036 % Therefore, after processing a \cmd\do@startcolumn\ interrupt, we must somehow force the completion of that column.
2037 % This could be done by inserting a \cmd\do@newpage@pen\ interrupt.
2038 %
2039 % And after processing a \cmd\do@startpage@pen\ interrupt, that results in \cmd\@dbltopinsert s,
2040 % we must ensure that the multiple columns on the page get completed, so that the page itself finally gets shipped out.
2041 % This part will proceed automatically given that \cmd\do@startcolumn\ processing completes successfully.
2042 %
2043 % The process will not be complete until all deferred floats have been placed and shipped out, and all saved-up footnotes have been inserted.
2044 %
2045 % Full-page-width floats can get out of order of column floats. This problem can be remedied by holding them all in the same list.
2046 % We therefore stop using \cmd\@dbldeferlist\ entirely, and all of the procedures that formerly used it have been rewritten to
2047 % use \cmd\@deferlist\ instead. When traversing the list, we apply a selector on the given box that determines whether it is a column-width or page-width float.
2048 % This selector is different depending on the page grid.
2049 %
2050 % When the \cmd\@deferlist\ is processed (by any means), we have to take care of the case where a float of one category is passed over but we are looking for a float of the other category.
2051 % Here, we must terminate processing, to avoid disordering the floats. This we do by the usual means.
2052 %
2053 % The system has a Boolean that says we are clearing pages: \cmd\clearpage@sw; if it is true,
2054 % then at the tail of \cmd\do@startcolumn\ processing, we should put down a (\cmd\vfil?) \cmd\do@newpage@pen\ interrupt.
2055 % This is because the MVL is now empty, so we have to force the columns to complete.
2056 %
2057 % One potential very pathological case would be where there is one or more deferred floats that never successfully get placed:
2058 % placing floats has stalled, and we will ship out blank pages indefinitely. How to detect this case?
2059 %
2060 % First, \cmd\do@startpage\ will evidently be stalled if the following are all true:
2061 % a) \cmd\@tryfcolumn\ and \cmd\@sdblcolelt\ both fail,
2062 % b) there are deferred floats available for page placement, and
2063 % c) the \cmd\@colht=\cmd\textheight, that is, the full page height is available for placement of column floats.
2064 %
2065 % Second, \cmd\do@startcolumn\ will evidently be stalled if the following are all true:
2066 % a) tryfcolumn fails,
2067 % b) there are deferred floats available for column placement, and
2068 % a) the \cmd\@colroom=\cmd\textheight, that is, the full page height is available for placement of column floats.
2069 %
2070 %
2071 % \begin{macro}{\cleardoublepage}
2072 % \begin{macro}{\clearpage}
2073 % \begin{macro}{\newpage}
2074 % \begin{macro}{\newpage@prep}
2075 % The function of \cmd\clearpage\ is to end the current page with \cmd\newpage\ and then
2076 % ship out additional pages until (\footins) inserts and (deferred) floats are exhausted.
2077 %
2078 % The method involves setting the float placement parameters to completely permissive values
2079 % and kicking out the current page (using a non-discardable penalty).
2080 % A possibly short page will be shipped out, followed
2081 % by any number of float pages. However these float pages, because using permissive float placement,
2082 % will exhaust all inserts and deferred floats.
2083 %
2084 % Bug Note: in the code for \cmd\clearpage, the first penalty we output is an unprotected \cmd\pagebreak@pen.
2085 % I tried using a protected \cmd\do@newpage@pen, but that gave rise to a corner case where a blank page
2086 % was output.
2087 %
2088 % At present, the \cmd\clearpage\ procedure does the same as \cmd\newpage,
2089 % except that \cmd\clearpage@sw\ is turned on,
2090 % and the (discardable) \cmd\newpage\ is inevitably followed by the same procedures
2091 % that are executed if a page is shipped out.
2092 %
2093 % FIXME: it seems that better than \cmd\pagebreak@pen\ would be an unprotected penalty of a special value that would
2094 % entail output routine processing consisting of the following steps:
2095 % 3) \cmd\unvbox\cmd\@cclv,
2096 % 1) set \cmd\clearpage@sw\ to \cmd\true@sw,
2097 % 2) put down a protected \cmd\do@startcolumn@pen,
2098 % 4) take a dead cycle.
2099 %
2100 % The effect would be to liberalize float placement options for the current column as well as further columns that may be output as part of \cmd\clearpage\ processing.
2101 % Of course, it would still be necessary to set \cmd\clearpage@sw\ again via an interrupt.
2102 %
2103 % An optimization might be to clear \cmd\clearpage@sw\ as part of the same interrupt,
2104 % but that would actually not work properly, because it is necessary for \cmd\do@endpage\ to
2105 % possibly invoke furhter visits to the output routine before clearpage processing ceases.
2106 % \begin{macrocode}
2107 \def\newpage@prep{%
2108 \if@noskipsec
2109 \ifx \@nodocument\relax
2110 \leavevmode
2111 \global \@noskipsecfalse
2112 \fi
2113 \fi
2114 \if@inlabel
2115 \leavevmode
2116 \global \@inlabelfalse
2117 \fi
2118 \if@nobreak \@nobreakfalse \everypar{}\fi
2119 \par
2120 }%
2121 \def \newpage {%
2122 \newpage@prep
2123 \do@output@MVL{%
2124 \vfil
2125 \penalty-\pagebreak@pen
2126 }%
2127 }%
2128 \def\clearpage{%
2129 \newpage@prep
2130 \do@output@MVL{%
2131 \vfil
2132 \penalty-\pagebreak@pen
2133 \global\@booleantrue\clearpage@sw
2134 \protect@penalty\do@startcolumn@pen
2135 \protect@penalty\do@endpage@pen
2136 }%
2137 \do@output@MVL{%
2138 \global\@booleanfalse\clearpage@sw
2139 }%
2140 }%
2141 \def\cleardoublepage{%
2142 \clearpage
2143 \@if@sw\if@twoside\fi{%
2144 \@ifodd\c@page{}{%
2145 \null\clearpage
2146 }%
2147 }{}%
2148 }%
2149 \@booleanfalse\clearpage@sw
2150 % \end{macrocode}
2151 % \end{macro}
2152 % \end{macro}
2153 % \end{macro}
2154 % \end{macro}
2155 %
2156 % \begin{macro}{\do@endpage@pen}
2157 % The penalty \cmd\do@endpage@pen\ simply dispatches to the page grid procedure that forces an end page.
2158 % That procedure should test whether there is anything to ship out (say committed floats), then act accordingly.
2159 % Note that as part of this work, it should \cmd\unvbox\cmd\@cclv, which has been left boxed up so it can be
2160 % measured.
2161 % \begin{macrocode}
2162 \mathchardef\do@endpage@pen=10007
2163 \@namedef{output@-\the\do@endpage@pen}{%
2164 \csname end@column@\thepagegrid\endcsname
2165 }%
2166 % \end{macrocode}
2167 % \end{macro}
2168 %
2169 % \begin{macro}{\do@newpage@pen}
2170 % The penalty \cmd\do@newpage@pen\ allows a ``non-discardable \cmd\newpage'' command:
2171 % a \cmd\newpage\ command that will not disappear at a pagebreak.
2172 % This visit to the output routine will not be dispatched to an interrupt,
2173 % rather the natural output routine will be executed, where it
2174 % will remove the protection box.
2175 %
2176 % Call this routine by executing \cmd\protect@penalty\cmd\do@newpage@pen.
2177 % \begin{macrocode}
2178 \mathchardef\do@newpage@pen=10001
2179 \expandafter\let\csname output@-\the\do@newpage@pen\endcsname\relax
2180 % \end{macrocode}
2181 % \end{macro}
2182 %
2183 % \begin{macro}{\@clearfloatplacement}
2184 % The procedure \cmd\@clearfloatplacement\ sets all of the float placement parameters
2185 % to completely permissive values. The standard values appear as comments.
2186 % \begin{macrocode}
2187 \def\@clearfloatplacement{%
2188 \global\@topnum \maxdimen % \c@topnumber
2189 \global\@toproom \maxdimen % \topfraction\@colht
2190 \global\@botnum \maxdimen % \c@bottomnumber
2191 \global\@botroom \maxdimen % \bottomfraction\@colht
2192 \global\@colnum \maxdimen % \c@totalnumber
2193 %\global\@fpmin \z@ % \floatpagefraction\@colht
2194 \global\@dbltopnum \maxdimen % \c@dbltopnumber
2195 \global\@dbltoproom \maxdimen % \dbltopfraction\@colht
2196 \global\@textmin \z@ % \@colht\advance \@textmin -\@dbltoproom
2197 \global\@fpmin \z@ % \dblfloatpagefraction\textheight
2198 \let\@testfp\@gobble
2199 \appdef\@setfloattypecounts{\@fpstype16\advance\@fpstype\m@ne}%
2200 }%
2201 % \end{macrocode}
2202 % \end{macro}
2203 %
2204 % \begin{macro}{\@doclearpage}
2205 % The \cmd\@doclearpage\ procedure is now obsoleted, as is \cmd\@makefcolumn, which it invoked.
2206 % \begin{macrocode}
2207 \let\@doclearpage\@undefined
2208 \let\@makefcolumn\@undefined
2209 % \end{macrocode}
2210 % \end{macro}
2211 %
2212 % \begin{macro}{\clr@top@firstmark}
2213 % \begin{macro}{\set@top@firstmark}
2214 % \begin{macro}{\@outputpage}
2215 % We want accurate values of \cmd\topmark\ and \cmd\firstmark, but we must deal with
2216 % the fact that there are many different ways of contributing material
2217 % to the page. Only upon the first contribution to the page is the value of \cmd\topmark\
2218 % accurate. However, with \cmd\firstmark\ we must potentially examine each contribution
2219 % because the first mark on the page may happen to fall in the last piece of material contributed.
2220 %
2221 % To begin, we define the procedure that initializes the macros to appropriate flag values.
2222 % \begin{macrocode}
2223 \def\clr@top@firstmark{%
2224 \global\let\saved@@topmark\@undefined
2225 \global\let\saved@@firstmark\@empty
2226 \global\let\saved@@botmark\@empty
2227 }%
2228 \clr@top@firstmark
2229 % \end{macrocode}
2230 %
2231 % Note that the flag value for \cmd\saved@@topmark\ is \cmd\@undefined, just as one would
2232 % expect. But that for \cmd\saved@@firstmark\ and \cmd\saved@@botmark\ is \cmd\@empty.
2233 %
2234 % Next, we define procedure \cmd\set@top@firstmark; it will be exercised everywhere material is contributed,
2235 % capturing the mark values if appropriate.
2236 % \begin{macrocode}
2237 \def\set@top@firstmark{%
2238 \@ifxundefined\saved@@topmark{\expandafter\gdef\expandafter\saved@@topmark\expandafter{\@@topmark}}{}%
2239 \@if@empty\saved@@firstmark{\expandafter\gdef\expandafter\saved@@firstmark\expandafter{\@@firstmark}}{}%
2240 \@if@empty\@@botmark{}{\expandafter\gdef\expandafter\saved@@botmark\expandafter{\@@botmark}}%
2241 }%
2242 % \end{macrocode}
2243 % When should \cmd\set@top@firstmark\ be called?
2244 % A good candidate for a universal procedure for handling contributed material is
2245 % the natural output routine; are any other calls needed?
2246 %
2247 % Yes, in \cmd\save@column\ we must execute \cmd\set@top@firstmark\ because we are about to
2248 % save away \cmd\box\cmd\@cclv, and we will never see its marks again (unless it is unboxed into the MVL),
2249 % because \TeX\ lets one access a box's marks only within an output routine that has put that box into \cmd\box\cmd\@cclv.
2250 %
2251 % As soon as a page is shipped out, we initialize the two macros that
2252 % hold the values of \cmd\topmark\ and \cmd\firstmark, respectively.
2253 % \LaTeX\ has exactly one procedure \cmd\@outputpage\ that does \cmd\shipout,
2254 % which is as it should be: we tailpatch it, and the job is done.
2255 % \begin{macrocode}
2256 \appdef\@outputpage{%
2257 \clr@top@firstmark
2258 }%
2259 % \end{macrocode}
2260 % \end{macro}
2261 % \end{macro}
2262 % \end{macro}
2263 %
2264 %
2265 % \subsection{Other interfaces to \LaTeX}%
2266 %
2267 % \begin{macro}{\@float}
2268 % \begin{macro}{\@dblfloat}
2269 % \begin{macro}{\@yfloat}
2270 % \begin{macro}{\fps@}
2271 % \begin{macro}{\fpsd@}
2272 % The \LaTeX\ kernel procedures \cmd\@float\ and \cmd\@dblfloat\ are treated on an equal footing.
2273 % Each now takes environment-specific float placement defaults.
2274 % If none are defined for the calling environment, we apply a default.
2275 %
2276 % A parameter is passed that will set the width of text within the float, normally \cmd\columnwidth,
2277 % and in the "dbl" version, \cmd\textwidth. However, an environment such as \env{turnpage}
2278 % may change the meanings of these macros to allow turnpage floats.
2279 %
2280 % \begin{macrocode}
2281 \def\@float#1{%
2282 \@ifnextchar[{%}]{%Brace-matching klootch
2283 \@yfloat\width@float{#1}%
2284 }{%
2285 \@ifxundefined@cs{fps@#1}{%
2286 \edef\reserved@a{\noexpand\@yfloat\noexpand\width@float{#1}[\csname fps@\endcsname]}\reserved@a
2287 }{%
2288 \edef\reserved@a{\noexpand\@yfloat\noexpand\width@float{#1}[\csname fps@#1\endcsname]}\reserved@a
2289 }%
2290 }%
2291 }%
2292 \def\@dblfloat#1{%
2293 \@ifnum{\pagegrid@col=\@ne}{%
2294 \@float{#1}%
2295 }{%
2296 \@ifnextchar[{%}]{%Brace-matching klootch
2297 \@yfloat\widthd@float{#1}%
2298 }{%
2299 \@ifxundefined@cs{fpsd@#1}{%
2300 \edef\reserved@a{\noexpand\@yfloat\noexpand\widthd@float{#1}[\csname fpsd@\endcsname]}\reserved@a
2301 }{%
2302 \edef\reserved@a{\noexpand\@yfloat\noexpand\widthd@float{#1}[\csname fpsd@#1\endcsname]}\reserved@a
2303 }%
2304 }%
2305 }%
2306 }%
2307 \def\@yfloat#1#2[#3]{%
2308 \@xfloat{#2}[#3]%
2309 \hsize#1\linewidth\hsize
2310 \minipagefootnote@init
2311 }%
2312 \def\fps@{tbp}%
2313 \def\fpsd@{tp}%
2314 \def\width@float{\columnwidth}%
2315 \def\widthd@float{\textwidth}%
2316 % \end{macrocode}
2317 % \end{macro}
2318 % \end{macro}
2319 % \end{macro}
2320 % \end{macro}
2321 % \end{macro}
2322 %
2323 % \begin{macro}{\end@float}
2324 % \begin{macro}{\end@dblfloat}
2325 % \begin{macro}{\end@@float}
2326 % \begin{macro}{\check@currbox@count}
2327 % \begin{macro}{\minipagefootnote@init}
2328 % \begin{macro}{\minipagefootnote@here}
2329 % \LaTeX\ kernel procedures \cmd\end@float\ and \cmd\end@dblfloat\
2330 % have been changed to work alike; in particular, floats of both classes
2331 % are deferred into the same queue.
2332 % This measure ensures that they will be placed in their original order,
2333 % an aspect in which \LaTeX\ is broken.
2334 %
2335 % Note: when retrieving floats from the queues, we can differentiate those of the two categories
2336 % by the width of the box.
2337 %
2338 % Floats are processed via an output routine message, and are checked for
2339 % sanity in re the float placement options. In the case of full-page-width floats,
2340 % we ensure that the h and b float placement options are never asserted, because they
2341 % make no sense.
2342 %
2343 % Note that if we get to the end of the float box and still have pending
2344 % footnotes, we put then out.
2345 %
2346 % LaTeX Bug note: if a user types \cmd\begin{table*}[h], the float will never succeed in being placed!
2347 % we try to catch such cases.
2348 %
2349 % Note that the macro \cmd\check@currbox@count\ trys to catch cases where the float placement options
2350 % are such that the float can never be placed.
2351 % \begin{macrocode}
2352 \def\end@float{%
2353 \end@@float{%
2354 \check@currbox@count
2355 }%
2356 }%
2357 \def\end@dblfloat{%
2358 \@ifnum{\pagegrid@col=\@ne}{%
2359 \end@float
2360 }{%
2361 \end@@float{%
2362 \@boxfpsbit\@currbox{1}\@ifodd\@tempcnta{\global\advance\count\@currbox\m@ne}{}%
2363 \@boxfpsbit\@currbox{4}\@ifodd\@tempcnta{\global\advance\count\@currbox-4\relax}{}%
2364 \global\wd\@currbox\textwidth % Klootch
2365 \check@currbox@count
2366 }%
2367 }%
2368 }%
2369 \def\end@@float#1{%
2370 \minipagefootnote@here
2371 %\minipagefootnotes
2372 \@endfloatbox
2373 #1%
2374 \@ifnum{\@floatpenalty <\z@}{%
2375 \@largefloatcheck
2376 \@cons\@currlist\@currbox
2377 \@ifnum{\@floatpenalty <-\@Mii}{%
2378 \do@output@cclv{\@add@float}%
2379 }{%
2380 \vadjust{\do@output@cclv{\@add@float}}%
2381 \@Esphack
2382 }%
2383 }{}%
2384 }%
2385 \def\check@currbox@count{%
2386 \@ifnum{\count\@currbox>\z@}{%
2387 \count@\count\@currbox\divide\count@\sixt@@n\multiply\count@\sixt@@n
2388 \@tempcnta\count\@currbox\advance\@tempcnta-\count@
2389 \@ifnum{\@tempcnta=\z@}{%
2390 \ltxgrid@warn{Float cannot be placed}%
2391 }{}%
2392 }{%
2393 % Is a \marginpar
2394 }%
2395 }%
2396 \providecommand\minipagefootnote@init{}%
2397 \providecommand\minipagefootnote@here{}%
2398 % \end{macrocode}
2399 % \end{macro}
2400 % \end{macro}
2401 % \end{macro}
2402 % \end{macro}
2403 % \end{macro}
2404 % \end{macro}
2405 %
2406 % \begin{macro}{\@specialoutput}
2407 % The \cmd\@add@float\ procedure used to reside in standard \LaTeX's \cmd\@specialoutput,
2408 % which is no more.
2409 %
2410 % Historical Note: \cmd\@specialoutput\ and Lamport's method of an output routine dispatcher
2411 % is the genesis of our more powerful and refined way of using \TeX's output routine to
2412 % safely accomplish page makeup tasks. To it and to him we owe acknowledgement and thanks.
2413 % \begin{macrocode}
2414 \let\@specialoutput\@undefined
2415 % \end{macrocode}
2416 % \end{macro}
2417 %
2418 % \begin{macro}{\@add@float}
2419 % In the following, we do not need to execute \cmd\@reinserts, which was wrong anyway, as you cannot
2420 % reliably recover insertions when they split (unless you have a way of reinserting the captured insertion
2421 % ahead of the split-off part).
2422 %
2423 % Now that full-page-width floats are being processed the same as column floats, we
2424 % have to nip in here and cause them always to be deferred.
2425 %
2426 % At the very end, the \cmd\vsize\ is adjusted for any newly committed float.
2427 % \begin{macrocode}
2428 \def\@add@float{%
2429 \@pageht\ht\@cclv\@pagedp\dp\@cclv
2430 \unvbox\@cclv
2431 \@next\@currbox\@currlist{%
2432 \csname @floatselect@sw@\thepagegrid\endcsname\@currbox{%
2433 \@ifnum{\count\@currbox>\z@}{%
2434 \advance \@pageht \@pagedp
2435 \advance \@pageht \vsize \advance \@pageht -\pagegoal % do not assume \holdinginserts is cleared!
2436 % \@ifvbox\@kludgeins{%
2437 % \@ifdim{\wd\@kludgeins=\z@}{%
2438 % \advance \@pageht \ht\@kludgeins
2439 % }{}%
2440 % }{}%
2441 % \@reinserts
2442 \@addtocurcol % Commit an h float
2443 }{%
2444 % \@reinserts
2445 \@addmarginpar
2446 }%
2447 }{%
2448 \@resethfps
2449 \@cons\@deferlist\@currbox
2450 }%
2451 }{\@latexbug}%
2452 \@ifnum{\outputpenalty<\z@}{%
2453 \@if@sw\if@nobreak\fi{%
2454 \nobreak
2455 }{%
2456 \addpenalty \interlinepenalty
2457 }%
2458 }{}%
2459 \set@vsize
2460 }%
2461 % \end{macrocode}
2462 % \end{macro}
2463 %
2464 % \begin{macro}{\@reinserts}
2465 % The \cmd\@reinserts\ procedure of standard \LaTeX\ is now obsoleted.
2466 % \begin{macrocode}
2467 \let\@reinserts\@undefined
2468 % \end{macrocode}
2469 % \end{macro}
2470 %
2471 % \begin{macro}{\@addtocurcol}
2472 % We modify the \cmd\@addtocurcol\ procedure of standard \LaTeX\
2473 % so that a float placed ``here'' may break over pages.
2474 % \begin{macrocode}
2475 \def \@addtocurcol {%
2476 \@insertfalse
2477 \@setfloattypecounts
2478 \ifnum \@fpstype=8
2479 \else
2480 \ifnum \@fpstype=24
2481 \else
2482 \@flsettextmin
2483 \advance \@textmin \@textfloatsheight
2484 \@reqcolroom \@pageht
2485 \ifdim \@textmin>\@reqcolroom
2486 \@reqcolroom \@textmin
2487 \fi
2488 \advance \@reqcolroom \ht\@currbox
2489 \ifdim \@colroom>\@reqcolroom
2490 \@flsetnum \@colnum
2491 \ifnum \@colnum>\z@
2492 \@bitor\@currtype\@deferlist
2493 \if@test
2494 \else
2495 \@bitor\@currtype\@botlist
2496 \if@test
2497 \@addtobot
2498 \else
2499 \ifodd \count\@currbox
2500 \advance \@reqcolroom \intextsep
2501 \ifdim \@colroom>\@reqcolroom
2502 \global \advance \@colnum \m@ne
2503 \global \advance \@textfloatsheight \ht\@currbox
2504 \global \advance \@textfloatsheight 2\intextsep
2505 \@cons \@midlist \@currbox
2506 \if@nobreak
2507 \nobreak
2508 \@nobreakfalse
2509 \everypar{}%
2510 \else
2511 \addpenalty \interlinepenalty
2512 \fi
2513 \vskip \intextsep
2514 \unvbox\@currbox %AO
2515 \penalty\interlinepenalty
2516 \vskip\intextsep
2517 \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
2518 \outputpenalty \z@
2519 \@inserttrue
2520 \fi
2521 \fi
2522 \if@insert
2523 \else
2524 \@addtotoporbot
2525 \fi
2526 \fi
2527 \fi
2528 \fi
2529 \fi
2530 \fi
2531 \fi
2532 \if@insert
2533 \else
2534 \@resethfps
2535 \@cons\@deferlist\@currbox
2536 \fi
2537 }%
2538 % \end{macrocode}
2539 % \end{macro}
2540 %
2541 % \begin{macro}{\if@twocolumn}
2542 % The \cmd\newif\ switch \cmd\if@twocolumn\ is entirely unused. However its access words are invoked by
2543 % \LaTeX's \cmd\document\ procedure, so we de-fang it.
2544 % \begin{macrocode}
2545 \@twocolumnfalse
2546 \let\@twocolumntrue\@twocolumnfalse
2547 % \end{macrocode}
2548 % \end{macro}
2549 %
2550 % \begin{macro}{\@addmarginpar}
2551 % The procedure \cmd\@addmarginpar\ used to access \cmd\if@twocolumn, but that switch is not reliable;
2552 % the better way is to use \cmd\thepagegrid. We establish a convention for a page-grid-oriented
2553 % procedure, e.g., \cmd\@addmarginpar@one, that emits a boolean, telling this procedure
2554 % whether to set the marginpar on the left or right.
2555 % \begin{macrocode}
2556 \def\@addmarginpar{%
2557 \@next\@marbox\@currlist{%
2558 \@cons\@freelist\@marbox\@cons\@freelist\@currbox
2559 }\@latexbug
2560 \setbox\@marbox\hb@xt@\columnwidth{%
2561 \csname @addmarginpar@\thepagegrid\endcsname{%
2562 \hskip-\marginparsep\hskip-\marginparwidth
2563 \box\@currbox
2564 }{%
2565 \hskip\columnwidth\hskip\marginparsep
2566 \box\@marbox
2567 }%
2568 \hss
2569 }%
2570 \setbox\z@\box\@currbox
2571 \@tempdima\@mparbottom
2572 \advance\@tempdima -\@pageht
2573 \advance\@tempdima\ht\@marbox
2574 \@ifdim{\@tempdima >\z@}{%
2575 \@latex@warning@no@line {Marginpar on page \thepage\space moved}%
2576 }{%
2577 \@tempdima\z@
2578 }%
2579 \global\@mparbottom\@pageht
2580 \global\advance\@mparbottom\@tempdima
2581 \global\advance\@mparbottom\dp\@marbox
2582 \global\advance\@mparbottom\marginparpush
2583 \advance\@tempdima -\ht\@marbox
2584 \global\setbox \@marbox
2585 \vbox {\vskip \@tempdima
2586 \box \@marbox}%
2587 \global \ht\@marbox \z@
2588 \global \dp\@marbox \z@
2589 \kern -\@pagedp
2590 \nointerlineskip
2591 \box\@marbox
2592 \nointerlineskip
2593 \hbox{\vrule \@height\z@ \@width\z@ \@depth\@pagedp}%
2594 }%
2595 % \end{macrocode}
2596 % \end{macro}
2597 %
2598 % \begin{environment}{turnpage}
2599 % Any float (viz., \env{figure} or \env{table}) within the scope of this environment
2600 % will be a turnpage float: It will be assumed to occupy an entire page (constitute a float page),
2601 % the width will be \cmd\textheight, the height \cmd\textwidth, and the entire float will be presented
2602 % rotated 90 degrees.
2603 %
2604 % The implementation requires the services of the \cmd\rotatebox\ command, so we supply a dummy definition
2605 % that explains things to the user.
2606 % \begin{macrocode}
2607 \newenvironment{turnpage}{%
2608 \def\width@float{\textheight}%
2609 \def\widthd@float{\textheight}%
2610 \appdef\@endfloatbox{%
2611 \@ifxundefined\@currbox{%
2612 \ltxgrid@warn{Cannot rotate! Not a float}%
2613 }{%
2614 \setbox\@currbox\vbox to\textwidth{\vfil\unvbox\@currbox\vfil}%
2615 \global\setbox\@currbox\vbox{\rotatebox{90}{\box\@currbox}}%
2616 }%
2617 }%
2618 }{%
2619 }%
2620 \def\rotatebox@dummy#1#2{%
2621 \ltxgrid@warn{You must load the graphics or graphicx package in order to use the turnpage environment}%
2622 #2%
2623 }%
2624 \AtBeginDocument{%
2625 \@ifxundefined\rotatebox{\let\rotatebox\rotatebox@dummy}{}%
2626 }%
2627 % \end{macrocode}
2628 % \end{environment}
2629 %
2630 %
2631 % \subsection{One-off output routines}
2632 %
2633 % These procedures are executed in lieu of \cmd\the\cmd\output\ when the output penalty has the associated flag value.
2634 %
2635 % \begin{macro}{output@-1073741824}
2636 % The first one-off output routine handles the end of the job, wherein
2637 % \LaTeX\ executes \cmd\@@end, and breaks to the output with a penalty of
2638 % $"40000000 = 2^{32}/4$. We simply discard \cmd\box\cmd\@cclv\ and leave.
2639 % This means that \LaTeX\ is obligated to do \cmd\clearpage\ as part of
2640 % its \enve{document} processing, otherwise material will be lost.
2641 % \begin{macrocode}
2642 \@namedef{output@-1073741824}{%"40000000
2643 \deadcycles\z@
2644 %\showbox\@cclv
2645 \setbox\z@\box\@cclv
2646 }%
2647 % \end{macrocode}
2648 % \end{macro}
2649 %
2650 % \begin{macro}{\save@column@pen}
2651 % The one-off output routine associated with \cmd\penalty\cmd\save@column@pen\
2652 % will be called within a sequence of three such routines by \cmd\execute@message
2653 % or its companion routine \cmd\execute@message@insert.
2654 % This procedure must save away any the current page and preserve marks.
2655 % \begin{macrocode}
2656 \mathchardef\save@column@pen=10016
2657 \@namedef{output@-\the\save@column@pen}{\save@column}%
2658 % \end{macrocode}
2659 % \end{macro}
2660 %
2661 % \begin{macro}{\@cclv@saved}
2662 % We take over the \cmd\@holdpg\ box register. Hereafter,
2663 % we no longer use the \cmd\@holdpg\ box register, so let the world know.
2664 % This should decisively break packages that assume standard \LaTeX.
2665 % Breaking decisively is preferred to quietly proceeding erroneously.
2666 % \begin{macrocode}
2667 \let \@cclv@saved \@holdpg
2668 \let \@holdpg \@undefined
2669 % \end{macrocode}
2670 % \end{macro}
2671 %
2672 % \begin{macro}{\save@column}
2673 % The procedure \cmd\save@column\ does the actual work of saving away the material
2674 % on the page. It is invoked both by \cmd\save@column@pen\ and by \cmd\save@column@insert@pen.
2675 % We save \cmd\box\cmd\@cclv\ and the primitive \cmd\@@topmark.
2676 % \begin{macrocode}
2677 \def\save@column{%
2678 \@ifvoid\@cclv@saved{%
2679 \set@top@firstmark
2680 \global\@topmark@saved\expandafter{\@@topmark}%
2681 }{}%
2682 \global\setbox\@cclv@saved\vbox{%
2683 \@ifvoid\@cclv@saved{}{%
2684 \unvbox\@cclv@saved
2685 \marry@baselines
2686 }%
2687 \unvbox\@cclv
2688 \lose@breaks
2689 \setbox\z@\lastbox
2690 }%
2691 }%
2692 \newtoks\@topmark@saved
2693 % \end{macrocode}
2694 % \end{macro}
2695 %
2696 % \begin{macro}{\prep@cclv}
2697 % The procedure \cmd\prep@cclv\ is used by message handlers to set up their environment
2698 % to ape that of the usual output routine, with the boxed-up page in \cmd\box\cmd\@cclv.
2699 % Here, we retrieve the material from \cmd\@cclv@saved, where it was saved away by
2700 % the one-off output routine associated with \cmd\save@column@pen.
2701 % \begin{macrocode}
2702 \def\prep@cclv{%
2703 \setbox\z@\box\@cclv
2704 \setbox\@cclv\box\@cclv@saved
2705 \vbadness\@M
2706 }%
2707 % \end{macrocode}
2708 % \end{macro}
2709 %
2710 % \begin{macro}{\save@column@insert@pen}
2711 % The one-off output routine associated with \cmd\penalty\cmd\save@column@insert@pen\
2712 % is similar to that of \cmd\save@column@pen\ augmented with the processing of insertions.
2713 % It is called by \cmd\execute@message@insert\ (i.e., at a grid change)
2714 % and saves away the current page and preserves marks.
2715 % In addition, it saves away any insertions that fall on the current page.
2716 % As with the regular output routine, it executes in two phases,
2717 % first with \cmd\holdinginserts\ set, then with it cleared.
2718 % \begin{macrocode}
2719 \mathchardef\save@column@insert@pen=10017
2720 \@namedef{output@-\the\save@column@insert@pen}{\toggle@insert\savecolumn@holding\savecolumn@moving}%
2721 % \end{macrocode}
2722 % The procedure \cmd\savecolumn@holding\ is the first phase of saving a column with its inserts.
2723 % This phase must detect and remedy the one circumstance that will confound our efforts to propagate marks.
2724 % It is similar to \cmd\output@holding, except that we have to deal with the protection box, which must
2725 % remain, because the messaging mechanism is being used.
2726 %
2727 % If it appears that we have the pathological ``Big Bad Box'' case at hand, we use the \cmd\dead@cycle@repair@protected\
2728 % procedure instead of \cmd\dead@cycle\ to do our dead cycle.
2729 % \begin{macrocode}
2730 \def\savecolumn@holding{%
2731 \@if@exceed@pagegoal{\unvcopy\@cclv\setbox\z@\lastbox}{%
2732 \setbox\z@\vbox{\unvcopy\@cclv\setbox\z@\lastbox}%
2733 \outputdebug@sw{{\tracingall\scrollmode\showbox\z@}}{}%
2734 \dimen@\ht\@cclv\advance\dimen@-\ht\z@
2735 \dead@cycle@repair@protected\dimen@
2736 }{%
2737 \dead@cycle
2738 }%
2739 }%
2740 % \end{macrocode}
2741 % The procedure \cmd\save@column@moving\ is the second phase of saving a column with its inserts.
2742 % Now that \cmd\holdinginserts\ is cleared, we can look in the various \cmd\insert\ registers for
2743 % our inserts (at present there is only one, \cmd\footins).
2744 % if anything is there, we save it away and ask for another cycle (because it may have split).
2745 %
2746 % Note that the message that is about to be executed had better deal properly with the contents of
2747 % the \cmd\footins@saved\ box.
2748 % \begin{macrocode}
2749 \def\savecolumn@moving{%
2750 \@cclv@nontrivial@sw{%
2751 \save@column
2752 }{%
2753 {\setbox\z@\box\@cclv}%
2754 }%
2755 \@ifvoid\footins{}{%
2756 \outputdebug@sw{{\tracingall\scrollmode\showbox\footins}}{}%
2757 \global\setbox\footins@saved\vbox{\unvbox\footins@saved\marry@baselines\unvbox\footins}%
2758 \protect@penalty\save@column@insert@pen
2759 }%
2760 }%
2761 \newbox\footins@saved
2762 % \end{macrocode}
2763 % \end{macro}
2764 %
2765 % \begin{macro}{\save@message@pen}
2766 % The one-off output routine associated with \cmd\penalty\cmd\save@message@pen\
2767 % saves away the message that has been passed.
2768 % This procedure is penultimate in a sequence of one-off output routine calls;
2769 % earlier ones have saved away the MVL and preserved marks, the last executes the message.
2770 %
2771 % Note that we are passing tokens to \TeX's primitive \cmd\mark\ mechanism, so we must ensure
2772 % that they are not inappropriately expanded. We use the same mechanism for all such cases,
2773 % namely \cmd\let@mark.
2774 %
2775 % Note: we expect that \cmd\box\cmd\@cclv's contents are well known:
2776 % \cmd\topskip, protection box, and a \cmd\mark, the latter havin the
2777 % message.
2778 % But if we came here via \cmd\penalty 10017, there might be an \cmd\insert\ node here as well, because
2779 % a footnote split.
2780 % Because this procedure simply voids out \cmd\box\cmd\@cclv, such material would be lost.
2781 % Perhaps we can repair things by manipulating the \cmd\insert \ mechanism temporarily.
2782 % \begin{macrocode}
2783 \mathchardef\save@message@pen=10018
2784 \@namedef{output@-\the\save@message@pen}{\save@message}%
2785 \def\save@message{%
2786 \setbox\z@\box\@cclv %FIXME: what if \box\@cclv is not empty?
2787 \toks@\expandafter{\@@firstmark}%
2788 \expandafter\gdef\expandafter\@message@saved\expandafter{\the\toks@}%
2789 \expandafter\do@@mark\expandafter{\the\@topmark@saved}%
2790 }%
2791 \gdef\@message@saved{}%
2792 % \end{macrocode}
2793 % \end{macro}
2794 %
2795 % \begin{macro}{\execute@message@pen}
2796 % The one-off output routine associated with \cmd\execute@message@pen\
2797 % simply executes the given message. It is last in a sequence of one-off output routine calls;
2798 % earlier ones have saved all that require saving.
2799 % \begin{macrocode}
2800 \mathchardef\execute@message@pen=10019
2801 \@namedef{output@-\the\execute@message@pen}{\@message@saved}%
2802 % \end{macrocode}
2803 % \end{macro}
2804 %
2805 %
2806 % \subsection{Output messages}
2807 %
2808 % Message handlers are procedures that execute output messages, tokens that are passed to
2809 % the output routine for execution in an environment appropriate to page makeup.
2810 %
2811 % How it works. We put down three large negative penalties, each of which will be handled by
2812 % the output dispatcher (not the output routine), each penalty being protected by
2813 % a removable, non-discardable item (i.e., a box).
2814 % Either three or four invocations of one-off output routines are involved per message.
2815 %
2816 % We make the last of the three protection boxes have a depth equal to the value of \cmd\prevdepth\
2817 % that was current when the procedure is called. This effectively restores \cmd\prevdepth.
2818 %
2819 % In each case, the one-off output routine will remove the extraneous box we have inserted.
2820 % And the second and third one-off routines will simply void \cmd\box\cmd\@cclv, because its contents
2821 % are entirely artificial.
2822 %
2823 % FIXME: not so! If \cmd\holdinginserts\ is cleared, that box may have an insert node; it must be preserved, too.
2824 %
2825 % The first routine saves away the current column contents and remembers the \cmd\topmark\ for later
2826 % use. There is a variant routine that first clears \cmd\holdinginserts, so that the message can
2827 % handle any inserts present in the boxed-up page; this of course entails yet another
2828 % visit to the output routine.
2829 %
2830 % The penultimate routine saves away the tokens transmitted in via the \cmd\@@mark: the argument of
2831 % the macro. These tokens are of course the very thing we wish to execute within the safety
2832 % of the output routine. It also puts down a mark containing the \cmd\topmark\ tokens saved
2833 % by the first routine. By this means, the mark, which we have clobbered, is restored.
2834 %
2835 % The last routine simply executes the given tokens.
2836 % In the course of doing this, it must take care of \cmd\box\cmd\@cclv, either by shipping it out,
2837 % or by \cmd\unvbox ing it onto the MVL.
2838 %
2839 % \begin{macro}{\execute@message}
2840 % The procedure \cmd\execute@message\ simply calls the utility procedure \cmd\@execute@message\
2841 % with a penalty value for the standard treatment.
2842 % \begin{macrocode}
2843 \def\execute@message{%
2844 \@execute@message\save@column@pen %Implicit #2
2845 }%
2846 % \end{macrocode}
2847 % \end{macro}
2848 %
2849 % \begin{macro}{\execute@message@insert}
2850 % The procedure \cmd\execute@message@insert\ is like \cmd\execute@message\ in all respects
2851 % except that the penalty value is \cmd\save@column@insert@pen, which arranges for the
2852 % message handler involved to deal with the page's insertions.
2853 % At the same time, we prepare the \cmd\footins\ box so that these insertions can be dealt with.
2854 %
2855 % Note:
2856 % If more insertions are added to \LaTeX\ (presumably via \cmd\newinsert), then they
2857 % must be dealt with in a way entirely analogous to \cmd\footins.
2858 % \begin{macrocode}
2859 \def\execute@message@insert#1{%
2860 \@execute@message\save@column@insert@pen{\setbox\footins\box\footins@saved#1}%
2861 }%
2862 % \end{macrocode}
2863 % \end{macro}
2864 %
2865 % \begin{macro}{\@execute@message}
2866 % The utility procedure \cmd\@execute@message\ is called by \cmd\execute@message\ and \cmd\execute@message@insert.
2867 % We prepare by creating a \cmd\vbox\ containing all the needed nodes and proceed by simply
2868 % \cmd\unvbox ing that box onto the MVL.
2869 % We ensure that \cmd\box\cmd\@cclv\ is properly set up for the output message handler
2870 % by always inserting \cmd\prep@cclv\ in advance of the argument.
2871 %
2872 % Note that each one-off output routine is invoked effectively the same as
2873 % \cmd\protect@penalty, except that the second invocation involves an additional
2874 % \cmd\mark\ node, and the third a specially prepared protection box.
2875 %
2876 % Note also that \TeX's primitive \cmd\mark\ is called here without any expansion protection.
2877 % This is the only place where it is called that way, but it's OK because those tokens
2878 % have have been pre-expanded by procedures that call \cmd\execute@message.
2879 % FIXME: all procedures calling \cmd\execute@message\ must pre-expand their tokens!
2880 % \begin{macrocode}
2881 \long\def\@execute@message#1#2{%
2882 \begingroup
2883 \dimen@\prevdepth\@ifdim{\dimen@<\z@}{\dimen@\z@}{}%
2884 \setbox\z@\vbox{%
2885 \protect@penalty#1%
2886 \protection@box
2887 \toks@{\prep@cclv#2}%
2888 \@@mark{\the\toks@}%
2889 \penalty-\save@message@pen
2890 % \hbox{\vrule\@height\z@\@width\z@\@depth\dimen@}%
2891 \setbox\z@\null\dp\z@\dimen@\ht\z@-\dimen@
2892 \nointerlineskip\box\z@
2893 \penalty-\execute@message@pen
2894 }\unvbox\z@
2895 \endgroup
2896 }%
2897 % \end{macrocode}
2898 % \end{macro}
2899 %
2900 % \begin{macro}{\do@output@cclv}
2901 % The procedure \cmd\do@output@cclv\ provides access to message handlers at their simplest.
2902 % The message will execute in the usual environment of the output routine, with
2903 % the boxed-up page in \cmd\box\cmd\@cclv, and we assume that \cmd\holdinginserts\ remains set.
2904 % This procedure must be invoked within main vertical mode;
2905 % it is the obligation of the macro writer to ensure that this is the case.
2906 % \begin{macrocode}
2907 \def\do@output@cclv{\execute@message}%
2908 % \end{macrocode}
2909 % \end{macro}
2910 %
2911 % \begin{macro}{\do@output@MVL}
2912 % The procedure \cmd\do@output@MVL, like \cmd\do@output@cclv, is an interface for messages,
2913 % but provides two additional services: the command may also be invoked in horizontal mode, and
2914 % the message handler will execute with the MVL unboxed.
2915 % \begin{macrocode}
2916 \def\do@output@MVL#1{%
2917 \@ifvmode{%
2918 \begingroup\execute@message{\unvbox\@cclv#1}\endgroup
2919 }{%
2920 \@ifhmode{%
2921 \vadjust{\execute@message{\unvbox\@cclv#1}}%
2922 }{%
2923 \@latexerr{\string\do@output@MVL\space cannot be executed in this mode!}\@eha
2924 }%
2925 }%
2926 }%
2927 % \end{macrocode}
2928 % \end{macro}
2929 %
2930 % \begin{macro}{\lose@breaks}
2931 % The purpose of this procedure is to get rid of all the extraneous
2932 % \cmd\penalty\cmd\@M\ nodes that tend to build up in the MVL.
2933 % \begin{macrocode}
2934 \def\lose@breaks{%
2935 \loopwhile{%
2936 \count@\lastpenalty
2937 \@ifnum{\count@=\@M}{% 10000 is a TeX magic number!
2938 \unpenalty\true@sw
2939 }{%
2940 \false@sw
2941 }%
2942 }%
2943 }%
2944 % \end{macrocode}
2945 % \end{macro}
2946 %
2947 % \begin{macro}{\removestuff}
2948 % \cmd\removestuff\ is a document-level command that removes the bottom skip glue item
2949 % from the MVL.
2950 % \begin{macrocode}
2951 \def\removestuff{\do@output@MVL{\unskip\unpenalty}}%
2952 % \end{macrocode}
2953 % \end{macro}
2954 %
2955 % \begin{macro}{\removephantombox}
2956 % The procedure \cmd\removephantombox\ is a special-purpose message handler exclusively for
2957 % preventing incorrect spacing above display math. It must be issued in
2958 % horizontal mode within the phantom paragraph generated when display math starts up in
2959 % vertical mode.
2960 % \begin{macrocode}
2961 \def\removephantombox{%
2962 \vadjust{%
2963 \execute@message{%
2964 \unvbox\@cclv
2965 \setbox\z@\lastbox
2966 \unskip
2967 \unskip
2968 \unpenalty
2969 \penalty\predisplaypenalty
2970 \vskip\abovedisplayskip
2971 }%
2972 }%
2973 }%
2974 % \end{macrocode}
2975 % \end{macro}
2976 %
2977 % \begin{macro}{\addstuff}
2978 % \cmd\addstuff\ is a document-level command that adds penalty, glue, or both to the
2979 % MVL. The penalty and glue items are rearranged so that all penalties nodes precede all the glue nodes,
2980 % which is the canonical arrangement.
2981 % \begin{macrocode}
2982 \def\addstuff#1#2{\edef\@tempa{\noexpand\do@output@MVL{\noexpand\@addstuff{#1}{#2}}}\@tempa}%
2983 \def\@addstuff#1#2{%
2984 \skip@\lastskip\unskip
2985 \count@\lastpenalty\unpenalty
2986 \@if@empty{#1}{}{\penalty#1\relax}%
2987 \@ifnum{\count@=\z@}{}{\penalty\count@}%
2988 \vskip\skip@
2989 \@if@empty{#2}{}{\vskip#2\relax}%
2990 }%
2991 % \end{macrocode}
2992 % \end{macro}
2993 %
2994 % \begin{macro}{\replacestuff}
2995 % \cmd\replacestuff\ is a document-level command similar to \cmd\addstuff;
2996 % but it replaces penalty, glue, or both in the MVL.
2997 % The penalty and glue items are rearranged so that all penalties nodes precede all the glue nodes,
2998 % which is the canonical arrangement.
2999 % \begin{macrocode}
3000 \def\replacestuff#1#2{\edef\@tempa{\noexpand\do@output@MVL{\noexpand\@replacestuff{#1}{#2}}}\@tempa}%
3001 \def\@replacestuff#1#2{%
3002 \skip@\lastskip\unskip
3003 \count@\lastpenalty\unpenalty
3004 \@if@empty{#1}{}{%
3005 \@ifnum{\count@>\@M}{}{%
3006 \@ifnum{\count@=\z@}{\count@=#1\relax}{%
3007 \@ifnum{\count@<#1\relax}{}{%
3008 \count@=#1\relax
3009 }%
3010 }%
3011 }%
3012 }%
3013 \@ifnum{\count@=\z@}{}{\penalty\count@}%
3014 \@if@empty{#2}{}{%
3015 \@tempskipa#2\relax
3016 \@ifdim{\z@>\@tempskipa}{%
3017 \advance\skip@-\@tempskipa
3018 }{%
3019 \@ifdim{\skip@>\@tempskipa}{}{%
3020 \skip@\@tempskipa
3021 }%
3022 }%
3023 }%
3024 \vskip\skip@
3025 }%
3026 % \end{macrocode}
3027 % \end{macro}
3028 %
3029 % \begin{macro}{\move@insertions}
3030 % \begin{macro}{\hold@insertions}
3031 % \begin{macro}{\move@insert@sw}
3032 % In order to avoid bolluxing up \cmd\insert\ registers by our one-off
3033 % output routines, we set \cmd\holdinginserts\ to zero by default and only
3034 % clear it (briefly) while we handle cases where we want inserts to show up.
3035 % \begin{macrocode}
3036 \def\move@insertions{\global\holdinginserts\z@}%
3037 \def\hold@insertions{\global\holdinginserts\@ne}%
3038 \hold@insertions
3039 \def\move@insert@sw{\@ifnum{\holdinginserts=\z@}}%
3040 \def\toggle@insert#1#2{%
3041 \@ifnum{\holdinginserts=\z@}{\hold@insertions#2}{\move@insertions#1}%
3042 }%
3043 % \end{macrocode}
3044 % \end{macro}
3045 % \end{macro}
3046 % \end{macro}
3047 %
3048 %
3049 % \subsection{Messages to alter the page grid}%
3050 %
3051 % Here is the implementation of the grid-switching procedures.
3052 % We perform two checks when changing the page grid; first to ensure that
3053 % the target page grid is known (defensive programming), second to ensure that
3054 % the switch is a non-trivial one. The latter check must be performed within
3055 % the safety of the output routine, so requires using an output message.
3056 % Thus, a grid change requires two messages, for a total of six visits to the output routine.
3057 %
3058 % \begin{macro}{\do@columngrid}
3059 % Utility procedure \cmd\do@columngrid\ changes the page grid.
3060 % Note that this command forces an end to the current paragraph. This is necessary, because
3061 % a page grid change makes no sense unless we can alter the \cmd\hsize\ before commencing to
3062 % typeset the following paragraph. So the command should never be executed in horizontal mode
3063 % anyway.
3064 % \begin{macrocode}
3065 \def\do@columngrid#1#2{%
3066 \par
3067 \expandafter\let\expandafter\@tempa\csname open@column@#1\endcsname
3068 \@ifx{\relax\@tempa}{%
3069 \ltxgrid@warn{Unknown page grid #1. No action taken}%
3070 }{%
3071 \do@output@MVL{\start@column{#1}{#2}}%
3072 }%
3073 }%
3074 % \end{macrocode}
3075 % \end{macro}
3076 %
3077 % \begin{macro}{\start@column}
3078 % Procedure \cmd\start@column\ lays down the interrupts to switch the page grid.
3079 % If the change to the page grid would have been trivial, it bails out.
3080 % It seems a reasonable tradeoff of processing versus security: once we commit
3081 % to changing the page grid, we clear \cmd\holdinginserts, so there is no turning back.
3082 %
3083 % Note that the second argument to the macro allows us to pass an argument to the
3084 % page grid that is starting up. This can be handy, because a single procedure can
3085 % handle multiple page grids, differing only by the value of a parameter.
3086 %
3087 % FIXME: this means that you cannot switch between mlt page grids in a single step.
3088 % But do we want to do this, at all, at all?
3089 % \begin{macrocode}
3090 \def\start@column#1#2{%
3091 \def\@tempa{#1}\@ifx{\@tempa\thepagegrid}{%
3092 \ltxgrid@info{Already in page grid \thepagegrid. No action taken}%
3093 }{%
3094 \expandafter\execute@message@insert
3095 \expandafter{%
3096 \csname shut@column@\thepagegrid\expandafter\endcsname
3097 \csname open@column@#1\endcsname{#2}%
3098 \set@vsize
3099 }%
3100 }%
3101 }%
3102 % \end{macrocode}
3103 % \end{macro}
3104 %
3105 % \begin{macro}{\thepagegrid}
3106 % The macro \cmd\thepagegrid\ tracks what kind of page grid we are in.
3107 %
3108 % Note: Access \cmd\thepagegrid\ only within the safety of the output routine.
3109 %
3110 % Warning: The page grid should be changed only within the safety of the output routine.
3111 % People who write multicol page grid mechanisms appear not to understand the matter, so they
3112 % should particularly heed this warning. Think about it: obviously Lamport did so, which is why
3113 % his \cmd\twocolumn\ command forced a pagebreak, which is limiting, but safe.
3114 % \begin{macrocode}
3115 \def\thepagegrid{one}%
3116 % \end{macrocode}
3117 % \end{macro}
3118 %
3119 %
3120 % \subsection{Application Note: implementing a page grid}
3121 %
3122 % If you want to create a new page grid for \LaTeX,
3123 % you must define five procedures with specific names:
3124 % \cmd\open@column@ name, \cmd\shut@column@ name, \cmd\end@column@ name,
3125 % \cmd\output@column@ name, and \cmd\@addmarginpar@ name, where ``name'' is the
3126 % name of your page grid.
3127 %
3128 % The procedure \cmd\open@column@ name starts the new page grid. It should define \cmd\thepagegrid,
3129 % deal with \cmd\box\cmd\pagesofar\ and \cmd\box\cmd\footbox\ (perhaps by leaving them alone),
3130 % and it should set the values of \LaTeX's page layout parameters for the column size and height.
3131 %
3132 % The procedure \cmd\shut@column@ name should expect to be called with \cmd\holdinginserts\
3133 % cleared (it can assume that \cmd\holdinginserts\ will automatically be restored).
3134 % It should properly deal with insertions (like footnotes); calling \cmd\@makecol\
3135 % is a good way to do this. It should know that the page grid is being terminated
3136 % in the middle of a page, so it should make arrangements to carry the footnotes down to the
3137 % bottom of the column or page, and it should possibly salt away the material for later
3138 % incorporation into the page. The box registers \cmd\footbox\ and \cmd\pagesofar\ are customarily used
3139 % for this purpose.
3140 %
3141 % The procedure \cmd\end@column@ name should kick out a possibly short page containing all the
3142 % floats committed to the page. It will be invoked during \cmd\clearpage\ processing.
3143 % After that, it should \cmd\unvbox\cmd\@cclv.
3144 %
3145 % The procedure \cmd\output@column@ name should ship out or commit the current \cmd\@outputbox.
3146 % In a one-column layout, you ship out; in a multicolumn layout, you commit the box as the contents
3147 % of a particular column, and if that column is the last, you ship out.
3148 %
3149 % The procedure \cmd\@addmarginpar@ name should return a boolean (either \cmd\true@sw\ or \cmd\false@sw\ or an equivalent)
3150 % to tell the marginpar mechanism to place the marginal material to the right or left, respectively.
3151 %
3152 % You can use the existing page grids ``one'' and ``mlt'' as a point of departure for creating others.
3153 % The former can be the basis for, say, a single-column page grid with a side column.
3154 %
3155 % \begin{macro}{\pagesofar}
3156 % \begin{macro}{\footbox}
3157 % \begin{macrocode}
3158 \newbox\pagesofar
3159 \newbox\footbox
3160 % \end{macrocode}
3161 % \end{macro}
3162 % \end{macro}
3163 %
3164 %
3165 % \subsubsection{One-column page grid}
3166 %
3167 % \begin{macro}{\onecolumngrid}
3168 % \begin{macro}{\open@column@one}
3169 % \begin{macro}{\shut@column@one}
3170 % \begin{macro}{\float@column@one}
3171 % \begin{macro}{\end@column@one}
3172 % \begin{macro}{\output@column@one}
3173 % \begin{macro}{\@addmarginpar@one}
3174 % Here are all the procedures necessary for the standard page grid named ``one'':
3175 % a single column layout. It is, of course, \LaTeX's familiar \cmd\onecolumn\ layout.
3176 % We begin with the procedure exposed to the style writer.
3177 % This is, however, not a \LaTeX\ command; users should not change the page grid.
3178 % \begin{macrocode}
3179 \newcommand\onecolumngrid{\do@columngrid{one}{\@ne}}%
3180 % \end{macrocode}
3181 %
3182 % Note that a document class that issues the command \cmd\onecolumn\ will break. This includes
3183 % \LaTeX's standard classes.dtx-based classes: if your class descends from one of these, you
3184 % must expunge it of all such commands.
3185 % \begin{macrocode}
3186 \let\onecolumn\@undefined
3187 % \end{macrocode}
3188 %
3189 % The procedure \cmd\open@column@one\ takes advantage of the special nature of the one-column
3190 % page grid to deal with \cmd\box\cmd\pagesofar, therefore it must also reset \cmd\@colroom.
3191 % \begin{macrocode}
3192 \def\open@column@one#1{%
3193 \unvbox\pagesofar
3194 \gdef\thepagegrid{one}%
3195 \global\pagegrid@col#1%
3196 \global\pagegrid@cur\@ne
3197 \set@colht
3198 %\set@colroom
3199 \set@column@hsize\pagegrid@col
3200 }%
3201 % \end{macrocode}
3202 %
3203 % The procedure \cmd\shut@column@one\ saves away the one-column material into the box register \cmd\pagesofar.
3204 % Because it is called from a message handler, we are assured that marks are properly taken care of.
3205 % \begin{macrocode}
3206 \def\shut@column@one{%
3207 \@makecol
3208 \global\setbox\pagesofar\vbox{\unvbox\@outputbox\recover@footins}%
3209 \set@colht
3210 %\set@colroom
3211 }%
3212 % \end{macrocode}
3213 %
3214 % The procedure \cmd\float@column@one\ takes care of a float column that has been built by \cmd\@tryfcolumn,
3215 % in the single-column page grid.
3216 % \begin{macrocode}
3217 \def\float@column@one{%
3218 \@makecol
3219 \@outputpage
3220 }%
3221 % \end{macrocode}
3222 %
3223 % The procedure \cmd\end@column@one\ is executed at the end of \cmd\clearpage\ processing,
3224 % if we were in a one-column page grid, once all permissive float pages have been shipped out.
3225 % At this point, one could perhaps
3226 % assume that nothing more need be done, but let us anyway test for committed floats and force a shipout.
3227 %
3228 % FIXME: this procedure does the same as \cmd\end@column@mlt
3229 % (except for the test of \cmd\@ifx@empty\cmd\@dbltoplist):
3230 % the two could almost be the same procedure.
3231 %
3232 % I have changed this procedure to avoid the testing it once did: it simply puts down interrupts,
3233 % upon which it relies to correctly do what \cmd\clearpage\ requires.
3234 % \begin{macrocode}
3235 \def\end@column@one{%
3236 \unvbox\@cclv\setbox\z@\lastbox
3237 \protect@penalty\do@newpage@pen
3238 }%
3239 % \end{macrocode}
3240 %
3241 % The procedure \cmd\output@column@one\ is dispatched from the output routine when
3242 % we have completed a page (that is, a column in a one-column page grid).
3243 % It ships out the page using the \cmd\@outputpage\ of standard \LaTeX,
3244 % which has been retained (it is needed also in \cmd\output@column@mlt,
3245 % and in any case should remain as the sole procedure in \LaTeX\ where \cmd\shipout\ is performed).
3246 % It will be followed up with an output routine message to prepare a new column.
3247 % \begin{macrocode}
3248 \def\output@column@one{%
3249 \@outputpage
3250 }%
3251 % \end{macrocode}
3252 %
3253 % The following procedure determines which side of the page a marginpar will appear.
3254 % It reproduces the behavior of standard \LaTeX.
3255 % \begin{macrocode}
3256 \def\@addmarginpar@one{%
3257 \@if@sw\if@mparswitch\fi{%
3258 \@ifodd\c@page{\false@sw}{\true@sw}%
3259 }{\false@sw}{%
3260 \@if@sw\if@reversemargin\fi{\false@sw}{\true@sw}%
3261 }{%
3262 \@if@sw\if@reversemargin\fi{\true@sw}{\false@sw}%
3263 }%
3264 }%
3265 % \end{macrocode}
3266 %
3267 % The following procedure yields a Boolean value; it determines whether a float in the deferred queue
3268 % is appropriate for placing. In the one-column grid, all floats are so.
3269 % \begin{macrocode}
3270 \def\@floatselect@sw@one#1{\true@sw}%
3271 % \end{macrocode}
3272 %
3273 % \begin{macrocode}
3274 \def\onecolumngrid@push{%
3275 \do@output@MVL{%
3276 \@ifnum{\pagegrid@col=\@ne}{%
3277 \global\let\restorecolumngrid\@empty
3278 }{%
3279 \xdef\restorecolumngrid{%
3280 \noexpand\start@column{\thepagegrid}{\the\pagegrid@col}%
3281 }%
3282 \start@column{one}{\@ne}%
3283 }%
3284 }%
3285 }%
3286 \def\onecolumngrid@pop{%
3287 \do@output@MVL{\restorecolumngrid}%
3288 }%
3289 % \end{macrocode}
3290 % \end{macro}
3291 % \end{macro}
3292 % \end{macro}
3293 % \end{macro}
3294 % \end{macro}
3295 % \end{macro}
3296 % \end{macro}
3297 %
3298 %
3299 % \subsubsection{Two-column page grid}
3300 %
3301 % \begin{macro}{\twocolumngrid}
3302 % \begin{macro}{\open@column@mlt}
3303 % \begin{macro}{\shut@column@mlt}
3304 % \begin{macro}{\end@column@mlt}
3305 % \begin{macro}{\output@column@mlt}
3306 % \begin{macro}{\@addmarginpar@mlt}
3307 % Here are all the procedures necessary for the standard page grid named ``mlt'':
3308 % the multi-column page grid. With an argument of "2", it is,
3309 % of course, \LaTeX's familiar \cmd\twocolumn\ layout.
3310 %
3311 % We start with the procedure to switch to the two-column page grid.
3312 % \begin{macrocode}
3313 \newcommand\twocolumngrid{\do@columngrid{mlt}{\tw@}}%
3314 % \end{macrocode}
3315 %
3316 % The corresponding command of \LaTeX\ is obsolete.
3317 % \begin{macrocode}
3318 \let\twocolumn\@undefined
3319 % \end{macrocode}
3320 %
3321 % Of course, \cmd\@topnewpage\ is also obsolete. Just do
3322 %\begin{quote}
3323 % \cmd\clearpage\cmd\onecolumngrid<vertical mode material>\cmd\twocolumngrid.
3324 %\end{quote}
3325 % \begin{macrocode}
3326 \let\@topnewpage\@undefined
3327 % \end{macrocode}
3328 %
3329 % If your document class descends from one of \LaTeX's standard classes.dtx-derived
3330 % classes, it will break. You must expunge from it all such commands.
3331 %
3332 % \begin{macrocode}
3333 \def\open@column@mlt#1{%
3334 \gdef\thepagegrid{mlt}%
3335 \global\pagegrid@col#1%
3336 \global\pagegrid@cur\@ne
3337 \set@column@hsize\pagegrid@col
3338 \set@colht
3339 %\set@colroom
3340 }%
3341 % \end{macrocode}
3342 %
3343 % The procedure \cmd\shut@column@mlt\ ends the current column, balances the columns, and
3344 % salts away all in \cmd\pagesofar. Because it is called in a message handler,
3345 % we are assured that marks are handled properly.
3346 % Attention: because this procedure balances columns, all footnotes are
3347 % held aside in \cmd\footbox\ for placement at the bottom of the page.
3348 %
3349 % Bug note: the last macro executed by this procedure is \cmd\set@colht, but had been erroneously \cmd\set@colroom.
3350 % I now believe that the latter should be changed pretty much everywhere to the former.
3351 % \begin{macrocode}
3352 \def\shut@column@mlt{%
3353 \@cclv@nontrivial@sw{%
3354 \@makecol
3355 \@ifnum{\pagegrid@cur<\pagegrid@col}{%
3356 \expandafter\global\expandafter\setbox\csname col@\the\pagegrid@cur\endcsname\box\@outputbox
3357 \global\advance\pagegrid@cur\@ne
3358 }{}%
3359 }{%
3360 {\setbox\z@\box\@cclv}%
3361 }%
3362 \@ifnum{\pagegrid@cur>\@ne}{%
3363 \csname balance@\the\pagegrid@col\endcsname
3364 \grid@column{}%
3365 \@combinepage
3366 \@combinedblfloats
3367 \global\setbox\pagesofar\box\@outputbox
3368 }{}%
3369 \set@colht
3370 }%
3371 % \end{macrocode}
3372 %
3373 % The procedure \cmd\float@column@mlt\ takes care of a float page that has been built by \cmd\@tryfcolumn,
3374 % in the multi-column page grid.
3375 % \begin{macrocode}
3376 \def\float@column@mlt{%
3377 \@combinepage
3378 \@combinedblfloats
3379 \@outputpage
3380 \global\pagegrid@cur\@ne
3381 \protect@penalty\do@startpage@pen
3382 }%
3383 % \end{macrocode}
3384 %
3385 % The procedure \cmd\end@column@mlt\ is executed at the end of \cmd\clearpage\ processing,
3386 % if we were in a multi-column page grid, once all permissive float pages have been shipped out.
3387 % If no floats are committed and if no columns are yet filled, we have nothing to do.
3388 % Otherwise, we kick out a column and try again.
3389 %
3390 % Note that in our code to kick out a column, we must deal properly with the case where the column
3391 % is trivial: it will have nothing but \cmd\topskip\ glue plus a protection box. We substitute an ordinary
3392 % \cmd\null\ for the protection box.
3393 %
3394 % \begin{macrocode}
3395 \def\end@column@mlt{%
3396 \@ifx@empty\@toplist{%
3397 \@ifx@empty\@botlist{%
3398 \@ifx@empty\@dbltoplist{%
3399 \@ifx@empty\@deferlist{%
3400 \@ifnum{\pagegrid@cur=\@ne}{%
3401 \false@sw
3402 }{%
3403 \true@sw
3404 }%
3405 }{%
3406 \true@sw
3407 }%
3408 }{%
3409 \true@sw
3410 }%
3411 }{%
3412 \true@sw
3413 }%
3414 }{%
3415 \true@sw
3416 }%
3417 % true = kick out a column and try again
3418 {%
3419 \@cclv@nontrivial@sw{%
3420 \unvbox\@cclv\setbox\z@\lastbox
3421 }{%
3422 \unvbox\@cclv\setbox\z@\lastbox\unskip\null
3423 }%
3424 \protect@penalty\do@newpage@pen
3425 \protect@penalty\do@endpage@pen
3426 }{%
3427 \unvbox\@cclv\setbox\z@\lastbox
3428 }%
3429 }%
3430 % \end{macrocode}
3431 % The procedure \cmd\output@column@mlt (cf. \cmd\output@column@one)
3432 % is dispatched from the output routine when
3433 % we have completed a column in a multi-column page grid).
3434 % (It replaces the \cmd\@outputdblcol\ of standard \LaTeX.)
3435 % If a complete set of columns is at hand, it ships out the page and
3436 % lays down an interrupt for \cmd\do@startpage@pen, which will commit the
3437 % full-page-width floats to the next page.
3438 % Like \cmd\output@column@mlt, this is followed by
3439 % an output routine message to prepare a new column.
3440 % \begin{macrocode}
3441 \def\output@column@mlt{%
3442 \@ifnum{\pagegrid@cur<\pagegrid@col}{%
3443 \expandafter\global\expandafter\setbox\csname col@\the\pagegrid@cur\endcsname\box\@outputbox
3444 \global\advance\pagegrid@cur\@ne
3445 }{%
3446 \set@adj@colht\dimen@
3447 % \advance\dimen@-\topskip
3448 \grid@column{}%{\dimen@}%
3449 \@combinepage
3450 \@combinedblfloats
3451 \@outputpage
3452 \global\pagegrid@cur\@ne
3453 \protect@penalty\do@startpage@pen
3454 }%
3455 }%
3456 % \end{macrocode}
3457 % The procedure \cmd\output@column@mlt\ obsoletes \LaTeX's \cmd\@outputdblcol
3458 % \begin{macrocode}
3459 \let\@outputdblcol\@undefined
3460 % \end{macrocode}
3461 %
3462 % The following procedure yields a Boolean value; it determines whether a float in the deferred queue
3463 % is appropriate for placement in the column. In the multi-column grid, only those narrower than \cmd\textwidth\ are so.
3464 % \begin{macrocode}
3465 \def\@floatselect@sw@mlt#1{\@if@notdblfloat{#1}}%
3466 % \end{macrocode}
3467 %
3468 % The following procedure determines which side of the page a marginpar will appear.
3469 % It reproduces the behavior of standard \LaTeX.
3470 % \begin{macrocode}
3471 \def\@addmarginpar@mlt{% emits a boolean
3472 \@ifnum{\pagegrid@cur=\@ne}%
3473 }%
3474 % \end{macrocode}
3475 % \end{macro}
3476 % \end{macro}
3477 % \end{macro}
3478 % \end{macro}
3479 % \end{macro}
3480 % \end{macro}
3481 %
3482 %
3483 % \subsubsection{Page grid utility procedures}
3484 %
3485 % \begin{macro}{\pagegrid@cur}
3486 % \begin{macro}{\pagegrid@col}
3487 % \begin{macro}{\col@}
3488 % \begin{macro}{\pagegrid@init}
3489 % We take over \LaTeX's \cmd\col@number\ and \cmd\@leftcolumn, which are obsolete.
3490 % We create two counters to hold the columns in the page grid and the current column within.
3491 % We also create the first of a set of box registers to hold the committted columns.
3492 % \begin{macrocode}
3493 \let\pagegrid@cur\col@number
3494 \let\col@number\@undefined
3495 \newcount\pagegrid@col
3496 \pagegrid@cur\@ne
3497 \expandafter\let\csname col@\the\pagegrid@cur\endcsname\@leftcolumn
3498 \let\@leftcolumn\@undefined
3499 % \end{macrocode}
3500 %
3501 % The default is for maximum two columns.
3502 % If your class will require more columns, assign that number to \cmd\pagegrid@col\
3503 % before \envb{document} time.
3504 % \begin{macrocode}
3505 \pagegrid@col\tw@
3506 % \end{macrocode}
3507 %
3508 % The procedure \cmd\pagegrid@init\ exercises \cmd\newbox\ sufficiently to create the
3509 % boxes for holding the columns in the page grid.
3510 % \begin{macrocode}
3511 \def\pagegrid@init{%
3512 \advance\pagegrid@cur\@ne
3513 \@ifnum{\pagegrid@cur<\pagegrid@col}{%
3514 \csname newbox\expandafter\endcsname\csname col@\the\pagegrid@cur\endcsname
3515 \pagegrid@init
3516 }{%
3517 }%
3518 }%
3519 \appdef\class@documenthook{%
3520 \pagegrid@init
3521 }%
3522 % \end{macrocode}
3523 % \end{macro}
3524 % \end{macro}
3525 % \end{macro}
3526 % \end{macro}
3527 %
3528 % \begin{macro}{\grid@column}
3529 % The procedure \cmd\grid@column\ knows how to lay up the columns in a multi-column page grid.
3530 % It uses utility procedures \cmd\append@column\ and \cmd\box@column.
3531 %
3532 % \begin{macrocode}
3533 \def\grid@column#1{%
3534 \global\setbox\@outputbox\vbox{%
3535 \hb@xt@\textwidth{%
3536 \vrule\@height\z@\@width\z@\@if@empty{#1}{}{\@depth#1}%
3537 \pagegrid@cur\@ne
3538 \append@column
3539 \box@column\@outputbox
3540 }%
3541 \vskip\z@skip % FIXME: page depth!
3542 }%
3543 }%
3544 % \end{macrocode}
3545 % \end{macro}
3546 %
3547 % \begin{macro}{\append@column}
3548 % \begin{macro}{\box@column}
3549 % \begin{macro}{\marry@baselines}
3550 % The procedure \cmd\append@column\ appends columns for \cmd\grid@column,
3551 % \cmd\box@column\ builds the columns for \cmd\append@column,
3552 % and \cmd\marry@baselines\ pastes vertical things back together.
3553 % \changes{v4.0rc1}{2001/06/18}
3554 % {Introoduce \cs{marry@height} }
3555 %
3556 % Note that \cmd\box@column\ makes an attempt to prevent excessive \cmd\topskip\
3557 % or \cmd\baselineskip\ glue
3558 % from being applied by \TeX\ when \cmd\@outputbox\ is contributed to the MVL.
3559 % If this is not done, it is possible to get into an infinite loop in the corner case,
3560 % wherein the page grid is changed to one column and the balanced-up columns are
3561 % already sufficient to fill the page.
3562 %
3563 % Note (AO 0920): I have changed the dimension involved with \cmd\box@column\ from
3564 % \cmd\vsize\ to \cmd\textheight, because the former is certainly not the correct value
3565 % to use: it will change if floats have been placed in the last column of the page.
3566 % I believe \cmd\textheight\ is the correct parameter to use here.
3567 %
3568 % A REVTeX4 beta user, Sergey Strelkov ([email protected]), wants the option
3569 % of ragged-bottom columns. Implementing this feature properly means reboxing the
3570 % columns to their natural height only if \cmd\raggedcolumn@sw\ is true.
3571 % Otherwise, they get reboxed to their common height (\cmd\@colht?).
3572 %
3573 % Note that the default has hereby changed from ragged to flush.
3574 % It's not clear that anyone but Sergey will notice.
3575 %
3576 % The macro \cmd\marry@skip\ addresses (in a limited way)
3577 % the fact that neither the value of \cmd\baselineskip\ nor that of \cmd\topskip\
3578 % can be relied upon for the purpose of marrying the baselines of two split columns.
3579 % (Because there might have been a local change to their values at the point where
3580 % the output routine got triggered.)
3581 %
3582 % For best results, your document class should call for grid changes only when in basal text
3583 % settings. The \cmd\marry@baselines\ procedure will use the values appropriate to that point
3584 % when attempting to put the columns back together.
3585 %
3586 % In any case, we are not attempting to solve the more general problem of how to marry baselines
3587 % where the leading can change arbitrarily within the galley or where glue could have been trimmed
3588 % at a page top.
3589 % \begin{macrocode}
3590 \def\append@column{%
3591 \@ifnum{\pagegrid@cur<\pagegrid@col}{%
3592 \expandafter\box@column\csname col@\the\pagegrid@cur\endcsname
3593 \hfil
3594 \vrule \@width\columnseprule
3595 \hfil
3596 \advance\pagegrid@cur\@ne
3597 \append@column
3598 }{%
3599 }%
3600 }%
3601 \def\box@column#1{%
3602 \raise\topskip
3603 \hb@xt@\columnwidth{%
3604 \dimen@\ht#1\@ifdim{\dimen@>\@colht}{\dimen@\@colht}{}%
3605 % \advance\dimen@-\topskip
3606 \count@\vbadness\vbadness\@M
3607 \dimen@ii\vfuzz\vfuzz\maxdimen
3608 \outputdebug@sw{\saythe\@colht\saythe\dimen@}{}%
3609 \vtop to\dimen@
3610 % \@ifdim{\ht#1>\textheight}{to\textheight}{}%
3611 {\hrule\@height\z@
3612 \unvbox#1%
3613 \raggedcolumn@skip
3614 }%
3615 \vfuzz\dimen@ii
3616 \vbadness\count@
3617 \hss
3618 }%
3619 }%
3620 \def\marry@baselines{%
3621 %{\tracingall\scrollmode\showlists}%
3622 %\skip@\baselineskip\advance\skip@-\topskip %FIXME: cannot assume \baselineskip nor \topskip
3623 \vskip\marry@skip\relax
3624 }%
3625 \gdef\marry@skip{\z@skip}%
3626 \def\set@marry@skip{%
3627 \begingroup
3628 \skip@\baselineskip\advance\skip@-\topskip
3629 \@ifdim{\skip@>\z@}{%
3630 \xdef\marry@skip{\the\skip@}%
3631 }{}%
3632 \endgroup
3633 }%
3634 \AtBeginDocument{%
3635 \@ifxundefined\raggedcolumn@sw{\@booleanfalse\raggedcolumn@sw}{}%
3636 }%
3637 \def\raggedcolumn@skip{%
3638 \vskip\z@\raggedcolumn@sw{\@plus.0001fil\@minus.0001fil}{}\relax
3639 }%
3640 % \end{macrocode}
3641 % \end{macro}
3642 % \end{macro}
3643 % \end{macro}
3644 %
3645 % \begin{macro}{\@combinepage}
3646 % The procedure \cmd\@combinepage\ prepends the stored page to \cmd\@outputbox.
3647 % \begin{macrocode}
3648 \def\@combinepage{%
3649 \@ifvoid\pagesofar{}{%
3650 \setbox\@outputbox\vbox{%
3651 \unvbox\pagesofar
3652 \marry@baselines
3653 \unvbox\@outputbox
3654 }%
3655 }%
3656 \@ifvoid\footbox{}{%
3657 \setbox\@outputbox\vbox{%
3658 \unvbox\@outputbox
3659 \marry@baselines
3660 \unvbox\footbox
3661 }%
3662 }%
3663 }%
3664 % \end{macrocode}
3665 % \end{macro}
3666 %
3667 % \begin{macro}{\@combinedblfloats}
3668 % We modify \LaTeX's \cmd\@combinedblfloats\ to be more appropriate for incremental page building:
3669 % we \cmd\unvbox\ the \cmd\@outputbox.
3670 % \begin{macrocode}
3671 \def\@combinedblfloats{%
3672 \@ifx@empty\@dbltoplist{}{%
3673 \setbox\@tempboxa\vbox{}%
3674 \let\@elt\@comdblflelt\@dbltoplist
3675 \let\@elt\relax\xdef\@freelist{\@freelist\@dbltoplist}%
3676 \global\let\@dbltoplist\@empty
3677 \setbox\@outputbox\vbox{%
3678 %\boxmaxdepth\maxdepth %% probably not needed, CAR
3679 \unvbox\@tempboxa\unskip
3680 \@ifnum{\@dbltopnum>\m@ne}{\dblfigrule}{}%FIXME: how is \@dbltopnum maintained?
3681 \vskip\dbltextfloatsep
3682 \unvbox\@outputbox
3683 }%
3684 }%
3685 }%
3686 % \end{macrocode}
3687 % \end{macro}
3688 %
3689 % \begin{macro}{\set@column@hsize}%
3690 % The procedure \cmd\set@column@hsize\ takes care of setting up the horizontal dimensions
3691 % for the current page grid. The present routine will certainly not be adequate for more
3692 % complex page layouts (e.g., with a side column), but works for the common ones.
3693 % \changes{v4.0rc1}{2001/06/18}
3694 % {Introoduce \cs{set@marry@height} }
3695 % \begin{macrocode}
3696 \def\set@column@hsize#1{%
3697 \pagegrid@col#1%
3698 \global\columnwidth\textwidth
3699 \global\advance\columnwidth\columnsep
3700 \global\divide\columnwidth\pagegrid@col
3701 \global\advance\columnwidth-\columnsep
3702 \global\hsize\columnwidth
3703 \global\linewidth\columnwidth
3704 \skip@\baselineskip\advance\skip@-\topskip
3705 \@ifnum{\pagegrid@col>\@ne}{\set@marry@skip}{}%
3706 }%
3707 % \end{macrocode}
3708 % \end{macro}
3709 %
3710 % \begin{macro}{\set@colht}%
3711 % \begin{macro}{\set@colroom}%
3712 % \begin{macro}{\set@vsize}%
3713 % \begin{macro}{\set@adj@colht}%
3714 % The story of \cmd\textheight, \cmd\@colht, \cmd\@colroom, and \cmd\vsize.
3715 %
3716 % \cmd\textheight---height of the text column. Not a running parameter, however, each time a page is
3717 % shipped out, the \cmd\textheight\ could in principle be altered. This must be done before
3718 %
3719 % \cmd\@colht---\cmd\textheight\ minus the height of any full-page-width floats. The latter are committed
3720 % only just after shipping out, and only if we are in a multicolumn page grid.
3721 % Therefore, \cmd\@colht\ should be set after a \cmd\shipout\ (by \cmd\@outputpage) and
3722 % will be adjusted when full-page-width floats are committed to the fresh page by \cmd\do@startpage.
3723 %
3724 % \cmd\@colroom---\cmd\@colht\ (adjusted by \cmd\pagesofar) minus the height of any column-width floats.
3725 % The latter are committed anywhere on the page, at which point \cmd\@colroom\ must be adjusted.
3726 % Therefore, \cmd\@colroom\ should be set (by \cmd\set@colroom) whenever a column is prepared (by ).
3727 %FIXME: committed (by \cmd\output@column@) and
3728 % will be adjusted (by \cmd\@add@float\ or \cmd\do@startcolumn) whenever a float is committted to the column.
3729 %
3730 % \cmd\vsize---\cmd\@colroom.
3731 % Therefore, \cmd\vsize\ should be set (by \cmd\set@vsize) whenever
3732 % the \cmd\@colroom\ is set (by \cmd\set@colroom) or adjusted (by \cmd\@add@float\ or \cmd\do@startcolumn)
3733 %FIXME: or when the \cmd\pagesofar\ box is changed (after invoking \cmd\open@column@).
3734 %
3735 % Question: what if there are committed floats? Footnotes?
3736 % Answer: full-page-width floats are only committed at top, and they are already reckoned with in \cmd\@colht.
3737 % Column-width committed floats are incorporated by \cmd\@makecol; footnotes need help.
3738 %
3739 % Note: FIXME: adjusting for \cmd\pagesofar\ is done at not quite the right time. I need to reexamine \cmd\set@colht,
3740 % because \cmd\@dbltoplist\ and \cmd\pagesofar\ really should be on the same footing.
3741 % Perhaps \cmd\@colht\ and \cmd\@colroom\ should both deal with their respective ``lists'' in the same way?
3742 %
3743 % These concerns will be particularly germane if we ever extend this package to deal with full-page-width floats
3744 % placed at the bottom of the page, or committed on the same page as called out.
3745 %
3746 % It occurs to me that we should ditch \cmd\set@colroom\ and only ever execute \cmd\set@colht, which sets \cmd\@colroom\ as a side effect.
3747 % If so, we can make \cmd\@colht\ take \cmd\pagesofar\ into account, as it should. Then \cmd\@colht\ will return to its
3748 % original significance as the value that \cmd\@colroom\ is set to after a column is committed.
3749 %
3750 % On the other hand, why not simply forget all this caching and (re-)calculate \cmd\vsize\ as late as possible?
3751 % Paticularly, \cmd\@colht\ is an artifact of the old way of doing things, where once it was set, it would never change.
3752 %
3753 % \begin{macrocode}
3754 \def\set@colht{%
3755 \set@adj@textheight\@colht
3756 \global\let\enlarge@colroom\@empty
3757 \set@colroom
3758 }%
3759 \def\set@adj@textheight#1{%
3760 #1\textheight
3761 \def\@elt{\adj@page#1}%
3762 \@booleantrue\firsttime@sw\@dbltoplist
3763 \let\@elt\relax
3764 %\@ifvoid\pagesofar{}{%
3765 % \advance#1-\ht\pagesofar\advance#1-\dp\pagesofar
3766 %}%
3767 \global#1#1\relax
3768 \outputdebug@sw{\saythe#1}{}%
3769 }%
3770 \def\set@colroom{%
3771 \set@adj@colht\@colroom
3772 \@if@empty\enlarge@colroom{}{%
3773 \global\advance\@colroom\enlarge@colroom\relax
3774 }%
3775 \outputdebug@sw{\saythe\@colroom}{}%
3776 \@ifdim{\@colroom>\topskip}{}{%
3777 \ltxgrid@info{Not enough room: \string\@colroom=\the\@colroom; increasing to \the\topskip}%
3778 \@colroom\topskip
3779 }%
3780 \global\@colroom\@colroom
3781 \set@vsize
3782 }%
3783 %
3784 \def\set@vsize{%
3785 \global\vsize\@colroom
3786 \outputdebug@sw{\saythe\vsize}{}%
3787 }%
3788 %
3789 \def\set@adj@colht#1{%
3790 #1\@colht
3791 \@ifvoid\pagesofar{}{%
3792 \advance#1-\ht\pagesofar\advance#1-\dp\pagesofar
3793 }%
3794 \@ifvoid\footbox{}{%
3795 \advance#1-\ht\footbox\advance#1-\dp\footbox
3796 }%
3797 \def\@elt{\adj@column#1}%
3798 \@booleantrue\firsttime@sw\@toplist
3799 \@booleantrue\firsttime@sw\@botlist
3800 \let\@elt\relax
3801 \outputdebug@sw{\saythe#1}{}%
3802 }%
3803 \def\adj@column#1#2{%
3804 \advance#1-\ht#2%
3805 \advance#1-\firsttime@sw{\textfloatsep\@booleanfalse\firsttime@sw}{\floatsep}%
3806 }%
3807 \def\adj@page#1#2{%
3808 \advance#1-\ht#2%
3809 \advance#1-\firsttime@sw{\dbltextfloatsep\@booleanfalse\firsttime@sw}{\dblfloatsep}%
3810 }%
3811 % \end{macrocode}
3812 % \end{macro}
3813 % \end{macro}
3814 % \end{macro}
3815 % \end{macro}
3816 %
3817 % \begin{macro}{\@outputpage}%
3818 % At the tail of \cmd\@outputpage, we set \cmd\@colht\ and the float placement parameters
3819 % (this is the one point where it is appropriate to set \cmd\@colht).
3820 % At \cmd\do@startpage\ time, we adjust \cmd\@colht's value to reflect committed
3821 % full-page-width floats.
3822 %
3823 % Note: with a correctly written output routine, a call to \cmd\@outputpage\ will inevitably be
3824 % followed by a call to \cmd\do@startpage, so these procedure calls would be unneeded.
3825 % \begin{macrocode}
3826 \appdef\@outputpage{%
3827 \set@colht % FIXME: needed?
3828 \@floatplacement % FIXME: needed?
3829 \@dblfloatplacement % FIXME: needed?
3830 }%
3831 % \end{macrocode}
3832 % \end{macro}
3833 %
3834 % \begin{macro}{balance@2}
3835 % We define procedures for balancing columns in a multicolumn layout.
3836 % For now, we define only one: a procedure for the two-column grid.
3837 % All others will simply \cmd\relax\ out.
3838 % \begin{macrocode}
3839 \@namedef{balance@2}{%
3840 \expandafter\balance@two\csname col@1\endcsname\@outputbox
3841 % Avoid a bug by preventing a restore when leaving this group
3842 \global\setbox\csname col@1\endcsname\box\csname col@1\endcsname
3843 \@ifvoid\footbox{}{%
3844 \global\setbox\footbox\vbox{%
3845 \setbox\z@\box\@tempboxa
3846 \let\recover@footins\relax
3847 \balance@two\footbox\@tempboxa
3848 \hb@xt@\textwidth{\box\footbox\hfil\box\@tempboxa}%
3849 }%
3850 }%
3851 }%
3852 % \end{macrocode}
3853 % \end{macro}
3854 %
3855 % \begin{macro}{\balance@two}
3856 % The procedure \cmd\balance@two\ takes two columns and balances them; in the process it removes
3857 % any footnotes that may be present to a place of safety, for later placement at the foot of the
3858 % shipped-out page.
3859 % The box register \cmd\box\cmd\@ne\ is the aggregate of all columns.
3860 % The box register \cmd\box\cmd \z@\ is the last column.
3861 % The box register \cmd\box\cmd\tw@\ is the first column.
3862 % The \cmd\dimen\ register \cmd\dimen@\ is the trial value to balance to,
3863 % initially half the height of \cmd\box\cmd\@ne.
3864 % The \cmd\dimen\ register \cmd\dimen@i\ is the increment for the next trial;
3865 % its initial value is equal to the initial value of \cmd\dimen@.
3866 % The \cmd\dimen\ register \cmd\dimen@ii\ is the difference of the heights of the two columns.
3867 %
3868 % The procedure uses a binary search for that value of \cmd\dimen@\ which is stable to within .5\cmd\p@\ and which
3869 % makes the last column be shorter than the others.
3870 %
3871 % This procedure can be extended to multiple columns simply by changing it to execute \cmd\vsplit\ multiple
3872 % times (one less than the total number of columns in the page layout) and to calculating \cmd\dimen@ii\
3873 % to be the difference of the heights of last column and the \cmd\dimen@.
3874 % Upon termination of the search, one would excute the \cmd\vsplit s once again, this time
3875 % using the actual \cmd\col@\ box registers to store the
3876 % balanced columns, thereby clobbering their former contents.
3877 %
3878 % Bug Note:
3879 % as originally written, this macro had a bug, which is well worth avoiding under similar circumstances anywhere.
3880 % So, learn from the mistakes of others, as they say.
3881 % In trying to remove the depth of the boxes created via \cmd\vsplit\ within the \cmd\loopwhile\ control,
3882 % I originally coded
3883 % \cmd\unvbox
3884 % \cmd\z@\
3885 % \cmd\setbox
3886 % \cmd\z@
3887 % \cmd\lastbox\
3888 % \cmd\dimen@
3889 % \cmd\dp
3890 % \cmd\z@\
3891 % \cmd\box
3892 % \cmd\z@\
3893 % \cmd\vskip-%
3894 % \cmd\dimen@.
3895 % The error here is that the shift of the last box in the vertical list will be lost in the process.
3896 % Simply put, \cmd\setbox\cmd\z@\cmd\lastbox\ fails to retain the shift of the box node in the vertical list,
3897 % and when it is put down again via \cmd\box\cmd\z@, it will no longer have the correct shift.
3898 %
3899 % This bug affected things placed in the MVL with \cmd\moveleft, \cmd\moveright, \cmd\parshape, and
3900 % \cmd\hangindent, as well as things shifted by \TeX's primitive mechanisms.
3901 %
3902 % A superior strategy for removing the depth of the last line of the list is more expensive, but safer:
3903 % make a separate copy of the list, measure the depth of the last box as above, but then discard
3904 % the list, retaining only the value of the dimension.
3905 %
3906 % Note that this procedure will not work if the material within is excessively chunky.
3907 % A particular failure mode exists where none of the material is allocated to the last (right) column.
3908 % We detect this case and revert to unbalanced columns.
3909 %
3910 % Another failure mode is where a large chunk occurs at the beginning of the composite box.
3911 % In this case, the left column may fill up even when \cmd\dimen@\ is very small.
3912 % If this configuration leaves the left column longer than the right, then we are done,
3913 % but \cmd\dimen@\ by no means represents the height of either finished box.
3914 %
3915 % Therefore the last step in the process is to rebox the two columns to a common height determined
3916 % independently of the balancing process.
3917 %
3918 % The dimension involved is checked against the current \cmd\@colroom\ to guard against the case where
3919 % excessive material happens to fall in either column.
3920 % \begin{macrocode}
3921 \def\balance@two#1#2{%
3922 \outputdebug@sw{{\tracingall\scrollmode\showbox#1\showbox#2}}{}%
3923 \setbox\@ne\vbox{%
3924 \@ifvoid#1{}{%
3925 \unvcopy#1\recover@footins
3926 \@ifvoid#2{}{\marry@baselines}%
3927 }%
3928 \@ifvoid#2{}{%
3929 \unvcopy#2\recover@footins
3930 }%
3931 }%
3932 \dimen@\ht\@ne\divide\dimen@\tw@
3933 \dimen@i\dimen@
3934 \vbadness\@M
3935 \vfuzz\maxdimen
3936 \loopwhile{%
3937 \dimen@i=.5\dimen@i
3938 \outputdebug@sw{\saythe\dimen@\saythe\dimen@i\saythe\dimen@ii}{}%
3939 \setbox\z@\copy\@ne\setbox\tw@\vsplit\z@ to\dimen@
3940 \setbox\z@ \vbox{%
3941 \unvcopy\z@
3942 \setbox\z@\vbox{\unvbox\z@ \setbox\z@\lastbox\aftergroup\vskip\aftergroup-\expandafter}\the\dp\z@\relax
3943 }%
3944 \setbox\tw@\vbox{%
3945 \unvcopy\tw@
3946 \setbox\z@\vbox{\unvbox\tw@\setbox\z@\lastbox\aftergroup\vskip\aftergroup-\expandafter}\the\dp\z@\relax
3947 }%
3948 \dimen@ii\ht\tw@\advance\dimen@ii-\ht\z@
3949 \@ifdim{\dimen@i>.5\p@}{%
3950 \advance\dimen@\@ifdim{\dimen@ii<\z@}{}{-}\dimen@i
3951 \true@sw
3952 }{%
3953 \@ifdim{\dimen@ii<\z@}{%
3954 \advance\dimen@\tw@\dimen@i
3955 \true@sw
3956 }{%
3957 \false@sw
3958 }%
3959 }%
3960 }%
3961 \outputdebug@sw{\saythe\dimen@\saythe\dimen@i\saythe\dimen@ii}{}%
3962 \@ifdim{\ht\z@=\z@}{%
3963 \@ifdim{\ht\tw@=\z@}{%
3964 \true@sw
3965 }{%
3966 \false@sw
3967 }%
3968 }{%
3969 \true@sw
3970 }%
3971 {%
3972 }{%
3973 \ltxgrid@info{Unsatifactorily balanced columns: giving up}%
3974 \setbox\tw@\box#1%
3975 \setbox\z@ \box#2%
3976 }%
3977 \setbox\tw@\vbox{\unvbox\tw@\vskip\z@skip}%
3978 \setbox\z@ \vbox{\unvbox\z@ \vskip\z@skip}%
3979 \set@colroom
3980 \dimen@\ht\z@\@ifdim{\dimen@<\ht\tw@}{\dimen@\ht\tw@}{}%
3981 \@ifdim{\dimen@>\@colroom}{\dimen@\@colroom}{}%
3982 \outputdebug@sw{\saythe{\ht\z@}\saythe{\ht\tw@}\saythe\@colroom\saythe\dimen@}{}%
3983 \setbox#1\vbox to\dimen@{\unvbox\tw@\unskip\raggedcolumn@skip}%
3984 \setbox#2\vbox to\dimen@{\unvbox\z@ \unskip\raggedcolumn@skip}%
3985 \outputdebug@sw{{\tracingall\scrollmode\showbox#1\showbox#2}}{}%
3986 }%
3987 % \end{macrocode}
3988 % \end{macro}
3989 %
3990 % \begin{macro}{\recover@footins}
3991 % The procedure \cmd\recover@footins\ is the utility procedure for recovering the footnotes
3992 % from the bottom of a column. It is used when the page grid is changed, so that footnotes can be
3993 % set at the bottom of the shipped out page.
3994 % \begin{macrocode}
3995 \def\recover@footins{%
3996 \skip\z@ \lastskip\unskip
3997 \skip\@ne\lastskip\unskip
3998 \setbox\z@\lastbox
3999 \@ifvbox\z@{%
4000 \setbox\z@\vbox{%
4001 \unvbox\z@
4002 \setbox\z@\lastbox
4003 % \outputdebug@sw{{\tracingall\showbox\lastbox}}{}%
4004 \@ifvoid\z@{}{%
4005 \global\setbox\footbox\vbox{%
4006 \unvbox\footbox
4007 \@ifvbox\z@{%
4008 \unvbox\z@
4009 }{%
4010 \box\z@
4011 }%
4012 }%
4013 }%
4014 }%
4015 }{}%
4016 \outputdebug@sw{{\tracingall\scrollmode\showbox\footbox}}{}%
4017 }%
4018 % \end{macrocode}
4019 % \end{macro}
4020 %
4021 % \begin{macro}{\@begindocumenthook}
4022 % Initialization:
4023 % we initialize to the page grid named ``one''.
4024 % If the class decides to initially set type in a different grid, it
4025 % should execute these same commands, but changing the first to the appropriate procedure.
4026 %
4027 % Note that the point where this sequence is executed would be an excellent place to arrange for
4028 % floats to be committed to the first page of a document.
4029 % That is, we execute \cmd\do@startpage, which triggers \cmd\do@startcolumn.
4030 %
4031 % FIXME: it should be the job of the page grid to determine the procedure to execute at
4032 % the start of the job. Make this a hook.
4033 % \begin{macrocode}
4034 \rvtx@ifformat@geq{2020-10-01}%
4035 {%
4036 \AddToHook{begindocument}{%
4037 \open@column@one\@ne
4038 \set@colht
4039 \@floatplacement
4040 \@dblfloatplacement
4041 }%
4042 }{%
4043 \prepdef\@begindocumenthook{%
4044 \open@column@one\@ne
4045 \set@colht
4046 \@floatplacement
4047 \@dblfloatplacement
4048 }%
4049 }
4050 % \end{macrocode}
4051 % \end{macro}
4052 %
4053 % Comment: our technique of balancing columns is severely limited, because it cannot properly work
4054 % with \env{longtable}, which places material at the bottom and top of the column break.
4055 %
4056 % The proper way to handle a grid change in the middle of the page is to accumulate all the material for
4057 % an entire article (or chapter) and then assemble finished pages therefrom. This approach is fundamentally
4058 % superior for complex layouts: it corresponds to real-world workflows.
4059 % Such a scheme is an excellent subject for another \LaTeX\ package.
4060 %
4061 %
4062 % \subsection{Patches for the longtable package}%
4063 %
4064 % \LaTeX's ``required'' package \classname{longtable} (written by David P. Carlilsle),
4065 % which is part of /latex/required/tools, is incmpatible with both
4066 % \LaTeX's ``required'' package \classname{multicol} and with
4067 % \LaTeX's native \cmd\twocolumn\ capability. There is no essential reason
4068 % for this incompatability, aside from implementation details, and the
4069 % \classname{ltxgrid} package gives us the ability to lift them.
4070 %
4071 % Only four of \classname{longtable}'s procedures require rewriting:
4072 % \cmd\longtable,
4073 % \cmd\endlongtable,
4074 % \cmd\LT@start, and
4075 % \cmd\LT@end@hd@ft.
4076 % The procedure \cmd\switch@longtable\ checks against their expected meanings
4077 % and, if all is as expected, applies the patches.
4078 % In the process, we simplify things considerably and also make them more
4079 % secure.
4080 %
4081 % Why does \classname{longtable} need to access the output routine, anyway?
4082 % What it comes down to, is what happens when a pagebreak falls within a
4083 % long table. If this happens, we would like to append a row at the bottom of
4084 % the broken table and add a row at the top of the next page.
4085 %
4086 % These things can be accomodated easily by the \classname{ltxgrid} output
4087 % routine hooks.
4088 %
4089 %
4090 % \begin{macro}{\longtable}
4091 % \begin{macrocode}
4092 \def\longtable@longtable{%
4093 \par
4094 \ifx\multicols\@undefined\else\ifnum\col@number>\@ne\@twocolumntrue\fi\fi
4095 \if@twocolumn\LT@err{longtable not in 1-column mode}\@ehc\fi
4096 \begingroup
4097 \@ifnextchar[\LT@array{\LT@array[x]}%
4098 }%
4099 \def\longtable@new{%
4100 \par
4101 \@ifnextchar[\LT@array{\LT@array[x]}%
4102 }%
4103 % \end{macrocode}
4104 % \end{macro}
4105 %
4106 % \begin{macro}{\endlongtable}
4107 % \begin{macrocode}
4108 \def\endlongtable@longtable{%
4109 \crcr
4110 \noalign{%
4111 \let\LT@entry\LT@entry@chop
4112 \xdef\LT@save@row{\LT@save@row}}%
4113 \LT@echunk
4114 \LT@start
4115 \unvbox\z@
4116 \LT@get@widths
4117 \if@filesw
4118 {\let\LT@entry\LT@entry@write\immediate\write\@auxout{%
4119 \gdef\expandafter\noexpand
4120 \csname LT@\romannumeral\c@LT@tables\endcsname
4121 {\LT@save@row}}}%
4122 \fi
4123 \ifx\LT@save@row\LT@@save@row
4124 \else
4125 \LT@warn{Column \@width s have changed\MessageBreak
4126 in table \thetable}%
4127 \LT@final@warn
4128 \fi
4129 \endgraf\penalty -\LT@end@pen
4130 \endgroup
4131 \global\@mparbottom\z@
4132 \pagegoal\vsize
4133 \endgraf\penalty\z@\addvspace\LTpost
4134 \ifvoid\footins\else\insert\footins{}\fi
4135 }%
4136 \def\endlongtable@new{%
4137 \crcr
4138 \noalign{%
4139 \let\LT@entry\LT@entry@chop
4140 \xdef\LT@save@row{\LT@save@row}%
4141 }%
4142 \LT@echunk
4143 \LT@start
4144 \unvbox\z@
4145 \LT@get@widths
4146 \@if@sw\if@filesw\fi{%
4147 {%
4148 \let\LT@entry\LT@entry@write
4149 \immediate\write\@auxout{%
4150 \gdef\expandafter\noexpand\csname LT@\romannumeral\c@LT@tables\endcsname
4151 {\LT@save@row}%
4152 }%
4153 }%
4154 }{}%
4155 \@ifx\LT@save@row\LT@@save@row{}{%
4156 \LT@warn{%
4157 Column \@width s have changed\MessageBreak in table \thetable
4158 }\LT@final@warn
4159 }%
4160 \endgraf
4161 \nobreak
4162 \box\@ifvoid\LT@lastfoot{\LT@foot}{\LT@lastfoot}%
4163 \global\@mparbottom\z@
4164 \endgraf
4165 \LT@post
4166 }%
4167 % \end{macrocode}
4168 % \end{macro}
4169 %
4170 % \begin{macro}{\LT@start}
4171 % \begin{macrocode}
4172 \def\LT@start@longtable{%
4173 \let\LT@start\endgraf
4174 \endgraf
4175 \penalty\z@
4176 \vskip\LTpre
4177 \dimen@\pagetotal
4178 \advance\dimen@ \ht\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
4179 \advance\dimen@ \dp\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
4180 \advance\dimen@ \ht\LT@foot
4181 \dimen@ii\vfuzz\vfuzz\maxdimen
4182 \setbox\tw@\copy\z@
4183 \setbox\tw@\vsplit\tw@ to \ht\@arstrutbox
4184 \setbox\tw@\vbox{\unvbox\tw@}%
4185 \vfuzz\dimen@ii
4186 \advance\dimen@ \ht
4187 \ifdim\ht\@arstrutbox>\ht\tw@\@arstrutbox\else\tw@\fi
4188 \advance\dimen@\dp
4189 \ifdim\dp\@arstrutbox>\dp\tw@\@arstrutbox\else\tw@\fi
4190 \advance\dimen@ -\pagegoal
4191 \ifdim \dimen@>\z@\vfil\break\fi
4192 \global\@colroom\@colht
4193 \ifvoid\LT@foot\else
4194 \advance\vsize-\ht\LT@foot
4195 \global\advance\@colroom-\ht\LT@foot
4196 \dimen@\pagegoal\advance\dimen@-\ht\LT@foot\pagegoal\dimen@
4197 \maxdepth\z@
4198 \fi
4199 \ifvoid\LT@firsthead\copy\LT@head\else\box\LT@firsthead\fi
4200 \output{\LT@output}%
4201 }%
4202 \def\LT@start@new{%
4203 \let\LT@start\endgraf
4204 \endgraf
4205 \markthr@@{}%
4206 \LT@pre
4207 \@ifvoid\LT@firsthead{\LT@top}{\box\LT@firsthead\nobreak}%
4208 \mark@envir{longtable}%
4209 }%
4210 % \end{macrocode}
4211 % \end{macro}
4212 %
4213 % \begin{macro}{\LT@end}
4214 % \begin{macrocode}
4215 \def\LT@end@hd@ft@longtable#1{%
4216 \LT@echunk
4217 \ifx\LT@start\endgraf
4218 \LT@err{Longtable head or foot not at start of table}{Increase LTchunksize}%
4219 \fi
4220 \setbox#1\box\z@
4221 \LT@get@widths\LT@bchunk
4222 }%
4223 \def\LT@end@hd@ft@new#1{%
4224 \LT@echunk
4225 \@ifx{\LT@start\endgraf}{%
4226 \LT@err{Longtable head or foot not at start of table}{Increase LTchunksize}%
4227 }%
4228 \global\setbox#1\box\z@
4229 \LT@get@widths
4230 \LT@bchunk
4231 }%
4232 % \end{macrocode}
4233 % \end{macro}
4234 %
4235 % \begin{macro}{\LT@array}
4236 % \begin{macrocode}
4237 \def\LT@array@longtable[#1]#2{%
4238 \refstepcounter{table}\stepcounter{LT@tables}%
4239 \if l#1%
4240 \LTleft\z@ \LTright\fill
4241 \else\if r#1%
4242 \LTleft\fill \LTright\z@
4243 \else\if c#1%
4244 \LTleft\fill \LTright\fill
4245 \fi\fi\fi
4246 \let\LT@mcol\multicolumn
4247 \let\LT@@tabarray\@tabarray
4248 \let\LT@@hl\hline
4249 \def\@tabarray{%
4250 \let\hline\LT@@hl
4251 \LT@@tabarray}%
4252 \let\\\LT@tabularcr\let\tabularnewline\\%
4253 \def\newpage{\noalign{\break}}%
4254 \def\pagebreak{\noalign{\ifnum`}=0\fi\@testopt{\LT@no@pgbk-}4}%
4255 \def\nopagebreak{\noalign{\ifnum`}=0\fi\@testopt\LT@no@pgbk4}%
4256 \let\hline\LT@hline \let\kill\LT@kill\let\caption\LT@caption
4257 \@tempdima\ht\strutbox
4258 \let\@endpbox\LT@endpbox
4259 \ifx\extrarowheight\@undefined
4260 \let\@acol\@tabacol
4261 \let\@classz\@tabclassz \let\@classiv\@tabclassiv
4262 \def\@startpbox{\vtop\LT@startpbox}%
4263 \let\@@startpbox\@startpbox
4264 \let\@@endpbox\@endpbox
4265 \let\LT@LL@FM@cr\@tabularcr
4266 \else
4267 \advance\@tempdima\extrarowheight
4268 \col@sep\tabcolsep
4269 \let\@startpbox\LT@startpbox\let\LT@LL@FM@cr\@arraycr
4270 \fi
4271 \setbox\@arstrutbox\hbox{\vrule
4272 \@height \arraystretch \@tempdima
4273 \@depth \arraystretch \dp \strutbox
4274 \@width \z@}%
4275 \let\@sharp##\let\protect\relax
4276 \begingroup
4277 \@mkpream{#2}%
4278 \xdef\LT@bchunk{%
4279 \global\advance\c@LT@chunks\@ne
4280 \global\LT@rows\z@\setbox\z@\vbox\bgroup
4281 \LT@setprevdepth
4282 \tabskip\LTleft\halign to\hsize\bgroup
4283 \tabskip\z@ \@arstrut \@preamble \tabskip\LTright \cr}%
4284 \endgroup
4285 \expandafter\LT@nofcols\LT@bchunk&\LT@nofcols
4286 \LT@make@row
4287 \m@th\let\par\@empty
4288 \everycr{}\lineskip\z@\baselineskip\z@
4289 \LT@bchunk
4290 }%
4291 \def\LT@LR@l{\LTleft\z@ \LTright\fill}%
4292 \def\LT@LR@r{\LTleft\fill \LTright\z@ }%
4293 \def\LT@LR@c{\LTleft\fill \LTright\fill}%
4294 \def\LT@array@new[#1]#2{%
4295 \refstepcounter{table}\stepcounter{LT@tables}%
4296 \table@hook
4297 \LTleft\fill \LTright\fill
4298 \csname LT@LR@#1\endcsname
4299 \let\LT@mcol\multicolumn
4300 \let\LT@@hl\hline
4301 \prepdef\@tabarray{\let\hline\LT@@hl}%
4302 \let\\\LT@tabularcr
4303 \let\tabularnewline\\%
4304 \def\newpage{\noalign{\break}}%
4305 \def\pagebreak{\noalign{\ifnum`}=0\fi\@testopt{\LT@no@pgbk-}4}%
4306 \def\nopagebreak{\noalign{\ifnum`}=0\fi\@testopt\LT@no@pgbk4}%
4307 \let\hline\LT@hline
4308 \let\kill\LT@kill
4309 \let\caption\LT@caption
4310 \@tempdima\ht\strutbox
4311 \let\@endpbox\LT@endpbox
4312 \@ifxundefined\extrarowheight{%
4313 \let\@acol\@tabacol
4314 \let\@classz\@tabclassz
4315 \let\@classiv\@tabclassiv
4316 \def\@startpbox{\vtop\LT@startpbox}%
4317 \let\@@startpbox\@startpbox
4318 \let\@@endpbox\@endpbox
4319 \let\LT@LL@FM@cr\@tabularcr
4320 }{%
4321 \advance\@tempdima\extrarowheight
4322 \col@sep\tabcolsep
4323 \let\@startpbox\LT@startpbox
4324 \let\LT@LL@FM@cr\@arraycr
4325 }%
4326 %
4327 \let\@acoll\@tabacoll
4328 \let\@acolr\@tabacolr
4329 \let\@acol\@tabacol
4330 %
4331 \setbox\@arstrutbox\hbox{%
4332 \vrule
4333 \@height \arraystretch \@tempdima
4334 \@depth \arraystretch \dp \strutbox
4335 \@width \z@
4336 }%
4337 \let\@sharp##%
4338 \let\protect\relax
4339 \begingroup
4340 \@mkpream{#2}%
4341 \@mkpream@relax
4342 \edef\@preamble{\@preamble}%
4343 \prepdef\@preamble{%
4344 \global\advance\c@LT@chunks\@ne
4345 \global\LT@rows\z@
4346 \setbox\z@\vbox\bgroup
4347 \LT@setprevdepth
4348 \tabskip\LTleft
4349 \halign to\hsize\bgroup
4350 \tabskip\z@
4351 \@arstrut
4352 }%
4353 \appdef\@preamble{%
4354 \tabskip\LTright
4355 \cr
4356 }%
4357 \global\let\LT@bchunk\@preamble
4358 \endgroup
4359 \expandafter\LT@nofcols\LT@bchunk&\LT@nofcols
4360 \LT@make@row
4361 \m@th
4362 \let\par\@empty
4363 \everycr{}%
4364 \lineskip\z@
4365 \baselineskip\z@
4366 \LT@bchunk
4367 }%
4368 \appdef\table@hook{}%
4369 % \end{macrocode}
4370 % \end{macro}
4371 %
4372 % \begin{macro}{\switch@longtable}
4373 %
4374 % Here is the switch from standard \classname{longtable} to the new, \classname{ltxgrid}-compatible values.
4375 %
4376 % At this point, we extend \env{longtable} with a \env{longtable*} form, which signifies that we want to
4377 % use the full page width for setting the table.
4378 % You can think this way: \env{longtable*} is to \env{longtable} as \env{table*} is to \env{table}.
4379 %
4380 %FIXME: the following is no longer true:
4381 %% Note that it is not enough to define the environment itself; we also have to create the corresponding
4382 %% \cmd\output\ routine procedures, which provide for continued footers and headers
4383 %% (the very feature of \env{longtable} requiring support in the output routine).
4384 %
4385 %% This same consideration would arise in defining any syntactic extension to \env{longtable}, because
4386 %% the environment name itself is exposed in the output routine.
4387 %
4388 % \begin{macrocode}
4389 \def\switch@longtable{%
4390 \@ifpackageloaded{longtable}{%
4391 \@ifx{\longtable\longtable@longtable}{%
4392 \@ifx{\endlongtable\endlongtable@longtable}{%
4393 \@ifx{\LT@start\LT@start@longtable}{%
4394 \@ifx{\LT@end@hd@ft\LT@end@hd@ft@longtable}{%
4395 \@ifx{\LT@array\LT@array@longtable}{%
4396 \true@sw
4397 }{\false@sw}%
4398 }{\false@sw}%
4399 }{\false@sw}%
4400 }{\false@sw}%
4401 }{\false@sw}%
4402 {%
4403 \class@info{Patching longtable package}%
4404 }{%
4405 \class@info{Patching unrecognized longtable package. (Proceeding with fingers crossed)}%
4406 }%
4407 \let\longtable\longtable@new
4408 \let\endlongtable\endlongtable@new
4409 \let\LT@start\LT@start@new
4410 \let\LT@end@hd@ft\LT@end@hd@ft@new
4411 \let\LT@array\LT@array@new
4412 \newenvironment{longtable*}{%
4413 \onecolumngrid@push
4414 \longtable
4415 }{%
4416 \endlongtable
4417 \onecolumngrid@pop
4418 }%
4419 % \expandafter\let\csname output@init@longtable*\endcsname\output@init@longtable
4420 % \expandafter\let\csname output@prep@longtable*\endcsname\output@prep@longtable
4421 % \expandafter\let\csname output@post@longtable*\endcsname\output@post@longtable
4422 }{}%
4423 }%
4424 % \end{macrocode}
4425 % \end{macro}
4426 %
4427 % \begin{macro}{\LT@pre}
4428 % \begin{macro}{\LT@bot}
4429 % \begin{macro}{\LT@top}
4430 % \begin{macro}{\LT@post}
4431 % \begin{macro}{\LT@adj}
4432 % Note that at the end of the longtable environment, we reestablish the \cmd\mark@envir\ of the
4433 % containing environment. We have left \cmd\curr@envir\ alone, so this will work.
4434 % \begin{macrocode}
4435 \def\LT@pre{\penalty\z@\vskip\LTpre}%
4436 \def\LT@bot{\nobreak\copy\LT@foot\vfil}%
4437 \def\LT@top{\copy\LT@head\nobreak}%
4438 \def\LT@post{\penalty\z@\addvspace\LTpost\mark@envir{\curr@envir}}%
4439 \def\LT@adj{%
4440 \setbox\z@\vbox{\null}\dimen@-\ht\z@
4441 \setbox\z@\vbox{\unvbox\z@\LT@bot}\advance\dimen@\ht\z@
4442 \global\advance\vsize-\dimen@
4443 }%
4444 % \end{macrocode}
4445 % \end{macro}
4446 % \end{macro}
4447 % \end{macro}
4448 % \end{macro}
4449 % \end{macro}
4450 %
4451 % \begin{macro}{output@init}
4452 % \begin{macro}{output@prep}
4453 % \begin{macro}{output@post}
4454 % \begin{macrocode}
4455 \def\output@init@longtable{\LT@adj}%
4456 \def\output@prep@longtable{\setbox\@cclv\vbox{\unvbox\@cclv\LT@bot}}%
4457 \def\output@post@longtable{\LT@top}%
4458 % \end{macrocode}
4459 % \end{macro}
4460 % \end{macro}
4461 % \end{macro}
4462 %
4463 %
4464 % \subsection{Patches for index processing}%
4465 %
4466 % Another feature that uses the output routine hooks occurs within
4467 % an index, where one wishes to apply a ``continue head'' when a
4468 % column breaks within a primary index entry.
4469 % Some book designs call for the continue head to only be applied
4470 % at a turnpage break.
4471 %
4472 % In any case, it is easy enough for \cmd\output@post@theindex\
4473 % to do this in conjunction with component marks.
4474 % Only the bare outlines are shown here.
4475 %
4476 % \begin{macro}{\output@init}
4477 % \begin{macro}{\output@prep}
4478 % \begin{macro}{\output@post}
4479 % \begin{macrocode}
4480 \let\output@init@theindex\@empty
4481 \let\output@prep@theindex\@empty
4482 \def\output@post@theindex{%
4483 \@ifodd\c@page{}{%
4484 \@ifnum{\pagegrid@cur=\@ne}{% we have the leftmost column of a verso page
4485 % insert the current top-level continued head
4486 }%
4487 }%
4488 }%
4489 % \end{macrocode}
4490 % \end{macro}
4491 % \end{macro}
4492 % \end{macro}
4493 %
4494 %
4495 % \subsection{Checking the auxiliary file}%
4496 %
4497 % We relegate the checking of the auxiliary file to the output routine.
4498 % This task must wait until the last page is shipped out, because otherwise
4499 % the stream might get closed before the last page is shipped out.
4500 % Obviously, we must use \cmd\do@output@MVL\ for the job.
4501 %
4502 % \begin{macro}{\check@aux}
4503 % \begin{macrocode}
4504 \def\check@aux{\do@output@MVL{\do@check@aux}}%
4505 % \end{macrocode}
4506 % \end{macro}
4507 %
4508 %
4509 %
4510 % \subsection{Dealing with stuck floats and stalled float dequeueing}%
4511 %
4512 % \LaTeX's float placement mechanism is fundamentally flawed, as evidenced by
4513 % its warning message ``too many unprocessed floats'', which users understandably find frustrating.
4514 % The \classname{ltxgrid} package provides tools for ameliorating the situation somewhat.
4515 %
4516 % Two cases require detection and rectification:
4517 % \begin{enumerate}
4518 % \item
4519 % A float is ``stuck'' in the \cmd\@deferlist: for whatever reason, the float fails to be committed,
4520 % even at the start of a fresh page.
4521 % Once this condition prevails, following floats can never be committed, subsequently all of \LaTeX's
4522 % float registers are used up.
4523 %
4524 % If this condition is detected, we reconsider float dequeueing under permissive (\cmd\clearpage-style) processing.
4525 %
4526 % \item
4527 % The \cmd\@freelist\ is exhausted:
4528 % a large concentration of floats, say, uses up all of \LaTeX's float registers all at once.
4529 % This condition commonly occurs when the user collects floats at the end of the document, for some reason.
4530 %
4531 % When a float is encountered, \LaTeX\ uses a float register (allocated from a pool of free registers) to contain it until it can be placed.
4532 % However, no further action is taken until the pagebuilder is visited, so floats can accumulate.
4533 % Also, even after the pagebuilder is visited, deferred floats can accumulate, and these are not committed
4534 % until a column (or page) of text is completed.
4535 %
4536 % Once the last free float register is used, action should be taken that will commit some of the deferred floats,
4537 % even if this might require ending the page right where we are (resulting in a short page).
4538 %
4539 % Perhaps, committed floats should be stored using some mechanism other than a list, as is currently done.
4540 % A feasible alternative storage method would be to use a \cmd\box\ register in place of
4541 % \cmd\@toplist,
4542 % \cmd\@botlist, and
4543 % \cmd\@dbltoplist.
4544 % This is probably just fine, since such committed floats are not reconsidered (I think).
4545 %
4546 % \end{enumerate}
4547 %
4548 % The emergency processing implemented here immediately ends the current page and begins to output float pages under (\cmd\clearpage-style) rules.
4549 % It proceeds until all deferred floats have been flushed.
4550 %
4551 % Users should expect non-optimal page makeup under these circumstances.
4552 %
4553 % Note that there is a weakness in our approach that we have not attempted to repair: if floats are being
4554 % added as part of a paragraph, we will not be able to take these remedial steps until the paragraph ends.
4555 % This means that the approach implemented here cannot fix all \LaTeX\ documents. Users can still construct
4556 % documents that exhaust \LaTeX's pool of float registers!
4557 %
4558 % \begin{macro}{\check@deferlist@stuck}
4559 % \begin{macro}{\@outputpage}
4560 % We detect the case where, at the start of a fresh page, there are deferred floats, but none are
4561 % committed. We memorize the \cmd\@deferlist\ at \cmd\shipout\ time, then examine it at the point where
4562 % our efforts to commit floats to the new page are complete.
4563 % If it has not changed, the first float must be stuck, and we
4564 % attempt to fix things via \cmd\force@deferlist@stuck.
4565 %
4566 % This simple approach is comp[letely effective in for typical documents.
4567 %
4568 % Note that we try to avoid an infinite loop by examining the value of \cmd\clearpage@sw:
4569 % if we come here with that boolean true, we are in a loop.
4570 % \begin{macrocode}
4571 \def\check@deferlist@stuck#1{%
4572 \@ifx{\@deferlist@postshipout\@empty}{}{%
4573 \@ifx{\@deferlist@postshipout\@deferlist}{%
4574 \@fltstk
4575 \clearpage@sw{%
4576 \ltxgrid@warn{Deferred float stuck during \string\clearpage\space processing}%
4577 }{%
4578 \force@deferlist@stuck#1%
4579 }%
4580 }{%
4581 %Successfully committed float(s)
4582 }%
4583 \global\let\@deferlist@postshipout\@empty
4584 }%
4585 }%
4586 \def\@fltstk{%
4587 \@latex@warning{A float is stuck (cannot be placed without \string\clearpage)}%
4588 }%
4589 \appdef\@outputpage{%
4590 \global\let\@deferlist@postshipout\@deferlist
4591 }%
4592 % \end{macrocode}
4593 % \end{macro}
4594 % \end{macro}
4595 %
4596 % \begin{macro}{\@next}
4597 % \begin{macro}{\@xnext}
4598 % We rewrite the \LaTeX\ kernel macros that dequeue float registers from, e.g., \cmd\@deferlist,
4599 % providing a test for the condition where the pool of free registers is about to underflow.
4600 %
4601 % In this case, we attempt to fix things via \cmd\force@deferlist@empty.
4602 % \begin{macrocode}
4603 \def\@next#1#2{%
4604 \@ifx{#2\@empty}{\false@sw}{%
4605 \expandafter\@xnext#2\@@#1#2%
4606 \true@sw
4607 }%
4608 }%
4609 \def\@xnext\@elt#1#2\@@#3#4{%
4610 \def#3{#1}%
4611 \gdef#4{#2}%
4612 \def\@tempa{#4}\def\@tempb{\@freelist}%
4613 \@ifx{\@tempa\@tempb}{%
4614 \@ifx{#4\@empty}{%
4615 \force@deferlist@empty%{Float register pool exhausted}%
4616 }{}%
4617 }{}%
4618 }%
4619 % \end{macrocode}
4620 % \end{macro}
4621 % \end{macro}
4622 %
4623 % \begin{macro}{\force@deferlist@stuck}
4624 % \begin{macro}{\force@deferlist@empty}
4625 % \begin{macro}{\force@deferlist@sw}
4626 % \begin{macro}{\do@forcecolumn@pen}
4627 % \begin{macro}{\do@forcecolumn}
4628 % The procedure \cmd\force@deferlist@empty\ is an attempt to rectify a situation where \LaTeX's float placement mechanism
4629 % may fail (``too many unprocessed floats'').
4630 %
4631 % We put down interrupts that call for the float placement to be redone, but under permissive conditions,
4632 % just the same as if \cmd\clearpage\ had been invoked.
4633 %
4634 % Note that the attempt to rectify the error is contingent on the setting of \cmd\force@deferlist@sw,
4635 % default false. A document class using this package that wishes to enable this error recovery mechanism should
4636 % set this boolean to true.
4637 %
4638 % The interrupt \cmd\do@forcecolumn@pen, which invokes the procedure \cmd\do@forcecolumn,
4639 % does the same as \cmd\do@startcolumn, except under permissive conditions:
4640 % we are trying to empty out the float registers completely.
4641 %
4642 % In order to properly with the case where there is material in \cmd\box\cmd\@cclv,
4643 % \cmd\@toplist, \cmd\@botlist, \cmd\@dbltoplist, etc,
4644 % we do what amounts to \cmd\newpage\ to get things rolling.
4645 %
4646 % In \cmd\force@deferlist@stuck, we take advantage of already being in the output routine:
4647 % simply reinvoke \cmd\do@startcolumn\ under permissive conditions.
4648 %
4649 % \begin{macrocode}
4650 \def\force@deferlist@stuck#1{%
4651 \force@deferlist@sw{%
4652 \@booleantrue\clearpage@sw
4653 \@booleantrue\forcefloats@sw
4654 #1%
4655 }{%
4656 }%
4657 }%
4658 \def\force@deferlist@empty{%
4659 \force@deferlist@sw{%
4660 % \ltxgrid@info{#1, attempting rectification}%
4661 \penalty-\pagebreak@pen
4662 \protect@penalty\do@forcecolumn@pen
4663 }{%
4664 % \ltxgrid@info{#1}%
4665 }%
4666 }%
4667 \@booleanfalse\force@deferlist@sw
4668 \mathchardef\do@forcecolumn@pen=10009
4669 \@namedef{output@-\the\do@forcecolumn@pen}{\do@forcecolumn}%
4670 \def\do@forcecolumn{%
4671 \@booleantrue\clearpage@sw
4672 \@booleantrue\forcefloats@sw
4673 %\unvbox\@cclv
4674 %\vfil
4675 %\penalty-\pagebreak@pen
4676 \do@startcolumn
4677 }%
4678 % \end{macrocode}
4679 % \end{macro}
4680 % \end{macro}
4681 % \end{macro}
4682 % \end{macro}
4683 % \end{macro}
4684 %
4685 % A more thorough revision of \LaTeX's float placement mechanism would involve substituting a single \cmd\box\
4686 % register for the \cmd\@deferlist. This way, \LaTeX's ability to have latent floats would be limited by
4687 % box memory alone.
4688 %
4689 % Because only the \cmd\box\ and \cmd\count\ components of the float box register are actually used by \LaTeX,
4690 % our scheme can be accomplished if we can find a way to encode the information held in the \cmd\count\ component.
4691 %
4692 % A first-in, first-out mechanism exists, wherein a box-penalty pair is dequeued by \cmd\lastbox\cmd\lastpenalty\cmd\unpenalty\ and enqueued
4693 % by \cmd\setbox\cmd\foo=\cmd\hbox\cmd\bgroup\cmd\penalty\cmd\floatpenalty\cmd\box\cmd\floatbox\cmd\unhbox\cmd\foo\cmd\egroup.
4694 %
4695 % Note that this scheme is made possible by our change to \LaTeX's float placement mechanism,
4696 % wherein we consolidated the two \cmd\@deferlist s into one.
4697 %
4698 % \section{Support for legacy \LaTeX\ commands}
4699 %
4700 % We provide support for the \cmd\enlargethispage\ command.
4701 %
4702 % Note: using a command of this sort is questionable.
4703 % Instead, people should enlarge the entire spread.
4704 %
4705 % Timing Note: In a multicolumn page grid, the user should issue the \cmd\enlargethispage\ command
4706 % while the first column of the page is being typeset.
4707 % We provide a helpful message if the timing is wrong.
4708 %
4709 % This code can serve as a model for introducing commands that need to execute within the safety of the output routine.
4710 % We ensure that the arguments are fully expanded, then execute \cmd\do@output@MVL\ to cause an output procedure,
4711 % \cmd\@@enlargethispage, to execute. When it does execute, the MVL will be exposed.
4712 %
4713 % The \cmd\@@enlargethispage\ procedure simply adjusts the vertical dimensions of the page.
4714 % The adjustment will persist until the column is committed, at which point the page dimension
4715 % will revert to its standard value.
4716 % \begin{macrocode}
4717 \def\enlargethispage{%
4718 \@ifstar{%
4719 \@enlargethispage{}%
4720 }{%
4721 \@enlargethispage{}%
4722 }%
4723 }%
4724 \def\@enlargethispage#1#2{%
4725 \begingroup
4726 \dimen@#2\relax
4727 \edef\@tempa{#1}%
4728 \edef\@tempa{\noexpand\@@enlargethispage{\@tempa}{\the\dimen@}}%
4729 \expandafter\do@output@MVL\expandafter{\@tempa}%
4730 \endgroup
4731 }%
4732 \def\@@enlargethispage#1#2{%
4733 \def\@tempa{one}%
4734 \@ifx{\thepagegrid\@tempa}{%
4735 \true@sw
4736 }{%
4737 \def\@tempa{mlt}%
4738 \@ifx{\thepagegrid\@tempa}{%
4739 \@ifnum{\pagegrid@cur=\@ne}{% OK to adjust this page
4740 \gdef\enlarge@colroom{#2}%
4741 \true@sw
4742 }{% Can only adjust this column; give up
4743 \ltxgrid@warn{Too late to enlarge this page; move the command to the first column.}%
4744 \false@sw
4745 }%
4746 }{% Unknown page grid
4747 \ltxgrid@warn{Unable to enlarge a page of this kind.}%
4748 \false@sw
4749 }%
4750 }%
4751 {%
4752 \class@info{Enlarging page \thepage\space by #2}%
4753 \global\advance\@colroom#2\relax
4754 \set@vsize
4755 }{%
4756 % Could not adjust this page
4757 }%
4758 }%
4759 \let\enlarge@colroom\@empty
4760 % \end{macrocode}
4761 % The \cmd\@kludgeins\ insert register is now unneeded.
4762 % Ensure that packages using this mechanism break (preferrable to subtle bugs).
4763 % \begin{macrocode}
4764 \let\@kludgeins\@undefined
4765 % \end{macrocode}
4766 %
4767 % \subsubsection{Building the page for shipout}
4768 %
4769 % \begin{macro}{\@outputpage}
4770 % The procedures that build \cmd\@outputbox\ just before a page is shipped out by \cmd\@outputpage\ are:
4771 % \cmd\@makecol,
4772 % \cmd\@combinepage, and
4773 % \cmd\@combinedblfloats.
4774 % We headpatch \cmd\@outputpage\ to make the \cmd\@outputbox\ be of fixed height.
4775 % \begin{macrocode}
4776 \@booleantrue\textheight@sw
4777 \prepdef\@outputpage{%
4778 \textheight@sw{%
4779 \count@\vbadness\vbadness\@M
4780 \dimen@\vfuzz\vfuzz\maxdimen
4781 \setbox\@outputbox\vbox to\textheight{\unvbox\@outputbox}%
4782 \vfuzz\dimen@
4783 \vbadness\count@
4784 }{}%
4785 }%
4786 % \end{macrocode}
4787 % \end{macro}
4788 %
4789 % \subsubsection{Warning message}
4790 %
4791 % \begin{macro}{\ltxgrid@info}
4792 % \begin{macro}{\ltxgrid@warn}
4793 % Something has happened that the user might be interested in.
4794 % Print a message to the log, but only if the user selected the verbose option.
4795 % \begin{macrocode}
4796 \def\ltxgrid@info{%
4797 \ltxgrid@info@sw{\class@info}{\@gobble}%
4798 }%
4799 \@booleanfalse\ltxgrid@info@sw
4800 \def\ltxgrid@warn{%
4801 \ltxgrid@warn@sw{\class@warn}{\@gobble}%
4802 }%
4803 \@booleantrue\ltxgrid@warn@sw
4804 % \end{macrocode}
4805 % \end{macro}
4806 % \end{macro}
4807 %
4808 % \section{End of the \file{ltxgrid} {\sc docstrip} module}
4809 % Here ends the module.
4810 % \begin{macrocode}
4811 %</ltxgrid-krn>
4812 % \end{macrocode}
4813 %
4814 % \Finale
4815 % %Here ends the programmer's documentation.
4816 % \endinput
4817 %
4818 \endinput
4819 %%EOF