Skip to content

engine: a table cell keeps its nested environments whole - #171

Merged
tannevaled merged 1 commit into
mainfrom
tabular-nested-env
Aug 31, 2026
Merged

engine: a table cell keeps its nested environments whole#171
tannevaled merged 1 commit into
mainfrom
tabular-nested-env

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

collectTabularBody tracked brace depth — and a matrix is not braced here. It is the same fault #153 fixed in the maths alignment scanner, in the scanner next door:

\begin{tabular}{ c c }
 $\begin{matrix} a & b \end{matrix}$ & $\begin{bmatrix} c & d \end{bmatrix}$ \\

became four cells of fragments, and the maths layer refused each one:

texmath: unexpected "}"   "\begin {matrix} d_{\ell _2}}"

224 of the corpus's dropped formulas are that, all of them tables of matrices.

TeX protects a nested alignment with the brace \@array opens (latex.ltx:12101, reached through amsmath's \env@matrix), counted in align_state (tex.web §6738-6742, §7259-7264). This engine never expands \matrix, so the environment is counted instead, and \bgroup/\egroup count as the braces they are (§7492-7493).

A nested tabular was broken the same way and is fixed with it: its \end closed the outer table, so everything after it was swallowed. Its test fails on main too.

Measured — 200 arXiv papers, 200 beamer talks

15 documents change and 7 repaginate, for +5094 glyphs:

avant après tectonic
5 14 14
41 35 34
29 30 29
33 32 34

The page error against the 157 tectonic renders falls 670 → 656. beamer does not move by one glyph.

collectTabularBody tracked brace depth, and a matrix is not braced here — the same
fault #153 fixed in the maths alignment scanner, in the scanner next door. So

	$\begin{matrix} a & b \end{matrix}$ & $\begin{bmatrix} c & d \end{bmatrix}$

became four cells of fragments, and the maths layer refused each one:

	texmath: unexpected "}"   "\begin {matrix} d_{\ell _2}}"

224 of the corpus's dropped formulas are that, all of them tables of matrices.

TeX protects a nested alignment with the brace \@array opens (latex.ltx:12101,
reached through amsmath's \env@matrix), counted in align_state (tex.web §6738-6742,
§7259-7264). This engine never expands \matrix, so the environment is counted
instead, and \bgroup/\egroup count as the braces they are (§7492-7493).

A nested tabular was broken the same way and is fixed with it: its \end closed the
OUTER table, so everything after it was swallowed.

Measured over 200 arXiv papers and 200 beamer talks: 15 documents change and 7
repaginate, for +5094 glyphs. One goes 5 -> 14 pages, exactly what tectonic renders;
another 41 -> 35 against 34. The page error against the 157 tectonic renders falls
670 -> 656. beamer does not move by one glyph.
@tannevaled
tannevaled merged commit 6a0b323 into main Aug 31, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant