Repository navigation
compiler(math): intertext math, nested $ in \text, \pod, \allowbreak (#791) - #797
Merged
Merged
Conversation
…791) Fixes 4 pre-existing gaps found while reviewing PR #783: 1. Math inside `\intertext{...}`/`\shortintertext{...}` was silently flattened to plain text: `inlines_from_tokens` (the general text-mode inline parser also used by headings, captions and style arguments) had no `$...$`/`\(...\)`/`\[...\]` handling at all — the delimiters fell into a catch-all and vanished. Added `flat_math`, mirroring the main token loop's math-shift handling (including `$$...$$` display), with a brace-depth-aware close scan and an unclosed-delimiter diagnostic. 2. `$..$` inside `\text{}` inside inline math broke the parse: `required_text_group`/`required_text_group_styled` in `math.rs` already supported a nested `$` correctly, but the *outer* `dollar_math` (and its `\(...\)`/`\[...\]` siblings, plus the new `flat_math`) scan closed the outer formula at the first `$`/`\)`/`\]` regardless of what was inside `\text{}`'s braces. Added selective brace-depth tracking: a delimiter is only suppressed inside a group opened immediately by one of the six text-mode-switching commands (`text`, `textit`, `textrm`, `textnormal`, `mbox`, `hbox` — verified against `math.rs`'s actual dispatch, not assumed), never for ordinary math grouping (`x^{...}`, `\frac{...}{...}`). An earlier version of this fix tracked depth for every `{`, which silently changed a pre-existing recovery diagnostic for an unrelated, unclosed-ordinary-brace fixture; caught by running the FULL test suite (not a filtered subset) before publishing, and fixed before this push — the regression never reached this branch's history. 3. `\pmod` still opened with a fixed 8mu/18mu split regardless of display style, even though a separate, already-merged PR threaded a `display: bool` flag through the math parser specifically to drive this (the old code comment said so explicitly and was stale). Now uses `self.display`: amsmath's real `\if@display\mkern18mu\else\mkern8mu\fi`, kernel always 18mu. `\pod` itself had no dispatch arm at all (unknown-command) — implemented it too: amsmath-gated like `\mod`, `(arg)` with no "mod" text and no leading 6mu, same display/inline split as `\pmod`. 4. `\allowbreak` had no math-mode dispatch arm (unknown-command inside `$...$`), despite existing in text mode. The math layout has no breakpoint concept (a formula lays out as one unbreakable box), so this is recognised as a documented, layout-neutral no-op: a zero-width space atom that `atom_class` skips like any other kern, byte-identical widths with or without it. Regenerated `docs/user/compiler.md`, both `supported-latex.json` copies and `supported/coverage.md` via `render_supported_latex.sh` (new `pod`/ `allowbreak` inventory rows), since `\pod` and math `\allowbreak` are now real dispatch arms `tests/supported_latex.rs` checks for. Tests: `cargo test --lib` in `crates/compiler`: 436 passed, 0 failed (8 new: intertext-math, nested-delimiter x2 regression-fix pair, pmod-display, pod x2, allowbreak, plus the two selective-brace-tracking regression tests). Full `cargo test` (every binary, not a filtered subset): all green, including `recovery_evidence_is_current` (the committed snapshot needed no regeneration — the final fix is byte-identical to pre-existing behavior outside the six text-switching commands). Independently re-run in this exact worktree from this commit. Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane math-gaps-791, slices 1-2) Commit-Executor: daniel-muse-lead (Claude Sonnet — the lane's sandbox could not reach this worktree's git metadata to commit itself; verified and committed the lane's working-tree diff directly, unmodified)
Contributor
Author
|
Commander (daniel-parent): the independent review returned APPROVE. It was a fresh read-only Opus review.
Follow-ups, filed separately and not blocking: math inside |
d-q222
added a commit
that referenced
this pull request
Sep 17, 2026
#797 gave \allowbreak its math-mode inventory description; the completion test still expected the old '\penalty0' detail and failed on main CI (45ddaef). CompletionTests passes locally. Commit-Executor: daniel-parent Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
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.
Fixes #791: 4 pre-existing gaps found while reviewing PR #783.
What was wrong
\intertext{...}/\shortintertext{...}was silentlyflattened to plain text — the general text-mode inline parser
(
inlines_from_tokens, also used by headings/captions/style arguments)had no
$...$/\(...\)/\[...\]handling at all.$..$inside\text{}inside inline math broke the parse —math.rs's text-group reader already supported this correctly, but theouter scan that finds where a
$...$/\(...\)/\[...\]region endsclosed at the first inner delimiter regardless of what was inside
\text{}'s braces.\pmodignored display style even though a separate PR had alreadythreaded a
display: boolthrough the math parser specifically todrive this (the old code comment said so and was stale).
\poditself was entirely unimplemented.
\allowbreakhad no math-mode dispatch arm at all (unknown-commandinside
$...$), despite existing in text mode.The fixes
flat_mathtoinlines_from_tokens, mirroring the main tokenloop's math-shift handling.
(
dollar_math,paren_math,bracket_math,flat_math): a delimiteris only suppressed inside a group opened immediately by one of the six
text-mode-switching commands (
text,textit,textrm,textnormal,mbox,hbox), never for ordinary math grouping likex^{...}.\pmodnow readsself.displayfor amsmath's real\if@display\mkern18mu\else\mkern8mu\fi.\podimplemented: samepackage gate and display split as
\pmod, but(arg)with no "mod"text.
\allowbreakin math is a documented, layout-neutral no-op (the mathlayout has no breakpoint concept — a formula is one unbreakable box).
A regression caught before it ever reached this branch
An earlier version of fix #2 tracked brace depth for every
{, whichsilently changed an existing recovery-diagnostic fixture for an unrelated,
already-broken (unclosed ordinary brace) case. Caught by running the
full
cargo testsuite (not a filtered subset) before publishing —the fix was corrected to only track depth inside the six specific
text-switching commands before this ever reached the branch history.
Tests
cargo test --libincrates/compiler: 436 passed, 0 failed (8 new).Full
cargo test(every binary, not a filtered subset): all green,including
recovery_evidence_is_current(no snapshot regen needed — thefinal fix is byte-identical to pre-existing behavior outside the six
text-switching commands). Independently re-run in the exact worktree this
was published from, not just the authoring lane's self-report.
Provenance
Muse lane
math-gaps-791(muse-spark-1.3-contributor), slices 1-2 —slice 1 implemented all 4 fixes, slice 2 fixed the brace-depth regression
I found during independent full-suite verification. I reviewed and
independently re-ran everything before publishing; full trailers in the
commit.
🤖 Generated with Claude Code