Skip to content

An undefined code environment no longer swallows the document - #226

Merged
tannevaled merged 1 commit into
mainfrom
undefined-env-code
Sep 4, 2026
Merged

An undefined code environment no longer swallows the document#226
tannevaled merged 1 commit into
mainfrom
undefined-env-code

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

An undefined environment's body is typeset with the ordinary category codes. Right
for a prose wrapper, ruinous for a code block: a lone $ — as in

path = "$write_dir/therm_comp_MPI/"

opens math mode, and the scan then runs past the environment's own \end looking
for the closing $, eating the rest of the document with it. Against main the
minimal case does not merely lose text, it fails outright:

math error … texmath: unknown command \endjlcode

The rule

The test is the imbalance itself: prose does not carry an odd number of math
shifts, code does.
When the body between \begin{env} and \end{env} has one, it
is read raw and set as a verbatim block. A balanced body keeps exactly the behaviour
it had — a prose environment is still prose, its maths still rendered (both are
tested).

Two guards keep it narrow: the \end must be in the character buffer, and no
pending token list may hold an \end of its own. A captured body (a minipage, a
float, a beamer column) carries its \end in the lists, and reading the buffer
there would copy the document that follows — the mistake #214 fixed.

Measured

No corpus movement: 516 pages of error before and after, over the 157 arXiv
papers with a tectonic reference. I am landing it on the strength of the
reproduction, not of a number.

The paper that led me here (#225) reaches this failure by another route — its
jlcode bodies arrive through a token list, so the buffer path never fires — and
stays open. This is the defence, not that paper's fix.

🤖 Generated with Claude Code

An undefined environment's body is typeset with the ordinary category codes. That
is right for a prose wrapper and ruinous for a code block: a lone $ — as in

	path = "$write_dir/therm_comp_MPI/"

opens math mode, and the scan then runs PAST the environment's own \end looking for
the closing $, eating the rest of the document with it. In a minimal case the text
after the block simply disappears; against main the run does not even survive, it
fails with "math error … texmath: unknown command \endjlcode".

The test is the imbalance itself: prose does not carry an odd number of math
shifts, code does. When the body between \begin{env} and \end{env} has one, it is
read raw and set as a verbatim block, and a balanced body keeps exactly the
behaviour it had — a prose environment is still prose, its maths still rendered.

Two guards keep it narrow. The \end must be in the character buffer, and no pending
token list may hold an \end of its own: a captured body (a minipage, a float, a
beamer column) carries its \end in the lists, and reading the buffer there would
copy the document that follows — the mistake #214 fixed.

No corpus movement: 516 pages of error before and after over the 157 arXiv papers.
The one paper that shows this failure (#225) reaches it by another route — its
jlcode bodies arrive through a token list, so the buffer path never fires — and is
still open. This is the defence, not that paper's fix.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 840a5f2 into main Sep 4, 2026
18 checks passed
@tannevaled
tannevaled deleted the undefined-env-code branch September 4, 2026 21:38
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