summaryrefslogtreecommitdiff
path: root/macros/plain/contrib/misc/doublecol.tex
blob: ef05057bda4c3f268f5c97b4edd6ad1fd715bd46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
%  Generic double column output.
%
%    Modified from a routine written by Donald Knuth (The TeXBook, App. E)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  The user may modify the following to his tastes:
%
%      \pagewidth     vertical length of page.
%      \pageheight    horizontal width of page.
%      \colwidth      column width
%      \separator     macro to generate column separator. Default is nothing.
%                     \rulesep sets it to \vrule. \norulesep doesn't.
%      \makepage      default is what is contained in plain.
\catcode`@=11 % from plain.tex
% Create and initialize new dimensions.
\newdimen\pagewidth  \newdimen\pageheight  \newdimen\colwidth
\pagewidth=\hsize    \pageheight=\vsize    \colwidth=3.2truein

% This routine is used by \output ; this is different from
%   the one found in App. E.
\def\onepageout#1{\shipout\vbox{\offinterlineskip
  \vbox to \pageheight {\makepage{#1}%
       \boxmaxdepth=\maxdepth}}
  \advancepageno}
\def\makepage#1{\makeheadline
    #1 % Page contents
    \makefootline}
     
\output{\onepageout{\unvbox255}}
\newbox\partialpage
\def\begindoublecolumns{\begingroup
  \output={\global\setbox\partialpage=\vbox{\unvbox255\bigskip}}\eject
  \output={\doublecolumnout} \hsize=\colwidth \vsize=2\pageheight}
\def\enddoublecolumns{\output={\balancecolumns}\eject
  \endgroup \pagegoal=\vsize}
\def\doublecolumnout{\splittopskip=\topskip \splitmaxdepth=\maxdepth
  \dimen@=\pageheight \advance\dimen@ by-\ht\partialpage
  \setbox0=\vsplit255 to\dimen@ \setbox2=\vsplit255 to\dimen@
  \onepageout\pagesofar
  \unvbox255 \penalty\outputpenalty}
\def\pagesofar{\unvbox\partialpage
  \wd0=\hsize \wd2=\hsize \hbox to\pagewidth{\box0\hfil\separator\hfil\box2}}
\def\norulesep{\let\separator=\relax}
\def\rulesep{\let\separator=\vrule}
\let\separator=\relax
\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>\dimen@ \global\advance\dimen@ by1pt \repeat}
  \setbox0=\vbox to\dimen@{\unvbox1}
  \setbox2=\vbox to\dimen@{\dimen2=\dp3 \unvbox3\kern-\dimen2 \vfil}
  \pagesofar}