Skip to content

render-pipeline, pdf: paint color/xcolor with pdfTeX's exact operators (28/28 oracle; needs #150 re-pin) - #158

Merged
jay3332 merged 2 commits into
mainfrom
agent/kabir-claude/xcolor-pipeline
Sep 13, 2026
Merged

jay3332 merged 2 commits into
mainfrom
agent/kabir-claude/xcolor-pipeline

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

What

Rendering half of color/xcolor (compiler half: #150). Based on main; needs vendor/compiler re-pinned to #150 (no vendor edits here).

  • render-pipeline: glyph runs take the compiler's TextStyle::color; formulas take Inline::Math::color (display and inline; math and fraction rules too); \colorbox/\fcolorbox are one box each (BoxRec::ColorBox): content as an \hbox, fill \fboxsep larger (\color@block), frame from xcolor's \boxframe (top/bottom \hrules, side \vrules \fboxrule shorter); \pagecolor is the page's first full-page rule (pdfTeX's q 0 0 W H re f Q); under an xcolor target model ([rgb], [cmyk]) default-coloured text is written in that model like pdfTeX's \normalcolor. Colour changes are hashed into the incremental caches.
  • Contract proposal protocol/proposals/display-list-v2-device-color.md: negotiated display-list-v2-device-color adds paint.device_color {space, values} with pdfTeX's exact operands; r,g,b stay the naive preview; nothing changes without negotiation (flashtex-render --device-color for files).
  • crates/pdf exact route: device_color becomes q <fill> <stroke> ... Q (rg/RG, k/K, g/G; new Op::FillCmyk/StrokeCmyk, parsed and validated).

Evidence

  • tests/xcolor_oracle.rs + tests/xcolor_oracle/oracle.py: 28 fixtures vs pdflatex (TeX Live 2026; models, expressions, dvips/svg/x11 names, rgb/cmyk/gray targets, nested scopes, colour across lines and pages, colorbox/fcolorbox/fboxsep/fboxrule, pagecolor, inline/display/boxed math, headings, macros, color.sty). 28/28: every glyph within 0.5 bp painting pdfTeX's exact fill operator, every rule within 0.1 bp with its operator. oracle.py check --pdf-exact: the exact PDF writes the same operator values (27/28 fully; 25-font-and-colour extracts 2 italic glyphs 3-5 bp off in text extraction, colours equal).
  • HW1, HW2 and the other 7 real-world fixtures: v2 display list and --pdf byte-identical to main.
  • cargo test --release: render-pipeline 146 passed / 0 failed / 1 ignored (with compiler: color/xcolor with pdfTeX-exact colour operators (982/982 oracle) #150's compiler vendored locally); pdf 102 passed / 0 failed.

Not in this PR

  • Colour changes inside a formula ($a \textcolor{red}{b}$): parsed by compiler: color/xcolor with pdfTeX-exact colour operators (982/982 oracle) #150 (color_ranges) but not painted: math-layout's positioned glyphs carry no atom spans (request to the math-layout owner).
  • colortbl \rowcolor/\cellcolor, hsb models, colour series.
  • Found while building fixtures (not colour, pre-existing): display math inside a {...} group, \normalfont after \bfseries in one group, and itemize at 12pt T1 misplace glyphs.

Mac painter

No change needed for correctness: r,g,b remain. A colour-managed painter can negotiate display-list-v2-device-color for CMYK.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…page colour)

Glyph runs, math and rules take the compiler's colour (TextStyle::color,
Inline::Math::color); \colorbox/\fcolorbox are boxes with xcolor's fill and
\boxframe geometry; \pagecolor is the page's first rule; the default colour of
an xcolor target model is written like pdfTeX's \normalcolor. Paints carry
pdfTeX's exact operands as device_color (proposal display-list-v2-device-color,
negotiated; flashtex-render --device-color) and crates/pdf writes them as
rg/RG, k/K, g/G (new FillCmyk/StrokeCmyk).

Oracle: 28 fixtures vs pdflatex (tests/xcolor_oracle, oracle.py): 28/28 glyph
positions (0.5 bp), rules (0.1 bp) and colour operators exact; the exact PDF
route writes the same operators (27/28 fully; one italic extraction offset).
HW1/HW2 and the real-world corpus byte-identical (v2 and PDF). Needs
vendor/compiler re-pinned to the xcolor compiler PR.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude xcolor support, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
Keeps both sides: NFSS caps/family/undefined and colour on TextStyle
(merge_style/merge_base carry the colour), footnote/logo/rule/kern items
next to ColorBox, clear_page_blocks next to math_colors, text_item's raise
next to the paint. With #150 vendored locally: cargo test --release 166
passed / 0 failed (pdf 115 / 0); xcolor oracle 28/28; HW1, HW2 and the
real-world corpus byte-identical to main (v2 and PDF).

Implementation-Agent: Claude Opus 5 (subagent kabir-claude xcolor support, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 13, 2026
Kept main's per-glyph math paint (an inner xcolor range wins) and made MathRec::paint_of fall back to the formula's own colour instead of black, so #158's whole-formula colour is not dropped. ColorBox hash tag moved off Item::Kern's 11 to 16; adapter Item/BoxItem/LengthItem/ColorBoxItem and the four inline arms written out around git's shared braces.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, nixos-pc-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 13, 2026
Main moved 18 commits past this lane's base (bffd168): the `flashtex` CLI,
inline-math line breaking (a2f85bf, 2c37374), entry-document command order
before `\input` (c1e3bab), thebibliography label geometry (ea4f383) and
enumitem keys in a list's own optional argument (ec10bc6).

15 conflicts: 3 in typeset.rs, 12 in adapter.rs. None of the vendored crates
changed on main, so the stage-2 re-pin at b1f5791 is still exact.

typeset.rs

- `MathRec`'s new fields are additive on both sides: this lane's
  `span_paints` (#165/#158) and main's `inline_breaks`/`continues`. Both kept,
  in the struct and in the initialiser.
- The `AItem::Math` arm was a real disagreement: this lane calls
  `math_box_sized(.., size)` then paints one `math_run`; main calls
  `math_box` then `math_pieces`. `math_pieces` already falls back to exactly
  one `math_run(root, size, span)` when `inline_breaks` is empty, so main's
  loop subsumes this lane's body. Resolved to main's structure with this
  lane's size-aware constructor, which is the one thing main's `math_box`
  drops (it hard-codes `style.body_size_pt`, wrong where the surrounding run
  is not body size).
- `BoxKind::Glue { mu }` no longer matches: this lane's math-layout carries
  real TeX glue components (tex.web 716 `math_glue`). main's `math_pieces`
  predates them and derives stretch/shrink from `mu` by plain.tex's muskip
  values, which is what its pdflatex line-break oracle measured, so the
  derivation is kept unchanged and the new fields are ignored (`{ mu, .. }`).
  Replacing it with the real components is a follow-up, not a merge decision.

adapter.rs — both sides independently rewrote the list-separation model

- Both implemented the *same* enumitem feature: applying the keys of a list's
  own `\begin[<keys>]` after every `\setlist`. This lane factored it into
  `class_seps` + `apply_sep_keys` + `list_seps(.., options, ..)`; main
  inlined it in a `list_seps`/`list_seps_with` pair. This lane's is a
  superset -- it also resolves `em`/`ex` against the EC body font (93d5573)
  -- so its structure stands and main's two wrappers are dropped. With that,
  `list_seps_with` has no callers left.
- Main's `gap_has_list_end` reaches only the innermost closed list; this
  lane's `list_end_skip` walks every list closed in the gap with per-level
  `begin_vmode` and `\addvspace` max semantics. This lane's is kept.
- Main's thebibliography coverage is preserved instead through `LIST_ENVS`,
  which now takes the union of both sides: `itemize`, `enumerate`,
  `description` (this lane) and `thebibliography` (main). All four are
  `\list`s, so all four count for `\@listdepth`. `list_env_after_begin` and
  `list_end_adjust` now test against `LIST_ENVS` rather than repeating the
  names, so the three predicates cannot drift apart again.
- Main's special case for thebibliography's `\begin{thebibliography}{99}`
  argument is unnecessary here: `is_key_list("99")` is already false (no `=`,
  no enumitem key), so this lane's stack passes it through harmlessly.
- `\@nbitem` after a heading: took main's ea4f383, which is the deliberate
  newer decision -- a non-negative `\addvspace{\@outerparskip - \parskip}`
  adds to the heading's after-skip rather than maxing with it.
- `BodyCommand`: both sides add variants (`RunIn`/`SecNumDepth` here,
  `Input` on main); all kept.
- git had also misaligned a doc comment, leaving `body_commands`' docs
  stranded above `math_title_spans`. `math_title_spans` now carries its own,
  and `body_commands` gets main's (which documents `\input`/`\include`).

Gates after the merge (NixOS PC, TeX Live 2025, bundled symlink-free tree
plus the nix-store `ec` for `ectt*`; no committed oracle data regenerated).
Every number below was taken with the fixed harness, which fails on any font
diagnostic, and all of them report zero:

- amsmath 59/59, amssymb 38/39, tabular 59/59, xcolor 28/28,
  display-placement 33/36 (the 3 are real content differences, not fallback).
- HW1 and HW2: 3 pages each, 0 overfull, 0 errors, 0 diagnostics of any kind.
- real-world corpus 10/10 recovered (main's a2f85bf adds `inline-math`),
  every page count equal to its committed MacTeX reference, 0 font-fatal
  diagnostics. `font_outline_substituted` appears twice on article-twocolumn
  and once on input-bibliography: advisory only, outlines not metrics.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, nixos-pc-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 13, 2026
5 conflicts (typeset.rs 4, lib.rs 1), plus the usual catching-up where #160
branched before several of this lane's changes.

- `Context`: #160's `multicol: multicol::State` field and initialiser join
  this branch's; in lib.rs `multicol::attach` is added to this branch's
  Context setup, which reads the original (unmasked) sources for float
  bodies and also installs the maths colours and graphics environment.

- `build_with_floats`: git had aligned #160's copy of the signature against
  this branch's `stretched_left`/`Flow`/`layout_blocks`, so the conflict
  looked like two functions claiming one body. Kept this branch's block and
  injected #160's `multicol::outer_doc` early return into the one real
  `build_with_floats` instead.

- Pagination: #160's `multicol::paginate` branch runs before the float
  branches; `images` stays mutable, which the float path needs.

`multicol.rs` predates three later changes and did not compile against them:

- `Block::Paragraph` gained `addvspace_flex` (#156) and `shape` (the list
  shape work). `split_paragraph` now carries both across the split -- the
  first half keeps the original's leading glue and shape, the second starts
  mid-paragraph with no leading glue but the same shape.
- `Doc` gained `default_color`, `math_colors` and `page_color` (#150/#158).
  The synthesised outer and per-column documents inherit the outer
  document's colour state rather than defaulting it, so a `multicols` body
  inside `\color` keeps its colour.
- `rec_span` did not cover `BoxRec::ColorBox`/`Graphic`/`Transform`/`Rules`.
  They are listed explicitly rather than wildcarded, so the next variant is
  caught here too instead of silently losing its span (which is what feeds
  the column-break search).

Gates (zero font diagnostics on every run): multicol_oracle passes,
theorem_oracle passes, amsmath 59/59, tabular 59/59, display-placement
33/36, real-world 10/10 recovered with every page count still equal to its
committed reference. `cargo test --release` in render-pipeline: the same 11
known failures, no more.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, nixos-pc-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@jay3332
jay3332 merged commit 93cd952 into main Sep 13, 2026
12 of 18 checks passed
@GoKubar
GoKubar deleted the agent/kabir-claude/xcolor-pipeline branch September 13, 2026 18:12
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