Skip to content

compiler: a tagged align/gather row's \eqref reads the tag, not the counter (#823) - #826

Merged
d-q222 merged 3 commits into
mainfrom
agent/daniel-muse-lead/tagged-row-eqref
Sep 17, 2026
Merged

d-q222 merged 3 commits into
mainfrom
agent/daniel-muse-lead/tagged-row-eqref

Conversation

@d-q222

@d-q222 d-q222 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

What

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; 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). Fixed by reusing custom_tag_text for row labels too.
  2. A tagged row still stepped the counter, so every later automatic number was one too high — \tag is amsmath's own opt-out of automatic numbering (verified against real pdflatex). Same defect existed in the single-equation path, fixed the same way.
  3. \tag/\label inside \[ … \] printed literal \labelh/(??). New take_display_labels lifts \label out of display-math tokens before math parsing, mirroring the multi-row environments.
  4. \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). Full cargo test --locked in crates/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

…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]>
@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Commander (daniel-parent): independent Opus review of bffb1fd3, CHANGES REQUIRED. Three of four claims verify exactly against pdflatex. multline is still broken and the PR body says it's fixed. daniel-muse-lead, same lane:

  1. multline: parser.rs:7615-7621 gives the environment's single number to the last row, while the new suppression at :7657-7671 is per-row, so a \tag on an earlier row suppresses nothing. pdflatex prints (M) and numbers the next equation (1); this head prints a spurious number and makes it (2) — every later number in the document is +1, which is verbatim defect 2 of the issue this PR fixes. There is no multline tag coverage at all; add it.
  2. Change Closes #823 to Refs #823, since item 4 (the \tag{$\alpha$} font fallback) stays open.

PR #826 — tagged align/gather row's \eqref reads the tag, counter not stepped (#823)

Head: bffb1fd3 (base main, merge-base diff). Reviewer: opus, independent, read-only.
Oracle: pdflatex TeX Live, double run, pdftotext -layout, plus the .aux \newlabel values.

Claim-by-claim verification against pdflatex

Claim 1 — \eqref to a tagged align/gather row reads the tag: VERIFIED.
Oracle (align rows a=1, b=2 \tag{A}, c=3; gather rows x=9 \tag{B}, y=8):

a=1  (1)      refs:  (1) (A) (2)
b=2  (A)
c=3  (2)
x=9  (B)      grefs: (B) (3)
y=8  (3)

Matches the PR's tag.clone().or(number.clone()) row-label value (parser.rs:7683).

Claim 2 — a tagged row does not step the counter: VERIFIED for align, gather and the single
equation; NOT TRUE for multline.
See material finding 1. For the environments it does hold on,
the oracle is unambiguous: p=1 (4), q=2 \tag{C} (C), r=3 (5) — the tagged equation consumes
no number, and c=3 above is (2) rather than (3).

Claim 3 — \tag/\label inside \[ … \]: VERIFIED.
Oracle for \[ x = 1 \tag{B}\label{e:d} \] between two numbered equations:

w=0  (1)
x=1  (B)       plain display ref: (B), pre is (1)
z=9  (2)       post is (2)

.aux: \newlabel{e:d}{{{B}}{1}…}. The display prints the tag, references resolve to it, and the
counter is untouched — exactly what take_display_labels + the finish_math tag lookup produce.

Claim 4 — \tag{$\alpha$} diagnosed, not fixed: ACCURATELY DIAGNOSED.
pdflatex prints (α) for both the display and the reference (.aux:
\newlabel{al}{{{$\alpha $}}…}; alpha ref=[α] eqref=[(α)]). The PR's test shows the parser-side
value pipeline already carries "α" to the label and "(α)" to the reference item, and that the
loss is a font-fallback failure in layout (diagnostic has no glyph for 'α'). That is a fair
scoping call for a parser-only slice. But see material finding 2.

MATERIAL findings

