Repository navigation
render-pipeline: graphicx draft and demo reserve the space pdfTeX reserves - #377
Merged
Merged
Conversation
… reserves
Both options are ways of keeping an image's space without embedding the
file, which is why test documents use them: four corpus fixtures write
`\includegraphics[draft]` and two load `\usepackage[demo]{graphicx}`. We
honoured neither, so each of those graphics reserved nothing and the
document reflowed.
`demo` (`graphics.sty` `\DeclareOption{demo}`) replaces the whole of
`\Ginclude@graphics` with `\rule{\@ifundefined{Gin@@ewidth}{150pt}
{\Gin@@ewidth}}{\@ifundefined{Gin@@Eheight}{100pt}{\Gin@@Eheight}}`. No file
is looked up. `\Gin@req@sizes` -- the only thing that scales a natural size,
applies `keepaspectratio` and honours a leading `scale=` -- is never used,
so all that reaches the rule is what `\Gin@esetsize` left in
`\Gin@@ewidth`/`\Gin@@eheight`, and it reaches it literally: `[width=W]`
gives a `W` x 100pt rule, not a proportional one. From the first
`angle=`/`scale=` onwards the rule is wrapped in `\Gin@erotate`/
`\Gscale@@box` exactly as a real graphic is, and `keepaspectratio` does
apply there. `demo` beats `draft`, whose branch lives in `\Gin@setfile`,
which is never reached.
`draft` changes no dimension at all: `\Gin@setfile` still reads the file's
bounding box and still sets a box of `\Gin@req@width` x `\Gin@req@height`,
it just fills it with a frame of default-thickness rules and a `\rlap`ped
file name instead of the image. What it does change is a file that is not
there: `pdftex.def`'s `\Gread@pdftex` leaves the bounding box at `0 0 72 72`
and, under `draft`, warns instead of raising its package error -- so the
graphic reserves one inch square, scaled by the keys. That is where the
corpus divergence came from: all six fixture graphics name files that do
not exist. `draft` is now a key (`draft=false` turns it off for one
graphic), a package option, and a class option, since LaTeX passes the
class options to every package; a `final` anywhere cancels it, because
`\ProcessOptions` runs the declared options in declaration order and
`final` is declared after `draft`.
The reserved box is painted: a solid rule for `demo`, the four-rule frame
for `draft`. The frame's `\rlap`ped file name is not set yet -- it is
centred inside the reserved box and contributes no dimension -- and neither
placeholder is painted when an `angle=` has turned the box, since the wire
`Rule` item is axis-aligned. `trim`/`clip`/`viewport` stay recognised and
deliberately unhonoured; no field was added to the wire `Image` item.
Verified on linux-primary NixOS against a control build of origin/main
bca6ce5 in the same worktree and the same target directory, oracle
pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025):
- 24 measured `demo` key combinations and the `draft` fallback size are
unit tests in `graphics.rs`; three end-to-end tests through a `figure`
are `tests/graphics_draft_demo.rs`.
- cargo test --release --locked --no-fail-fast: render-pipeline 244p/0f/1i
(control 241p/0f), compiler 498p/0f/4i (crate untouched).
- amsmath oracle 59/59 within 0.5 bp; tabular oracle 106/106 (words 0.5 bp,
rules 0.1 bp).
- HW1 and HW2 through `flashtex-render`: 3 pages each, 0 errors, 0
overfull, 0 font-failure diagnostics -- unchanged from control. (The
`flashtex-compiler` producer still reports HW2 as 4 pages; that
disagreement is untouched here.)
- real-world corpus vs control, `flashtex-render` producer: page-count
match 16/22 -> 19/22. article-twocolumn 1 -> 2 (= pdflatex 2),
hyperref-toc 3 -> 4 (= 4), lab-report 2 -> 3 (= 3). conf-paper 2 -> 3
(pdflatex 4, see below); thesis-chapter and twelvept-plain unchanged.
Render error-severity diagnostics 94 -> 89; no document gains an error.
Font diagnostics identical (only `missing_glyph`, same 20).
- conf-paper is still one page short for a reason that is not graphics:
its figure is a `figure*`, where pdflatex's `\linewidth` is `\textwidth`
(505.89pt) rather than the 243.91pt `\columnwidth` this engine resolves
it to, because a double-column float is not modelled. thesis-chapter's
and twelvept-plain's remaining page is also unrelated to graphics.
Implementation-Agent: engine-engineer (Claude Opus 5), linux-primary
Commit-Executor: this agent, direct Git under the observed Cursor-limit
fallback
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
…name}`
report.cls and book.cls open `thebibliography` with
`\chapter*{\bibname\@mkboth{...}}`, not article.cls's
`\section*{\refname}`. The compiler synthesises one unnumbered level-1
heading reading `References` for every class, and the pipeline laid that
out as a section in the flow — so in a `report` the bibliography was set
under the wrong name at the bottom of whatever page the body ended on,
with no `\clearpage` and no `\@makeschapterhead` drop.
`fixtures/real-world/thesis-chapter` is exactly this shape, and it is why
it came out **4 pages against pdflatex's 5**: pages 1-4 were already
word-for-word in the right places; the reference simply starts a fifth
page for the bibliography that we folded onto page 4.
**This is not the missing-`[draft]`-graphic cause it was attributed to.**
That fixture's `\includegraphics[draft,width=0.7\linewidth]{network.pdf}`
sits inside a `figure`, and PR #377's reservation already handles it:
probing that float against pdflatex gives dy **-0.086 bp** for the caption
and the text below it. The reservation gap is real but confined to
*running-text* `\includegraphics`, which every corpus fixture avoids (all
six are inside a `figure`/`figure*`) — see the PR body.
Measured against pdflatex (TeX Live 2025) on a minimal report:
pages 1 -> 2 (reference 2)
`Bibliography` head not set -> x 72.000, baseline 162.660 (both exact)
first `[1]` entry x 77.424, baseline 216.060 (both exact)
chapter body unmoved on page 1
Corpus (22 real documents vs pdflatex, tolerance 0.5 bp):
**page counts 20/22 -> 21/22**, dx 84.47% -> 84.55%, dy 65.21% -> 65.40%,
both 58.67% -> 58.90%, aligned 13985 -> 14062. `thesis-chapter` is the
only fixture that moves: 4/5 -> **5/5** pages, dx 91.87 -> 92.33, dy 99.84
-> 99.85, both 91.87 -> 92.33, aligned 1279 -> 1356 (the whole fifth page
now compares). The one page count still wrong is `twelvept-plain` (4
against 3), a different cause and not touched here.
Gates: `cargo test --release --no-fail-fast` on render-pipeline 254 passed
/ 0 failed / 2 ignored (plus the new `report_bibliography` tests),
class-geometry 4/0, compiler 577/0/4; amsmath 59/59, tabular 106/106, HW1
and HW2 3 pages / 0 errors / 0 font-FAILURE diagnostics.
Implementation-Agent: Claude Opus 5 (lane nixos-graphics-sectioning, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
GoKubar
added a commit
that referenced
this pull request
Sep 14, 2026
…name}` (#399) report.cls and book.cls open `thebibliography` with `\chapter*{\bibname\@mkboth{...}}`, not article.cls's `\section*{\refname}`. The compiler synthesises one unnumbered level-1 heading reading `References` for every class, and the pipeline laid that out as a section in the flow — so in a `report` the bibliography was set under the wrong name at the bottom of whatever page the body ended on, with no `\clearpage` and no `\@makeschapterhead` drop. `fixtures/real-world/thesis-chapter` is exactly this shape, and it is why it came out **4 pages against pdflatex's 5**: pages 1-4 were already word-for-word in the right places; the reference simply starts a fifth page for the bibliography that we folded onto page 4. **This is not the missing-`[draft]`-graphic cause it was attributed to.** That fixture's `\includegraphics[draft,width=0.7\linewidth]{network.pdf}` sits inside a `figure`, and PR #377's reservation already handles it: probing that float against pdflatex gives dy **-0.086 bp** for the caption and the text below it. The reservation gap is real but confined to *running-text* `\includegraphics`, which every corpus fixture avoids (all six are inside a `figure`/`figure*`) — see the PR body. Measured against pdflatex (TeX Live 2025) on a minimal report: pages 1 -> 2 (reference 2) `Bibliography` head not set -> x 72.000, baseline 162.660 (both exact) first `[1]` entry x 77.424, baseline 216.060 (both exact) chapter body unmoved on page 1 Corpus (22 real documents vs pdflatex, tolerance 0.5 bp): **page counts 20/22 -> 21/22**, dx 84.47% -> 84.55%, dy 65.21% -> 65.40%, both 58.67% -> 58.90%, aligned 13985 -> 14062. `thesis-chapter` is the only fixture that moves: 4/5 -> **5/5** pages, dx 91.87 -> 92.33, dy 99.84 -> 99.85, both 91.87 -> 92.33, aligned 1279 -> 1356 (the whole fifth page now compares). The one page count still wrong is `twelvept-plain` (4 against 3), a different cause and not touched here. Gates: `cargo test --release --no-fail-fast` on render-pipeline 254 passed / 0 failed / 2 ignored (plus the new `report_bibliography` tests), class-geometry 4/0, compiler 577/0/4; amsmath 59/59, tabular 106/106, HW1 and HW2 3 pages / 0 errors / 0 font-FAILURE diagnostics. Implementation-Agent: Claude Opus 5 (lane nixos-graphics-sectioning, linux-primary) Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both graphicx options are ways of reserving an image's space without reading the file, which is why test documents use them. Four corpus fixtures write
\includegraphics[draft]and two load\usepackage[demo]{graphicx}; we honoured neither, so each of those graphics reserved nothing and the document reflowed. This was the single biggest cause of page-count divergence on the real-world corpus (issue #2, comment 5662357740).What pdfTeX does — measured, not assumed
Oracle:
pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025),\wd/\ht/\dpof the\hbox. pdflatex is an oracle only and is never in the product path.demographics.sty's\DeclareOption{demo}replaces the whole of\Ginclude@graphicswithso no file is looked up at all, and
\Gin@req@sizes— the only thing that scales a natural size, applieskeepaspectratioand honours a leadingscale=— is never used. All that reaches the rule is what\Gin@esetsizeleft in\Gin@@ewidth/\Gin@@eheight, and it reaches it literally:width=100ptheight=40ptwidth=100pt,height=40ptkeepaspectratio,width=100pt,height=40ptkeepaspectrationever reaches\Gin@req@sizesscale=2scale, which only sets\if@tempswascale=2,width=100ptwidthafter it is a\Gscale@@boxaround the default rulewidth=100pt,scale=2scaledoes not consume a pendingwidthangle=90width=100pt,angle=90angledoes consume the pendingwidthinto the rule firstangle=90,width=100ptanglethewidthresizes the rotated boxangle=30angle=45,keepaspectratio,width=100pt,height=40pt\Gscale@@boxdoes honourkeepaspectratiowidth=100pt,angle=90,height=40ptDepth is 0 throughout. All 24 measured rows are a unit test.
draftdraftchanges no dimension:\Gin@setfilestill reads the file's bounding box and still sets a box of\Gin@req@width×\Gin@req@height— it just fills it withinstead of the image. Measured with a real 150 × 100 bp PNG, every key combination gives byte-identical dimensions with and without
draft.What it does change is a file that is not there.
pdftex.def's\Gread@pdftexleaves the bounding box at0 0 72 72and, underdraft, warns instead of raising its package error:draftdraft,width=100ptdraft,width=0.5\linewidthdraft,angle=30That is where the corpus divergence came from: all six fixture graphics name files that do not exist.
draftis a key (draft=falseturns it off for one graphic), a package option, and a class option — LaTeX passes the class options to every package. Afinalanywhere cancels it, in either list and in either order, because\ProcessOptionsruns the declared options in declaration order andfinalis declared right afterdraft.demobeatsdraft, whose branch lives in\Gin@setfile, which underdemois never reached — that is exactly thehyperref-tocfixture, which writes both.Result
Real-world corpus,
flashtex-renderproducer, against a control build oforigin/mainbca6ce52in the same worktree and the same target directory:[demo],width=\columnwidth[demo]+ a per-imagedraft[draft,width=0.8\linewidth]{plot.png}[draft,width=\linewidth]{fig.pdf}in afigure*— see below[draft,width=0.7\linewidth]— box now correct, page notPage-count match 16/22 → 19/22. Render error-severity diagnostics 94 → 89; no document gains an error. The other 16 documents are byte-for-byte unchanged in page count.
conf-paperis still one page short for a reason that is not graphics: its figure is afigure*, where pdflatex's\linewidthis\textwidth(505.89 pt) rather than the 243.911 pt\columnwidththis engine resolves it to, because a double-column float is not modelled at all —floats::scanmapsfigure*to plainFloatKind::Figureandfloatpage::build_boxsets every float atstyle.text_width_pt. That is the next thing to fix for this fixture, and it is a float-placement change, not a graphics one.Painting
The reserved box is painted: a solid rule for
demo, the four-rule frame fordraft. Two honest limits:\rlapped file name is not set — it is centred inside the reserved box and contributes no dimension, so it costs nothing in space;angle=has turned the box, since the wireRuleitem is axis-aligned. The space is still exact.trim/clip/viewportstay recognised and deliberately unhonoured; no field was added to the wireImageitem.\includegraphicsin running text is still dropped onmain(#325 is open, not merged).parse_keys,modeanddemo_boxare shared, so that PR picks up the key parsing for free but will need the samedemo/draftbranch at its own call site.Gates
Built with
CARGO_BUILD_JOBS=4; control and branch in the same directory.cargo test --release --locked --no-fail-fast: render-pipeline 244 passed / 0 failed / 1 ignored (control 241/0/1 — the three new tests), compiler 498 passed / 0 failed / 4 ignored (crate untouched).flashtex-render, 0 errors, 0 overfull, 0 font-failure diagnostics — unchanged from control. (Theflashtex-compilerproducer still reports HW2 as 4 pages; that producer disagreement is untouched here.)missing_glyphwarnings, noec_metrics_unavailable/font_unavailable/tfm_run_error.No vendor directory was touched, so no re-pin is needed. Only
crates/render-pipelinechanges, so there is no compiler PR to split off.🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu