Skip to content

compiler: color/xcolor with pdfTeX-exact colour operators (982/982 oracle) - #150

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

jay3332 merged 5 commits into
mainfrom
agent/kabir-claude/xcolor-support

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

What

color/xcolor in the compiler, with the exact operator values pdfTeX writes. Rendering half: #158.

  • New src/color.rs: xcolor 3.02 and color.sty replayed on TeX's own integer arithmetic (tex.web round_decimals, print_scaled, xn_over_d; xcolor's \lshift/\rshift re-reads, \rdivide, calc N/C/D/M/S/T, UCR/BG). Models rgb, cmy, cmyk, gray, RGB, HTML, Gray, named; targets natural/rgb/cmy/cmyk/gray; \definecolor, \providecolor, \colorlet, \definecolorset, expressions (red!30!blue, -red, ., chains). Named sets generated from dvipsnam.def, svgnam.def, x11nam.def (scripts/color_names.py, versions cited in src/color_names.rs).
  • Parser (src/parser/colors.rs): TextStyle::color (scoped by the style stack like pdfTeX's colour stack; font commands keep it), \color/\textcolor also in headings/flat content, colours inside math (Inline::Math::color + color_ranges), \colorbox/\fcolorbox (Inline::ColorBox with \fboxsep/\fboxrule), \pagecolor (Parsed::page_color), a target model's default colour (Parsed::default_color), \selectcolormodel, \DefineNamedColor.
  • Not replayed (typed diagnostic, never approximated): hsb-family models, colour series, rgb: extended expressions, >wheel, colortbl \rowcolor/\cellcolor.
  • Canonical list gains the xcolor.sty set (only addition). Inventory vs main: supported 458 -> 472 (xcolor 14/71); total denominator 1003 -> 1074, so the percentage reads 45.7% -> 43.9%.

Evidence

  • tests/color_oracle.rs: 982 expressions across 9 package setups (natural, rgb/cmyk/gray targets, dvipsnames/svgnames/x11names, color.sty, color.sty named) pinned from pdflatex (TeX Live 2026, scripts/color_oracle.py, oracle only): 982/982 exact fill and stroke operators, including artefacts such as 0.05 0.09999 0.15001 0.2 k.
  • tests/xcolor_parse.rs (8 tests): scoping, macros, headings, math ranges, boxes, page and default colour, error recovery.
  • Merged with main (tex-expansion adoption). cargo test --release (crates/compiler): 404 passed, 0 failed, 4 ignored.
  • With this compiler vendored (locally), render-pipeline, pdf: paint color/xcolor with pdfTeX's exact operators (28/28 oracle; needs #150 re-pin) #158's pdflatex oracle is 28/28 and HW1/HW2 plus the real-world corpus are byte-identical.

Integration notes

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 3 commits September 13, 2026 08:26
…lues

Replays xcolor 3.02's TeX dimension arithmetic (lshift/rshift re-reads,
rdivide, calc N/C/D/M/S/T, UCR/BG) on tex.web's round_decimals and
print_scaled, so every operand matches pdfTeX; named sets generated from
dvipsnam.def, svgnam.def and x11nam.def. Oracle: 982 expressions across
9 package setups pinned from pdflatex (TeX Live 2026), all exact.

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
\definecolor/\providecolor/\xdefinecolor/\colorlet/\definecolorset/
\DefineNamedColor/\selectcolormodel, \color and \textcolor (TextStyle::color,
scoped by the existing style stack like pdfTeX's colour stack), colours
inside math (Inline::Math::color and color_ranges), \colorbox/\fcolorbox
(Inline::ColorBox with \fboxsep/\fboxrule), \pagecolor (Parsed::page_color).
Canonical list gains the xcolor.sty set; inventory regenerated
(194/1003 -> 208/1074, xcolor 14/71). cargo test --release: 384 passed.

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
Resolves the tex-expansion adoption (box_inlines uses the Rc token stream;
macro scopes live in the expansion pass), keeps both sides for the new
Logo/Rule/Kern inlines, fontenc encoding and expansion sites. Inventory
regenerated. cargo test --release: 404 passed, 0 failed.

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 and others added 2 commits September 13, 2026 09:13
…olor)

Under [rgb]/[cmyk]/[gray] xcolor loads black in the target model and every
shipout writes it through \normalcolor (pdfTeX writes 0 0 0 rg, not 0 g).
cargo test --release: 404 passed, 0 failed.

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
Generated inventory regenerated (461/1003 on main -> 475/1074 with the xcolor
set). cargo test --release: 406 passed, 0 failed.

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
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
Conflicts: lib.rs modules (boxes + color/color_names), parser.rs modules (hyperlinks/boxes/lists + colors) and Inline enum (#137's Box/SetLength/LengthGlue + #150's ColorBox variant, then main's ReferenceForm and #150's ColorBox struct), incremental.rs span shifting (both). Integration fixes: #150's parser/colors.rs box_inlines renamed color_box_inlines (clashed with #137's); #149's theorems.rs ITALIC const gains color: None; set_length records \fboxsep/\fboxrule before #137's set_box_length claims the assignment, so \colorbox sees it (xcolor_parse fboxsep 3.0 vs 5.0).

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, 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
…ement and colortbl fills (tabular oracle 59/59 + 18/20 new)

Implements table.rs layout for the compiler fields of #173: kill rows,
booktabs' \@BTrule/\@BTendrule/\@xcmidrule rule classes (specialrule and
addlinespace as class 2, \cmidrulesep after \morecmidrules), explicit
cmidrule kerns, \arrayrulecolor on every rule kind, \doublerulesepcolor
gaps, and colortbl fills per \CT@@Do@color (cell over row over column,
overhangs from \col@sep then column then row). typeset: multirow boxes per
multirow.sty 168-201, fills painted under the entries, colours resolved by
a minimal xcolor stand-in (tablecolor.rs) until #150 lands. The tabular
oracle compares rule and fill colours; fixtures 60-79 with MacTeX 2026
references. Needs vendor/compiler re-pinned to #173. longtable follows.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude table packages, 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
Conflicts: canonical_latex.py/canonical-latex.tsv (xcolor then siunitx sets, both), supported.rs (theorem/listings commands + siunitx commands; hyperref package tuple, siunitx tuple, then PSEUDOCODE_PACKAGES; CANONICAL_SETS gains siunitx after xcolor), parser.rs (BUILT_INS both; preamble dispatch: main's arms, \sisetup/\DeclareSIUnit before the preamble guard, siunitx commands after \chapter; \usepackage raw options read + main's options_span, hyperref then siunitx loader; inlines_from_tokens uses one skip_to for #150's colour arm and #163's siunitx arm; token_source + siunitx_bracket_at/siunitx_group_at; package matches both). Integration fix: #163's two Inline::Math initialisers gain #150's color (running style colour) and empty color_ranges. Generated docs took main.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, 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
…ession handoff)

Stage 1 partly done: #131, #137, #153 (incl. #142), #144, #147, #149, #150,
#155, #159, #163, #164 merged with conflicts and post-expansion fixes recorded
in docs/evidence/integration-2026-09-13b/merge-log.md. Remaining: #166, #169,
#148, #161, then the inventory regeneration and stages 2-4. The helper scripts
under tools/ hard-code the original worktree path.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, 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
…merges

Every stage 1 merge took main's side of the generated inventory and deferred
the regeneration to the end of the stage. Running
crates/compiler/scripts/render_supported_latex.sh picks up #131, #137, #144,
#147, #149, #150, #153, #155, #159, #163, #164, #166 and #169, so
supported_latex::generated_artifacts_are_current passes again.

The TeX Live-derived canonical denominator is deliberately untouched: this
machine has TeX Live 2025, not the MacTeX the committed file was pinned from.

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 a252693 into main Sep 13, 2026
11 of 18 checks passed
@GoKubar
GoKubar deleted the agent/kabir-claude/xcolor-support branch September 13, 2026 18:12
GoKubar added a commit that referenced this pull request Sep 14, 2026
…n tables

Parses the table packages beyond tabular/array into the structured table
(crate::tabular), citing the TeX Live 2026 sources:

- longtable.sty v4.24: the environment (only with the package loaded) as a
  paragraph holding one Tabular with `longtable: Some(..)`; `[l|c|r]`;
  `\endfirsthead`/`\endhead`/`\endfoot`/`\endlastfoot` as Entry::Section
  markers; `\caption[short]{..}`/`\caption*` as Entry::Caption numbered by
  the table counter every longtable steps (text up to the row's `\\`,
  e.g. a `\label`, joins the caption); `\kill` rows (Row::kill); `\\*`
  (Row::nobreak); `\newpage`/`\pagebreak` as Entry::PageBreak;
  `\setlength` of `\LTleft`/`\LTright`/`\LTpre`/`\LTpost`/`\LTcapwidth`
  accepted (read from the source by the pipeline).