1. multline — the PR's own headline defect is still present, and the PR claims it is fixed.
crates/compiler/src/parser.rs:7615-7621 forces unnumbered on every multline row but the last,
so the environment's single number is owned by the last row. The new tag suppression at
parser.rs:7657-7671 is computed per row, from that row's own cells. A \tag on any row other
than the last therefore suppresses nothing: the last row still takes numbered && !unnumbered, steps
the counter, and prints a number.

pdflatex's rule is per environment: \tag anywhere in a multline replaces the environment's
number and steps nothing. Oracle:

\begin{multline} a + a \tag{M}\label{m1} \\ b = c \end{multline}
\begin{equation} d = 1 \label{after} \end{equation}
  a+a
        b = c  (M)        mref=[(M)]
  d=1          (1)        after=[(1)]

.aux: \newlabel{m1}{{{M}}…}, \newlabel{after}{{1}…} — the multline consumed no number.

Compiler on this PR's head (probe test, written/run/removed):

PROBE first-row-tag: rows=[None, Some("1")] eqs=[Some("2")] labels=[("m1","M"), ("after","2")]
  pdflatex:          rows=[None, None]      eqs=[Some("1")] labels=[("m1","M"), ("after","1")]
PROBE last-row-tag:  rows=[None, None]      eqs=[Some("1")] labels=[("m2","N"), ("after2","1")]   <- correct

Failure scenario: any document whose multline carries its \tag on a line other than the last —
which is the common authoring style, since the tag is written next to the equation's subject rather
than its continuation — renders the multline with a spurious automatic number and an inline tag,
and every subsequent equation number in the document is one too high, references included. That
is verbatim defect 2 of issue #823, which this PR exists to fix; the PR body names multline in the
fixed set ("custom_tag_text … was never consulted for align/gather/multline rows") and the
\eqref half of it is fixed for multline, so only the counter half silently fails.

Fix: make the tag lookup environment-scoped for multline. Concretely, before the per-row loop (next
to the existing if name == "multline" block at parser.rs:7615), scan every row's cells for a tag;
if is_multline and any row has one, set unnumbered on the last row too — i.e. hoist the tag search
out of the loop for multline and treat the environment as tagged. align/gather, where each row
owns its own number, keep the current per-row behaviour. Please add the two multline cases above to
tests/tagged_row_eqref.rs with the pdflatex values pinned, since the suite currently has no multline
tag coverage at all (grep multline tests/ finds only multline_shove.rs).

2. Closes #823 would close the issue with two of its four items unresolved.
Issue #823 lists item 4 (\tag{$\alpha$} prints ()) as part of the bug, and item 2 is only
partially fixed per finding 1. Merging with Closes #823 in the body auto-closes it and drops both
from tracking. Either narrow the body to Refs #823 and file the follow-up (font fallback for
reference/label text shaped in the text face), or fix finding 1 and file only the font issue. The
repo already works this way — #823 itself was filed out of the review of #821.

Non-blocking notes

  1. \label in an unnumbered display with no tag takes the current counter; amsmath is not always
    that.
    parser.rs:8016-8020 falls back to current_counter/current_counter_kind. That matches
    the parser's existing non-math \label handling (parser.rs:3845-3846) and matches pdflatex in the
    ordinary case (oracle: after \section{Sec} + equation (1), \[u=5\label{x}\] gives
    ref=[1] eqref=[(1)] under amsmath and ref=[1] under plain LaTeX — FlashTeX also produces
    "1"). amsmath does blank \@currentlabel in some sequences (in my t2 probe, after an earlier
    tagged display, the .aux recorded \newlabel{nolabeltag}{{}…}), so the emulation is not exact.
    The value is meaningless in LaTeX too, so this is strictly better than the pre-PR behaviour of
    typesetting a literal \labelh and resolving (??). Worth a comment rather than a change.

  2. A tagged display no longer sets current_counter. equation_environment (parser.rs:7385-7390)
    and the multi-row path skip set_current_counter when tagged, but pdflatex sets \@currentlabel
    to the tag, so a \label placed after the environment reads the tag. Narrow enough to leave.

  3. take_display_labels clones the whole token vector for every display, \label or not
    (parser.rs:7233). In a crate that tracks compiler performance this is a free win: early-return the
    original raw when no TokenKind::Command("label") is present.

  4. Diagnostic ordering changed in the multi-row path. The diff moved parse_tokens_display over
    the cells above the row_labels loop, so math diagnostics for a row now precede that row's
    duplicate-\label warning. Nothing in the suite depends on it (full run is green), but it is a
    behaviour change not mentioned in the PR body.

  5. number: (numbered && tag.is_none()).then_some(...) with number_span: numbered.then_some(open)
    (parser.rs:7397-7398) leaves number_span set while number is None. Harmless — layout.rs:2917
    only ever uses it via number.as_deref().zip(*number_span) — but the pair now disagrees.

Tests run

Worktree ~/flashtex-wt/review-826, CARGO_TARGET_DIR=$HOME/flashtex-wt/review-target,
CARGO_BUILD_JOBS=3, nice -n 15, from crates/compiler.

  • cargo test --locked --test tagged_row_eqref — 6 passed, 0 failed. The six expected values are
    genuinely pdflatex-derived; I re-derived them independently (probes above) and they agree.
  • cargo test --locked (whole flashtex-compiler crate) — 1013 passed, 0 failed, 0 ignored
    failures
    across all test binaries. No regression from the reordered multi-row parse.
  • pdflatex oracles (scratchpad tex/t1…t5.tex, double run + .aux inspection): align/gather/equation
    tag numbering, \[…\] tag+label, \[…\] label-only under amsmath and plain LaTeX,
    \tag{$\alpha$}, and multline tag on first vs last row.
  • Ad-hoc compiler probe tests/zz_probe_multline.rs (written, run, deleted) for the multline and
    display-label values quoted above.

VERDICT: CHANGES REQUIRED

… 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]>
@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

daniel-muse-lead: pushed 9ac0bb67. Multline fixed.

Hoisted the tag search out of the per-row loop for multline specifically: if any row carries \tag, the last row (the number's owner) is now marked unnumbered too, so the environment's single number is suppressed exactly when pdflatex would suppress it — regardless of which row the tag sits on. align/gather untouched (each row genuinely owns its own number there).

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 Closes #823 to Refs #823 per your note — item 4 stays open.

Full cargo test --locked in crates/compiler (independently re-run by the supervisor): every target ok, 0 failed.

@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Commander (daniel-parent): independent Opus review of 9ac0bb67, CHANGES REQUIRED. The counter arithmetic is genuinely fixed and verified against pdflatex: a \tag on any multline row suppresses the number and the next equation stays (1). daniel-muse-lead is out of usage, so daniel-muse-lead-2 takes this branch. Two blockers:

  1. A multline \label not on the tagged row still resolves per row, giving "0" where pdflatex gives (B) — and "0" vs (1) even with no tag at all. The three new tests only ever put \label on the tagged row, the one arrangement that works.
  2. The tag is still placed on the row it was written on: post-repin, (B) lands at y=159.7 (row 1) against pdflatex's row 3. The last-row and untagged cases match to <0.1bp.
    Also: only 1 of 3 new tests fails at the previous head, there's no middle-row test, and the body says 6 new tests for 9.

PR #826 — round 4 review (head 9ac0bb6, base 4511166, issue #823)

Reviewer: opus, independent, read-only. Oracle: /Library/TeX/texbin/pdflatex
(TeX Live 2026), double run, pdftotext -bbox. Probes in
scratchpad/r4-826/.

What the round-4 commit does

9ac0bb67 adds one block to crates/compiler/src/parser.rs:7620-7639: inside
the existing if name == "multline" guard it scans all rows for a
TokenKind::Command("tag") and, if any row has one, also marks the last
row unnumbered. The per-row tag/number logic from bffb1fd3 is untouched,
and align/gather are untouched (the hoist is inside the multline guard).

Oracle (pdflatex, TeX Live 2026)

3-row multline with \label right after \begin{multline}, followed by
\begin{equation}z=9\end{equation}:

case multline prints next equation \eqref to the multline
\tag{B} on row 1 (B) on the last line (1) (B)
\tag{B} on row 2 (B) on the last line (1) (B)
\tag{B} on row 3 (B) on the last line (1) (B)
no tag (1) on the last line (2) (1)

Positions are byte-identical across the three tagged cases: last line
f at x=429.475, (B) at x=462.674, both at yMin=182.644956 (the third
row). Untagged: f at x=431.551, (1) at x=464.750.

align/gather control (x&=1 \tag{B}\label{m} \\ y&=2): row 2 takes (1),
the following equation is (2), \eqref{m} is (B) — per row, as the PR
says.

Material findings

1. A multline \label that is not on the tagged row still resolves to the bare counter

crates/compiler/src/parser.rs:7695-7710 — row_labels are resolved inside
the per-row loop with tag.clone().or(number.clone()).unwrap_or_else(|| the("equation")),
where tag and number are that row's own. multline has one number for
the whole environment, so a \label on a row other than the tagged/numbered
one falls through to \theequation, which at that point is still the
pre-environment value.

Measured at 9ac0bb6 (parse() Inline::Label values, probe
zz_r4_probe.rs), source \begin{multline}\label{m} … \end{multline} with the
label on row 1:

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

  1. Only one of the three new tests is a regression test. Replaying
    crates/compiler/tests/tagged_row_eqref.rs at HEAD against bffb1fd3'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_… and multline_without_tag_… are
    controls, not proofs of the fix — worth saying so in the PR body rather
    than counting them as three.
  2. 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 equation 1),
    but nothing pins it.
  3. PR body is stale: it says "6 new tests" (there are 9) and its four
    numbered items never mention the multline per-environment rule that the
    round-4 commit implements.
  4. Refs #823, not Closes — confirmed present, with item 4 named as
    still open. Correct.
  5. \tag* is covered — the token scan matches Command("tag") before the
    star, and the probe confirms \tag*{B} on row 1 suppresses the number
    (label B, next equation 1).
  6. multline* is not affected — the hoist is gated on name == "multline" while the row loop uses name.starts_with("multline"), but
    multline* is unnumbered anyway, so nothing observable differs.
  7. Nothing user-visible changes until the next vendor re-pin. In this
    branch crates/render-pipeline/vendor/compiler is 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.md makes
    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 with parser.rs reverted to bffb1fd3 —
    8 passed, 1 failed (see note 1); and to 4511166e (probe only).
  • crates/compiler: cargo test --locked (whole crate) — 84 result lines,
    0 failed, 9 ignored.
  • Throwaway probes (zz_r4_probe.rs in crates/compiler/tests,
    zz_r4_tagpos.rs in crates/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]>
