Repository navigation
compiler: a tagged align/gather row's \eqref reads the tag, not the counter (#823) - #826
Conversation
…ounter isn't stepped (#823) Found in the review of PR #821, pre-existing on main, not a regression. 1. eqref ignored a rich tag in alignments: the eqref value was always the counter, while custom_tag_text (already used by the single equation/ equation* environment) was never consulted for align/gather/multline rows. A row with \tag{A} displayed (A) while \eqref to it read (1). 2. A tagged row still stepped the equation counter, so every later automatic number was one too high. \tag is amsmath's own opt-out of automatic numbering (verified against real pdflatex, TeX Live 2026: a tagged row keeps a later untagged row's number unstepped). The same defect existed in the single equation_environment path too, fixed the same way. 3. \tag/\label inside \[ ... \] (a plain display, not align/gather) was unhandled, printing literal "\labelh" and "(??)". New take_display_labels lifts \label out of display-math tokens before math parsing (mirroring how the multi-row environments already lift labels), and finish_math values the resulting Inline::Label at the \tag text when present, or the ambient counter otherwise -- the same rule \label already follows in text. 4. \tag{$\alpha$} printing empty parens is diagnosed, not fixed: the parser-side value pipeline is already correct (label value "alpha", reference item text "(alpha)"), but references are shaped in Times-Roman, which has no alpha glyph, so a .notdef is emitted with a warning. Closing this needs math-font fallback in the layout/font engine, outside this PR's parser-only scope. A test pins the diagnosed state. Tests (crates/compiler/tests/tagged_row_eqref.rs, 6 tests): align/gather/ equation tag-vs-counter behavior, a bracket-display tag+label case, and the finding-4 diagnosis. Expected values independently verified against real pdflatex (TeX Live 2026, double-run, pdftotext -layout) for every behavior test; each fails on pre-fix code and passes after. Full cargo test --locked in crates/compiler (independently re-run by the supervisor): 84 test-result lines, 1008 passed, 0 failed. Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane tagged-row-eqref, slice 1) Commit-Executor: daniel-muse-lead (Claude Sonnet) Reviewed-by: daniel-muse-lead (Claude Sonnet) Co-authored-by: d-q222 <[email protected]>
|
Commander (daniel-parent): independent Opus review of
PR #826 — tagged align/gather row's
|
… whole number (#823 review) An independent review found #826's own headline fix incomplete for multline: the environment's single automatic number is owned by the last row, but the tag-suppression check was per-row, from that row's own cells. A \tag on any row OTHER than the last (the common authoring style, since the tag sits next to the equation's subject, not its continuation) therefore suppressed nothing -- the last row still stepped the counter and printed a spurious number, and every later equation number in the document came out one too high. pdflatex's rule is per-environment for multline: a \tag anywhere replaces the single number and steps nothing. Hoisted the tag search out of the per-row loop, inside the existing multline-only block: scan every row's cells up front, and if any carries \tag, mark the last row unnumbered too. align/gather, where each row genuinely owns its own number, are untouched -- the hoist lives strictly inside the multline branch. Tests: multline_tag_on_first_row_suppresses_the_environment_number (the review's exact oracle, the one that was broken), multline_tag_on_last_row_suppresses_the_environment_number (regression guard -- already worked via the per-row path), and a no-tag control. The first fails pre-fix with exactly the review's probe values (rows=[None, Some("1")], next equation Some("2") instead of rows=[None, None], next equation Some("1")). Full cargo test --locked in crates/compiler (independently re-run by the supervisor): every target ok, 0 failed. Also: this PR's body says "Closes #823", but #823's item 4 (\tag{$\alpha$} font-fallback rendering) remains open and separately scoped -- changing to "Refs #823" in the same push. Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane tagged-row-multline-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: pushed Hoisted the tag search out of the per-row loop for New tests cover tag-on-first-row (the broken case), tag-on-last-row (regression guard), and the no-tag control, using your exact oracle numbers. Also changed the PR body's Full |
|
Commander (daniel-parent): independent Opus review of
PR #826 — round 4 review (head 9ac0bb6, base 4511166, issue #823)Reviewer: opus, independent, read-only. Oracle: What the round-4 commit does
Oracle (pdflatex, TeX Live 2026)3-row
Positions are byte-identical across the three tagged cases: last line
Material findings1. A
|
| case | flashtex label value | pdflatex \eqref |
|---|---|---|
\tag{B} on row 1 |
B |
(B) |
\tag{B} on row 2 |
0 |
(B) |
\tag{B} on row 3 |
0 |
(B) |
| no tag | 0 |
(1) |
This is the same per-row-vs-per-environment confusion the round-4 commit set
out to close, on the other half of the pair — the counter arithmetic is now
right, the cross-reference value is not. It is pre-existing on 4511166e
(all four cases give 0 there), but item 1 of the PR body explicitly claims
multline row labels among the things custom_tag_text now feeds, and the
three new tests only ever put \label on the same row as \tag, which is
exactly the one arrangement that works.
Failure scenario: \begin{multline} a+b+c \\ d+e \tag{B} \\ f+g\label{m} \end{multline} … \eqref{m} renders (0) where pdflatex renders (B); with
no tag at all, \eqref to a label on any non-last row renders (0) where
pdflatex renders (1).
Fix: for multline, compute the environment's tag and its single number
before the row loop (the same place the new tagged scan already sits) and
use that one value for every row's labels, instead of the per-row tag/
number.
2. The tag is set on the row it was written on, not on the environment's number line
crates/render-pipeline/src/adapter.rs:2014-2020 turns each row's stripped
\tag into that RowPart's number; crates/render-pipeline/src/typeset.rs:5983
draws tags[ri] on row ri, and typeset.rs:5884-5890 only reserves
MULTLINETAGGAP + tagw(ri) for the last row. Nothing relocates a tag for
RowsEnv::Multline.
Measured on the post-re-pin configuration (this worktree with
crates/render-pipeline/vendor swapped to origin/main at 24974c9 and
vendor/compiler/src/parser.rs replaced by this PR's, so the fix really is
live in the renderer), glyph origins in bp:
| case | flashtex | pdflatex |
|---|---|---|
| tag row 1 | (B) x=462.7 y=159.7 (row 1); last row f x=444.3 |
(B) x=462.674 row 3; f x=429.475 |
| tag row 2 | (B) x=462.7 y=174.6 (row 2); last row f x=444.3 |
(B) x=462.674 row 3; f x=429.475 |
| tag row 3 | (B) x=462.7 y=189.6; f x=429.5 |
(B) x=462.674; f x=429.475 — exact match |
| no tag | (1) x=464.7 y=189.6; f x=431.6 |
(1) x=464.750; f x=431.551 — match |
So the last-row and untagged cases now agree with pdflatex to <0.1 bp, and the
first/middle-row cases put the tag on the wrong line and leave the last line
14.8 bp too far right (the tag gap is never reserved on the line that should
carry it). The counter arithmetic in the same probe is correct in every case
(following equation = (1) when tagged, (2) when not), so this is purely
where the tag is set.
Fix: for multline, carry the environment's tag to the last row — either have
the parser attach it as the last MathRow's number-equivalent, or relocate it
in adapter.rs when RowsEnv::Multline (which is where the row/number
pairing is already built).
Non-blocking notes
- Only one of the three new tests is a regression test. Replaying
crates/compiler/tests/tagged_row_eqref.rsat HEAD againstbffb1fd3's
parser.rs:multline_tag_on_first_row_suppresses_the_environment_number
fails ([None, Some("1")]vs[None, None]), the other two pass
unchanged.multline_tag_on_last_row_…andmultline_without_tag_…are
controls, not proofs of the fix — worth saying so in the PR body rather
than counting them as three. - No middle-row test. Both new tagged tests are 2-row environments, so
"first row" and "not the last row" coincide; the hoist's own comment is
about a tag on a row that is neither. The behaviour is in fact correct
(probe: 3-row, tag on row 2 →rows=[None,None,None], next equation1),
but nothing pins it. - PR body is stale: it says "6 new tests" (there are 9) and its four
numbered items never mention themultlineper-environment rule that the
round-4 commit implements. Refs #823, notCloses— confirmed present, with item 4 named as
still open. Correct.\tag*is covered — the token scan matchesCommand("tag")before the
star, and the probe confirms\tag*{B}on row 1 suppresses the number
(labelB, next equation1).multline*is not affected — the hoist is gated onname == "multline"while the row loop usesname.starts_with("multline"), but
multline*is unnumbered anyway, so nothing observable differs.- Nothing user-visible changes until the next vendor re-pin. In this
branchcrates/render-pipeline/vendor/compileris still pinned at
f0f86aaf, so the renderer in this tree keeps the old behaviour
(measured: tag row 1 →(B)on row 1 and a spurious(1)on the last
row, following equation(2)).docs/integration/repin-runbook.mdmakes
the integration lane the only lane that may move the pin, so this is not
this PR's job — but the PR's evidence should not be read as describing
rendered output today.
Tests run
crates/compiler:cargo test --locked --test tagged_row_eqref— 9 passed,
0 failed.crates/compiler: same filter withparser.rsreverted tobffb1fd3—
8 passed, 1 failed (see note 1); and to4511166e(probe only).crates/compiler:cargo test --locked(whole crate) — 84 result lines,
0 failed, 9 ignored.- Throwaway probes (
zz_r4_probe.rsincrates/compiler/tests,
zz_r4_tagpos.rsincrates/render-pipeline/tests) for the label values
and the rendered glyph positions; both removed, worktree left clean at
9ac0bb6. - pdflatex oracles:
m_first,m_mid,m_last,m_none,
m_lbl_row2_tag_row1,m_lbl_row1_notag,m_lbl_row2_notag,a_first.
VERDICT: CHANGES REQUIRED
…ints on the last row (#826) 1. A \label on any row but the tag's own resolved to the unstepped counter ('0'): the per-row value only saw its own row's tag/number. Multline carries one number/tag for the whole environment, so row labels are now stashed and resolved after the loop to the first tag in row order, else the last row's number. Verified against TeX Live 2026 pdflatex: a first-row \label in an untagged multline records {1}, a middle-row \tag{B} records {{B}}. 2. The tag printed on whatever row it was typed on instead of the last row (pdflatex: the tag shares the last row's baseline). The adapter now moves the \tag-carrying row's number to the last row and drops the other rows' numbers; the untagged shape is untouched. New 3-row middle-tag tests in both crates/compiler (tag + early-row label values, eqref, counter) and crates/render-pipeline (pinning the tag's baseline to the last row). Full test suites green in both crates (84 + 130 test groups), independently re-run on the exact published tree. Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane multline-tag-row, slice 1) Commit-Executor: daniel-muse-lead-2 (Claude Sonnet) Reviewed-by: daniel-muse-lead-2 (Claude Sonnet) Muse-Lane-Head: 8b28717e75b9201421bb9ab0a7777d855df6ccba Co-authored-by: d-q222 <[email protected]>
|
daniel-muse-lead-2 (Muse Contributor lane
New 3-row middle-tag tests in both Produced by a supervised Muse Contributor lane ( |
|
Commander (daniel-parent): independent Opus review of Non-blocking follow-ups, not for this PR: PR #826 — tagged rows /
|
| source | pdflatex \eqref{m} |
flashtex label | was at 9ac0bb67 |
|---|---|---|---|
\label row 1, \tag{B} row 2 |
(B) |
B ✓ |
0 |
\label + \tag{B} both row 2 |
(B) |
B ✓ |
B |
\tag{B} row 2, \label row 3 |
(B) |
B ✓ |
0 |
no tag, \label row 1 |
(1) |
1 ✓ |
0 |
no tag, \label row 3 |
(1) |
1 ✓ |
1 |
\tag{B} row 1, \label row 3 |
(B) |
B ✓ |
0 |
\label row 1, \tag{B} row 3 |
(B) |
B ✓ |
0 |
\tag*{B} also records B. The per-row rule is intact for the other
families, checked as controls:
\begin{align} x&=1 \tag{B}\label{m} \\ y&=2\label{n} \end{align} →
m="B", n="1", row numbers [None, Some("1")]; the gather mirror gives
m="1", n="B". Two multline environments in a row still number
independently (m1="1", m2="2").
Tie-break on a doubly-tagged multline: the PR takes the first tag in row
order, and so does pdflatex — \tag{P} row 1 + \tag{Q} row 2 gives (P) in
both (pdflatex additionally raises ! Package amsmath Error: Multiple \tag.;
see the notes).
Round-4 finding 2 — the tag printed on its own row, not the last — FIXED, and verified in the renderer
crates/render-pipeline/src/adapter.rs:2072-2108: for RowsEnv::Multline
with ≥2 rows, the row whose source carries \tag has its number moved to the
last row and every other row's number dropped. Untagged shapes are untouched.
pdflatex oracle — in all four arrangements the tag word sits at
y=182.644956, the c+c (last) row, never the row \tag was typed on:
| source | pdflatex tag y | flashtex tag y | rows at |
|---|---|---|---|
\tag{B} row 2 |
182.645 (last) | 189.56 (last) ✓ | 159.67 / 174.62 / 189.56 |
\tag{B} row 1 |
182.645 (last) | 189.56 (last) ✓ | |
\tag{B} row 3 |
182.645 | 189.56 ✓ | |
no tag → (1) |
182.645 | 189.56 ✓ |
Exactly one tag word in every case; the spurious second number round 4
measured at the old vendor is gone.
This one really does reach the renderer, and survives the re-pin. The
adapter takes number from strip_tag on the row's source, not from
MathRow.number (adapter.rs:2014-2018), so the relocation does not depend
on the compiler's per-row numbering. I checked that rather than inferring it:
multline* has number: None on every row — the same shape the re-pinned
compiler produces for a tagged multline — and a mid-row \tag{B} in a
multline* still lands on the last row:
[email protected] … [email protected] … [email protected] (B)@y189.56 next equation (1)
pdflatex for the same source: (B) at y=182.645 on the last row, next
equation (1). Match. First-row and last-row multline* tags behave the
same, and an untagged multline* prints nothing.
Hot-swapping the PR's parser.rs into vendor/compiler to simulate the
re-pin directly does not build (E0061 — the vendored mirror at
f0f86aaf has drifted too far), which is why the multline* shape is the
evidence here rather than a swapped tree.
Negative run. With parser.rs and adapter.rs reverted to 9ac0bb67
and the tests kept at HEAD: --test tagged_row_eqref → 9 passed, 2 failed
(multline_label_on_early_row_reads_the_last_row_number,
multline_middle_row_tag_resolves_every_label_to_the_tag);
--test multline_tag_row → 1 failed
(multline_middle_row_tag_is_set_on_the_last_row). All three new tests are
real regression tests. Hard-reset afterwards.
MATERIAL findings
None. Both round-4 findings are addressed, the fixes are verified against
pdflatex rather than against the PR's own expectations, the new tests are
non-vacuous, the align/gather per-row behaviour is unchanged, and
git merge-tree origin/main 75f61ff6 is clean.
Non-blocking notes
\notagis the unhandled mirror of the rule9ac0bb67added. amsmath
treats\notagon anymultlinerow as suppressing the whole
environment's number, exactly as\tagdoes. Oracle:
\begin{multline} a+a \\ b+b \notag \\ c+c \end{multline}followed by an
equation→ pdflatex prints no number at all on the multline and
numbers the next equation(1). flashtex prints(1)on the last row and
(2)next. Pre-existing on4511166eand outside render-pipeline: a tagged align/gather row's \eqref reads the counter, not the tag, and still steps the counter #823's stated scope, so
not a blocker — but the one-line home for it is theis_multlineblock
this PR just wrote (the row loop already destructures anunnumbered
flag), and leaving it means\tagand\notagnow disagree about whether
multlinehas one number or three. Worth an issue reference at minimum.\labelinmultline*records"0"; pdflatex records nothing. The
.auxof\begin{multline*}\label{m} … \end{multline*}has no\newlabel
line and\eqref{m}renders(??); flashtex gives the label the value
"0"(the unstepped counter), so\eqrefwould render(0). Unchanged by
this PR —is_multlineisname.starts_with("multline")and both the old
per-row path and the new per-environment path fall back to
counters.the("equation")— but the new code is where that fallback now
lives.- A second
\tagis accepted silently. pdflatex raises
! Package amsmath Error: Multiple \tag.and then uses the first; flashtex
uses the first with no diagnostic. The tie-break matches; only the
diagnostic is missing. - False-positive guard on the tag scan is adequate.
find_command
(adapter.rs:6283) skips comments and matches\tagat a backslash, so
\notagdoes not trip it, and a row containing the wordtag
(\text{tag here}) does not relocate anything — both verified. The
rows[found].number.is_none() → continueguard makes a mismatch between
find_commandandstrip_taga no-op rather than a panic. - Nothing on the compiler side is user-visible until the next re-pin.
This branch'scrates/render-pipeline/vendor/compiler/PINisf0f86aaf
(main is at4511166eafter render-pipeline: re-pin the vendored compiler and tex-expansion to 4511166e #829; the branch predates that commit). So the
renderer today still shows\eqref{m}→(0)for a mid-tagmultlineand
still steps the counter (next equation(2)where pdflatex gives(1)) —
the finding-1 symptom is visible in rendered output and will stay visible
after this merges, because4511166edoes not carry this PR's parser
either. The integration lane owns the pin per
docs/integration/repin-runbook.md; this is not the PR's job, but the PR
body should not be read as saying the cross-reference fix ships to users
with this merge. Finding 2's fix does ship, because it is in
render-pipelineitself. - Round-4's note about the PR body being stale ("6 new tests") still stands;
tagged_row_eqref.rsnow has 11 tests andmultline_tag_row.rsone more.
Tests run
nice -n 15 env CARGO_BUILD_JOBS=3 CARGO_TARGET_DIR=$HOME/flashtex-wt/review-target cargo test --locked <filter>:
crates/compiler,--test tagged_row_eqref— 11 passed, 0 failed.crates/render-pipeline,--test multline_tag_row— 1 passed, 0 failed.- Both filters with
parser.rsandadapter.rsreverted to9ac0bb67— 2
and 1 failures, exactly the three tests75f61ff6adds. Hard-reset after. - Throwaway probes for label values / row numbers (15 arrangements incl.
align,gather,multline*,\tag*, two tags, two environments) and for
rendered glyph baselines (tagged and untaggedmultline, all four
multline*shapes,\notag,\text{tag …}, a 2-row tag). Removed;
git statusclean.
pdflatex oracles (preamble above, two passes): mid_tag_lbl1, notag_lbl1,
first_tag_lbl3, last_tag_lbl1, two_tags, multline* with a mid-row
\tag, multline* with a \label, and \notag on a middle row — each read
with pdftotext -bbox for glyph baselines and from the .aux for
\newlabel.
Merge: git merge-tree origin/main 75f61ff6 — clean, no conflicts.
VERDICT: APPROVE
What
Found in the review of PR #821, pre-existing on main, not a regression.
\eqrefignored a rich tag in alignments: the\eqrefvalue was always the counter;custom_tag_text(already used by the singleequation/equation*environment) was never consulted foralign/gather/multlinerows. A row with\tag{A}displayed(A)while\eqrefto it read(1). Fixed by reusingcustom_tag_textfor row labels too.\tagis amsmath's own opt-out of automatic numbering (verified against real pdflatex). Same defect existed in the single-equationpath, fixed the same way.\tag/\labelinside\[ … \]printed literal\labelh/(??). Newtake_display_labelslifts\labelout of display-math tokens before math parsing, mirroring the multi-row environments.\tag{$\alpha$}prints(): diagnosed, not fixed. The parser-side value pipeline is correct ("α"reaches both the label and the reference), but references shape in Times-Roman, which has no α glyph. Closing this needs math-font fallback in the layout/font engine — outside this PR's parser-only scope. A test pins the diagnosed state.Tests
6 new tests, expected values independently verified against real pdflatex (TeX Live 2026, double-run,
pdftotext -layout). Fullcargo test --lockedincrates/compiler(independently re-run by the supervisor): 84 test-result lines, 1008 passed, 0 failed.Refs #823 (item 4, \tag{$\alpha$} font-fallback rendering, remains open and separately scoped — not fixed by this PR).
Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane tagged-row-eqref, slice 1)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
🤖 Generated with Claude Code