Arrays

We describe here the implementation of the arrays in Tralics. One has to distinguish between table which is an environment in which you can put some objects (in general tables) with a caption; like the figure environment, this generates a floating object. On the other hand, the array and tabular environements can be used to create table: the first one is designed for math only, the second for non-math material. In the current version, something like <{$} does not work.

The tabular environment

You can say \begin{tabular}[pos]{cols} ... \end{tabular} or \begin{tabular*}{width}[pos]{cols} ... \end{tabular*}.

In both cases, the result is a <table> element. This element has a vpos attribute whose value is t, b or c, provided that the optional [pos] argument is one of [t], [b] or [c]. The element has a width attribute with value xx, provided that the tabular* environment has been used and the first argument evaluates to xx as a dimension. The resulting element consists of some <row> elements, each of which contains some <cell> elements. Example

\begin{tabular*}{10pc}[b]{lrc}
\hline
a&b&c\\[2pt]
\multicolumn{1}{l}{A}&B&C\\\hline
\end{tabular*}

The translation is the following.

<table vpos='b' width='120.0pt' rend='inline'>
 <row  spaceafter='2.0pt' top-border='true'>
  <cell halign='left'>a</cell>
  <cell halign='right'>b</cell>
  <cell halign='center'>c</cell>
 </row>
 <row bottom-border='true'>
  <cell halign='left' cols='1'>A</cell>
  <cell halign='right'>B</cell>
  <cell halign='center'>C</cell>
 </row>
</table>

Preview some table

Not all names are hard-coded. If the configuration file contains the following lines,

  att_vpos = "Vpos"
  att_halign = "Halign"
  att_cols = "Cols"
  att_table_width = "Width"
  xml_table_name = "Table" 
  xml_row_name = "Row"
  att_row_spaceafter = "Spaceafter"
  xml_cell_name = "Cell"
  att_cell_left =  "Left"
  att_cell_right =  "Right"
  att_cell_center =  "Center"
  att_cell_leftborder = "Leftborder"
  att_cell_rightborder = "Rightborder"
  att_cell_topborder = "Topborder"
  att_cell_bottomborder = "Bottomborder"
  att_rend = "Rend"

then the translation is the following.

<Table Vpos='b' Width='120.0pt' Rend='inline'>
 <Row Spaceafter='2.0pt' Topborder='true'>
  <Cell Halign='Left'>a</Cell>
  <Cell Halign='Right'>b</Cell>
  <Cell Halign='Center'>c</Cell>
 </Row>
 <Row Bottomborder='true'>
  <Cell Halign='Left' Cols='1'>A</Cell>
  <Cell Halign='Right'>B</Cell>
  <Cell Halign='Center'>C</Cell>
 </Row>
</Table>

Interpreting the preamble

The preamble of the array is the quantity marked `{cols}' in the description above. This is a specification for columns. It specifies how the columns should be formatted. In standard latex, you cannot use more columns than specified; in Tralics, this is not relevant.

As the previous example shows, there are three standard column types: c, l and r (centered, left-aligned, right-aligned). You can also say p{dim}. This should typeset the column in a \parbox[t]{dim}. This feature is not implemented: the argument is ignored, and p is replaced by c.

The `array.sty' adds two options: m and b. The b option is like the p option, but bottom-aligned. The m option should be used only in math mode (i.e. for the array environment, and not tabular). In Tralics, there is no difference between b, m and p.

There is an @{text} option. It inserts text in every row, where text is processed in math mode in the array environment and in LR mode in the tabular and tabular* environments. Such an expression suppresses the space that LATEX normally inserts between columns. For instance, an array specification like {l@{\hspace{1cm}}l} says that the two columns of text should be separated by exactly one centimeter. A specification like {@{}c@{}} says that no additional space should be added neither of the left not the right of the column. An \extracolsep{wd} command can be used inside such an expression. It causes an extra space to appear to the left of all subsequent columns. Note that \extracolsep expands to \tabskip; this TEX primitive is not implemented in Tralics. In fact, Tralics ignores an @ and its argument.

You can use a | for specifying a vertical rule. However, in Tralics you cannot use double or triple rules. Sorry. There is also a !{...} options that is not implemented.

