summaryrefslogtreecommitdiff
path: root/macros/text1/macros/flexcol.tex
blob: 441066c68110dc733cb9f3ed0bf9e42ea10458de (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
%         This work is protected as an unpublished work under
%         U.S. copyright laws.
%         Copyright 1987, by Washington State University.
%         All rights reserved.
%
%               Last updated on 7/1/89
%
%     MULTIPLE COLUMN FORMATS FLEXIBLE MODE, two and three column
%
\catcode`*=11\catcode`@=11
\global\output{\flex*ut{\unvbox255}} %     FLEXCOL normal output routine
\gdef\flex*ut#1{% FLEXIBLE OUTPUT, flex*ut
    \boxmaxdepth=\maxdepth
    \shipout\vbox{
    \offinterlineskip                % butt boxes together
    \if*title                        % Do nothing if this is a title page
    \else\makeheadline\fi            % makeheadline redefined in TEXT1
    \vbox to\*txth{                  % page height equals single column text height
    \ifvoid\topins                   % no top insert present
    \else\unvbox\topins\fi           % place top insert before main text
    #1                               % insert the main information
    \vfil                            % PREVENTS UNDERFULL BOX WHEN ONLY A FEW POINTS OFF
    \ifvoid\footins                  % no foot insert present
    \else\vskip\skip\footins         % skip to footnote position
    \footnoterule                    % print footnote rule
       \unvbox\footins\fi            % place foot insert after main text and rule
    \makefootline} % end vbox to *txth
    } % end vbox with running heads, if any
    \if*title\notitlepage\fi         % reset vsize for a normal page
    \if\*pcount>0\*blkpg\fi          % call for empty page macro, TEXT1
    \*ncfalse
    \advancepageno}                  % End flex*ut, flexible output macro
%
\gdef\*adjp#1{% ADJUST PAGE MACRO, height of inserts lost during output call, this macro
   \global\advance#1 by-\topskip     % restores these values to the output routines
    \ifvoid\topins                   % compensate for topskip
    \else                            % if no insert present do nothing else
       \global\advance#1 by-\ht\topins % routine restores those values
       \global\advance#1 by-\dp\topins % to the new output routines.
       \global\advance#1 by-\skip\topins
       \global\advance#1 by\dp\strutbox % fine tune split
    \fi
    \ifvoid\footins                  % do nothing if no footinsert present
    \else                            % else compensate for skips when footins present
       \global\advance#1 by-\ht\footins %
       \global\advance#1 by-\dp\footins %
       \global\advance#1 by-\skip\footins %
       \global\advance#1 by\dp\strutbox % fine tune split
    \fi}% END *adjp, adjust page macro
%
%         \*balctest is called whenever leaving 2 or 3 column formatting
%
\gdef\*balctest{% TEST REMAINING TEXT DEPTH text for more than one page of remaining text
    \setbox0=\vbox{\unvbox255}       % height box255 always=vsize
    \dimen9=\ht0                     % find height of material in box255
    \advance\dimen9 by\topskip       % account for top of page topskip
    \if*dbl \advance\dimen9 by\splittopskip % second column splittopskip
    \else\advance\dimen9 by2\splittopskip % second and third columns
    \fi % end accounting for topskips for splitting routines
    \setbox255=\vbox{\unvbox0}
    \ifdim\dimen9>\vsize             % too much material for one page
       \if*dbl\expandafter\global\output={\*balc}\*twcout %
       \else\expandafter\global\output={\*balc}\*thcout %
       \fi                           % use normal output before using balance columns routine
    \else                            % less than one full page of text remaining
       \*balc                        % use balance columns routine
    \fi}% END, *balctest, test for output routine to balance columns