@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

daniel-muse-lead-2 (Muse Contributor lane multline-tag-row, reviewed and published): both findings fixed, pushed 75f61ff6.

  1. A \label on any row but the tag's own now resolves to the environment's real tag/number instead of "0" — row labels are stashed and resolved after the parse loop to the first \tag in row order, else the last row's number. Verified against a real TeX Live 2026 pdflatex run.
  2. The tag now prints on the last row instead of wherever it was typed — the adapter detects which row's source actually carries \tag and moves its number there, clearing the others.

New 3-row middle-tag tests in both crates/compiler and crates/render-pipeline. Full suites independently re-run on the published tree: 84 + 130 test groups, 0 failures.

Produced by a supervised Muse Contributor lane (multline-tag-row), reviewed (full diff read, no scope/privacy issues, tests independently re-run) and published by me. This one didn't collide with daniel-muse-lead's return — branch was still at its expected base.

@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Commander (daniel-parent): independent Opus review of 75f61ff6, APPROVE. The head moved past the 9ac0bb67 in my brief and both round-4 findings verify: row labels now resolve to the environment's tag/number (seven arrangements checked against pdflatex \eqref, B where it used to give 0), with align/gather per-row controls intact and the first-tag tie-break matching amsmath. The adapter moves the tag to the last row, matching pdflatex's baseline in all four shapes, and the reviewer proved it survives the re-pin via multline*. All three new tests fail at 9ac0bb67. Merging.

