| 1 |
% \subsection{Creating cells} |
| 2 |
|
| 3 |
% \begin{macro}{\cals@cell} |
| 4 |
% \begin{macro}{\cals@cell@end} |
| 5 |
% Creates an individual cell before socialization into a table. |
| 6 |
% Content of the cell is typeset inside a group. |
| 7 |
% Execution continues in |\cals@celll@end|. Parameters: |
| 8 |
% \begin{enumerate} |
| 9 |
% \item Width of the cell |
| 10 |
% \item Vertical correction: when we have a rowspan, the cell is created while processing the last row. The vertical correction is required to raise the text back to the first row of the rowspan. |
| 11 |
% \item (Implicit parameter.) Content. It is important that it contains a switch to the horizontal mode, otherwise horizontal dimensions of the cell will be incorrect. |
| 12 |
% \end{enumerate} |
| 13 |
% Using an implicit parameter instead of putting it to a macro |
| 14 |
% parameter is probably a premature optimization. |
| 15 |
% |
| 16 |
% |
| 17 |
% \begin{macrocode} |
| 18 |
\newcommand\cals@cell[3]{} |
| 19 |
\def\cals@cell#1#2{% |
| 20 |
% \end{macrocode} |
| 21 |
% |
| 22 |
% Start immediately with |\vbox| to allow |\setbox0=\cals@cell{...}| |
| 23 |
% construction. Later, white integrating the cell into |
| 24 |
% a row, the content will be unvboxed and put to a vbox |
| 25 |
% of the row height. |
| 26 |
% |
| 27 |
% \begin{macrocode} |
| 28 |
\vbox\bgroup% |
| 29 |
% \end{macrocode} |
| 30 |
% |
| 31 |
% Implicitely sets the width and the horizontal paddings |
| 32 |
% of the cell. These settings come into effect on |
| 33 |
% switch from the restricted vertical mode (our |\vbox|) to |
| 34 |
% the horizontal mode. Therefore, the content must force such |
| 35 |
% switch, otherwise the code fails. |
| 36 |
% |
| 37 |
% \begin{macrocode} |
| 38 |
\hsize=#1 |
| 39 |
\linewidth=#1 |
| 40 |
\leftskip=\cals@paddingL % |
| 41 |
\rightskip=\cals@paddingR % |
| 42 |
% \end{macrocode} |
| 43 |
% |
| 44 |
% Vertical correction and top padding |
| 45 |
% |
| 46 |
% \begin{macrocode} |
| 47 |
\ifdim #2>0pt % |
| 48 |
\vskip-#2 |
| 49 |
\fi |
| 50 |
\vskip\cals@paddingT % |
| 51 |
% \end{macrocode} |
| 52 |
% |
| 53 |
% Tuning the top padding. First, compensate the |\parskip|, |
| 54 |
% which appears on the mode switch. Second, adjusts baselineskip, |
| 55 |
% so in the case of the right preliminimary setup, the top of the |
| 56 |
% letters "Al" touches the padding border. Meanwhile, setting |
| 57 |
% prevdepth aligns the baselines of the first text lines |
| 58 |
% of the row cells. |
| 59 |
% |
| 60 |
% \begin{macrocode} |
| 61 |
\vskip-\parskip % |
| 62 |
\prevdepth=\cals@paddingD % |
| 63 |
% \end{macrocode} |
| 64 |
% |
| 65 |
% Finally, the content. And the switch to the horizontal mode (we hope). |
| 66 |
% |
| 67 |
% We want more work afrer typesetting the content, but it is not |
| 68 |
% desirable to collect all the tokens. Instead, start a group and use |
| 69 |
% |\aftergroup| to finish typesetting. For more explanations, see |
| 70 |
% ``\TeX{} by Topic'', Chapter 12 ``Expansion''. |
| 71 |
% |
| 72 |
% \begin{macrocode} |
| 73 |
\bgroup\aftergroup\cals@cell@end |
| 74 |
\cals@AtBeginCell\let\next=% eat '{' of the content |
| 75 |
}%{Implicit content} |
| 76 |
|
| 77 |
% \end{macrocode} |
| 78 |
% |
| 79 |
% The infinite glue before the bottom padding is useful later, |
| 80 |
% when we will re-height the cells in a row. |
| 81 |
% |
| 82 |
% \begin{macrocode} |
| 83 |
\def\cals@cell@end{\vfil\vskip\cals@paddingB |
| 84 |
\cals@AtEndCell\egroup % finish vbox |
| 85 |
% \end{macrocode} |
| 86 |
% Call the caller |
| 87 |
% \begin{macrocode} |
| 88 |
\cals@celll@end} |
| 89 |
% \end{macrocode} |
| 90 |
% \end{macro} |
| 91 |
% \end{macro} |
| 92 |
|
| 93 |
% \begin{macro}{\cell} |
| 94 |
% Creates a cell and appends it to the hbox |\cals@current@row|. |
| 95 |
% \begin{macrocode} |
| 96 |
\newcommand\cell[1]{} |
| 97 |
\def\cell{% |
| 98 |
% \end{macrocode} |
| 99 |
% Get the width of the cell and typeset it to the box 0. |
| 100 |
% The execution flow is: |\cell| to |\cals@cell| |
| 101 |
% to |\cals@cell@end| to |\cals@celll@end|. |
| 102 |
% \begin{macrocode} |
| 103 |
\llt@rot\cals@colwidths |
| 104 |
\let\cals@cell@width=\llt@car |
| 105 |
\setbox0=\cals@cell\cals@cell@width{0pt}% |
| 106 |
} |
| 107 |
% \end{macrocode} |
| 108 |
% \end{macro} |
| 109 |
|
| 110 |
% \begin{macro}{\cals@AtBeginCell} |
| 111 |
% \begin{macro}{\cals@AtEndCell} |
| 112 |
% Additional code to be executed at the begin and at the end |
| 113 |
% of a cell. An use case is a hook for pdfsync: |
| 114 |
% |\def\cals@AtBeginCell{\pdfsyncstart}|. I am not sure if the end-hook |
| 115 |
% is useful because all the changes are local for the cell group, |
| 116 |
% but decided to retain it for symmetry. |
| 117 |
% \begin{macrocode} |
| 118 |
\let\cals@AtBeginCell=\relax |
| 119 |
\let\cals@AtEndCell=\relax |
| 120 |
% \end{macrocode} |
| 121 |
% \end{macro} |
| 122 |
% \end{macro} |
| 123 |
|
| 124 |
% \begin{macro}{\cals@width@cell@put@row} |
| 125 |
% Implicit setting of the cell width can fail (example is an empty cell). |
| 126 |
% In this case, force the width explicitely. Then put the cell |
| 127 |
% to the current row. This code should be a part of |\cals@celll@end|, |
| 128 |
% but due to |\spancontent| is in a separate macro. |
| 129 |
% \begin{macrocode} |
| 130 |
\newcommand\cals@width@cell@put@row{% |
| 131 |
\ifdim \cals@cell@width=\wd0 \relax \else \wd0=\cals@cell@width \fi |
| 132 |
\setbox\cals@current@row=\hbox{\unhbox\cals@current@row\box0 }}% |
| 133 |
% \end{macrocode} |
| 134 |
% \end{macro} |
| 135 |
|
| 136 |
% \begin{macro}{\cals@celll@end} |
| 137 |
% After a cell is typeset to the box 0, execution continues here |
| 138 |
% (see notes to |\cell|). Update the current row and its decorations. |
| 139 |
% \begin{macrocode} |
| 140 |
\newcommand\cals@celll@end{% |
| 141 |
\cals@width@cell@put@row |
| 142 |
\cals@decor@next\cals@cell@width} |
| 143 |
% \end{macrocode} |
| 144 |
% \end{macro} |
| 145 |
|
| 146 |
% \begin{macro}{\spancontent} |
| 147 |
% Typesets a spanned cell (the content is in the implicit argument) |
| 148 |
% and puts it to the current row. |
| 149 |
% The width and height correction are |
| 150 |
% already calculated, the decorations are also already added. |
| 151 |
% \begin{macrocode} |
| 152 |
\newcommand\spancontent[1]{} |
| 153 |
\def\spancontent{% |
| 154 |
\let\cals@tmp@celll=\cals@celll@end |
| 155 |
\let\cals@cell@width=\cals@span@width |
| 156 |
\def\cals@celll@end{% |
| 157 |
\cals@width@cell@put@row% |
| 158 |
\let\cals@celll@end=\cals@tmp@celll}% |
| 159 |
\setbox0=\cals@cell{\cals@span@width}{\cals@span@height}% |
| 160 |
}%{Implicit content} |
| 161 |
% \end{macrocode} |
| 162 |
% \end{macro} |
| 163 |
|
| 164 |
% \subsubsection{Cell padding} |
| 165 |
|
| 166 |
% \begin{macro}{\cals@setpadding} |
| 167 |
% \begin{macro}{\cals@paddingL} |
| 168 |
% \begin{macro}{\cals@paddingR} |
| 169 |
% \begin{macro}{\cals@paddingT} |
| 170 |
% \begin{macro}{\cals@paddingB} |
| 171 |
% |
| 172 |
% Calculates and sets the cell padding. It seems that a good value |
| 173 |
% is the half of the font size, calculated as the full height of |
| 174 |
% a box with the content \#1. The calstable environment uses |
| 175 |
% the letters ``Ag''. |
| 176 |
% |
| 177 |
% \begin{macrocode} |
| 178 |
\newskip\cals@paddingL |
| 179 |
\newskip\cals@paddingR |
| 180 |
\newskip\cals@paddingT |
| 181 |
\newskip\cals@paddingB |
| 182 |
|
| 183 |
\newcommand{\cals@setpadding}[1]{% |
| 184 |
\setbox0=\hbox{#1}% |
| 185 |
\dimen0=\ht0 \advance\dimen0 by \dp0 \divide\dimen0 by 2 |
| 186 |
\cals@paddingL=\dimen0 \relax |
| 187 |
\cals@paddingR=\cals@paddingL |
| 188 |
\cals@paddingT=\cals@paddingL |
| 189 |
\cals@paddingB=\cals@paddingL |
| 190 |
} |
| 191 |
% \end{macrocode} |
| 192 |
% \end{macro}\end{macro}\end{macro}\end{macro}\end{macro} |
| 193 |
|
| 194 |
% \begin{macro}{\cals@setcellprevdepth} |
| 195 |
% \begin{macro}{\cals@paddingD} |
| 196 |
% The function |\cals@cell| uses the |
| 197 |
% length |\cals@paddingD| to tune the top padding. The macro |
| 198 |
% |\cals@setcellprevdepth| calculates and sets this parameter, |
| 199 |
% so that a box with the content \#1 touches the padding border. |
| 200 |
% The calstable environment uses the letters ``Al''. |
| 201 |
% |
| 202 |
% \begin{macrocode} |
| 203 |
\newdimen\cals@paddingD |
| 204 |
|
| 205 |
\newcommand{\cals@setcellprevdepth}[1]{% |
| 206 |
\setbox0=\vbox{\prevdepth=0pt #1}% |
| 207 |
\setbox1=\vbox{#1}% |
| 208 |
\dimen0=\ht0 \advance\dimen0 by \dp0 % |
| 209 |
\advance\dimen0 by -\ht1 \advance\dimen0 by -\dp1% |
| 210 |
\cals@paddingD=\dimen0 } |
| 211 |
% \end{macrocode} |
| 212 |
% \end{macro}\end{macro} |
| 213 |
|
| 214 |
% \begin{macro}{\alignL} |
| 215 |
% \begin{macro}{\alignC} |
| 216 |
% \begin{macro}{\alignR} |
| 217 |
% To align the table cell text left, center or right we add or |
| 218 |
% remove vfill-part of the left and right padding. Executed |
| 219 |
% by assigning skip to dimen. |
| 220 |
% \begin{macrocode} |
| 221 |
\newcommand\alignL{% |
| 222 |
\cals@vfillDrop\cals@paddingL |
| 223 |
\cals@vfillDrop\cals@paddingR} |
| 224 |
|
| 225 |
\newcommand\alignC{% |
| 226 |
\cals@vfillAdd\cals@paddingL |
| 227 |
\cals@vfillAdd\cals@paddingR} |
| 228 |
|
| 229 |
\newcommand\alignR{% |
| 230 |
\cals@vfillAdd\cals@paddingL |
| 231 |
\cals@vfillDrop\cals@paddingR} |
| 232 |
% \end{macrocode} |
| 233 |
% \end{macro} |
| 234 |
% \end{macro} |
| 235 |
% \end{macro} |
| 236 |
|
| 237 |
% \begin{macro}{\cals@vfillAdd} |
| 238 |
% \begin{macro}{\cals@vfillDrop} |
| 239 |
% Add or remove the |vfill|-part of a skip. Retain the existing |
| 240 |
% value if possible. |
| 241 |
% \begin{macrocode} |
| 242 |
\newcommand\cals@vfillAdd[1]{\ifnum\gluestretchorder#1>1\relax\else |
| 243 |
\dimen0=#1\relax #1=\dimen0 plus 1fill\relax \fi} |
| 244 |
\newcommand\cals@vfillDrop[1]{\ifnum\gluestretchorder#1>0\relax |
| 245 |
\dimen0=#1\relax #1=\dimen0\relax \fi} |
| 246 |
% \end{macrocode} |
| 247 |
% \end{macro} |
| 248 |
% \end{macro} |
| 249 |
|
| 250 |
% \subsection{From cells to a row} |
| 251 |
|
| 252 |
% \begin{macro}{\cals@current@row} |
| 253 |
% Rows are first typeset to this hbox. |
| 254 |
% \begin{macrocode} |
| 255 |
\newbox\cals@current@row |
| 256 |
% \end{macrocode} |
| 257 |
% \end{macro} |
| 258 |
|
| 259 |
% \begin{macro}{\colwidths} |
| 260 |
% \begin{macro}{\cals@colwidths} |
| 261 |
% The macro |\cals@colwidths| contains a list of column widths. |
| 262 |
% The user sets it through the API macro |\colwidths|, which performs |
| 263 |
% expansion. The list is alive, it is rotated after a cell is finished, |
| 264 |
% so the width of the next cell is always the first element. |
| 265 |
% \begin{macrocode} |
| 266 |
\newcommand\colwidths[1]{} |
| 267 |
\def\colwidths#{\edef\cals@colwidths} |
| 268 |
\def\cals@colwidths{{100pt}} |
| 269 |
% \end{macrocode} |
| 270 |
% \end{macro}\end{macro} |
| 271 |
|
| 272 |
% Initially, I planned to use |\row{...}| to create a row. |
| 273 |
% In order to perform actions at the end of the row I used |
| 274 |
% the aftergroup-trick, like for |\cell| command. Unfortunately, |
| 275 |
% the decorations were lost after the |
| 276 |
% group finished. I tried to save them to global temporary |
| 277 |
% macros at the end of each cell, but the saving list was big. |
| 278 |
% Finally, I decided that the construction |\brow...\erow| |
| 279 |
% is much easier to implement. |
| 280 |
|
| 281 |
% \begin{macro}{\brow} |
| 282 |
% Starts a row. Resets the rowspan markers, |\cals@current@row| |
| 283 |
% and decorations. |
| 284 |
% \begin{macrocode} |
| 285 |
\newcommand\brow{% |
| 286 |
\cals@updateRspanMarkers |
| 287 |
\setbox\cals@current@row=\hbox{}% |
| 288 |
\cals@decor@begin} |
| 289 |
% \end{macrocode} |
| 290 |
% \end{macro} |
| 291 |
|
| 292 |
% \begin{macro}{\erow} |
| 293 |
% Finishes a row. All the cells are re-layouted to the row height. |
| 294 |
% Decorations are finalized, and the row is dispatched. |
| 295 |
% \begin{macrocode} |
| 296 |
\newcommand\erow{% |
| 297 |
\cals@reheight@cells\cals@current@row |
| 298 |
\cals@last@row@height=\ht\cals@current@row\relax |
| 299 |
\cals@decor@end\cals@lastWidth |
| 300 |
\ht\cals@current@cs=\ht\cals@current@row |
| 301 |
\cals@row@dispatch |
| 302 |
} |
| 303 |
% \end{macrocode} |
| 304 |
% \end{macro} |
| 305 |
|
| 306 |
% \begin{macro}{\cals@reheight@cells} |
| 307 |
% Re-heights all the boxes of a row. |
| 308 |
% Retains the widths of these boxes. |
| 309 |
% \begin{macrocode} |
| 310 |
\newcommand\cals@reheight@cells[1]{% |
| 311 |
\dimen0=\ht#1\relax |
| 312 |
\setbox2=\hbox{}% |
| 313 |
\def\next{% |
| 314 |
\setbox4=\lastbox |
| 315 |
\ifvoid4 |
| 316 |
\def\next{\global\setbox2=\box2}% |
| 317 |
\else |
| 318 |
\dimen4=\wd4 |
| 319 |
\setbox4=\vbox to \dimen0{\unvbox4}% |
| 320 |
\ifdim \dimen4=\wd4 \relax \else \wd4=\dimen4 \fi |
| 321 |
\setbox2=\hbox{\box4\unhbox2 }% |
| 322 |
\fi |
| 323 |
\next}% |
| 324 |
\setbox0=\hbox{\unhbox#1\next}% |
| 325 |
\setbox#1=\box2 } |
| 326 |
% \end{macrocode} |
| 327 |
% \end{macro} |