engine: the cell scanner counts braces the way align_state does - #154
Merged
Conversation
#153 said "a matrix is not braced". That is true of this engine and FALSE of TeX, and the difference is worth stating where the code is read. tex.web §6738-6742: align_state is increased by 1 for a { and decreased by 1 for a }, and §7259-7264: an alignment entry ends at a tab or \cr only when align_state is back where it started. A nested matrix is protected by a real brace, an implicit one: \newenvironment{bmatrix}{\left[\env@matrix}{\endmatrix\right]} amsmath.sty:1082 \def\env@matrix{…\array{*\c@MaxMatrixCols c}} amsmath.sty:1058 \def\@array[#1]#2{…\bgroup …} latex.ltx:12101 This engine never expands \bmatrix — the maths layer parses the source text itself — so that \bgroup never arrives and the counter cannot see it. Counting the environment is the same protection by another road, and the comment now says so. The reading also turned up something the code did not do: tex.web §7492-7493 counts IMPLICIT braces, \bgroup and \egroup, in align_state. The cell scanner looked only at category-1 and -2 characters, so a & inside \bgroup…\egroup cut a cell that TeX would not have cut. implicitChar is what the box scanner already uses for \bgroup; the cell scanner now uses it too. Measured over 200 arXiv papers and 200 beamer talks: not one document changes — the corpus does not exercise it. The unit test does, on the scanner directly: with \bgroup x & y\egroup a row has two cells, and had three.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#153 said "a matrix is not braced". That is true of this engine and false of TeX, and the difference is worth stating where the code is read.
A nested matrix is protected by a brace in TeX — an implicit one:
This engine never expands
\bmatrix— the maths layer parses the source text itself — so that\bgroupnever arrives and the counter cannot see it. Counting the environment is the same protection by another road, and the comment now says that instead of a false statement about TeX.The reading also turned up something the code did not do. tex.web §7492-7493 counts implicit braces —
\bgroupand\egroup— inalign_state. The cell scanner looked only at category-1 and -2 characters, so a&inside\bgroup…\egroupcut a cell TeX would not have cut.implicitCharis what the box scanner already uses for\bgroup; the cell scanner now uses it too.Measured — 200 arXiv papers, 200 beamer talks
Not one document changes. The corpus does not exercise it; this plugs a gap rather than fixing a visible defect, like #117 before it.
Test
The unit test drives the scanner directly, since
&must carry category 4 for any of this to mean anything (tokenizeTeXmakes it an ordinary character): witha &= \bgroup x & y\egroupa row has two cells, and onmainit has three.