summaryrefslogtreecommitdiff
path: root/macros/plain/contrib/cellular/cell4.tex
blob: 498fd6f004434ec65f5cbc10689c638ba5a38b4a (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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
% File:       TeX Inputs Cell4.tex
% Author:     J E Pittman
% Bitnet:     JEPTeX@TAMVenus
% Internet:   JEPTeX@Venus.TAMU.EDU
% Date:       November 8, 1988
%
% Set up to output the data.
%
\catcode`_=11 % Protect local control sequence names.
%
% The user supplied information about the column has already been 
% processed.
%
\def\column #1{\relax\ignorespaces}%
%
\row_number=0
\rowpenalty=0
%
% This routine is used for horizontal kerning when there might be a 
% kern to the left of the current position.
%
\def\move_right_via_lastkern #1{\relax
   \temp_dimen=#1\relax
   \ifdim \lastkern>\zeropt
      \advance \temp_dimen \by \lastkern
      \unkern
   \else
   \fi
   \kern \temp_dimen
   }%
%
% \row begins a row by getting its specifications, terminating the 
% previous row (if any) and going into horizontal mode.
%
\def\row #1{\relax
   \advance \row_number \by 1
   \everyrow
   \get_row_number_data
   \advance \rowheight \by \expansion
   \ifdim \bottomrulewidth>\zeropt
      \advance \bottomrulewidth \by \horizontal_rule_adjust
   \fi
   \column_number=0
   \par
   \ifnum \rowpenalty=0
   \else
      \penalty \rowpenalty
      \rowpenalty=0
   \fi
   \noindent
   \ignorespaces
   \message{Outputting row \the\row_number.}%
   }%
%
% \blank creates a blank cell by kerning the appropriate amount.
%
\def\blank {\relax
   \advance \column_number \by 1
   \everycolumn
   \get_column_number_data
   \advance \columnwidth \by \expansion
   \advance \merge_width \by \expansion
   \move_right_via_lastkern \merge_width
%
% Terminate merger(s).
%
   \merge_width=\zeropt
   \merge_columns=0
   \ifnum \merge_rows>0
      \add_column_number_data
            {\merge_rows=0\relax\merge_height=\zeropt\relax}%
   \fi
   }%
%
% \cell outputs a cell.  The components of the cell are (in the order 
% output) the entry, the top ruler, the bottom ruler, and the left and 
% right rulers.
%
\def\cell #1{\relax
   \advance \column_number \by 1
   \everycolumn
   \get_column_number_data
   \advance \columnwidth \by \expansion
   \advance \merge_height \by \rowheight
   \advance \merge_width \by \columnwidth
   \ifdim \leftrulewidth>\zeropt
      \advance \leftrulewidth \by \vertical_rule_adjust
   \fi
   \ifdim \rightrulewidth>\zeropt
      \advance \rightrulewidth \by \vertical_rule_adjust
   \fi
%
% Get the correct top border skip and rule width.  Note that it is 
% necessary to extract this informaion even if a row merger is not 
% present because a previous row merger might have left the wrong 
% values.
%
   \begingroup
      \advance \row_number \by -\merge_rows
      \everyrow
      \get_row_number_data
      \xdef\globaltemp{\topborderskip=\the\topborderskip\relax
         \toprulewidth=\the\toprulewidth\relax
         }%
      \aftergroup \globaltemp
      \endgroup
   \ifdim \toprulewidth>\zeropt
      \advance \toprulewidth \by \horizontal_rule_adjust
   \fi
%
% Same procedure for the left border skip and rule width except that 
% extraction is necessary only in the presense of a column merger due 
% to the execution of an every column and a get at the start of \cell.  
%
   \ifnum \merge_columns>0
      \begingroup
         \advance \column_number \by -\merge_columns
         \everycolumn
         \get_column_number_data
         \xdef\globaltemp{\leftrulewidth=\the\leftrulewidth\relax
            \leftborderskip=\the\leftborderskip\relax
            }%
         \aftergroup \globaltemp
         \endgroup
      \ifdim \leftrulewidth>\zeropt
         \advance \leftrulewidth \by \vertical_rule_adjust
      \fi
   \fi
%
% Typeset the entry into temp box horizontally first, trying kerns 
% before glue in case the cell does not require horizontal stretching 
% and taking advantage of an empty cell by doing nothing, if such is 
% the case.
%
   \setbox\temp_box=\hbox{#1}%
   \ifdim\wd\temp_box>\zeropt
      \setbox\temp_box=\hbox \bgroup
         \kern \leftborderskip
         \box\temp_box
         \egroup
      \temp_dimen=\wd\temp_box
      \advance\temp_dimen \by \rightborderskip
      \wd\temp_box=\temp_dimen
%
      \ifdim\wd\temp_box=\merge_width
%
% then the kerns can be used instead of skips.
%
      \else
         \setbox\temp_box=\hbox \to \merge_width \bgroup
            \hskip \leftborderskip
            #1%
            \hskip \rightborderskip
            \egroup
      \fi
%
% Hide the width of temp box and put a phantom into it the hard way.
%
      \wd\temp_box=\zeropt
      \setbox\scratch_box=\hbox{#1)}%
      \ifdim \dp\scratch_box>\dp\temp_box
         \dp\temp_box=\dp\scratch_box
      \fi
      \ifdim \ht\scratch_box>\ht\temp_box
         \ht\temp_box=\ht\scratch_box
      \fi
%
      \temp_dimen=\ht\temp_box
      \advance \temp_dimen \by \dp\temp_box
      \advance \temp_dimen \by \bottomborderskip
      \advance \temp_dimen \by \topborderskip
      \ifdim \temp_dimen=\merge_height
%
% then the entry can be positioned vertically via a raise statement.  
% The total height of the material output should be equal to the row 
% height, thus acting as a strut.
%
         \temp_dimen=\bottomborderskip
         \advance \temp_dimen \by \dp\temp_box
         \scratch_dimen=\rowheight
         \advance\scratch_dimen by -\temp_dimen
         \ht\temp_box=\scratch_dimen
         \raise \temp_dimen \box\temp_box
      \else % have to do it via a box
         \setbox\temp_box=\vbox \to \rowheight \bgroup
%
% Subtracting merge height - row height from top border skip allows 
% the cell to stick up into the next row by an appropriate amount.
%
            \advance \topborderskip \by \rowheight
            \advance \topborderskip \by -\merge_height
            \vskip \topborderskip
            \box\temp_box
            \vskip \bottomborderskip
            \egroup
         \box\temp_box
      \fi
   \fi
%
% All of the rules are typeset with an overlap of at least pixel width 
% which insures that there will be no gaps.
%
% Typeset the top rule into an hbox and use a raise statement to put 
% it into position.
%
   \ifdim \toprulewidth>\zeropt
      \setbox\temp_box=\hbox \bgroup
         \temp_dimen=\merge_width
         \ifdim \half\leftrulewidth<\pixelwidth
            \kern -\pixelwidth
         \else
            \kern -\half\leftrulewidth
         \fi
         \advance \temp_dimen \by -\lastkern
         \vrule \height \half\toprulewidth
                \depth  \half\toprulewidth
                \width  \temp_dimen
         \ifdim \half\rightrulewidth<\pixelwidth
            \temp_dimen=\pixelwidth
         \else
            \temp_dimen=\half\rightrulewidth
         \fi
         \kern -\temp_dimen
         \vrule \height \half\toprulewidth
                \depth  \half\toprulewidth
                \width  2\temp_dimen
         \egroup
      \wd\temp_box=\zeropt
      \temp_dimen=\rowheight
      \advance\temp_dimen \by -\merge_height
      \ht\temp_box=\temp_dimen
      \dp\temp_box=\merge_height
      \raise \merge_height \box\temp_box
   \fi
%
% Output the bottom rule using the same methods.
%
   \ifdim \bottomrulewidth>\zeropt
      \setbox\temp_box=\hbox \bgroup
         \temp_dimen=\merge_width
         \ifdim \half\leftrulewidth<\pixelwidth
            \kern -\pixelwidth
         \else
            \kern -\half\leftrulewidth
         \fi
         \advance \temp_dimen \by -\lastkern
         \vrule \height \half\bottomrulewidth
                \depth  \half\bottomrulewidth
                \width  \temp_dimen
         \ifdim \half\rightrulewidth<\pixelwidth
            \temp_dimen=\pixelwidth
         \else
            \temp_dimen=\half\rightrulewidth
         \fi
         \kern -\temp_dimen
         \vrule \height \half\bottomrulewidth
                \depth  \half\bottomrulewidth
                \width  2\temp_dimen
         \egroup
      \wd\temp_box=\zeropt
      \dp\temp_box=\zeropt
      \ht\temp_box=\rowheight
      \box\temp_box
   \fi
%
% Test to see if the left inclusive-or right rule width is non-zero.
%
   \ifdim \leftrulewidth=\zeropt
      \temp_dimen=\rightrulewidth
   \else
      \temp_dimen=\leftrulewidth
   \fi
   \ifdim \temp_dimen>\zeropt
      \setbox\temp_box=\hbox \bgroup
         \temp_dimen=\merge_height
         \advance \merge_height \by \pixelwidth
         \ifdim \leftrulewidth>\zeropt
            \kern -\half\leftrulewidth
            \vrule \height \temp_dimen
                   \depth  \pixelwidth
                   \width  \leftrulewidth
         \fi
         \ifdim \rightrulewidth>\zeropt
            \scratch_dimen=\merge_width
            \advance \scratch_dimen \by -\half\leftrulewidth
            \advance \scratch_dimen \by -\half\rightrulewidth
            \kern \scratch_dimen
            \vrule \height \temp_dimen
                   \depth  \pixelwidth
                   \width  \rightrulewidth
         \fi
         \egroup
      \wd\temp_box=\merge_width
      \ht\temp_box=\rowheight
      \dp\temp_box=\zeropt
      \box\temp_box
   \else
      \move_right_via_lastkern \merge_width
   \fi
%
% Cancel the mergers.
%
   \merge_width=\zeropt
   \merge_columns=0
   \ifnum \merge_rows>0
      \add_column_number_data
            {\merge_rows=0\relax\merge_height=\zeropt\relax}%
   \fi
   \ignorespaces
   }%
%
% No surprises here.
%
\def\mergeright {\relax
   \advance \column_number \by 1
   \everycolumn
   \get_column_number_data
   \advance \columnwidth \by \expansion
   \advance \merge_width \by \columnwidth
   \advance \merge_columns \by 1
   \ifnum \merge_rows>0
      \add_column_number_data
            {\merge_rows=0\relax\merge_height=\zeropt\relax}%
   \fi
   }%
%
% No surprises here.
%
\def\mergedown {\relax
   \advance \column_number \by 1
   \everycolumn
   \get_column_number_data
   \advance \columnwidth \by \expansion
   \advance \merge_width \by \columnwidth
   \move_right_via_lastkern \merge_width
   \merge_width=\zeropt
   \merge_columns=0
   \advance \merge_height \by \rowheight
   \let\info=\relax
   \edef\temp{\the\column_number>\info
         {\merge_height=\the\merge_height\relax
         \advance\merge_rows \by 1\relax}}%
   \let\info=\column_info
   \x_after \add_data \temp
   \rowpenalty=10000 % do not allow a break over a row merge.
   }%
%
\catcode`_=8 % Back to normal.
%
\def\noalign#1{\relax
   \vadjust{#1}%
   \ignorespaces
   }%
%
\endinput