%
% Name: two_col.tex Double Column Format for plain TeX.
%
% Author:
% E. Myers and F.E. Paige
% clean up and modifications by Jeroen Hellingman
%
% Description:
%
% two_col.tex produces double-column output with balanced columns.
% Adapted from The TeXBook, pg 417, and The TUGboat, Vol 6, pg 29.
%
% \setdoublecolumns initializes the double column format, including
% setting \hsize and \vsize:
%
% \setdoublecolumns#1#2#3 initializes double column format
% #1 = overall width
% #2 = overall height
% #3 = column width
%
% \begindoublecolumns and \enddoublecolumns are used to switch between
% single and double column format:
%
% \begindoublecolumns starts double column format
% \enddoublecolumns returns to single column format
% and balances columns
% \leftcolrule draws a rule across left column
% \rightcolrule draws a rule across right column
%
%
% A typical TeX double-column document will contain:
%
% \setdoublecolumns{width}{height}{colwidth} % in cm, in, pt,...
% ... title page, etc ...
% ... title, author, etc ... % default is single column
% \begindoublecolumns % switch to 2 columns
% ... text ...
% \enddoublecolumns % switch to 1 column
% \leftcolrule % rule left column (optional)
% $$
% ... long equation, table, etc ... % across both columns
% $$
% \rightcolrule % rule right column (optional)
% \begindoublecolumns % again 2 columns
% ... text ...
% \enddoublecolumns % end
%
% Since double columns are narrow, the normal TeX spacing will produce
% many overfull hboxes. To avoid this, the interword skip \spaceskip is
% replaced by \doublecolskip with the default value
%
% \doublecolskip=.3333em plus .2em minus .1em
%
% and the \hyphenpenalty is set to zero. To balance the columns, it is
% necessary to allow some vertical stretch; for example use
%
% \parskip=\smallskipamount
%
% \topinsert and \midinsert, etc. will usually work with double column
% format. However, because the macros build a box longer than two columns and
% then split it, it is possible for a \midinsert to fit on the oversize
% page but not on the real one. In this case it will be lost. If this
% happens, move the insertion to another position.
%
% To type oversize documents on an 8.5 x 11 inch laser printer, use
% \tenpoint and set the dimensions in \setdoublecolumns to 10/12 of the
% desired size. Then the document enlarged by 1.2 will be correct.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newskip\doublecolskip \newskip\savespaceskip
%\doublecolskip=.3333em plus .3333em minus .1em
\doublecolskip=\spaceskip % changed --JH, use \emergencystretch
\newbox\partialpage
\newdimen\savesize
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% From the TeXBook:
\newif\iftitle
\newinsert\margin
\dimen\margin=\maxdimen % no limit on the number of marginal notes
%\def\rhead{} % \rhead contains the running headline
%\def\leftheadline{\hbox to \pagewidth{%
% \vbox to 10pt{} % strut to position the baseline
% \llap{\tenbf\folio\kern1pc} % folio to left of text
% \tenit\rhead\hfil}} % running hed flush left
%\def\rightheadline{\hbox to \pagewidth{\vbox to 10pt{}%
% \hfil\tenit\rhead\/ % running head flush right
% \rlap{\kern1pc\tenbf\folio}}} % folio to right of text
% No nonsens headline --JH:
\headline={\hfill\folio\hfill}
\newtoks\leftheader \leftheader=\headline
\newtoks\rightheader \rightheader=\headline
\def\leftheadline{\hbox to \pagewidth{\vbox to 10pt{}%
\the\leftheader}}
\def\rightheadline{\hbox to \pagewidth{\vbox to 10pt{}%
\the\rightheader}}
% --JH.
\def\onepageout#1{\shipout\vbox{ % here we define one page of output
\offinterlineskip % butt the boxes together
\vbox to 3pc{ % this part goes on top of the 44pc pages
\iftitle \global\titlefalse \setcornerrules
\else\ifodd\pageno\rightheadline\else\leftheadline\fi\fi \vfill}
\vbox to \pageheight{
\ifvoid\margin\else % marginal info is present
\rlap{\kern31pc\vbox to0pt{\kern4pt\box\margin \vss}}\fi
#1 % now insert the main information
\ifvoid\footins\else % footnote info present
\vskip\skip\footins \kern-3pt
\hrule height\ruleht width\pagewidth \kern-\ruleht \kern3pt
\unvbox\footins\fi
\boxmaxdepth=\maxdepth}}
\advancepageno}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% From the TugBoat, with some additions. Note that calling
% \setdoublecolumns redefines \output.
\def\setdoublecolumns#1#2#3{
\global\hsize=#1 \global\vsize=#2 \global\colwidth=#3
\pagewidth=\hsize \pageheight=\vsize
\bigcolheight=\vsize
\multiply \bigcolheight by 2 \advance \bigcolheight by 1cm
\leftpluscenter=\pagewidth \advance \leftpluscenter by -\colwidth
\output{\onepageout{\unvbox255}}}