Every specification (l, r, c, p, b, m) can be preceded by a >{xx} declaration, and followed by a <{yy} declaration. In case of multiple declarations, the last will be executed first. Said otherwise, >{3}>{b}c<{a}<{z} is the same as >{b3}c<{za}. The effect is to insert b3 before the cell in the current position, and za after the cell. Note that the cell is finished when a token is sensed that indicates either a new cell, a new row or the end of the array. Technically, this means a & a \\, or an \end (the end of the environment). A special marker is pushed back after the za. This is a special endtemplate token in the case of a cell, and a \cr in the case of \\. You should not use \cr or \crcr outside an array defined by \halign (this is not yet implemented). You must be careful that the za (or equivalent) does not contain something that reads the special end marker. For instance \def\x#1{}\halign{#\x&#\cr 1&2\cr} is an error.

Finally, *{N}{text} can be used instead of N occurences and text.

Note. At the end of Chapter 22 of the TeXbook, Knuth gives an example of a table where the preamble is \centerline{#}. Such a construction cannot be done in Tralics, since >{\centerline?}c<{?} would transform into \centerline?#? and question marks cannot be replaced by braces; you could try >{\expandafter\centerline?} and replace the question mark by something that expands to an open brace but contains as many open braces as closing ones, for instance \expandafter{\iffalse}\fi. However, it is not possible to put in the <{?} part something that the parser considers as a closing brace followed by some other text (otherwise, this closing brace would terminate parsing of the <{?} part).

Knuth says that an entry of the form a}b{c is legitimate, with respect to this template. This cannot be the case in Tralics, but it would be valid for a template like >{\bgroup\bf}c<{\egroup}. This justifies that a table has to be terminated by \cr or \crcr. In the case of Tralics, this is not needed.

New column types

You can say things like these

  
\newcolumntype{C}{>{$}c<{$}}
\newcolumntype{L}{>{$}l<{$}}
\newcolumntype{R}{>{$}r<{$}}
\newcolumntype{d}[1]{>{\rightdots{#1}}r<{\endrightdots}}
\newcolumntype{X}{CLR}

\begin{tabular}{*{3}{|c|}d{23}X}
\end{tabular}

In this case, the log file will contains,

array preamble at start: |c||c||c|d{23}X
array preamble after X: |c||c||c|d{23}CLR
array preamble after d: |c||c||c|>{\rightdots {23}}r<{\endrightdots }CLR
array preamble after C: |c||c||c|>{\rightdots {23}}r<{\endrightdots }>{$}c<{$}LR
array preamble after L: |c||c||c|>{\rightdots {23}}r<{\endrightdots }>{$}c<{$}>{$}l<{$}R
array preamble after R: |c||c||c|>{\rightdots {23}}r<{\endrightdots }>{$}c<{$}>{$}l<{$}>{$}r<{$}
array preamble parse: | c | | c 1| | c 2| >3>{} r <<{} >4>{} c <<{} >5>{} l <<{} >6>{} r <<{} 7

The first line is printed after evaluation of the * arguments.

After that, the preamble contains, at toplevel (outside braces) two characters `d' and `X' that are defined to be new column types. These are evaluated one after the other (the order is irrelevant, here alphabetic order is used so that X is expanded first). Since the expansion was non trivial, a second try is made. Note that only a finite numbers of tries are executed. In case of recursion, strange things can happen. Note how you can use commands with arguments (here `d' takes one argument, it is `23').

The last line of the log indicates parsing of standard options. In the case of p{...}, you will see a p first, followed by a p{}. Whenever a new cell is started, a number is printed. Hence c 1 indicates that cell 0 was finished, cell 1 started, and cell is is centered; >5>{} means that cell 5 was started because of the > sign. The final number just says that the seventh cell information were stored.

Table is empty, on purpose because there are two undefined macros, moreover, because, in the current version of Tralics, dollar signs have to be explicit, and not hidden in a >{}...<{} construction.

Another example

We consider here the following new column types. As you can see, one of them is the character +, another is the character _. The fact that these characters have special catcodes is irrelevant (they cannot be of catcode 1 and 2, because this would interfere with brace matching, and they cannot be of catcode 10, because space characters should be ignored in the preamble).

 
\newcolumntype{L} {>{\large\bfseries 2}l <{y}|}
\newcolumntype{+} {>{B}l <{D}|}
\newcolumntype{_}{rlc<{x}}
\newcolumntype{x}{>{b}c<{a}}

Consider the four following tables

 
\begin{tabular*}{5cm}[b]{*{4}{_c|}}
a1&a2&a3&a4  & b1&b2&b3&b4 & c1&c2&c3&c4& d1&d2&d3&d4\\
Wa1&Wa2&Wa3&Wa4  & Wb1&Wb2&Wb3&Wb4 & Wc1&Wc2&Wc3&Wc4& Wd1&Wd2&Wd3&Wd4\\
\end{tabular*}

\begin{tabular}{|ll|rr|cc|}
\hline a&b&c&d&e&f\\
aaa&bbb&ccc&ddd&eee&fff\\
\hline
A&\multicolumn{3}{+}{C}&E&F\\
\multicolumn{2}{|l}{ab}&c&d&e&f\\
\cline{1-3}\cline{6-6}
aaa&bbb&ccc&ddd  &eee&fff\\\hline
\end{tabular}

\begin{tabular} {| >{\large 1}c <{x}| L > {\large\itshape 3}c <{z}|}
\hline A&B&C\\\hline 100&10 &1\\\hline
\end{tabular}


\begin{tabular} {| >{\large 1}c <{x}| L > {\large\itshape 3}x <{z}|}
\hline A&B&C\\\hline 100&10 &1
\end{tabular}

Preview is below. Currently, each table is as wide as the current page. This is a bad thing, it should be arranged in a future version.

four tables

This is the XML translation of the first table. Note how the first two arguments {5cm}[b] are translated. Note also the preamble: *{4}{_c|}. This means a sequence, repeated for times, of a right-aligned cell, a left-aligned cell, a centered cell and a cell with a vertical rule after it. The table is terminated by a \\, this one is not necessary.

<table vpos='b' width='142.26378pt' rend='inline'>
<row><cell halign='right'>a1</cell>
<cell halign='left'>a2</cell>
<cell halign='center'>a3x</cell>
<cell halign='center' right-border='true'>a4</cell>
<cell halign='left'>b1</cell>
<cell halign='center'>b2x</cell>
<cell halign='center' right-border='true'>b3</cell>
<cell halign='right'>b4</cell>
<cell halign='left'>c1</cell>
<cell halign='center'>c2x</cell>
<cell halign='center' right-border='true'>c3</cell>
<cell halign='right'>c4</cell>
<cell halign='left'>d1</cell>
<cell halign='center'>d2x</cell>
<cell halign='center' right-border='true'>d3</cell>
<cell>d4</cell>
</row><row><cell halign='right'>Wa1</cell>
<cell halign='left'>Wa2</cell>
<cell halign='center'>Wa3x</cell>
<cell halign='center' right-border='true'>Wa4</cell>
<cell halign='left'>Wb1</cell>
<cell halign='center'>Wb2x</cell>
<cell halign='center' right-border='true'>Wb3</cell>
<cell halign='right'>Wb4</cell>
<cell halign='left'>Wc1</cell>
<cell halign='center'>Wc2x</cell>
<cell halign='center' right-border='true'>Wc3</cell>
<cell halign='right'>Wc4</cell>
<cell halign='left'>Wd1</cell>
<cell halign='center'>Wd2x</cell>
<cell halign='center' right-border='true'>Wd3</cell>
<cell>Wd4</cell>
</row></table>

This is the translation of the third table. The preamble of the table is something like |c|l|c|, indicating a centered row, a left-aligned row and a centered row. There are four vertical rules, the first two ones are attached to the first cell, and after that, there is a rule on the right of each cell. The specification of the second cell is L, and, after expansion, >{\large\bfseries 2}l <{y}, so that a B is replaced by \large\bfseries 2By. Remember that each cell is translated in a group, so that the scopr of the \large\bfseries is limited to a single cell.

In the example we can see that \hline produces an horizontal ruule by adding an attribute to the row that preceeds it (the \hline at the start of the table induces a second rule for the first row).

<table rend='inline'>
 <row bottom-border='true' top-border='true'>
  <cell left-border='true' halign='center' right-border='true'><hi rend='large1'>1Ax</hi></cell>
  <cell halign='left' right-border='true'><hi rend='large1'></hi><hi rend='large1'><hi rend='bold'>2By</hi></hi></cell>
  <cell halign='center' right-border='true'><hi rend='large1'></hi><hi rend='large1'><hi rend='it'>3Cz</hi></hi></cell>
 </row>
 <row bottom-border='true'>
  <cell left-border='true' halign='center' right-border='true'><hi rend='large1'>1100x</hi></cell>
  <cell halign='left' right-border='true'><hi rend='large1'></hi><hi rend='large1'><hi rend='bold'>210y</hi></hi></cell>
  <cell halign='center' right-border='true'><hi rend='large1'></hi><hi rend='large1'><hi rend='it'>31z</hi></hi></cell>
</row></table>

This is the fourth table. It is like the table above, without the final \\\hline. As you can see, the end of a cell is obtained when the next character is either & (and the cell is followed by another cell), or a \\ command (and this means the end of a complete row), or, as in this case, a \\end command. In this case, we have to insert the <{} material, and the \end token.

The specifications of the last column are >{\large\itshape 3}x <{z}|. If we replace x by its value, we get >{\large\itshape 3}>{b}c<{a}<{z}| and this is the same as >{b\large\itshape 3}c<{za}|. This strange behaviour is explained in the array.syt documentation.

<table rend='inline'>
 <row bottom-border='true' top-border='true'>
  <cell left-border='true' halign='center' right-border='true'><hi rend='large1'>1Ax</hi></cell>
  <cell halign='left' right-border='true'><hi rend='large1'></hi><hi rend='large1'><hi rend='bold'>2By</hi></hi></cell>
  <cell halign='center' right-border='true'>b<hi rend='large1'></hi><hi rend='large1'><hi rend='it'>3Cza</hi></hi></cell>
 </row>
 <row>
  <cell left-border='true' halign='center' right-border='true'><hi rend='large1'>1100x</hi></cell>
  <cell halign='left' right-border='true'><hi rend='large1'></hi><hi rend='large1'><hi rend='bold'>210y</hi></hi></cell>
  <cell halign='center' right-border='true'>b<hi rend='large1'></hi><hi rend='large1'><hi rend='it'>31za</hi></hi></cell>
 </row>
</table>

This is now the second table. Its preamble is|ll|rr|cc|, this means two left-align columns, two right-aligned columns, and two centered columns, with four vertical rules. The table contains three \hline, hence three horizontal rules.

The table contains \multicolumn{2}{|l}{ab} at the start of row 4. This means that a cell spans two coumns. Ths preamble |ll| is replaced by |l, this means an interruption of the second vertical rule. The quantity ab is translated (inside a group), an put in this cell.

The table contains \multicolumn{3}{+}{C} in row 3. We have something that spans three rows, thus removing l|rr| from the preamble, replacing it by +. This is handled like a normal preamble (but for one column only), and here is >{B}l <{D}|. In fact, since the cell contains C, it is as if you said \multicolumn{3}{l|}{BCD}. Normally, the vertical rule implied by the bar should span the whole table. The hole is strange.

The table contains also a \cline{1-3}\cline{6-6} instead of a \hline. This indicates a horizontal rule that spans columns 1, 2, 3 and 6 (hence column 4 and 5 are omitted). In the translation, a bottom-border attribute is used for each cell, instead of a unique attribute for the row. Note that, in the example, there is a cell that spans columns 1 and 2, so that only three cells are marked. If you had said \cline{1-1}\cline{4-6}, there would be a problem.

<table rend='inline'>
 <row top-border='true'>
  <cell left-border='true' halign='left'>a</cell>
  <cell halign='left' right-border='true'>b</cell>
  <cell halign='right'>c</cell>
  <cell halign='right' right-border='true'>d</cell>
  <cell halign='center'>e</cell>
  <cell halign='center' right-border='true'>f</cell>
 </row>
 <row bottom-border='true'>
  <cell left-border='true' halign='left'>aaa</cell>
  <cell halign='left' right-border='true'>bbb</cell>
  <cell halign='right'>ccc</cell>
  <cell halign='right' right-border='true'>ddd</cell>
  <cell halign='center'>eee</cell>
  <cell halign='center' right-border='true'>fff</cell>
 </row>
 <row>
  <cell left-border='true' halign='left'>A</cell>
  <cell halign='left' right-border='true' cols='3'>BCD</cell>
  <cell halign='center'>E</cell>
  <cell halign='center' right-border='true'>F</cell>
 </row>
 <row>
  <cell bottom-border='true' left-border='true' halign='left' cols='2'>ab</cell>
  <cell bottom-border='true' halign='right'>c</cell>
  <cell halign='right' right-border='true'>d</cell>
  <cell halign='center'>e</cell>
  <cell bottom-border='true' halign='center' right-border='true'>f</cell>
 </row>
 <row bottom-border='true'>
  <cell left-border='true' halign='left'>aaa</cell>
  <cell halign='left' right-border='true'>bbb</cell>
  <cell halign='right'>ccc</cell>
  <cell halign='right' right-border='true'>ddd</cell>
  <cell halign='center'>eee</cell>
  <cell halign='center' right-border='true'>fff</cell>
 </row>
</table>

Valid XHTML 1.0 Strict back to home page © INRIA 2005, 2006 Last modified $Date: 2008/12/05 18:23:46 $