<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">% The twocolumns environment can be used anywhere in a one column document to
% produce two column output.  The twocolumns environment may extend for an
% unlimited number of pages, and start and finish mid-page.  Columns are
% always balanced.  The code works very hard to avoid two-column ``widows''
% and ``orphans''.  No inserts are supported (haven't worked out where to put
% them yet).
 
\newbox\partialpage
\newbox\leftcolumn
\newdimen\dimen@
\newdimen\colsize
\newdimen\lastpageshrink
\newdimen\dimend
\newenvironment{twocolumns}{\begingroup \global\@twocolumntrue
\def\fps@table{t}
   \pagegoal=2\textheight
   \lastpageshrink=\pageshrink
   \output={\global\setbox\partialpage=\vbox{\unvbox255}}\penalty-10000%
   \def\columnout{\trycolumnout}%
   \output={\columnout}%
   \hsize=\textwidth \advance\hsize-\columnsep \divide\hsize by 2
   \columnwidth=\hsize \linewidth=\hsize
   \global\colsize=\textheight
   \global\advance\colsize by-\ht\partialpage
   \vsize=\colsize
   \global\advance\vsize by\lastpageshrink
   \multiply\vsize by2}%
% \end{twocolumns}
   {\pagegoal=4\textheight
   \output={\balancecolumns\pagesofar}\break
   \endgroup \global\vsize=\textheight \pagegoal=\vsize}
 
\def\pagesofar{\unvbox\partialpage%
   \wd0=\hsize \wd2=\hsize \hbox to\textwidth{\box0\hfil\box2}}
\def\balancecolumns{\setbox0\vbox{\unvbox255} \dimen@=\ht0
   \advance\dimen@ by\topskip \advance\dimen@ by-\baselineskip
   \divide\dimen@ by2 \splittopskip=\topskip
   {\vbadness=10000 \loop \global\setbox3=\copy0
     \global\setbox1=\vsplit3 to\dimen@
     \ifdim\ht3&gt;\dimen@ \global\advance\dimen@ by1pt\repeat}
   \ifdim\dimen@&gt;\textheight \dimen@=\textheight\fi
   \setbox0=\vbox to \dimen@{\unvbox1} \setbox2=\vbox to \dimen@{\unvbox3}
   \if\ht0&gt;\ht2\setbox2=\vbox to\ht0{\unvbox2}\else
   \if\ht2&gt;\ht0\setbox0=\vbox to\ht2{\unvbox0}\fi\fi}
 
\def\trycolumnout{%
%   \@dblfloatplacement
   \global\def\columnout{\leftcolumnout}
   \global\vsize=\colsize
   \unvbox255\penalty\outputpenalty}
\def\leftcolumnout{%
   \global\def\columnout{\rightcolumnout}
   \global\setbox\leftcolumn=\vbox to\vsize{\unvbox255}}
\def\rightcolumnout{%
   \global\def\columnout{\trycolumnout}
   \setbox0=\box\leftcolumn
   \setbox2=\vbox to \vsize{\unvbox255}
   \setbox\@outputbox=\vbox{\pagesofar}\@outputpage
   \global\colsize=\textheight
   \global\vsize=2\colsize}

</pre></body></html>