blob: 52bfc2cc77d09c63b753eb7fca5ac0d22a647e44 (
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
% This file is public domain.
%
% These are the double-column macros from Paul Abrahams, Dec 1991
% They add the following features:
% \ifbalance (by default true, causes last page to be balanced)
% \everycolumn (a token list, useful for marks)
% \pageeject
% \eject does a column eject
\newtoks\mainoutput
\newbox\partialpage
\newdimen\fullvsize \newdimen \fullhsize
\newbox\leftcolumn \newbox \rightcolumn
\newbox\savefootins \newskip\footskip
\newbox\savetopins \newskip\topinsskip
\newif\ifbalance \balancetrue
\newtoks\everycolumn
\def\pageeject{\penalty -10005 }%
\def\doublecolumns{%
\mainoutput = \output % Save the previous \output.
%
% This grabs any single-column material.
\output = {\global\setbox\partialpage = \vbox{\unvbox255}}%
\vskip\abovedoublecolumnskip
\par % \par updates \pagetotal
\pagegoal = \pagetotal
\break % Now expand the \output we assigned just above.
\output = {\doublecolumnoutput}%
%
% Set up \hsize and \vsize for double columns.
\fullvsize = \vsize
\fullhsize = \hsize
\advance\hsize by -\gutter
\divide \hsize by 2
\advance\vsize by -\ht\partialpage
%
% Take account of existing insertions.
\ifvoid\footins\else
\advance\vsize by -\ht\footins
\advance\vsize by -\skip\footins
\fi
\setbox\savefootins = \box\footins
\footskip = \skip\footins
%
\ifvoid\topins\else
\advance\vsize by -\ht\topins
\advance\vsize by -\skip\topins
\fi
\setbox\savetopins = \box\topins
\topinsskip = \skip\topins
%
% Start at the left, clear the existing columns.
\let\lr = L%
\setbox0 = \box\leftcolumn \setbox0 = \box\rightcolumn
}%
%
% This routine actually does the outputting.
\def\doublecolumnoutput{%
\ifbalance\else \ifnum \outputpenalty < -10000
\setbox255 = \vbox{\unvbox255 \vfil}%
\fi\fi
%
\the\everycolumn
\if \lr L%
\buildcolumn\leftcolumn
\global\let\lr = R%
\else
\buildcolumn\rightcolumn
\global\let\lr = L%
\fi
%
\ifnum \outputpenalty < -10000
\ifbalance
\ifdim \ht\leftcolumn > 8\baselineskip
\balancecolumns
\global \let \lr = L%
\fi\fi\fi
%
\if \lr L%
\setbox255 = \vbox{%
\unvbox\partialpage
\dimen0 = \ht\leftcolumn \dimen1 = \dp\leftcolumn
\joincolumns
\ifnum \outputpenalty = -10005 \vfil \fi
}%
% The restoration of the insertion boxes happens only once, since
% they are empty thereafter.
\setbox\footins = \box\savefootins
\setbox\topins = \box\savetopins
\vsize = \fullvsize % Because we've taken care of \partialoutput
\ifnum \outputpenalty = -10006
\unvbox255
\else
\the\mainoutput
\global\vsize = \fullvsize
\fi
\fi
}%
%
%
% \joincolumns joins \leftcolumn and \rightcolumn into a vbox that aligns
% the tops of the two columns and has the depth of the deeper column.
% It adds the resulting box to the main vertical list.
%
\def\joincolumns{%
\dimen0 = \dp\leftcolumn \dimen1 = \dp \rightcolumn
\setbox0 = \hbox to \fullhsize{%
\vtop to \ht\leftcolumn{\unvbox\leftcolumn}%
\hfil
\vtop to \ht\rightcolumn{\unvbox\rightcolumn}%
}%
\dimen2 = \boxmaxdepth % For restoring it later
\ifdim \dimen0 < \dimen1
\boxmaxdepth = \dimen1
\else
\boxmaxdepth = \dimen0
\fi
\setbox0 = \vbox{\box0}%
\boxmaxdepth = \dimen2
\box0 % Produce for the calling context
}%
\def\buildcolumn #1{%
\ifnum \outputpenalty < -9999
\global \setbox #1 = \vbox{\pagecontents}%
\else
\global \setbox #1 = \vbox to \vsize{\pagecontents}%
\fi
}%
%
%
% Go back to single-column typesetting. Unfortunately, we cannot start
% a group in \doublecolumns and end it here, because some documents
% might want double-column mode to continue to the end. So we have to
% restore the things we've changed manually.
%
\def\singlecolumn{%
\penalty -10006
\output = \mainoutput
\hsize = \fullhsize
\vsize = \fullvsize
%
% Add \belowdoublecolumnskip if there's enough room, otherwise a \vfil
% to fill out the page.
\dimen0 = \pagetotal \advance \dimen0 by \belowdoublecolumnskip
\ifdim \dimen0 < \pagegoal
\vskip\belowdoublecolumnskip
\else
\vfil
\fi
\allowbreak
}%
%
\def \balancecolumns{%
\setbox\leftcolumn = \vbox{\unvbox\leftcolumn \unskip}%
\setbox\rightcolumn = \vbox{\unvbox\rightcolumn \unskip}%
\setbox0 = \vbox{%
\dimen0 = \dp\leftcolumn
\unvbox \leftcolumn
\if \lr L
\kern -\dimen0
\vskip -\topskip
\vskip \baselineskip
\unvbox \rightcolumn
\fi
}%
\dimen0 = \ht0
\advance \dimen0 by \topskip \advance \dimen0 by -\baselineskip
\divide \dimen0 by 2 \splittopskip = \topskip
\count@ = \vbadness \vbadness = 10000
\loop
\setbox2 = \copy0
\setbox1 = \vsplit2 to \dimen0
\ifdim \ht2 > \dimen0
\advance \dimen0 by 1pt
\repeat
\vbadness = \count@
\setbox \leftcolumn = \vbox to \dimen0{\unvbox1}%
\setbox \rightcolumn = \vbox to \dimen0{\unvbox2}%
}%
|