GNU TeXmacsUser manualReferenceAboutEnglish
Editing tables

1.Representation

A table is a table node whose children are row nodes, whose children are cell nodes. Formatting is attached by wrapping any of these nodes in a tformat node: all children of a tformat except the last one are formatting instructions, and the last one is the formatted table, row or cell (which may itself be a tformat). Two kinds of instructions exist:

twith

(var, val) sets a property of the whole table, such as table-width or table-min-rows.

cwith

(i1, i2, j1, j2, var, val) sets a cell property for the rows i1 to i2 and the columns j1 to j2. Positive indices count from 1 at the top or left, negative ones from -1 at the bottom or right, so that (1, -1, 2, 2) means “the whole second column” whatever the number of rows.

Tabular environments of the style files (tabular, matrix, eqnarray*, …) are macros whose body contains a tformat applied to their argument; they supply default formats.

Inside

Edit/Modify/edit_table.cpp

, rows and columns are numbered from 0, and the cwith indices are converted with with_decode (positive index \(k\) becomes \(k - 1\), negative index \(- k\) becomes \(n - k\)). The public routines exported to Scheme use the 1-based convention of the format.

2.Finding the table

All public routines start from the cursor. The protected helpers are

search_table ()

The innermost table around the cursor.

search_table (row, col)

The same, and the coordinates of the cell containing the cursor (skipping tformat nodes around rows and cells).

search_format (), search_format (row, col)

The tformat around that table, if there is one. The second variant inserts an empty tformat when there is none, so that the caller can add formats.

search_row (fp, row), search_cell (fp, row, col)

The paths of a row and of the content of a cell (inside the cell node).

Most public routines call search_format (row, col) and silently do nothing when the cursor is not inside a table.

3.Formats

table_get_format (fp)

All formats which apply to the table: the inherited cell-format of the environment followed by the instructions of the tformat at fp.

table_set_format, table_get_format, table_del_format

For a table property (twith): set replaces an existing instruction, get returns the last one which applies or the environment value.

The same with I1, J1, I2, J2

For cell properties (cwith) over a rectangle. Getting returns the value of the last instruction whose rectangle contains the requested one; deleting removes the instructions whose rectangle is contained in it.

table_individualize (fp, var)

Splits every cwith for var which covers several cells into one instruction per cell; used before decorating.

table_format_center (fp, row, col)

Rewrites all cwith indices so that rows and columns before the cursor are counted from the start and those after it from the end (table-format-center).

The exported routines table_set_format (var, val) and friends (table-set-format, …) act on the table around the cursor, and cell_set_format (var, val), cell_get_format and cell_del_format (cell-set-format, …) on the selected cells, or, without a table selection, on the cell, row, column or whole table depending on the cell mode (set_cell_mode, one of cell, row, column, table). When a selection extends to the last row or column, the corresponding index is written as -1, so that the format also applies to rows or columns added later. After each change of a cell format, table_correct_block_content wraps or unwraps the cell contents in a document according to the cell-block and cell-hyphen properties.

4.Rows, columns and extents

table_insert (fp, row, col, nr_rows, nr_cols) and table_remove (fp, row, col, nr_rows, nr_cols) are the primitives: they insert or remove rows and columns of empty cells and then shift the cwith indices so that every format keeps applying to the same cells. Removing all rows or all columns destroys the table (destroy_table, which also removes an enclosing tabular macro or subtable). On top of them:

table_insert_row (forward), table_insert_column

(table-insert-row, table-insert-column) Insert after or before the current one, within the limits table-max-rows and table-max-cols, and move the cursor there. These are the actions of structured-insert-vertical and structured-insert-horizontal inside tables (

table/table-edit.scm

).

table_remove_row (forward, flag), table_remove_column

Remove the current or a neighbouring row or column, or destroy the table when the minimum (table-min-rows, table-min-cols) would be violated.

table_set_extents (rows, cols)

(table-set-extents) Resize to the given size, clamped to the limits.

table_nr_rows, table_nr_columns, table_which_row, table_which_column, table_which_cells, table_search_cell, table_go_to

Queries and cursor movement, with 1-based indices (negative ones count from the end).

After a change of the shape, table_resize_notify calls the Scheme hook table-resize-notify, which does nothing by default and is overloaded by spreadsheets (

dynamic/calc-table.scm

) to update their cells.

5.Creating tables

Tables are normally created through make: when the macro definition of a tag contains a tformat applied to one of its arguments, make_compound inserts the tag and then calls make_table (1, 1) inside it (see making compound structures). make_table (rows, cols) inserts a tformat around an empty table, enlarges it to the minimal size given by the formats, puts the table in a paragraph of its own when table-hyphen or table-block asks for it, and corrects the block contents. make_subtable (make-subtable) replaces the contents of the current cell by a subtable.

6.Cell spans, subtables and decorations

table_bound (fp, row1, col1, row2, col2) enlarges a rectangle of cells so that it contains every cell which spans into it (cell-row-span, cell-col-span); it is used when moving the cursor and when computing table selections.

table_get_subtable (fp, row1, col1, row2, col2) extracts a rectangle of cells, together with the cwith instructions which apply to it (renumbered relative to the rectangle); this is what is copied when a table selection is copied. table_write_subtable (fp, row, col, subt) writes such a subtable into an existing table at a given position, enlarging the table if needed and shifting the formats of the subtable; pasting a table selection inside a table uses it (see selections and the clipboard). Inside a calc-table, the Scheme function calc-table-renumber adjusts the cell references of a spreadsheet before writing.

Decorations (table_row_decoration, table_column_decoration, table-row-decoration, table-column-decoration) move a neighbouring row or column of cells into the cell-decoration format of the current cells: the cell then displays a small table in which a tmarker stands for its own content.

7.Deletion inside tables

The deletion algorithm of inserting, deleting and making structure calls back_table when the cursor is just outside a table (it moves into the first or last cell) and back_in_table when it is at the border of a cell. The latter removes the current row if it is entirely empty, then the current column if it is entirely empty, then the whole table if all cells are empty (always within the minimum sizes); otherwise it moves to the previous or next cell, and finally out of the table.

8.Pitfalls

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".