Skip to content

render-pipeline: indent paragraph-initial tikzpictures (#857) - #866

Merged
d-q222 merged 4 commits into
mainfrom
muse/tikz-parindent-rp
Sep 18, 2026
Merged

d-q222 merged 4 commits into
mainfrom
muse/tikz-parindent-rp

Conversation

@d-q222

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

Copy link
Copy Markdown
Contributor

Fixes #857. A tikzpicture that starts a paragraph missed \parindent, so every TikZ figure written the normal way — after a blank line — sat 15pt left of where pdflatex puts it.

Why it needed this crate

A previous slice investigated and correctly stopped: the fix is not in crates/compiler. UnitKind::Picture carried only {document, picture, centered} with no indent or list geometry, Block::Picture likewise, and picture_block hardcoded x = 0 unless centered. It ruled out three compiler-only routes with reasons (a leading indent inline splits into a spurious empty paragraph; emitting no inlines deletes the picture; shifting spans breaks picture recognition) and handed over exact file:line targets.

The fix

UnitKind::Picture / Block::Picture now carry the paragraph path's own signals — initial (the picture opens its paragraph; whitespace-only runs before it don't count), after_env, theorem_item, list, caption, styled. The blocks stage computes indent from them, and picture_block offsets x by parindent_pt when indented, else by the list hanging indent (with the paragraph path's itemindent/description adjustments). The centered branch is untouched; both call sites (main and float) pass the fields through.

Oracle ground truth matched

\documentclass{article} + \usepackage{tikz}, 10pt, node-text xMin via pdftotext -bbox; tikz confirmed loaded:

case pdflatex before
paragraph-initial 152.033 137.089 ❌
\noindent 137.089 137.089 ✅
ordinary text 148.712 148.712 ✅

The \noindent and ordinary-text rows are the controls that pinned the diagnosis: with the indent explicitly suppressed both engines already agreed exactly, so nothing else about picture placement was wrong.

It also un-encodes the bug in crates/render-pipeline/tests/tikz_pipeline.rs, which had asserted left-margin placement — i.e. the old test was pinning the defect.

Known divergence, pre-existing and out of scope

Two pictures with no blank line between them render at 152.033/152.033 (each on its own line) versus pdflatex's 152.033/170.297 (the second continues inline). Recorded, not fixed here.

crates/render-pipeline: 131 suites ok, 0 failed.

This lands in render-pipeline, which is live — no re-pin needed, it reaches users on merge.

Implemented by a sandboxed Muse lane; reviewed and published by the Commander.

🤖 Generated with Claude Code

d-q222 and others added 4 commits September 17, 2026 21:07
A tikzpicture that opens a paragraph sat 15pt left of pdflatex's
placement: UnitKind::Picture/Block::Picture carried no indent or
list-geometry context and picture_block hardcoded x = 0.

Carry the paragraph path's own signals (initial/noindent/after_env/
theorem_item/list/caption/styled) into the picture units and blocks,
and offset x by parindent_pt (or the list hanging indent, with the
paragraph path's itemindent/description adjustments) in picture_block.
Centered pictures are untouched.

Implementation-Agent: muse-spark-1.3-contributor
Commit-Executor: muse-spark-1.3-contributor
tikzpicture_becomes_paths_and_glyph_runs asserted left-margin
placement with a one-sided bound that passed with the picture glued
to the margin even when an indent was due. Lock the measured value
with a comment saying so, and add pdflatex-oracle regression tests
(article+tikz, 10pt; node-text xMin in bp): paragraph-initial
152.033, noindent 137.089, two consecutive 152.033/152.033,
parindent=0pt 137.089, itemize hang 161.996, center 301.473
unchanged, plus text controls at 148.712/133.768 that must not move.

Implementation-Agent: muse-spark-1.3-contributor
Commit-Executor: muse-spark-1.3-contributor
The `engine performance` gate failed with "output changed in 6 place(s)". That
is the intended effect of this PR: paragraph-initial tikzpictures now carry
\parindent, so every tikz-heavy fixture renders 15pt to the right.

Per crates/perf-bench/README.md, the timing checks only fire when
meta.host_fingerprint matches the pinned reference host, which no public CI
runner does -- so a failing engine-performance check means rendered output
changed, not that anything got slower. The +281% timing lines in that log are
cross-host noise and were never the failure.

Re-recorded with merge_digests.py --case tikz-heavy, which is a diff tool
rather than an accept-all: it compared 26 cases, touched the 1 named, and
printed each old -> new. The six it changed are exactly the six CI listed:

  tikz-heavy.cold.reply                      6eb062ab -> fa8304c2
  tikz-heavy.export.pdf                      2cbc0787 -> 842a6395
  tikz-heavy.warm.delete-restore-line.v1     fbd44f14 -> 9b33fda1
  tikz-heavy.warm.delete-restore-line.v2     26589d92 -> f034980b
  tikz-heavy.warm.type-paragraph.v1          1736053d -> 209aeb04
  tikz-heavy.warm.type-paragraph.v2          e1b38ff9 -> 00d014dd

Recorded from a --release build (debug and release can render differently,
#667). No other case moved; `git diff --stat` shows the baseline as the only
changed file.

Commit-Executor: daniel-parent
Co-authored-by: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

@jay3332 jay3332 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mac-claude-a verification: Read the full diff. crates/render-pipeline tikz_pipeline.rs: 7/7 passed, including the 6 new pdflatex-oracle tests. Reproduced issue #857's exact repro via CLI build of this branch vs oracle /Library/TeX/texbin/pdflatex (TeX Live 2026): AAA (paragraph-initial) x=152.033 bp, BBB (\noindent) x=137.089 bp — both match the oracle and the issue's table exactly (152.0 / 137.1).

Two things worth the Commander's attention, neither a blocker:

  1. This PR tightens a pre-existing test's assertion in tikz_pipeline.rs (tikzpicture_becomes_paths_and_glyph_runs): the old bound was a loose min_x >= 72bp ("at the left margin"), now an exact (min_x_bp - 87.094).abs() <= 0.5. The PR's own comment explains the old bound "encoded the bug" (passed even when indented placement was wrong) — legitimate, but it is a changed expectation on a test that predates this PR.
  2. The PR also updates crates/perf-bench/baselines/linux-x86_64-ryzen7-7800x3d.json (re-recorded digests) since node-text geometry shifted. Not a vendor snapshot, so out of scope for that flag, but worth a sanity check that the new digests were regenerated from an actual run rather than hand-edited (diff shows only digest values changed, no accompanying regeneration log in the PR body).

No unwrap/expect added on data paths; picture_block's new indent math reuses existing list_geometry/text_params helpers rather than introducing new constants. No blockers found.

@jay3332

jay3332 commented Sep 18, 2026

Copy link
Copy Markdown
Member

mac-claude-a verification (comment only): the PR's oracle table reproduces exactly on this Mac — AAA 152.033, BBB 137.089, Normal 148.712 bp, branch vs pdflatex TL2026 — measured with tools/visual-oracle/pdftext.py from a CLI build of 9179214a.

One gap, not covered by the six new tests: crates/render-pipeline/src/typeset.rs:5162-5163 picture_block does if indent { x += self.style.parindent_pt } with no self.parbox guard. paragraph_block (typeset.rs:4072) zeroes \parindent inside parbox/float/minipage bodies (\@parboxrestore), and adapter.rs's indent computation has no parbox term either. So a paragraph-initial tikzpicture inside a minipage/\parbox/float body will be indented 15pt where pdflatex indents 0. Suggest gating on !self.parbox like the paragraph path, plus one test with the picture inside a minipage.

Mid-paragraph pictures are correctly excluded (initial requires whitespace-only inlines before the segment in split_at_page_breaks). vendor/ untouched; no new unwrap/expect; the changed tikz_pipeline.rs:67 bound was one-sided, not a buggy pin. Full cargo test on this branch could not complete here (machine at load 110+ from concurrent lanes) — the PR's 131-suite claim is unverified by me.

@d-q222
d-q222 merged commit ecd49f7 into main Sep 18, 2026
21 of 22 checks passed
jay3332 added a commit that referenced this pull request Sep 18, 2026
…#890

The previous re-record took tikz-heavy's digest from a run of the
pre-rebase commit; #866 (paragraph-initial tikz indent) and #890
(tikz inside floats) changed that case's output. 685eaf426bbefc9b is
what three local runs and CI's own run of e667cae produce.

Implementation-Agent: Claude Code (mac-claude-a)
Commit-Executor: git via Claude Code
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y1nAv4pEnmMYXgteBoadHn
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