Skip to content

render-pipeline: macro-body text takes the body's fonts; declaration groups add no italic correction (stacked on #547) - #556

Merged
GoKubar merged 3 commits into
mainfrom
agent/daniel-parent/macro-body-fonts
Sep 15, 2026
Merged

GoKubar merged 3 commits into
mainfrom
agent/daniel-parent/macro-body-fonts

Conversation

@d-q222

@d-q222 d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Stacked on #547 (base branch agent/daniel-parent/probes-fidelity). Review/merge #547 first; this PR's diff against main includes #547's commit.

What

Two render-pipeline gaps from the probes table (#2 comment 5676249771), both in crates/render-pipeline/src/adapter.rs:

  1. Literal text in a macro body takes the body's fonts. The compiler spans every replacement-text token at the invocation (\x), so \newcommand{\x}{\textbf{Note:}} set Note: in the call site's medium face. token_gap's BodyCursor now records where the word sits in the definition body. Styles::in_body applies the body's own groups and commands around it on top of the call site's font. A blank inside the body is set in the body's font at that blank.
  2. Italic correction. Font declarations (\itshape, \bfseries, \slshape, \em) no longer mark their group's end for \/. LaTeX adds it only through \text@command's \maybe@ic. \textit/\emph keep it, suppressed before ./, (\nocorrlist) and after a slanted font. The same rule now runs for \textit{...} closing inside a macro body (the next token is the body's next byte, or the byte after the invocation). macro_argument_intervals (render-pipeline: a macro body's font declarations apply to its arguments (min2-preamble-switches 419 bp -> 0.005 bp) #547) honours an interval's own correction flag.

Tests: crates/render-pipeline/tests/macro_body_fonts.rs, 4 tests pinned to pdfLaTeX run origins (pdfTeX 1.40.29, TeX Live 2026, SOURCE_DATE_EPOCH=0 FORCE_SOURCE_DATE=1, 2 passes, read with tools/visual-oracle/pdftext.py). 3 of them fail on #547's head. The \textit/\emph \nocorrlist pin passes on both.

Why

tools/visual-oracle/rank.py on scratch probes with fresh pdflatex references, max |Δ| in bp:

probe #547 head this PR
body text (\textbf{Note:}, {\itshape Remark} and {\bfseries Bold words}, \textit{Hint:} #1 done in bodies) 6.765 0.005
declaration groups ({\itshape leaf} then, {\em ff} after, {\bfseries f} then) 4.224 0.005
corrections inside bodies (\textit{leaf} at body end before upright / before ., \emph{elf} #1 \textbf{bold words}, \textsl{half}b) 9.438 0.005
\textit{a}. / \textit{a}b / \emph 0.005 0.005

Overlap check

Test results

  • cargo test --release --test macro_body_fonts: test result: ok. 4 passed; 0 failed; 0 ignored (on render-pipeline: a macro body's font declarations apply to its arguments (min2-preamble-switches 419 bp -> 0.005 bp) #547 head: test result: FAILED. 1 passed; 3 failed)
  • cargo test --release --test macro_argument_fonts: test result: ok. 3 passed; 0 failed; 0 ignored
  • cargo test --release --no-fail-fast (whole render-pipeline crate): 80 test binaries, passed 383 failed 0 ignored 3
  • rank.py over all 43 fixtures/divergence-probes: 0 pages changed (max Δ and within-0.5 bp identical), within 0.5 bp 1819 -> 1819
  • rank.py over fixtures/real-world (59 pages): 0 pages changed, within 0.5 bp 11183 -> 11183. An earlier draft lost 3 words per page on hw1/hw2 ([4 points] in \problem's \subsection* body got a bold space, -0.581 bp). It is fixed: a body blank keeps the heading's medium weight.

Not done

  • \newcommand{\w}{\textit{leaf}, then} loses its ,: no "," text inline reaches the adapter, likely compiler-side, so the rest of the line is 2.04 bp off. That needs a compiler PR.
  • Kern/Logo/Rule inlines of a replacement text still take the call site's font. Only text words and their blanks read the body.

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

What changed:
- adapter::style_intervals now adds macro_argument_intervals: the font
  commands a user macro's definition wraps around `#k` (`{\small\bfseries
  #1}`, `\textbf{#1}`, `\textit{#1}`) are laid over argument k's bytes at
  every invocation, in TeX's order (call site, then definition, then the
  argument's own). An ungrouped declaration (`\small\bfseries #1`) stays in
  force to the end of the call site's group, as if written there.
- space_style: after a replacement-text token (span = the invocation), the
  space before a later argument is in the call site's font, not the font of
  the earlier argument whose bytes sit in between.
- items_cached keys each text inline on the style in force at it, since a
  definition outside the block can now change that style.
- fixtures/divergence-probes/min2-preamble-switches: 419.027 bp -> 0.005 bp
  (the note was LMRoman9-Regular, pdfLaTeX sets SFBX0900; the narrower face
  reflowed "followed by" onto line 1).

What was run:
- cargo test --release --test macro_argument_fonts: test result: ok. 3 passed; 0 failed (all 3 fail on origin/main)
- cargo test --release --lib: test result: ok. 138 passed; 0 failed; 2 ignored
- cargo test --release --no-fail-fast (whole render-pipeline crate): 80 test binaries, passed 378 failed 0 ignored 3
- tools/visual-oracle/rank.py over fixtures/divergence-probes (MacTeX 2026 refs): within 0.5 bp 1799 -> 1819 words, no other probe changed
- tools/visual-oracle/rank.py over fixtures/real-world (pinned refs): only cv changed, max delta 37.439 -> 29.888 bp; within 0.5 bp 12277 -> 12277

Next step: replacement-text words (`\newcommand{\x}{\textbf{Note:}}`) still
take the call site's font; that needs the body cursor in the style lookup.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
… declaration groups add no italic correction

What changed:
- Replacement-text words (`\newcommand{\x}{\textbf{Note:}}`) were set in the
  call site's font, because the compiler spans them at the invocation. The
  body cursor (token_gap's BodyCursor) now records where the word was found
  in the definition body, and Styles::in_body applies the body's own groups
  and commands around it on top of the call site's font. A blank inside the
  body is set in the body's font at that blank.
- `\textit{...}`/`\emph{...}` closing inside a body get the same `\maybe@ic`
  italic correction as in the source: suppressed before `.`/`,` (the body's
  next byte, or the byte after the invocation) and after a slanted font.
- Font declarations (`\itshape`, `\bfseries`, `\slshape`, `\em`) no longer
  mark their group's end for italic correction. LaTeX adds `\/` only through
  `\text@command`; `{\itshape leaf} then` has no kern in pdfLaTeX. The flag is
  gone from font_declaration, and macro_argument_intervals honours an
  interval's own flag.
- tests/macro_body_fonts.rs: 4 tests pinned to pdfLaTeX (TeX Live 2026) run
  origins; 3 fail on the base (#547), the `\nocorrlist` pin passes on both.

What was run:
- cargo test --release --test macro_body_fonts: test result: ok. 4 passed; 0 failed (base: 1 passed; 3 failed)
- cargo test --release --test macro_argument_fonts: test result: ok. 3 passed; 0 failed
- cargo test --release --no-fail-fast (render-pipeline): 81 result lines (80 test binaries), passed 383 failed 0 ignored 3
- rank.py fixtures/divergence-probes (43): 0 pages changed, within 0.5 bp 1819 -> 1819
- rank.py fixtures/real-world (59 pages): 0 pages changed, within 0.5 bp 11183 -> 11183
- rank.py scratch probes (fresh pdflatex refs): body-text 6.765 -> 0.005 bp,
  itshape 4.224 -> 0.005 bp, body-ic2 9.438 -> 0.005 bp, textit 0.005 -> 0.005 bp

Next step: `\newcommand{\w}{\textit{leaf}, then}` loses its `,` (no ","
text inline reaches the adapter, likely compiler-side; not fixed here), so
the rest of that line is 2.04 bp off.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
d-q222 added a commit that referenced this pull request Sep 15, 2026
…p-2 regression verdicts

What changed:
- Merged origin/agent/daniel-parent/pdf-math-tounicode (d999108) with --no-ff; no conflicts.
  b283587: rank.norm folds U+2212 into "-", amsmath regroup orders with the same fold.
  d999108: rank.v2_words slices cluster byte ranges as bytes.
- Notes: new "Corpus sweep 2 regressions" section. Per regression: the cause PR found by
  rebuilding flashtex-render at each render-pipeline merge, the verdict against pdflatex's
  positions, and the oracle results. Also repaired the #556/#596 conflict-table row, which
  had swallowed the #536/#597 row.

What was run (this tip; render-pipeline unchanged by the merge, flashtex-render built at 5d1eb06):
- amsmath: TOTAL 59/59 within 0.5 bp
- amssymb: TOTAL 38/39 within 0.5 bp
- tabular: TOTAL 128/128 (words 0.5 bp, rules 0.1 bp)
- display-placement: TOTAL 35/36 within 0.5 bp
- tools/visual-oracle unit tests: Ran 15 tests, OK
- rank.py real-world: aligned words 15326 (15253 with the old rank.py)

Next step: comment the verdicts on #597, #596, #536 and #547.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
…uashed form

#556 refines #547, which has since squash-merged onto main along with five other
render-pipeline landings (#524, #536, #538, #543, #548). Exactly one line
conflicted:

  ours   .map(|(_, e, c, ic)| (*c, *ic && *e == p + 2, *e >= body.len()))
  main   .map(|(_, e, c, _)|  (*c,        *e == p + 2, *e >= body.len()))

The extra `*ic &&` is precisely this PR's change -- it gates the interval on the
fourth field #547 ignores -- so the branch side is kept.

Taking the branch wholesale would have been wrong here. Unlike a plain stacked
rebase, main carries five other commits in this file; git merged those cleanly
around this hunk, and only this one line needed a decision.

Implementation-Agent: orchestrator-astra
Commit-Executor: orchestrator-astra (direct; Cursor usage limit)
@GoKubar
GoKubar merged commit f7cf77e into main Sep 15, 2026
10 of 21 checks passed
@GoKubar
GoKubar deleted the agent/daniel-parent/macro-body-fonts branch September 16, 2026 04:16
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.

2 participants