| 1 |
% \subsection{Spanned cells} |
| 2 |
|
| 3 |
% The technical approach: |
| 4 |
% \begin{itemize} |
| 5 |
% \item Spanning is started in the left top corner using the |
| 6 |
% command |\nullcell{lt...}| |
| 7 |
% \item The spanned cell is split on the table cells using the |
| 8 |
% command |\nullcell|. These nullcells are responsible for |
| 9 |
% correct decorations and for calculating the big cell dimensions. |
| 10 |
% \item The content of the spanned cells comes in the end, |
| 11 |
% in the right bottom corner. |
| 12 |
% \end{itemize} |
| 13 |
|
| 14 |
% It is possible to have several active spans at once, therefore we |
| 15 |
% have to remember them. I use a queue. Each time a left column |
| 16 |
% of a span is started, we take span data from the queue. After the |
| 17 |
% right column of the span, we put the data back to the queue, |
| 18 |
% to the end. Probably it is not obvious at the first look (at least, |
| 19 |
% I needed time to find this simple idea) that this rotating queue |
| 20 |
% is always right: when spanning (its left column) starts again, |
| 21 |
% the beginning of the queue always contains data for exactly this spanning. |
| 22 |
|
| 23 |
% \begin{macro}{\cals@spanq@heights} |
| 24 |
% The queue for height tracking. In the first version I also had |
| 25 |
% a queue for decorations, but later cancelled it. |
| 26 |
% I use |\def| instead of |\newcommand| in order that |\show| |
| 27 |
% prints "|macro|" instead of "|\long macro|". The latter breaks |
| 28 |
% unit tests. |
| 29 |
% \begin{macrocode} |
| 30 |
\def\cals@spanq@heights{} |
| 31 |
% \end{macrocode} |
| 32 |
% \end{macro} |
| 33 |
|
| 34 |
% \begin{macro}{\cals@span@get} |
| 35 |
% Gets |\cals@span@height| from the queue. |
| 36 |
% \begin{macrocode} |
| 37 |
\newcommand\cals@span@get{% |
| 38 |
\llt@decons\cals@spanq@heights \cals@span@height=\llt@car\relax} |
| 39 |
% \end{macrocode} |
| 40 |
% \end{macro} |
| 41 |
|
| 42 |
% \begin{macro}{\cals@span@put} |
| 43 |
% Puts |\cals@span@height| to the queue. |
| 44 |
% \begin{macrocode} |
| 45 |
\newcommand\cals@span@put{% |
| 46 |
\edef\cals@tmp{\the\cals@span@height}\llt@snoc\cals@spanq@heights\cals@tmp} |
| 47 |
% \end{macrocode} |
| 48 |
% \end{macro} |
| 49 |
|
| 50 |
% \begin{macro}{\nullcell} |
| 51 |
% The big spanned cell is split on the table cells, which are |
| 52 |
% identified by |\nullcell|s. The task is to produce correct |
| 53 |
% decorations and to track the parameters of the spanned cell. |
| 54 |
% \begin{itemize} |
| 55 |
% \item Decorations: if defined, the background color is always |
| 56 |
% added to the column separation row. |
| 57 |
% \item Decorations: the borders are set to 0pt (disabled), |
| 58 |
% except for the borders which are requested by |
| 59 |
% the parameter of |\nullcell|: |l| for the left border, |
| 60 |
% |t| for the top, |r| for the right, |b| for the bottom. |
| 61 |
% \item More precisely, the letters in the argument are not to |
| 62 |
% specify which decorations to use, but to specify the location |
| 63 |
% of the small cell in the big cell. The use for decorations |
| 64 |
% is just an useful side-effect. |
| 65 |
% \item Action |l|: take the span data from the queue. |
| 66 |
% \item Action |r|: update the height of the current span, |
| 67 |
% put the data to the queue. |
| 68 |
% \item Action |b|: do not put an empty box to the current row. |
| 69 |
% Instead, accumulate the width of the current span. |
| 70 |
% (Preparation for |\spancontent|.) |
| 71 |
% \end{itemize} |
| 72 |
% \begin{macrocode} |
| 73 |
\newcommand\nullcell[1]{% |
| 74 |
% \end{macrocode} |
| 75 |
% First of all, parse the argument and set the if-commands |\cals@span@ifX|. |
| 76 |
% Then get the width of the cell. |
| 77 |
% \begin{macrocode} |
| 78 |
\let\cals@span@ifL=\cals@iffalse |
| 79 |
\let\cals@span@ifT=\cals@iffalse |
| 80 |
\let\cals@span@ifR=\cals@iffalse |
| 81 |
\let\cals@span@ifB=\cals@iffalse |
| 82 |
\def\next##1{\ifx\relax##1\let\next=\relax \else |
| 83 |
\expandafter\let\csname cals@span@if##1\endcsname=\cals@iftrue \fi |
| 84 |
\next}% |
| 85 |
\uppercase{\next #1}\relax |
| 86 |
\llt@rot\cals@colwidths \let\cals@nullcell@width=\llt@car |
| 87 |
% \end{macrocode} |
| 88 |
% Action "l": update the height, supress the borders, set the rowspan markers. |
| 89 |
% \begin{macrocode} |
| 90 |
\cals@span@ifL\iftrue |
| 91 |
\cals@span@ifT\iftrue |
| 92 |
\cals@span@height=0pt % |
| 93 |
\else |
| 94 |
\cals@span@get |
| 95 |
\advance\cals@span@height by \cals@last@row@height\relax |
| 96 |
\fi |
| 97 |
\cals@span@ifB\iftrue \else |
| 98 |
\let\cals@ifInRspan=\cals@iftrue |
| 99 |
\let\cals@ifLastRspanRow=\cals@iffalse |
| 100 |
\fi |
| 101 |
\let\cals@span@borderL=\cals@borderL \let\cals@span@borderT=\cals@borderT |
| 102 |
\let\cals@span@borderR=\cals@borderR \let\cals@span@borderB=\cals@borderB |
| 103 |
\fi |
| 104 |
% \end{macrocode} |
| 105 |
% Action "r": put the data to the queue, unless in the end of the spanning. |
| 106 |
% \begin{macrocode} |
| 107 |
\cals@span@ifR\iftrue |
| 108 |
\cals@span@ifB\iftrue \relax \else \cals@span@put \fi |
| 109 |
\fi |
| 110 |
% \end{macrocode} |
| 111 |
% Update the current row or calculate the span width |
| 112 |
% (in the case of the bottom row). |
| 113 |
% \begin{macrocode} |
| 114 |
\cals@span@ifB\iftrue |
| 115 |
\cals@span@ifL\iftrue |
| 116 |
\cals@span@width=\cals@nullcell@width\relax |
| 117 |
\else |
| 118 |
\advance\cals@span@width by \cals@nullcell@width\relax |
| 119 |
\fi |
| 120 |
\else |
| 121 |
\setbox\cals@current@row=\hbox{% |
| 122 |
\unhbox\cals@current@row |
| 123 |
\vbox{\hbox to\cals@nullcell@width{}\vfil}}% |
| 124 |
\fi |
| 125 |
% \end{macrocode} |
| 126 |
% Update decorations |
| 127 |
% \begin{macrocode} |
| 128 |
\cals@span@ifL\iftrue \let\cals@borderL=\cals@span@borderL |
| 129 |
\else \def\cals@borderL{0pt}\fi |
| 130 |
\cals@span@ifT\iftrue \let\cals@borderT=\cals@span@borderT |
| 131 |
\else \def\cals@borderT{0pt}\fi |
| 132 |
\cals@span@ifR\iftrue \let\cals@borderR=\cals@span@borderR |
| 133 |
\else \def\cals@borderR{0pt}\fi |
| 134 |
\cals@span@ifB\iftrue \let\cals@borderB=\cals@span@borderB |
| 135 |
\else \def\cals@borderB{0pt}\fi |
| 136 |
\cals@decor@next\cals@nullcell@width |
| 137 |
\let\cals@borderL=\cals@span@borderL \let\cals@borderR=\cals@span@borderR |
| 138 |
\let\cals@borderT=\cals@span@borderT \let\cals@borderB=\cals@span@borderB |
| 139 |
} |
| 140 |
% \end{macrocode} |
| 141 |
% \end{macro} |
| 142 |
|
| 143 |
% \begin{macro}{\cals@span@width} |
| 144 |
% \begin{macro}{\cals@span@height} |
| 145 |
% The width of the span cell. The height of the spanned cell (without |
| 146 |
% the last row). |
| 147 |
% \begin{macrocode} |
| 148 |
\newdimen\cals@span@width |
| 149 |
\newdimen\cals@span@height |
| 150 |
% \end{macrocode} |
| 151 |
% \end{macro} |
| 152 |
% \end{macro} |
| 153 |
|
| 154 |
% \begin{macro}{\cals@ifInRspan} |
| 155 |
% Set to |\cals@iftrue| if the current row is a part of a row span. |
| 156 |
% Otherwise |\cals@iffalse|. |
| 157 |
% \end{macro} |
| 158 |
|
| 159 |
% \begin{macro}{\cals@ifLastRspanRow} |
| 160 |
% Set to |\cals@iftrue| if the current row is the last row of |
| 161 |
% of a row span. Otherwise |\cals@iffalse|. |
| 162 |
% \end{macro} |
| 163 |
|
| 164 |
% \begin{macro}{\cals@updateRspanMarkers} |
| 165 |
% Resets the span markers, which are later updated by |\nullcell| |
| 166 |
% to the correct state for the current row. |
| 167 |
% \begin{macrocode} |
| 168 |
\newcommand\cals@updateRspanMarkers{% |
| 169 |
\ifx \empty\cals@spanq@heights |
| 170 |
\let\cals@ifInRspan=\cals@iffalse |
| 171 |
\else |
| 172 |
\let\cals@ifInRspan=\cals@iftrue |
| 173 |
\fi |
| 174 |
\let\cals@ifLastRspanRow=\cals@iftrue} |
| 175 |
% \end{macrocode} |
| 176 |
% \end{macro} |