%
\gdef\*flextwc{\par% BEGIN FLEX METHOD OF TWO COLUMNS
    \goodbreak
    \if*dbl\e*flextwc\fi             % end any active two column format
    \if*tpl\e*flexthc\else           % if previous material in threecolumns call
    \vskip\the\*mskb\fi              % end threecolumns, else skipbefore.
%
    \def\*balc{% BALANCECOLUMNS, TWO COLUMNS---beginning
       \*badj                        % check for binding adjust
       \splittopskip=\topskip        % splittopskip equals topskip
       \setbox0=\vbox{\unvbox255}    % release unbalanced page material
       \dimen0=\ht0                  % prepare to find equal height dimension
       \divide\dimen0 by2            % split dimension for two columns
       \advance\dimen0 by-\baselineskip % back up one line
       \ifdim\dimen0<\baselineskip   % check split depth
          \dimen0=\topskip           % account for the topskip
          \advance\dimen0 by\baselineskip % account for one line
       \fi
       {\vbadness=10000              % prevents underfull box message during loop
            \loop \global\setbox3=\copy0 % routine.
            \global\setbox1=\vsplit3 to\dimen0 %
            \ifdim\ht3>\dimen0       % if column longer...
            \global\advance\dimen0 by1pt %
            \repeat}                 % end balancing loop
       \setbox0=\vbox to\dimen0{\unvbox1} %
       \setbox2=\vbox to\dimen0{\dimen2=\dp3 %
          \unvbox3 \kern-\dimen2 \vfill} %
       \ifvoid2 \setbox2=\vbox to\dimen0{\null\vfill}\fi %
       \*pgsofar                     % format text accummulated so far
       \global\output={\*dbl-error}  % error message if balance fails
       \dimen@=\*txth                % return vsize to single page size
       \*adjp\dimen@                 % adjust vsize for any remaining inserts
       \global\vsize=\dimen@         % adjusted vsize
       }% END, *balc, balancecolumns macro, twocolumns
%
    \def\*pgsofar{% PAGESOFAR, format for two columns
        \unvbox\*ppage               % boxes two column material
        \D=\the\*twcgut \D=.5\D      % half gutter skip on either side of rule
        \wd0=\hsize \wd2=\hsize      % set text box width securely
        \hbox to\*txtw{\box0\hskip\D\vrule width\the\*clrw
               \hskip\D\box2\hfil}   % set boxes and rules
        }% END, *pgsofar, pagesofar output macro
%
   \def\*twcout{% TWO COLUMN OUTPUT, normal output routine
       \splittopskip=\topskip
       \splitmaxdepth=\maxdepth
       \*badj                        % check for binding adjust
       \dimen@=\vsize                % total text depth for two column out routine
       \divide\dimen@ by2            % set splitting dimension
       \*adjp\dimen@                 % adjust page size for inserts
       \setbox0=\vsplit255 to\dimen@ % split boxes to proper height
       \setbox2=\vsplit255 to\dimen@
       \flex*ut\*pgsofar             % output current page
       \unvbox255                    % release extra text material gathered
       \*bigch=2\*txth               % allow vsize changes from cpt*vsize
       \global\vsize=\*bigch         % reset vsize to two column format
       \penalty\outputpenalty}% END *twcout, two columns output routine
%
%     TWOCOLUMNS, NEW COLUMN ROUTINE
%     Harvey 12/06/85
%     This method will fail if a topinsert or footinsert is added to
%     the page after the new column call. The box and glue are set
%     at the newcolumn call accounting for inserts active then only
%
   \def\newcolumn{\par % NEWCOLUMN, Flexible method, two columns
       \D=.5\vsize                   % depth of one column
       \ifdim\pagetotal>\D           % determine which column is current
          \D=\pagegoal               % second column, depth > .5\vsize
          \advance\D by-\pagetotal
          \advance\D by-\topskip     % account for topskip of 1st column
          \advance\D by-\splittopskip % splittopskip of 2d column
          \advance\D by-\dp\strutbox % account for character depth
       \else                         % first column, depth equals half the vsize
          \advance\D by-\pagetotal   % subtract current page depth
          \advance\D by-\topskip     % subtract topskip form page depth
          \advance\D by-\dp\strutbox % account for character depth
       \fi
       \vbox to\D{\vfill}            % blank box to fill column
       \*nctrue
       \goodbreak}% END, newcolumn macro for two columns
    \let\nc=\newcolumn               % set two column definition of newcolumn
%
    \begingroup % BEGIN TWOCOLUMNS---set-up
    \global\*dbltrue                 % double columns active
    \brokenpenalty=0   % If these penalties are set to zero the text
    \clubpenalty=0     % will be formatted properly. If the are in force
    \widowpenalty=0    % uneven columns may result. The penalties will be
    \hyphenpenalty=0   % honored in either page or vsplit modes.
    \exhyphenpenalty=0
    \tolerance=6400                  % raise tolerance for short column material
    \hbadness=6400                   % warning message given at 6400
    \*bigch=2\*txth                  % initialize two column page height
    \dimen@=\*txth                   % set dimen@ to current page height
    \advance\dimen@ by-\pagetotal    % subtract current page depth
    \*adjp\dimen@                    % adjust page depth for inserts
    \vsize=2\dimen@                  % set vsize equal to twice the remaining depth
    \output={\global\setbox\*ppage=\vbox{\unvbox255}}\eject
    \output={\*twcout}               % output partial page and set output
    \hsize=\the\*twcw                % to twocolumnout, set new hsize for column
    \topskip=12pt plus4pt            % glue for vsplitting mechanism
    }% END, *flextwc, flexible two column---set-up
