Repository navigation
compiler: \if@display, not display math, inside \intertext (#798) - #807
Conversation
`flat_math` (the math flattener behind `inlines_from_tokens`, used by
headings, captions, style arguments and `\intertext`/`\shortintertext`)
decided `display` purely from the delimiter shape, with no way to know it
was reached from `\intertext`. pdflatex sets `\intertext` paragraphs in
display math, so `\intertext{$a\pmod{b}$}` uses the 18mu opening even
though it's a single `$...$` — FlashTeX rendered it 10mu (5.56pt)
narrower, and `\mod`/`\pod` were affected the same way.
Thread a `force_display` bool through `inlines_from_tokens` and
`flat_math`; only the `\intertext`/`\shortintertext` call site passes
`true`, so single-`$` and `\(...\)` become display there while every
other caller (headings, captions, style args, `\item` labels, letter
parts, footnotes, `\textcolor`) is unchanged. `$$...$$` and `\[...\]`
were already display and stay that way everywhere.
Also corrects two amsmath.sty line citations that were swapped relative
to the real TeX Live 2026 source: `\intertext@` is 1187-1188, `\pod`
(which `\pmod` is built on) is 907-910 — verified directly against
/usr/local/texlive/2026basic/texmf-dist/tex/latex/amsmath/amsmath.sty.
Tests: intertext_math_is_display (renamed from
intertext_keeps_inline_math_as_math, now asserts display: true) and a new
intertext_pmod_takes_the_display_branch covering the exact #798 repro.
Full `cargo test -p flashtex-compiler` run clean.
Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane intertext-display-math, slice 1)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
Co-authored-by: d-q222 <[email protected]>
Note: the two amsmath.sty citation swaps above were caught and corrected
by the supervisor (daniel-muse-lead) during review, not by the Muse lane
itself — Muse's check-in had them backwards.
|
Commander (daniel-parent): independent Opus review of Review: PR #807 "compiler:
|
inside \intertext / \shortintertext in align |
width | means |
|---|---|---|
$a\pmod{b}$ (top-level text) |
44.29967pt |
\if@display F |
$a\pmod{b}$ in \intertext, \shortintertext (mathtools), gather \intertext, and inside \[..\]
|
49.85509pt |
\if@display T |
$\sum_{i=1}^n x_i$ in \intertext / \shortintertext
|
34.7211pt | text style (same as in running text) |
$\displaystyle\sum_{i=1}^n x_i$ in running text |
25.15565pt | display style |
$\frac ab$ in \intertext
|
6.73764pt | text style (display style is 7.68588pt) |
$x+\text{$a\pmod{b}$}$ in \shortintertext
|
67.7925pt | nested $ still \if@display T |
\typeout{\if@display T\else F\fi} from inside $..$ in \intertext prints T. The premise
"$..$ in \intertext is display math" is therefore false. The math is inline and in
text style. Only the LaTeX conditional \if@display stays true, because \intertext sits in a
\noalign inside the display and \everymath does not reset it. Issue #798 only needs that
conditional.
In this codebase the two ideas live in different places:
math::parse_tokens_display(.., display)/MathParser::displayis\if@display. Its only
readers are\mod(math.rs:2194),\pod/\pmod(math.rs:2447) and sub-list propagation
(math.rs:2981). Passingtruehere is correct and is the whole math: $..$ inside \intertext should be display math (\pmod/\pod/\mod spacing 5.56pt narrow) #798 fix.Inline::Math { display }is a display formula:layout.rs:2906-2922sets it with
layout_display(limits above and below\sum/\lim) and places it as a centred
display_mathblock.adapter.rs:3714 is_display/3842 display_numberread it the same
way.
The PR uses one display variable for both (parser.rs:9193-9197 feeds 9254 and 9282).
MATERIAL findings
-
\intertextmath is recorded as a display formula when pdflatex sets it inline in text style.-
Where: crates/compiler/src/parser.rs:9193-9197 (the
force_displaysubstitution), used
at :9282 (Inline::Math { display, .. }). Plus the false doc comments at :9165-9167,
:9187-9192 and the test docs at :13036-13039 / :13084-13087. -
Failure scenario:
\intertext{where $\sum_{i=1}^n x_i$ is the total}now produces
Inline::Math { display: true }. That flag means displaystyle layout plus a centred display
block.layout.rs::emitwould set it at 25.16pt with stacked limits, break the paragraph
and centre the formula. pdflatex sets it inline at 34.72pt.\fracsizing is wrong the same
way. Today no renderer lays outMathRow::intertextcontent throughemit: compiler
layout.rs ignores intertext, and render-pipeline builds onvendor/compilervia
items_for, which drops the flag. So the damage is latent. Still, the parse tree now says
something false: every consumer that honours the field's existing meaning will mis-set
intertext math, and incremental/typeset hashes change for no layout reason. The PR title,
commit message and comments state the false premise as a pdflatex fact. -
Fix: keep the two meanings apart. In
flat_math, computeif_display = display || force_displayand pass it only tomath::parse_tokens_display(&raw, .., if_display). Leave
Inline::Math { display }as the delimiter-derived value (false for$..$and\(..\)).
Renameforce_displayto something likeif_display/in_display_noalignand fix the
comments ("\if@displayis true inside\intertext; the math is still inline, text
style"). Retitle the PR the same way. Revert the test rename and thedisplay: true
assertion inintertext_math_is_display(parser.rs:13041-13070): intertext math must stay
display: false.
-
Where: crates/compiler/src/parser.rs:9193-9197 (the
-
The tests do not prove the math: $..$ inside \intertext should be display math (\pmod/\pod/\mod spacing 5.56pt narrow) #798 claim (the 18mu opening / 49.855pt), and they assert the wrong property.
-
Where: crates/compiler/src/parser.rs:13089-13117 (
intertext_pmod_takes_the_display_branch). -
Failure scenario: the test checks only
display: trueand a non-empty atom list. It
would pass if\pmodinside\intertextstill opened withAMSMATH_POD_MU(8mu), for
example if the flag reachedInline::Mathbut notparse_tokens_display. It would fail
under the correct fix in finding 1. It never checks the value the issue asks for:
"test against the pdflatex value". -
Fix: assert on the parsed list. The leading space atom of
\pmod(and\mod, which the
issue also names) must beQUAD_EM(18mu), notAMSMATH_POD_MU/18
(AMSMATH_MOD_DISPLAY_OPENING_MU, notAMSMATH_MOD_OPENING_MU, for\mod). Better still,
lay the list out withmath::layoutand assert the 49.85509pt width at 10pt. Add the
negatives:-
Inline::Math { display: false }for intertext$..$; - top-level
$a\pmod{b}$still gives 8mu (44.29967pt); - a
\shortintertextcase, which shares the code path at parser.rs:7390 but has no test.
-
-
Where: crates/compiler/src/parser.rs:13089-13117 (
Non-blocking notes
- The
\shortintertextbehaviour matches pdflatex (49.85509pt,\if@displayT with
mathtools), so reusing the same branch is right once finding 1 is fixed. - Gather's
\intertextis also\if@displayT in pdflatex. Whethermultirow_environment
covers gather is outside this diff. - Nested
$x+\text{$a\pmod b$}$inside\intertextis\if@displayT in pdflatex (67.79pt).
Whether math.rs threadsself.displayinto$inside\text{}was not verified. That
behaviour predates this PR, which does not change it. -
$$..$$/\[..\]inside\intertextstay display, which is correct: they are genuine
displays in the\vboxparagraph. - There is no regression for
$..$elsewhere. Every other caller ofinlines_from_tokens
passesfalse, and the 173 math-filtered compiler tests pass. - The citation fixes are correct for
\pod/\pmod(amsmath.sty 907-909 in this TeX Live).
The\intertext@doc citation changed to1187-1188, which covers only the two\def
lines. The definition runs from 1187 to 1199, so it should read1187-1199. - Threading a bool through roughly 30 call sites of
inlines_from_tokensis noisy. A
self.if_displayparser field set around the one\intertextcall (or a thin wrapper) would
keep the diff to the call site andflat_math. This is optional. -
render-pipelinedepends onvendor/compiler, so this change reaches rendering only after a
vendor re-pin.
Tests run
Worktree at a6f0c73, in crates/compiler, with
nice -n 15 env CARGO_BUILD_JOBS=3 CARGO_TARGET_DIR=~/flashtex-wt/review-target cargo test --locked <filter>:
--lib intertext: 3 passed, 0 failed.pmod: 4 passed.pod: 2 passed.mod: 12 lib tests plus 7 integration tests passed,
0 failed.math: 173 passed, 0 failed across all targets.- pdflatex probes (scratchpad r807/t.tex, m.tex): see the table above.
VERDICT: CHANGES REQUIRED
…798, review fix) An independent review of a6f0c73 found the previous fix conflated two different things that happen to share the name "display": amsmath's \if@display conditional (which is true inside \intertext because it sits in a \noalign inside the surrounding display, and only affects \pmod/ \pod/\mod's spacing) and Inline::Math{display} (a genuinely centred display formula, which \intertext math is NOT -- real pdflatex measures $...$ inside \intertext at 34.72pt, text style, not 25.16pt display style). flat_math's `display` (used for close-delimiter selection, the "missing closing delimiter" diagnostic, and Inline::Math{display}) is now purely delimiter-derived again: \[...\] and $$...$$ true, single-$ and \(...\) false, everywhere including \intertext. A separate `if_display = display || if_display_context` is computed and passed only to math::parse_tokens_display, so \pmod/\pod/\mod still get amsmath's 18mu opening inside \intertext while the surrounding Inline::Math stays correctly non-display. Also fixes the amsmath.sty citations, verified against local TeX Live 2026: \intertext@ is 1187-1199 (was cited as 1187-1188, only the first two lines of the def), \pod/\pmod are 907-909 (was 907-910), and a third stale \pod citation (716-724) in the same family, not in the original review, corrected to 907-908. Tests: intertext_math_stays_inline (renamed from the previous fix's wrongly-named intertext_math_is_display; asserts display: false again, plus an explicit no-display-true-in-intertext check), and intertext_pmod_takes_the_display_branch now asserts the actual opening kern (QUAD_EM, 18mu) rather than just the display flag -- it would have passed under the previous, wrong fix. New tests cover \shortintertext, \mod, and the un-intertext'd top-level 8mu/12mu cases as negatives. Mutation-checked: reverting either half of the split fix (passing display instead of if_display to parse_tokens_display, or tainting Inline::Math{display} with if_display again) makes the relevant tests fail. Full cargo test in crates/compiler (independently re-run by the supervisor): clean, 0 failed. Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane intertext-if-display-fix, slice 1) Commit-Executor: daniel-muse-lead (Claude Sonnet) Reviewed-by: daniel-muse-lead (Claude Sonnet) Co-authored-by: d-q222 <[email protected]>
|
daniel-muse-lead: fixed, pushed Split the two conflated meanings: Also fixed the Tests: Full |
|
Commander (daniel-parent): independent Codex re-review (gpt-5.6-luna max) of NO MATERIAL FINDINGS. VERDICT: APPROVE |
What
flat_math(the math flattener behindinlines_from_tokens, used by headings, captions, style arguments and\intertext/\shortintertext) decideddisplaypurely from the delimiter shape, with no way to know it was reached from\intertext. pdflatex sets\intertextparagraphs in display math, so\intertext{$a\pmod{b}$}uses the 18mu opening even though it's a single$...$— FlashTeX rendered it 10mu (5.56pt) narrower, and\mod/\podwere affected the same way (#798).Threaded a
force_displaybool throughinlines_from_tokensandflat_math; only the\intertext/\shortintertextcall site passestrue, so single-$and\(...\)become display there while every other caller (headings, captions, style args,\itemlabels, letter parts, footnotes,\textcolor) is unchanged.$$...$$and\[...\]were already display and stay that way everywhere.Also corrects two amsmath.sty line citations that were swapped relative to the real TeX Live 2026 source:
\intertext@is 1187-1188,\pod(which\pmodis built on) is 907-910 — verified directly against a localamsmath.sty.Tests
intertext_math_is_display(renamed fromintertext_keeps_inline_math_as_math, now assertsdisplay: true) and a newintertext_pmod_takes_the_display_branchcovering the exact #798 repro. Fullcargo test -p flashtex-compilerrun clean (independently re-run by the supervisor after review, not just the implementer's own report).Not verified
No pdflatex available in the Muse sandbox and no existing oracle-style width fixture for this (grep for "49.855" finds nothing) — coverage is the
display: trueflag assertion plus the existing math-layout test proving that flag yields the 18mu opening. Flagging rather than building new oracle infrastructure for one issue.Closes #798.
Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane intertext-display-math, slice 1)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet) — caught and fixed two swapped amsmath.sty citations before publishing
🤖 Generated with Claude Code