| 1 |
% \iffalse |
| 2 |
%% |
| 3 |
%% File `tabularew.dtx'. |
| 4 |
%% Copyright (C) 2009 Diego Saba |
| 5 |
%% This file may be distributed under the terms of the LPPL. |
| 6 |
%% |
| 7 |
% |
| 8 |
%<*dtx> |
| 9 |
\ProvidesFile{tabularew.dtx} |
| 10 |
%</dtx> |
| 11 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 12 |
%<package>\ProvidesPackage{tabularew} |
| 13 |
% \fi |
| 14 |
% \ProvidesFile{tabularew.dtx} |
| 15 |
[2009/05/23 v0.1 tabularew package (DPC)] |
| 16 |
% |
| 17 |
% \iffalse |
| 18 |
%<*driver> |
| 19 |
\documentclass{ltxdoc} |
| 20 |
\usepackage{tabularew} |
| 21 |
\EnableCrossrefs |
| 22 |
\CodelineIndex |
| 23 |
\GetFileInfo{tabularew.dtx} |
| 24 |
\title{The \textsf{tabularew} package\thanks{This file |
| 25 |
has version number \fileversion, last |
| 26 |
revised \filedate.}} |
| 27 |
\author{Diego Saba} |
| 28 |
\date{\filedate} |
| 29 |
\RecordChanges |
| 30 |
\begin{document} |
| 31 |
\maketitle |
| 32 |
\DocInput{tabularew.dtx} |
| 33 |
\PrintChanges |
| 34 |
\end{document} |
| 35 |
%</driver> |
| 36 |
% \fi |
| 37 |
% \CheckSum{458} |
| 38 |
% |
| 39 |
% \MakeShortVerb{\"} |
| 40 |
% \def\<#1>{$\langle$#1\/$\rangle$}% |
| 41 |
% |
| 42 |
% \def\dataa{\ignorespaces |
| 43 |
% 1&7,4&2,9&0,83&0,83&37,0&54,7&30,7&1,2\\ |
| 44 |
% 2&59,9&8,9&0,83&0,83&4,61&17,9&4,46&1,2\\ |
| 45 |
% 3&64,0&7,5&0,83&0,83&4,31&21,1&4,22&1,2\\ |
| 46 |
% 4&46,3&4,8&0,83&0,83&5,95&33,5&5,86&1,2\\ |
| 47 |
% 5&48,4&6,8&0,83&0,83&5,70&23,3&5,53&1,2 |
| 48 |
% } |
| 49 |
% \def\datab{\ignorespaces |
| 50 |
% 1&7&,4&2&,9&0&,83&0&,83&37&,0&54&,7&30&,7&1&,2\\ |
| 51 |
% 2&59&,9&8&,9&0&,83&0&,83&4&,61&17&,9&4&,46&1&,2\\ |
| 52 |
% 3&64&,0&7&,5&0&,83&0&,83&4&,31&21&,1&4&,22&1&,2\\ |
| 53 |
% 4&46&,3&4&,8&0&,83&0&,83&5&,95&33&,5&5&,86&1&,2\\ |
| 54 |
% 5&48&,4&6&,8&0&,83&0&,83&5&,70&23&,3&5&,53&1&,2 |
| 55 |
% } |
| 56 |
% |
| 57 |
% \begin{abstract} |
| 58 |
% |
| 59 |
% This article proposes an extended implementation of the \LaTeX\ |
| 60 |
% \textsf{tabular} environment. It adds a new command to gain access |
| 61 |
% to a quantity, called here the \emph{excess width}, involved in |
| 62 |
% the process of |
| 63 |
% calculating the column widths. This allows to modify the default |
| 64 |
% algorithm, that produces undesirable effects in some circumstances. |
| 65 |
% |
| 66 |
% The same extension can easily be added in the future to the similar |
| 67 |
% \textsf{array} environment and to the star forms of both. |
| 68 |
% |
| 69 |
% This extension evaluates the whole table three times. It consumes |
| 70 |
% more resources than the standard environment and cannot be made 100\% |
| 71 |
% compatible, as it conceptually should. |
| 72 |
% |
| 73 |
% \end{abstract} |
| 74 |
% |
| 75 |
% |
| 76 |
% \section{Introduction} |
| 77 |
% |
| 78 |
% This package extends the implementation of the \textsf{tabular} |
| 79 |
% environment contained in the \textsf{array} package. More |
| 80 |
% information can be found in \cite{bk:companion}. |
| 81 |
% |
| 82 |
% Let us start with an example. Suppose that you have to modify |
| 83 |
% the following table, in order to align the decimal separators. |
| 84 |
% |
| 85 |
% \begin{center} |
| 86 |
% \begin{tabular}{*{9}{c}} |
| 87 |
% sez. & |
| 88 |
% $\sigma$ & |
| 89 |
% $\tau$ & |
| 90 |
% $\beta_{\mathrm{pl},\sigma}$ & |
| 91 |
% $\beta_{\mathrm{pl},\tau}$ & |
| 92 |
% $S_{\mathrm{pl},\sigma}$ & |
| 93 |
% $S_{\mathrm{pl},\tau}$ & |
| 94 |
% $S_{\mathrm{pl}}$ & |
| 95 |
% $S_{\mathrm{pl,am}}$ \\[-.2\normalbaselineskip] |
| 96 |
% & |
| 97 |
% \scriptsize [MPa] & |
| 98 |
% \scriptsize [MPa] \\[.2\normalbaselineskip] |
| 99 |
% \hline |
| 100 |
% \hbox{\vrule height .9\normalbaselineskip width0pt}\dataa |
| 101 |
% \end{tabular} |
| 102 |
% \end{center} |
| 103 |
% |
| 104 |
% This can be done using a well known stratagem: |
| 105 |
% each number can be split so that the integer part belongs to a column, |
| 106 |
% and the separator sign and the fractional part belong to the following |
| 107 |
% column. The labels must now span two columns. |
| 108 |
% |
| 109 |
% The code will change accordingly: |
| 110 |
% |
| 111 |
% \begin{center} |
| 112 |
% \begin{tabular}{m{.4\textwidth}@{}c@{}m{.5\textwidth}} |
| 113 |
% "\begin{tabular}{*{9}{c}}" \par |
| 114 |
% " sez. &" \par |
| 115 |
% " $\sigma$ &" \par |
| 116 |
% " $\tau$ &" \par |
| 117 |
% " "~\dots \par |
| 118 |
% " \hline" \par |
| 119 |
% " 1 & 7,4 & 2,9 &"~\dots \par |
| 120 |
% " "~\dots \par |
| 121 |
% "\end{tabular}" |
| 122 |
% & |
| 123 |
% $\Rightarrow$ |
| 124 |
% & |
| 125 |
% "\begin{tabular}{c*{8}{r@{}l}}" \par |
| 126 |
% " sez. &" \par |
| 127 |
% " \multicolumn{2}{c}{$\sigma$} &" \par |
| 128 |
% " \multicolumn{2}{c}{$\tau$} &" \par |
| 129 |
% " "~\dots \par |
| 130 |
% " \hline" \par |
| 131 |
% " 1 & 7&,4 & 2&,9 &"~\dots \par |
| 132 |
% " "~\dots \par |
| 133 |
% "\end{tabular}" |
| 134 |
% \end{tabular} |
| 135 |
% \end{center} |
| 136 |
% |
| 137 |
% The result is probably unexpected: |
| 138 |
% |
| 139 |
% \begin{center} |
| 140 |
% \begin{tabular}{c*{8}{r@{}l}} |
| 141 |
% sez. & |
| 142 |
% \multicolumn{2}{c}{$\sigma$} & |
| 143 |
% \multicolumn{2}{c}{$\tau$} & |
| 144 |
% \multicolumn{2}{c}{$\beta_{\mathrm{pl},\sigma}$} & |
| 145 |
% \multicolumn{2}{c}{$\beta_{\mathrm{pl},\tau}$} & |
| 146 |
% \multicolumn{2}{c}{$S_{\mathrm{pl},\sigma}$} & |
| 147 |
% \multicolumn{2}{c}{$S_{\mathrm{pl},\tau}$} & |
| 148 |
% \multicolumn{2}{c}{$S_{\mathrm{pl}}$} & |
| 149 |
% \multicolumn{2}{c}{$S_{\mathrm{pl,am}}$} \\[-.2\normalbaselineskip] |
| 150 |
% & |
| 151 |
% \multicolumn{2}{c}{\scriptsize [MPa]} & |
| 152 |
% \multicolumn{2}{c}{\scriptsize [MPa]} \\[.2\normalbaselineskip] |
| 153 |
% \hline |
| 154 |
% \hbox{\vrule height .9\normalbaselineskip width0pt}\datab |
| 155 |
% \end{tabular} |
| 156 |
% \end{center} |
| 157 |
% |
| 158 |
% Note that the last label is not centered on its data: it is aligned |
| 159 |
% to the left and hangs to the right. The same is true of the third label. |
| 160 |
% Actually, seven of the nine labels are wider than their data, though some |
| 161 |
% of them by very little. |
| 162 |
% When a |\multicolumn| is wider than the columns it spans, it is aligned |
| 163 |
% to the left, disregarding the alignment directive. |
| 164 |
% |
| 165 |
% The intent was to center all the labels, like this: |
| 166 |
% \newcolumntype{w}{>{\spew{.5}{+1}}} |
| 167 |
% \begin{center} |
| 168 |
% \begin{tabularew}{c*{8}{wr@{}l}} |
| 169 |
% sez. & |
| 170 |
% \multicolumn{2}{c}{$\sigma$} & |
| 171 |
% \multicolumn{2}{c}{$\tau$} & |
| 172 |
% \multicolumn{2}{c}{$\beta_{\mathrm{pl},\sigma}$} & |
| 173 |
% \multicolumn{2}{c}{$\beta_{\mathrm{pl},\tau}$} & |
| 174 |
% \multicolumn{2}{c}{$S_{\mathrm{pl},\sigma}$} & |
| 175 |
% \multicolumn{2}{c}{$S_{\mathrm{pl},\tau}$} & |
| 176 |
% \multicolumn{2}{c}{$S_{\mathrm{pl}}$} & |
| 177 |
% \multicolumn{2}{c}{$S_{\mathrm{pl,am}}$} \\[-.2\normalbaselineskip] |
| 178 |
% & |
| 179 |
% \multicolumn{2}{c}{\scriptsize [MPa]} & |
| 180 |
% \multicolumn{2}{c}{\scriptsize [MPa]} \\[.2\normalbaselineskip] |
| 181 |
% \hline |
| 182 |
% \hbox{\vrule height .9\normalbaselineskip width0pt}% |
| 183 |
% \datab |
| 184 |
% \end{tabularew} |
| 185 |
% \end{center} |
| 186 |
% |
| 187 |
% To understand the reason of this behaviour, and the difficulty to |
| 188 |
% ``correct'' it, the algorithm used by \LaTeX\ and by the underlying |
| 189 |
% \TeX\ to compute the column widths must be examined in greater detail. |
| 190 |
% |
| 191 |
% The column widths are first calculated without |
| 192 |
% considering |
| 193 |
% the |\multicolumn| cells, unless they span just one column and so |
| 194 |
% are ``fake'' |\multicolumn|s. Let us call the result of this first |
| 195 |
% computation the \emph{intrinsic width} of a column. Then each |
| 196 |
% |\multicolumn| in turn is taken into consideration. If it is |
| 197 |
% wider than the columns it spans, comprehensive of the space |
| 198 |
% between adjacent columns, the last column |
| 199 |
% is widened to accommodate the |\multicolumn|. |
| 200 |
% The order matters: |
| 201 |
% first the |\multicolumn|s that end at the second column are |
| 202 |
% considered, then those that end at the third column, and so on. |
| 203 |
% Let us call the column widths so obtained the |
| 204 |
% \emph{extrinsic widths}. |
| 205 |
% The difference between the extrinsic width and the intrinsic width is |
| 206 |
% the \emph{excess width}\footnote{Other names that I have considered are |
| 207 |
% \emph{proper}, \emph{inherent}, \emph{implicit}, \emph{essential}, |
| 208 |
% \emph{innate} for \emph{intrinsic} and \emph{relational}, |
| 209 |
% \emph{explicit}, \emph{accidental}, \emph{acquired} for |
| 210 |
% \emph{extrinsic}.}. |
| 211 |
% |
| 212 |
% The \textsf{tabular} environment relies on the \TeX\ primitive |
| 213 |
% |\halign|, from which it inherits the algorithm. It is |
| 214 |
% explained in a different and more formal way in |
| 215 |
% The~\TeX book~\cite[page~235]{bk:texbook}, but the result is |
| 216 |
% the same. |
| 217 |
% |
| 218 |
% This algorithm sometimes produces undesirable effects, as the |
| 219 |
% example above shows and Donald Knuth |
| 220 |
% himself points out~\cite[\textit{ibidem}]{bk:texbook}. |
| 221 |
% |
| 222 |
% |
| 223 |
% \section{Features} |
| 224 |
% |
| 225 |
% The \textsf{tabularew} environment has the same syntax as the |
| 226 |
% \textsf{tabular} environment, and should behave in the same |
| 227 |
% way, except for the new features (and a new bunch of incompatibilities |
| 228 |
% and bugs \dots). |
| 229 |
% \begin{quote} |
| 230 |
% "\begin{tabularew}"\marg{pream}" " \ldots\ "\end{tabularew}" |
| 231 |
% \end{quote} |
| 232 |
% |
| 233 |
% \DescribeMacro\GetExcessWidth |
| 234 |
% In the body of the environment a new command is available. |
| 235 |
% \begin{quote} |
| 236 |
% |\GetExcessWidth|\marg{column} \\ |
| 237 |
% \<\textit{column}>\ $\longrightarrow$~% |
| 238 |
% \<optional sign>\ \<number> |
| 239 |
% \end{quote} |
| 240 |
% The \<\textit{column}> indication can be absolute or relative to |
| 241 |
% the current position. It is relative if |
| 242 |
% the first character is `\texttt{+}' or |
| 243 |
% `\texttt{-}', otherwise it is absolute\footnote{I cannot see |
| 244 |
% a useful application for the `\texttt{-}' form, but it was natural |
| 245 |
% to include it.}. |
| 246 |
% \DescribeMacro\ExcessWidth |
| 247 |
% Its effect is to set the dimension register |\ExcessWidth| to |
| 248 |
% the excess width of \<\textit{column}>. |
| 249 |
% |
| 250 |
% \DescribeMacro\spew |
| 251 |
% The command\footnote{The name stands for \emph{add a \textsc{sp}ace |
| 252 |
% proportional to the \textsc{e}xcess \textsc{w}idth}, but the effect |
| 253 |
% seems a bit unfortunate.} |
| 254 |
% \begin{quote} |
| 255 |
% "\spew"\marg{factor}\marg{column} |
| 256 |
% \end{quote} |
| 257 |
% is just a shorthand for the idiom |
| 258 |
% \begin{quote} |
| 259 |
% "\GetExcessWidth"\marg{column}"\hspace{"\<\textit{factor}>"\ExcessWidth}" |
| 260 |
% \end{quote} |
| 261 |
% |
| 262 |
% Since there is no way to access the widths directly during |
| 263 |
% the evaluation of a table, a trick must be used. |
| 264 |
% The table is evaluated three times. During the first pass |
| 265 |
% every call to |\GetExcessWidth| sets |\ExcessWidth| to |
| 266 |
% a null length and every call to |
| 267 |
% |\multicolumn| generates an empty cell; thus the \emph{intrinsic widths} |
| 268 |
% are collected. |
| 269 |
% The second pass restores the normal behaviour of |\multicolumn|; the |
| 270 |
% \emph{extrinsic widths} are collected and the \emph{excess widths} |
| 271 |
% calculated. |
| 272 |
% In the third and last pass every call to |\ExcessWidth| returns the |
| 273 |
% requested measure. |
| 274 |
% |
| 275 |
% The column widths can change between the second and third pass, |
| 276 |
% but the total width of the table will not, |
| 277 |
% if |\spew| is used in the following way, that is the |
| 278 |
% way I had in mind when this package was conceived. |
| 279 |
% |
| 280 |
% When there is a |\multicolumn| cell, the columns crossed by it |
| 281 |
% form a group. It is sometimes |
| 282 |
% useful to access the excess width of the \emph{last} column of the |
| 283 |
% group from within the preceding columns \emph{of the same group}. |
| 284 |
% Moreover, the sum of the spaces |\spew|ed in each of the preceding |
| 285 |
% columns should not exceed the excess width of the last column; that is, |
| 286 |
% the sum of all the \<\textit{factor}> arguments should not exceed one. |
| 287 |
% In this way the net result is to redistribute the excess width in a |
| 288 |
% flexible way among the group of columns. |
| 289 |
% |
| 290 |
% \DescribeMacro\CurrentColumn |
| 291 |
% \DescribeMacro\NumberOfColumns |
| 292 |
% The two counters |\CurrentColumn| and |\NumberOfColumns| need not |
| 293 |
% normally be used explicitly, since |\GetExcessWidth| makes use |
| 294 |
% of them behind the scenes. Nonetheless I decided to expose them too |
| 295 |
% to the user. They should only be read and not assigned to. |
| 296 |
% |
| 297 |
% |
| 298 |
% \section{Example} |
| 299 |
% |
| 300 |
% The ``correct'' table shown in the introduction was obtained by |
| 301 |
% \begin{quote} |
| 302 |
% "\begin{tabularew}{c*{8}{>{\spew{.5}{+1}}r@{}l}}" \\ |
| 303 |
% " sez. &" \\ |
| 304 |
% " \multicolumn{2}{c}{$\sigma$} &" \\ |
| 305 |
% " \multicolumn{2}{c}{$\tau$} &" \\ |
| 306 |
% " "~\dots \\ |
| 307 |
% " \hline" \\ |
| 308 |
% " 1 & 7&,4 & 2&,9 &"~\dots \\ |
| 309 |
% " "~\dots \\ |
| 310 |
% "\end{tabularew}" |
| 311 |
% \end{quote} |
| 312 |
% |
| 313 |
% |
| 314 |
% \StopEventually{ |
| 315 |
% \begin{thebibliography}{1} |
| 316 |
% \bibitem{bk:companion} \textsc{M.~Goossens}, \textsc{F.~Mittelbach} |
| 317 |
% and \textsc{A.~Samarin}. |
| 318 |
% \newblock The \LaTeX{} Companion. |
| 319 |
% \newblock |
| 320 |
% Addison-Wesley, Reading, Massachusetts, 1994. |
| 321 |
% \bibitem{bk:texbook} \textsc{D. E. Knuth}. |
| 322 |
% \newblock The \TeX{}book (Computers \& Typesetting Volume A). |
| 323 |
% \newblock |
| 324 |
% Addison-Wesley, Reading, Massachusetts, 1986. |
| 325 |
% \end{thebibliography} |
| 326 |
% \PrintChanges |
| 327 |
% } |
| 328 |
% |
| 329 |
% |
| 330 |
% \clearpage |
| 331 |
% \section{The Code} |
| 332 |
% |
| 333 |
% I have succeeded in writing this code, thanks to David Carlisle's |
| 334 |
% \textsf{tabulary} environment and his well-commented code. |
| 335 |
% I have boldly and shamelessly copied it, without even fully |
| 336 |
% understanding it, and modified it to suite my needs. |
| 337 |
% |
| 338 |
% To simplify things, I have eliminated the |\verb| and \textsf{colortbl} |
| 339 |
% support (at least for the moment). |
| 340 |
% |
| 341 |
% \begin{macrocode} |
| 342 |
%<*package> |
| 343 |
% \end{macrocode} |
| 344 |
% |
| 345 |
% \begin{macrocode} |
| 346 |
\RequirePackage{array} |
| 347 |
% \end{macrocode} |
| 348 |
% |
| 349 |
% \begin{macrocode} |
| 350 |
\catcode`\Z=14 |
| 351 |
% \end{macrocode} |
| 352 |
% |
| 353 |
% \begin{macrocode} |
| 354 |
\DeclareOption{debugshow}{\catcode`\Z=9\relax} |
| 355 |
% \end{macrocode} |
| 356 |
% |
| 357 |
% \begin{macrocode} |
| 358 |
\ProcessOptions |
| 359 |
% \end{macrocode} |
| 360 |
% |
| 361 |
% \begin{macro}{\ExcessWidth} |
| 362 |
% \begin{macro}{\CurrentColumn} |
| 363 |
% \begin{macro}{\NumberOfColumns} |
| 364 |
% Allocate the registers for the user interface. |
| 365 |
% \begin{macrocode} |
| 366 |
\newdimen\ExcessWidth |
| 367 |
\newcount\CurrentColumn |
| 368 |
\newcount\NumberOfColumns |
| 369 |
% \end{macrocode} |
| 370 |
% \end{macro} |
| 371 |
% \end{macro} |
| 372 |
% \end{macro} |
| 373 |
% |
| 374 |
% \begin{macro}{\tabularew} |
| 375 |
% \begin{macro}{\TEW@get@body} |
| 376 |
% \begin{macro}{\TEW@find@end} |
| 377 |
% \begin{macro}{\endtabularew} |
| 378 |
% The \textsf{tabularew} environment uses the same mechanism of grabbing |
| 379 |
% its body as \textsf{tabulary}, \textsf{tabularx}, and the AMS alignment |
| 380 |
% environments. |
| 381 |
% The use of "{\ifnum0=`}\fi" to begin a grouping and of "\ifnum0=`{\fi}" |
| 382 |
% to end it is discussed in \textsf{tabularx}. See also |
| 383 |
% The \TeX book \cite[page 385]{bk:texbook}. |
| 384 |
% It is needed to allow the environment inside an alignment. |
| 385 |
% \begin{macrocode} |
| 386 |
\def\tabularew{% |
| 387 |
\edef\TEW@{\@currenvir}% |
| 388 |
{\ifnum0=`}\fi |
| 389 |
\TEW@setup |
| 390 |
\toks@{}\TEW@get@body} |
| 391 |
% \end{macrocode} |
| 392 |
|
| 393 |
% \begin{macrocode} |
| 394 |
\long\def\TEW@get@body#1\end |
| 395 |
{\toks@\expandafter{\the\toks@#1}\TEW@find@end} |
| 396 |
% \end{macrocode} |
| 397 |
|
| 398 |
% \begin{macrocode} |
| 399 |
\def\TEW@find@end#1{% |
| 400 |
\def\@tempa{#1}% |
| 401 |
\ifx\@tempa\TEW@\def\@tempa{\end{#1}}\expandafter\@tempa |
| 402 |
\else\toks@\expandafter |
| 403 |
{\the\toks@\end{#1}}\expandafter\TEW@get@body\fi} |
| 404 |
% \end{macrocode} |
| 405 |
|
| 406 |
% \begin{macrocode} |
| 407 |
\def\endtabularew{% |
| 408 |
Z \message{^^J^^JEW Table - first pass^^J}% |
| 409 |
\TEW@firstpass |
| 410 |
Z \message{\@spaces\@spaces\space - second pass^^J}% |
| 411 |
\TEW@secondpass |
| 412 |
Z \message{\@spaces\@spaces\space - last pass^^J}% |
| 413 |
\TEW@lastpass |
| 414 |
\TEW@cleanup |
| 415 |
\ifnum0=`{\fi}} |
| 416 |
% \end{macrocode} |
| 417 |
% \end{macro} |
| 418 |
% \end{macro} |
| 419 |
% \end{macro} |
| 420 |
% \end{macro} |
| 421 |
|
| 422 |
% \begin{macro}{\TEW@setup} |
| 423 |
% Save locally all the things that \textsf{tabularew} will assign to |
| 424 |
% globally. The values will be restored at the end by |\TEW@cleanup|. |
| 425 |
% \begin{macrocode} |
| 426 |
\def\TEW@setup{% |
| 427 |
\edef\@restorecounters{% |
| 428 |
\global\NumberOfColumns\the\NumberOfColumns |
| 429 |
\global\CurrentColumn\the\NumberOfColumns\relax}% |
| 430 |
% \end{macrocode} |
| 431 |
% The excess widths are stored as macro definitions because |
| 432 |
% this way is easier, and probably more efficient, than dealing with |
| 433 |
% an ``array'' of dimension registers. |
| 434 |
% \begin{macrocode} |
| 435 |
\count@\z@ |
| 436 |
\@tempswatrue |
| 437 |
\@whilesw\if@tempswa\fi{% |
| 438 |
\advance\count@\@ne |
| 439 |
\expandafter\ifx\csname TEW@\the\count@\endcsname\relax |
| 440 |
\@tempswafalse |
| 441 |
\else |
| 442 |
\expandafter\let\csname TEW@S\the\count@ |
| 443 |
\expandafter\endcsname\csname TEW@\the\count@\endcsname |
| 444 |
\fi}% |
| 445 |
% \end{macrocode} |
| 446 |
% These will only change locally. |
| 447 |
% \begin{macrocode} |
| 448 |
\let\@arraycr\TEW@arraycr |
| 449 |
\let\multicolumn\TEW@multicolumn |
| 450 |
\ExcessWidth\z@ |
| 451 |
% \end{macrocode} |
| 452 |
% This will only exist locally. But I'm not sure of this choice. |
| 453 |
% \begin{macrocode} |
| 454 |
\let\spew\TEW@spew |
| 455 |
} |
| 456 |
% \end{macrocode} |
| 457 |
% \end{macro} |
| 458 |
|
| 459 |
% \begin{macro}{\TEW@cleanup} |
| 460 |
% \begin{macrocode} |
| 461 |
\def\TEW@cleanup{% |
| 462 |
\count@\z@ |
| 463 |
\@tempswatrue |
| 464 |
\@whilesw\if@tempswa\fi{% |
| 465 |
\advance\count@\@ne |
| 466 |
\expandafter\ifx\csname TEW@S\the\count@\endcsname\relax |
| 467 |
\@tempswafalse |
| 468 |
\else |
| 469 |
\global\expandafter\let\csname TEW@\the\count@ |
| 470 |
\expandafter\endcsname\csname TEW@S\the\count@\endcsname |
| 471 |
\fi}% |
| 472 |
\@restorecounters |
| 473 |
} |
| 474 |
% \end{macrocode} |
| 475 |
% \end{macro} |
| 476 |
|
| 477 |
% \begin{macro}{\TEW@firstpass} |
| 478 |
% Build a table that will never show up and |
| 479 |
% is built in a special way with the purpose of taking measures. |
| 480 |
% |\ExcessWidth| is null and |\multicolumn|s are empty. |
| 481 |
% The \emph{intrinsic widths} are collected. |
| 482 |
% \begin{macrocode} |
| 483 |
\def\TEW@firstpass{% |
| 484 |
\let\multicolumn\TEW@multicolumnempty |
| 485 |
\TEW@tabsample |
| 486 |
\let\multicolumn\TEW@multicolumn |
| 487 |
\let\@computation\TEW@firstcomp |
| 488 |
\TEW@measure |
| 489 |
} |
| 490 |
% \end{macrocode} |
| 491 |
% \end{macro} |
| 492 |
|
| 493 |
% \begin{macro}{\TEW@secondpass} |
| 494 |
% Now |\multicolumn|s are honoured and |
| 495 |
% the \emph{extrinsic widths} are collected. |
| 496 |
% \begin{macrocode} |
| 497 |
\def\TEW@secondpass{% |
| 498 |
\TEW@tabsample |
| 499 |
\let\@computation\TEW@secondcomp |
| 500 |
\TEW@measure |
| 501 |
} |
| 502 |
% \end{macrocode} |
| 503 |
% \end{macro} |
| 504 |
|
| 505 |
% \begin{macro}{\TEW@lastpass} |
| 506 |
% Just build the real table. |
| 507 |
% \begin{macrocode} |
| 508 |
\def\TEW@lastpass{% |
| 509 |
\TEW@tabfinal |
| 510 |
} |
| 511 |
% \end{macrocode} |
| 512 |
% \end{macro} |
| 513 |
|
| 514 |
% \begin{macro}{\TEW@tabsample} |
| 515 |
% Add a row at the end of the table that won't affect the |
| 516 |
% column widths. This row will later be analyzed to collect |
| 517 |
% the widths. The last row provided by the user can't serve |
| 518 |
% this purpose because it could contain multicolumns or be |
| 519 |
% hidden by an hline. |
| 520 |
% \begin{macrocode} |
| 521 |
\def\TEW@tabsample{% |
| 522 |
\let\GetExcessWidth\@GetExcessWidthz@ |
| 523 |
\let\@mkpream\TEW@mkpream |
| 524 |
\setbox\z@\hbox{% |
| 525 |
\gdef\@halignto{}% |
| 526 |
\col@sep\tabcolsep |
| 527 |
\let\d@llarbegin\begingroup\let\d@llarend\endgroup |
| 528 |
\expandafter\TEW@tabarray\the\toks@ |
| 529 |
\crcr\omit |
| 530 |
{\count@\NumberOfColumns |
| 531 |
\xdef\TEW@save@row{}% |
| 532 |
\loop |
| 533 |
\advance\count@\m@ne |
| 534 |
\ifnum\count@>\z@ |
| 535 |
\xdef\TEW@save@row{\TEW@save@row&\omit}% |
| 536 |
\repeat}% |
| 537 |
\TEW@save@row |
| 538 |
\endarray |
| 539 |
\global\setbox\@ne\lastbox |
| 540 |
}% |
| 541 |
} |
| 542 |
% \end{macrocode} |
| 543 |
% \end{macro} |
| 544 |
|
| 545 |
% \begin{macro}{\TEW@tabfinal} |
| 546 |
% This mimics a regular \textsf{tabular}, the only difference |
| 547 |
% being that |\CurrentColumn| is updated before evaluating |
| 548 |
% the content of each cell and the command |\GetExcessWidth| is |
| 549 |
% made available. |
| 550 |
% \begin{macrocode} |
| 551 |
\def\TEW@tabfinal{% |
| 552 |
\leavevmode |
| 553 |
\let\GetExcessWidth\@GetExcessWidth |
| 554 |
\let\@mkpream\TEW@mkpream |
| 555 |
\gdef\@halignto{}% |
| 556 |
\col@sep\tabcolsep |
| 557 |
\let\d@llarbegin\begingroup\let\d@llarend\endgroup |
| 558 |
\expandafter\TEW@tabarray\the\toks@\endarray} |
| 559 |
% \end{macrocode} |
| 560 |
% \end{macro} |
| 561 |
|
| 562 |
% \begin{macro}{\TEW@tabarray} |
| 563 |
% \begin{macro}{\TEW@array} |
| 564 |
% Handle the optional position argument. |
| 565 |
% \begin{macrocode} |
| 566 |
\def\TEW@tabarray{\@ifnextchar[{\TEW@array}{\@array[t]}} |
| 567 |
% \end{macrocode} |
| 568 |
|
| 569 |
% \begin{macrocode} |
| 570 |
\def\TEW@array[#1]{\@array[t]} |
| 571 |
% \end{macrocode} |
| 572 |
% \end{macro} |
| 573 |
% \end{macro} |
| 574 |
|
| 575 |
% \begin{macro}{\TEW@@mkpream} |
| 576 |
% \begin{macro}{\TEW@@arraycr} |
| 577 |
% \begin{macro}{\TEW@@multicolumn} |
| 578 |
% Saved versions. |
| 579 |
% \begin{macrocode} |
| 580 |
\let\TEW@@mkpream\@mkpream |
| 581 |
\let\TEW@@arraycr\@arraycr |
| 582 |
\let\TEW@@multicolumn\multicolumn |
| 583 |
% \end{macrocode} |
| 584 |
% \end{macro} |
| 585 |
% \end{macro} |
| 586 |
% \end{macro} |
| 587 |
|
| 588 |
% \begin{macro}{\TEW@mkpream} |
| 589 |
% This is a one-shot customized version, that redifines itself |
| 590 |
% to the regular version. It's not clear to me why this is |
| 591 |
% needed. Maybe because the regular version is used to process |
| 592 |
% the multicolumns' preambles? |
| 593 |
% \begin{macrocode} |
| 594 |
\def\TEW@mkpream{% |
| 595 |
\global\NumberOfColumns\@ne |
| 596 |
\global\CurrentColumn\@ne |
| 597 |
\let\@addamp\TEW@addamp |
| 598 |
\global\let\@mkpream\TEW@@mkpream % needed! |
| 599 |
\TEW@@mkpream} |
| 600 |
% \end{macrocode} |
| 601 |
% \end{macro} |
| 602 |
|
| 603 |
% \begin{macro}{\TEW@arraycr} |
| 604 |
% \begin{macrocode} |
| 605 |
\def\TEW@arraycr{% |
| 606 |
\global\CurrentColumn\@ne |
| 607 |
\TEW@@arraycr |
| 608 |
} |
| 609 |
% \end{macrocode} |
| 610 |
% \end{macro} |
| 611 |
|
| 612 |
% \begin{macro}{\TEW@multicolumn} |
| 613 |
% For the multicolumn mechanism to work, the first token of the |
| 614 |
% expansion must be |\omit|. |
| 615 |
% \begin{macrocode} |
| 616 |
\long\def\TEW@multicolumn#1#2#3{% |
| 617 |
% Can't place anything before \omit |
| 618 |
\TEW@@multicolumn{#1}{#2}{\global\advance\CurrentColumn\@ne#3}% |
| 619 |
\global\advance\CurrentColumn#1% |
| 620 |
\global\advance\CurrentColumn\m@ne |
| 621 |
\ignorespaces} |
| 622 |
% \end{macrocode} |
| 623 |
% \end{macro} |
| 624 |
|
| 625 |
% \begin{macro}{\TEW@multicolumnempty} |
| 626 |
% To behave exactly as explained in the introduction, the special case |
| 627 |
% of a ``fake'' multicolumn should be dealt with. I don't think this |
| 628 |
% would give any practical advantage, though. |
| 629 |
% \begin{macrocode} |
| 630 |
\long\def\TEW@multicolumnempty#1#2#3{\multispan#1\relax} |
| 631 |
% \end{macrocode} |
| 632 |
% \end{macro} |
| 633 |
|
| 634 |
% \begin{macro}{\TEW@addamp} |
| 635 |
% During the evaluation of |\@mkpream|, while processing the pramble, |
| 636 |
% each `\texttt{\&}' increases |\NumberOfColumns|. After that, it will |
| 637 |
% keep it's value. During the evaluation of |\@preamble|, while |
| 638 |
% building a row, each `\texttt{\&}' increases |\CurrentColumn|. |
| 639 |
% The latter is reset at the end of each row when |
| 640 |
% |\@arraycr| is evaluated. |
| 641 |
% \begin{macrocode} |
| 642 |
\def\TEW@addamp{% |
| 643 |
\if@firstamp\@firstampfalse |
| 644 |
\else |
| 645 |
\global\advance\NumberOfColumns\@ne |
| 646 |
\expandafter\def\expandafter\@preamble\expandafter{\@preamble |
| 647 |
&\global\advance\CurrentColumn\@ne}% |
| 648 |
\fi |
| 649 |
}% |
| 650 |
% \end{macrocode} |
| 651 |
% \end{macro} |
| 652 |
|
| 653 |
% \begin{macro}{\TEW@measure} |
| 654 |
% Take the last row apart, unbox it, take each cell in turn |
| 655 |
% and note its width. |
| 656 |
% \begin{macrocode} |
| 657 |
\def\TEW@measure{% |
| 658 |
\setbox\z@\vbox{\unvbox\@ne\unskip\global\setbox\@ne\lastbox}% |
| 659 |
\setbox\tw@\hbox{% |
| 660 |
\count@\NumberOfColumns |
| 661 |
\unhbox\@ne |
| 662 |
\loop |
| 663 |
\unskip |
| 664 |
\setbox\tw@\lastbox |
| 665 |
\ifhbox\tw@ |
| 666 |
\@computation{\wd\tw@}% |
| 667 |
\advance\count@\m@ne |
| 668 |
\repeat |
| 669 |
}% |
| 670 |
} |
| 671 |
% \end{macrocode} |
| 672 |
% \end{macro} |
| 673 |
|
| 674 |
% \begin{macro}{\TEW@firstcomp} |
| 675 |
% The argument is stored in the database. |
| 676 |
% \begin{macrocode} |
| 677 |
\def\TEW@firstcomp#1{% |
| 678 |
Z \message{Col \the\count@: Intrinsic Width=\the#1^^J}% |
| 679 |
\TEW@width\xdef{\the#1}} |
| 680 |
% \end{macrocode} |
| 681 |
% \end{macro} |
| 682 |
|
| 683 |
% \begin{macro}{\TEW@secondcomp} |
| 684 |
% The argument is used to compute the excess width which is then stored |
| 685 |
% in the database. |
| 686 |
% \begin{macrocode} |
| 687 |
\def\TEW@secondcomp#1{% |
| 688 |
\TEW@width\dimen@ |
| 689 |
\advance\dimen@-#1% |
| 690 |
\multiply\dimen@\m@ne |
| 691 |
Z \message{Col \the\count@: Excess width=\the\dimen@^^J}% |
| 692 |
\TEW@width\xdef{\the\dimen@}} |
| 693 |
% \end{macrocode} |
| 694 |
% \end{macro} |
| 695 |
|
| 696 |
% \begin{macro}{\TEW@width} |
| 697 |
% A shorthand. |
| 698 |
% \begin{macrocode} |
| 699 |
\def\TEW@width#1{% |
| 700 |
\expandafter#1\csname TEW@\the\count@\endcsname} |
| 701 |
% \end{macrocode} |
| 702 |
% \end{macro} |
| 703 |
|
| 704 |
% \begin{macro}{\@GetExcessWidth} |
| 705 |
% Look up the excess widths database. |
| 706 |
% \begin{macrocode} |
| 707 |
\def\@GetExcessWidth#1{% |
| 708 |
\count@\CurrentColumn |
| 709 |
% \end{macrocode} |
| 710 |
% Process the optional sign. Need |
| 711 |
% to |\relax| at the end of the assignment, to prevent the following |
| 712 |
% token from |
| 713 |
% being expanded too early. |
| 714 |
% \begin{macrocode} |
| 715 |
\@ifnextchar+{\advance\count@}{% |
| 716 |
\@ifnextchar-{\advance\count@}{\count@}}#1\relax |
| 717 |
% \end{macrocode} |
| 718 |
% Check that the column exists. |
| 719 |
% \begin{macrocode} |
| 720 |
\@tempswafalse |
| 721 |
\ifnum\count@>\z@ |
| 722 |
\ifnum\count@>\NumberOfColumns |
| 723 |
\else\@tempswatrue |
| 724 |
\fi\fi |
| 725 |
% \end{macrocode} |
| 726 |
% Retrieve the datum. |
| 727 |
% \begin{macrocode} |
| 728 |
\if@tempswa\TEW@width\ExcessWidth |
| 729 |
\else\ExcessWidth\z@ |
| 730 |
\TEW@warn{nonexistent column \the\count@, assuming EW=0pt}% |
| 731 |
\fi |
| 732 |
Z \message{EW in col. \the\CurrentColumn\space references |
| 733 |
Z col. \the\count@: \the\ExcessWidth^^J}% |
| 734 |
} |
| 735 |
% \end{macrocode} |
| 736 |
% \end{macro} |
| 737 |
|
| 738 |
% \begin{macro}{\@GetExcessWidthz@} |
| 739 |
% To be used in the first two passes, when the excess widths are still |
| 740 |
% unknown. |
| 741 |
% \begin{macrocode} |
| 742 |
\def\@GetExcessWidthz@#1{\ExcessWidth\z@} |
| 743 |
% \end{macrocode} |
| 744 |
% \end{macro} |
| 745 |
|
| 746 |
% \begin{macro}{\TEW@spew} |
| 747 |
% A useful shorthand. |
| 748 |
% \begin{macrocode} |
| 749 |
\def\TEW@spew#1#2{\GetExcessWidth{#2}\hspace{#1\ExcessWidth}} |
| 750 |
% \end{macrocode} |
| 751 |
% \end{macro} |
| 752 |
|
| 753 |
% \begin{macro}{\TEW@warn} |
| 754 |
% Warning messages. |
| 755 |
% \begin{macrocode} |
| 756 |
\def\TEW@warn{% |
| 757 |
\PackageWarning{tabularew}} |
| 758 |
% \end{macrocode} |
| 759 |
% \end{macro} |
| 760 |
|
| 761 |
% \begin{macrocode} |
| 762 |
\catcode`\Z=11 |
| 763 |
% \end{macrocode} |
| 764 |
% |
| 765 |
% \begin{macrocode} |
| 766 |
%</package> |
| 767 |
% \end{macrocode} |
| 768 |
% \PrintIndex |
| 769 |
% \Finale |
| 770 |
% |