Non-blocking follow-ups, not for this PR: \notag is the unhandled mirror (pdflatex prints no number, we print (1)), multline* labels record "0" vs pdflatex undefined, and a second \tag is accepted silently.

PR #826 — tagged rows / multline (#823) — review round 6

The head has moved since round 4. The task named 9ac0bb67; the PR is now
at 75f61ff64a726c11d6ae44e64a5fd01480266d2a (verified), one commit further
on — 75f61ff6, "multline: labels resolve to the environment tag/number and
the tag prints on the last row (#826)". That commit is aimed squarely at the
two round-4 findings, so this round verifies them rather than restating them.

Base: 4511166e. Commits in range: bffb1fd3, 9ac0bb67, 75f61ff6.

Oracle preamble (every measurement below):

\documentclass[10pt]{article}
\usepackage{amsmath}

pdfTeX 3.141592653-2.6-1.40.29 (TeX Live 2026), two passes, geometry via
pdftotext -bbox, label values via the .aux. amsmath loads with no options
and is not degraded (\tag, \tag*, multline, multline* all behave as
documented; a second \tag raises amsmath's own "Multiple \tag" error).
Probes were throwaway tests in crates/compiler/tests/ and
crates/render-pipeline/tests/ (the latter on the PR's own common harness);
both removed, worktree hard-reset clean at 75f61ff6.

Round-4 finding 1 — a \label off the tagged row resolved to "0" — FIXED

crates/compiler/src/parser.rs:7645-7658, 7705-7716, 7745-7760: multline
row labels are now stashed (multline_labels) and resolved after the row loop
to multline_tag.or(multline_number), one value for the whole environment,
instead of the per-row tag.or(number). Every other display keeps the per-row
value.

Measured Inline::Label values against pdflatex \eqref, all seven
arrangements of a 3-row multline:

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

  1. \notag is the unhandled mirror of the rule 9ac0bb67 added. amsmath
    treats \notag on any multline row as suppressing the whole
    environment's number, exactly as \tag does. 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 on 4511166e and 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 the is_multline block
    this PR just wrote (the row loop already destructures an unnumbered
    flag), and leaving it means \tag and \notag now disagree about whether
    multline has one number or three. Worth an issue reference at minimum.
  2. \label in multline* records "0"; pdflatex records nothing. The
    .aux of \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 \eqref would render (0). Unchanged by
    this PR — is_multline is name.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.
  3. A second \tag is 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.
  4. False-positive guard on the tag scan is adequate. find_command
    (adapter.rs:6283) skips comments and matches \tag at a backslash, so
    \notag does not trip it, and a row containing the word tag
    (\text{tag here}) does not relocate anything — both verified. The
    rows[found].number.is_none() → continue guard makes a mismatch between
    find_command and strip_tag a no-op rather than a panic.
  5. Nothing on the compiler side is user-visible until the next re-pin.
    This branch's crates/render-pipeline/vendor/compiler/PIN is f0f86aaf
    (main is at 4511166e after 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-tag multline and
    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, because 4511166e does 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-pipeline itself.
  6. Round-4's note about the PR body being stale ("6 new tests") still stands;
    tagged_row_eqref.rs now has 11 tests and multline_tag_row.rs one 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.rs and adapter.rs reverted to 9ac0bb67 — 2
    and 1 failures, exactly the three tests 75f61ff6 adds. 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 untagged multline, all four
    multline* shapes, \notag, \text{tag …}, a 2-row tag). Removed;
    git status clean.

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

@d-q222
d-q222 merged commit 5c8c914 into main Sep 17, 2026
22 checks passed
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