- multirow.sty v2.9: `\multirow[vpos]{nrows}[bigstruts]{width|*|=}[vmove]{text}`
  anywhere at the top level of an entry, including inside `\multicolumn`
  (Cell::multirow; the text stays the entry's content).
- booktabs.sty v1.61803398: `\cmidrule(l{<dimen>}r)` explicit trims
  (kern_left_pt/kern_right_pt), `\addlinespace[..]`, `\specialrule{w}{a}{b}`,
  `\morecmidrules`.
- colortbl.sty v1.0k (or xcolor's `table` option): `\rowcolor[m]{c}[l][r]`
  (Row::color; the right overhang copies the left), `\cellcolor[m]{c}`
  (Cell::color), `>{\columncolor[m]{c}[l][r]}` (ColumnTemplate::color),
  `\arrayrulecolor`/`\doublerulesepcolor` before a table (Tabular fields)
  and between rows (Entry::RuleColor/DoubleRuleSepColor). Colours are kept
  as written (ColorSpec model/spec): resolving them is the colour model's
  job (PR #150).

Optional brackets glued to following text (`\rowcolor{x}[1pt][3pt]a`) are
split like `\\[2pt]Next`. The compiler's own layout honours kill rows,
cmidrule kerns, addlinespace, specialrule and captions; colour and page
breaking are the render pipeline's. Supported inventory regenerated
(booktabs, longtable, multirow, colortbl packages; \arrayrulecolor,
\doublerulesepcolor). apps/mac's bundled supported-latex.json needs the
usual sync. cargo test --release: all green (lib 256).

Rebased from the original base (bffd168) onto eea975c, 190 commits later.
Three things the branch did have to be rebuilt on what replaced them:

- The branch carried its own `equation_counter`/`figure_counter`/
  `table_counter` fields. `main` has since replaced all three with
  `crate::xref::Counters`, so the `table` counter every longtable steps is
  now `self.counters.step("table")` -- which also means `\thetable` picks up
  report/book's `\thechapter.` prefix and any `\numberwithin`/`\setcounter`
  in force, where the branch's plain `u32` could not. `Longtable::number`
  and `Entry::Caption::number` stay `u32` (the value, not the formatted
  label) because the pipeline prefixes "Table n: " from it; for a class
  whose `\thetable` is not plain arabic that prefix is still wrong, which
  is a gap this PR does not close.
- `main` grew `parser/colors.rs` with its own `color_argument` resolving
  `\color`/`\textcolor` against `crate::color::Colors`. The table one, which
  keeps the colour as written, is `table_color_argument` now; the two are
  genuinely different operations, not a duplicate.
- `\setlength` of the `\LT*` lengths joins the existing match arms rather
  than replacing `fboxsep`/`fboxrule`, and the `xcolor[table]` -> colortbl
  load joins `load_color_package` rather than replacing it. The recognised
  package-option list keeps both siunitx/multicol and the four table
  packages.

Measured on the rebased tree (not the numbers above, which predate it):
`cargo test --release` in crates/compiler, 40 test binaries, 0 failed;
lib 282 passed (main's baseline is 278, so the 4 new parser tests are the
whole delta). Supported inventory regenerated from this tree.

Rebase-Agent: Claude Opus 5 (engine lane, linux-primary)

Implementation-Agent: Claude Opus 5 (subagent kabir-claude table packages, 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 14, 2026
…ement and colortbl fills (tabular oracle 59/59 + 18/20 new)

Implements table.rs layout for the compiler fields of #173: kill rows,
booktabs' \@BTrule/\@BTendrule/\@xcmidrule rule classes (specialrule and
addlinespace as class 2, \cmidrulesep after \morecmidrules), explicit
cmidrule kerns, \arrayrulecolor on every rule kind, \doublerulesepcolor
gaps, and colortbl fills per \CT@@Do@color (cell over row over column,
overhangs from \col@sep then column then row). typeset: multirow boxes per
multirow.sty 168-201, fills painted under the entries, colours resolved by
a minimal xcolor stand-in (tablecolor.rs) until #150 lands. The tabular
oracle compares rule and fill colours; fixtures 60-79 with MacTeX 2026
references. Needs vendor/compiler re-pinned to #173. longtable follows.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude table packages, 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
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