An undefined code environment no longer swallows the document - #226
Merged
Conversation
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>
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.
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 inopens math mode, and the scan then runs past the environment's own
\endlookingfor the closing
$, eating the rest of the document with it. Againstmaintheminimal case does not merely lose text, it fails outright:
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, itis 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
\endmust be in the character buffer, and nopending token list may hold an
\endof its own. A captured body (a minipage, afloat, a beamer column) carries its
\endin the lists, and reading the bufferthere 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
jlcodebodies arrive through a token list, so the buffer path never fires — andstays open. This is the defence, not that paper's fix.
🤖 Generated with Claude Code