summaryrefslogtreecommitdiff
path: root/macros/plain/contrib/cellular/cell2.tex
blob: 4b025aabb8e9d6f3ecc7de31bd574531df91c462 (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
% File:       TeX Inputs Cell2.tex
% Author:     J E Pittman
% Bitnet:     JEPTeX@TAMVenus
% Internet:   JEPTeX@Venus.TAMU.EDU
% Date:       November 8, 1988
%
% Prepare to scan the data, taking notes as to span sizes, row and 
% column dimensions, et cetera.
%
\catcode`_=11 % Used to protect local control sequence names.
%
% The span info tokens contain sets of entries of the form \process 
% {position}{number}{dimension}, where position is the terminal column 
% or row, number is the number of columns or rows leading into the 
% column or row, and dimension is the size of the information.
% 
\declaretoks\column_span_info
\column_span_info={}%
\declaretoks\row_span_info
\row_span_info={}%
%
\let\process=\relax
%
\declarecount\column_number
\column_number=0
%
% Create a column information entry and put the user's specifications 
% into it.
%
\def\column#1{\relax
   \advance\column_number \by 1
   \last_column=\column_number
   \get_column_number_data
   \add_column_number_data {#1}%
   \ignorespaces
   }%
%
\declarecount\row_number
\row_number=0
%
% Same as \column.
%
\def\row#1{\relax
   \advance\row_number \by 1
   \message{Scanning row \the\row_number.}%
   \last_row=\row_number
   \everyrow
   \get_row_number_data
   \add_row_number_data {#1}%
   \column_number=0
   \ignorespaces
   }%
%
% \blank is used to generate a cell without a border or data.  In this 
% context, all it does is absorb merges.
%
\def\blank{\relax
   \advance\column_number \by 1
   \if\column_number>\last_column
      \advance\column_number \by -1
      \column{}%
   \fi
   \everycolumn
   \get_column_number_data
   \ifnum\merge_rows>1
      \add_column_number_data {\merge_rows=0\relax}%
   \fi
   \merge_columns=0
   }%
%
% \cell is used to generate a normal, ruled cell.  In this context, it 
% merely measures the cell and makes the appropriate notes.
%
\def\cell#1{\relax
   \advance\column_number \by 1
   \if\column_number>\last_column
      \advance\column_number \by -1
      \column{}%
   \fi
   \everycolumn
   \get_column_number_data
%
% Typeset the information into temp box.
%
   \setbox\temp_box=\vbox \bgroup
      \begingroup
         \ifnum\merge_rows>0
            \advance\row_number \by -\merge_rows
            \get_row_number_data
         \fi
         \vskip \topborderskip
         \endgroup
      \hbox \bgroup
         \begingroup
            \ifnum\merge_columns>0
               \advance\column_number \by -\merge_columns
               \get_column_number_data
            \fi
            \hskip \leftborderskip
            \endgroup
         #1\vphantom{)}%
         \hskip \rightborderskip
         \egroup
      \vskip \bottomborderskip
      \egroup
%
% If it is a row merger, record it for later processing.
%
   \ifnum \merge_rows>0
      \edef\temp{\process
         {\the\merge_rows}{\the\ht\temp_box}{\the\row_number}%
         \the\row_span_info
         }%
      \x_after\row_span_info\x_after=\x_after{\temp}%
%     \message{\string\row_span_info=\the\row_span_info}% debug
      \add_column_number_data {\merge_rows=0\relax}%
   \else
%
% Not a merger, record the height if max.
%
      \ifdim\ht\temp_box>\rowheight
         \let\info=\relax
         \edef\temp{\the\row_number>\info
               {\rowheight=\the\ht\temp_box\relax}}%
         \let\info=\row_info
         \x_after \add_data \temp
%        \message{\string\row_info=\the\row_info}% debug
         \rowheight=\ht\temp_box
      \fi
   \fi
%
% Same as above for column merger and width.
%
   \ifnum \merge_columns>0
      \edef\temp{\process
         {\the\merge_columns}{\the\wd\temp_box}{\the\column_number}%
         \the\column_span_info
         }%
      \x_after\column_span_info\x_after=\x_after{\temp}%
%     \message{\string\column_span_info=\the\column_span_info}% debug
      \merge_columns=0
   \else
      \ifdim\wd\temp_box>\columnwidth
         \let\info=\relax
         \edef\temp{\the\column_number>\info
               {\columnwidth=\the\wd\temp_box\relax}}%
         \let\info=\column_info
         \x_after \add_data \temp
%        \message{\string\column_info=\the\column_info}% debug
      \fi
   \fi
   }%
%
% \mergeright specifies that the corresponding position is to be 
% merged with the cell to its right.
%
\def\mergeright{\relax
   \advance\column_number \by 1
   \if\column_number>\last_column
      \advance\column_number \by -1
      \column{}%
   \fi
   \everycolumn
   \get_column_number_data
   \advance\merge_columns \by 1
%
% Cancel a row merge, if present.
%
   \ifnum\merge_rows>1
      \add_column_number_data {\merge_rows=0\relax}%
   \fi
   }%
%
% Same as \mergeright, except down.
%
\def\mergedown{\relax
   \advance\column_number \by 1
   \if\column_number>\last_column
      \advance\column_number \by -1
      \column{}%
   \fi
   \everycolumn
   \get_column_number_data
   \add_column_number_data {\advance\merge_rows \by 1\relax}%
   \merge_columns=0
   }%
%
% The horizontal and vertical stretch macros allow the user to specify 
% an explicit stretch that will subsequently be processed like a span.  
% User-specified stretches are processed after span caused ones.  The 
% parameters are the starting column/row, the ending column/row, and 
% the size of the stretch.
%
\def\horizontalstretch#1#2#3{\relax
   \temp_count=#2\relax
   \advance\temp_count \by -#1\relax
   \edef\temp{\the\column_span_info\process{\the\temp_count}{#3}{#2}}%
   \x_after \column_span_info\x_after=\x_after{\temp}%
%  \message{\string\column_span_info=\the\column_span_info}% debug
   \ignorespaces
   }%
%
\def\verticalstretch#1#2#3{\relax
   \temp_count=#2\relax
   \advance\temp_count \by -#1\relax
   \edef\temp{\the\row_span_info\process{\the\temp_count}{#3}{#2}}%
   \x_after \row_span_info\x_after=\x_after{\temp}%
%  \message{\string\row_span_info=\the\row_span_info}% debug
   \ignorespaces
   }%
%
\def\noalign#1{\ignorespaces}% don't do anything for the first pass
%
\catcode`_=8 % Return to normal.
%
\endinput