%
\gdef\e*flextwc{% TERMINATION MACRO FOR TWO COLUMNS FLEX METHOD
    \if*nc \vfill\eject\fi           % When we've done a \nc dump the page before balancing
    \output={\*balctest}\eject       % test for too much text for balancing
    \global\output={\flex*ut{\unvbox255}} % output page
    \global\*dblfalse                % change two column indicator to false
    \endgroup % END DOUBLE COLUMN FORMAT
    \global\vsize=\*txth             % reset page size to single column height
    \global\hsize=\*txtw             % reset page width to single column width
    \dimen@=\vsize                   % prepare to include current inserts
    \*adjp\dimen@                    % adjust for topskip and inserts
    \global\pagegoal=\dimen@         % adjust pagegoal for current inserts
    \penalty-500
    \vskip\the\*mska
    }% END e*flextwc, TWO COLUMNS termination routine
%
%
\gdef\*flexthc{\par% BEGIN FLEX METHOD OF THREE COLUMNS
    \goodbreak
    \if*tpl\e*flexthc\fi             % end any active triple columns
    \if*dbl\e*flextwc\else           % if previous material is in twocolumns, end
    \vskip\the\*mskb\fi              % twocolumns, else skipbefore
%
    \def\*balc{% BALANCECOLUMNS, THREECOLUMNS---beginning
       \*badj                        % check for binding adjust
       \splittopskip=\topskip        % split dimension for 3col
       \setbox0=\vbox{\unvbox255}
       \dimen0=\ht0                  % prepare to find equal height dimension
       \divide\dimen0 by3            % split dimension for each column
       \advance\dimen0 by-\baselineskip % back-up one baselineskip
       \ifdim\dimen0<\baselineskip   % check split depth
          \dimen0=\topskip           % account for the topskip
          \advance\dimen0 by\baselineskip % account for one line
       \fi
       {\vbadness=10000
            \loop \global\setbox5=\copy0 % begin vsplit loop for balancing
            \global\setbox3=\vsplit5 to\dimen0
            \global\setbox4=\vsplit5 to\dimen0
            \ifdim\ht5>\dimen0 \global\advance\dimen0 by1pt
            \repeat} % end balancing loop
       \setbox0=\vbox to\dimen0{\unvbox3} % first column
       \setbox1=\vbox to\dimen0{\unvbox4} % second column
       \ifvoid1 \setbox1=\vbox to\dimen0{\line{\hfil}\vfill}\fi
       \setbox2=\vbox to\dimen0{\dimen2=\dp5\unvbox5\kern-\dimen2 \vfill}
       \ifvoid2 \setbox2=\vbox to\dimen0{\line{\hfil}\vfill}\fi
       \*pgsofar
       \global\output={\*tpl-error}  % error message if loop fails
       \vsize=\*txth                 % reset page size to single column
       \dimen@=\vsize                % return vsize to single page vsize
       \*adjp\dimen@                 % adjust for topskip and inserts
       \global\vsize=\dimen@         % new vsize accounts for current inserts
       }% END, *balc, balance columns, threecolumns
%
    \def\*pgsofar{\unvbox\*ppage     % boxes three column material
        \D=\the\*thcgut \D=.5\D      % half gutter for each side of rule
        \wd0=\hsize \wd1=\hsize \wd2=\hsize % set text box width securely
        \hbox to\*txtw{\box0\hskip\D\vrule width\the\*clrw
            \hskip\D\box1\hskip\D\vrule width\the\*clrw
            \hskip\D\box2\hfil}      % set boxes and rules
            }% End *pgsofar, page-so-far macro
%
   \def\*thcout{% THREE COLUMNS OUT, normal output routine for threecolumns
       \splittopskip=\topskip
       \splitmaxdepth=\maxdepth
       \*badj                        % check for binding adjust
       \dimen@=\vsize                % total text depth for three column out routine
       \divide\dimen@ by3            % set splitting dimension
       \*adjp\dimen@                 % adjust for topskip and inserts
       \setbox0=\vsplit255 to\dimen@ % split boxes to proper height
       \setbox1=\vsplit255 to\dimen@ %
       \setbox2=\vsplit255 to\dimen@ %
       \flex*ut\*pgsofar             % send material to output routine
       \unvbox255                    % release any extra material gathered
       \*bigch=3\*txth               % allow vsize changes from cpt*vsize
       \global\vsize=\*bigch         % reset vsize for three column format
       \penalty\outputpenalty}% END *thcout,  normal output penalty set
%
%     THREECOLUMNS, NEW COLUMN ROUTINE
%     Harvey 12/19/85
%     This routine has no way to compensate for inserts following the
%     new column call and will produce an overfull vbox message while
%     output active. It may also produce and underfull vbox message
%     if there is no stretchable glue in the column.
   \def\newcolumn{\par               % new column, three columns
       \ifdim\pagetotal>.66666\vsize % you are in the third column
          \D=\pagegoal               % work from pagegoal for third column
          \advance\D by-\topskip     % account for topskip in 1st column
          \advance\D by-2\splittopskip % splittopskip in columns 2 and 3
          \advance\D by-\pagetotal   % subtract current pagetotal
          \advance\D by-\dp\strutbox % account for character depth
       \else\ifdim\pagetotal>.3\vsize % you are in the second column
          \D=.66666\vsize            % column goal is 2/3 vsize
          \advance\D by-\topskip     % account topskip in 1st column
          \advance\D by-\splittopskip % splittopskip in column 2
          \advance\D by-\pagetotal   % compensate for text
          \advance\D by-\dp\strutbox % account for character depth
            \else                    % you are in the first column
               \D=.33333\vsize       % goal is 1/3 vsize in first column
               \advance\D by-\topskip % account for splittopskip
               \advance\D by-\pagetotal % compensate for text
               \advance\D by-\dp\strutbox % account for character depth
          \fi\fi                     % end column determination and fil
    \vbox to\D{\vfill}
    \*nctrue
    \goodbreak}% END, newcolumn for three columns
%
    \let\nc=\newcolumn               % set new column definition to three columns
%
    \begingroup % BEGIN GROUP, THREE COLUMNS
    \global\*tpltrue                 % set three column indicator on
    \brokenpenalty=0     % These penalties should be zero in multicolumn
    \clubpenalty=0       % modes that use the vsplit method of paging,
    \widowpenalty=0      % the paging methods would honor the penalties.
    \hyphenpenalty=0     % is erratic columns.
    \exhyphenpenalty=0   %
    \tolerance=9600                  % raise tolerance for short columns
    \hbadness=9600                   % warnings issued at badness of 9600
    \*bigch=3\*txth                  % initialize three column height
    \dimen@=\*txth                   % set dimen@ to current page height
    \advance\dimen@ by-\pagetotal    % subtract current page depth
    \*adjp\dimen@                    % adjust page for topskip and inserts
    \vsize=3\dimen@                  % set vsize to 3 times remaining single column depth
    \output={\global\setbox\*ppage=\vbox{\unvbox255}}\eject
    \output={\*thcout}               % output partial page and set output
    \hsize=\the\*thcw                % to threecolumnout, set new hsize for column
    \topskip=12pt plus4pt            % glue for the vsplitting mechanism
    }% END *flexthc, three columns set-up
%
\gdef\e*flexthc{% TERMINATION THREE COLUMNS FLEX METHOD
    \if*nc \vfill\eject\fi           % When we've done a \nc dump the page before balancing
    \output={\*balctest}\eject           % balance remaining three column material
    \global\output={\flex*ut{\unvbox255}} % shipout page
    \global\*tplfalse                % end three column indicator
    \endgroup % END GROUP THREE COLUMNS
    \global\vsize=\*txth             % reset vsize to single column height
    \global\hsize=\*txtw             % reset hsize to single column width
    \dimen@=\vsize                   % prepare to include current inserts
    \*adjp\dimen@                    % adjust for topskip and inserts
    \global\pagegoal=\dimen@         % reset pagegoal to include inserts
    \penalty-500
    \vskip\the\*mska}% END E*flexthc, three columns termination macro
%
%
\gdef\onecolumn{\if*dbl\e*flextwc\fi  % end double column formatting
                \if*tpl\e*flexthc\fi
                \global\output={\*mkpg}
               }%  end triple column formatting
\global\let\oc=\onecolumn
%
\gdef\*dbl-error{\errhelp=\balerrhelp
    \errmessage{ Double columns can't be balanced on page \the\pageno . %
                Please type h for help. }%
    \flex*ut{\unvbox255}}
\gdef\*tpl-error{\errhelp=\balerrhelp
    \errmessage{ Triple columns can't be balanced on page \the\pageno . %
                Please type h for help. }%
    \flex*ut{\unvbox255}}%
%
\catcode`*=12\catcode`@=3