Skip to content

Export PDF: four routes collapse to one (flashtex-pdf-exact), Print sends its bytes, long documents still export - #671

Merged
GoKubar merged 5 commits into
mainfrom
export-consolidation
Sep 16, 2026
Merged

GoKubar merged 5 commits into
mainfrom
export-consolidation

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

The app offered four PDF export affordances. Three of them wrote a
lower-fidelity version of the same document:

Command Input Fidelity
Export PDF… (⌘⇧E) v1 page items CoreGraphics, Times fallback faces, no images, monochrome
Export PDF via Rust Writer… (⌘⌥E) v1 envelope flashtex-pdf, a self-described SHIM that re-encodes by character
Export PDF (exact, v2)… v2 display list original GIDs, embedded font programs, verbatim decimals, typed rules, paths, images, device colour
Export PDF (v2)… (v2 pane) v2 frame the preview's own draw routine, labelled experimental

The exact route survives, renamed to plain File > Export PDF… on ⌘⇧E.
flashtex build already standardised on it. The other three are removed.

Print

File > Print… (⌘P) printed a separate CoreGraphics rendering, so Print and
Export could disagree about the same document. It now prints exactly the bytes
Export writes. Producing them runs the tool, so PrintController.printableDocument
is async and prepareDocument takes finished bytes instead of a CompileResult.

Print and Export share one predicate, ShellModel.exportPDFRefusal():

  • a historical preview refuses rather than writing the older snapshot as current;
  • a windowed display list refuses by name rather than writing blank pages
    (a document big enough to engage the page window has to go through
    flashtex build — called out in docs/user/gui.md);
  • a missing flashtex-pdf-exact is reported instead of silently disabling.

Menu enablement reads a new change-only mirror, toolbarExportable, so the File
menu is not re-evaluated on every v2 frame.

Long documents still export (the regression this would otherwise have shipped)

A document long enough to engage display-list-v2-window could, before this PR,
still be exported through the low-fidelity v1 route. Collapsing to the exact
route alone would have left it with no in-app export at all.

Re-requesting an unwindowed list does not fix that: the window engages only
after
the producer has already refused the unwindowed reply as over the 16 MiB
limit (V2PageWindow.swift — overLimitFailure / declinedSibling are the only
callers of engage()), so the same request would be refused again. That ceiling
belongs to the JSON Lines transport, not to the document.

The producer's own --v2 FILE side output has no line limit, and
flashtex-render writes the complete list of the last render to it even when
the reply it sent was the over-limit refusal
— Outputs::write runs off
Reply.rendered, which crates/render-pipeline/src/protocol.rs:502 still
carries on that path. So Export and Print now run the same producer binary
one-shot in worker mode, hand it the current buffers on stdin, ignore the reply,
and take the complete list from the file (WholeDocumentList.swift). This is
what flashtex build --v2 does. No Rust change. The list comes from the
request the app just sent, so it matches the editor by construction; the file is
private to that run and read only after the process exited, so there is no
freshness check and no torn read.

The two situations now read differently, because they are different:

  • windowed with the render pipeline available → not a refusal at all; it
    re-renders, reporting "Rendering all N pages…" in the status bar;
  • windowed with no flashtex-render discoverable → "this document is too large
    to send in one reply… attach it with ⌘⇧R, build crates/render-pipeline, or run
    flashtex build".

Stale docs corrected

apps/mac/README.md claimed the exact route "still refuses image items" and
"refuses path_fill/path_stroke", recommending Export PDF (v2)… for those.
crates/pdf/src/v2.rs paints both today (glyph_run, rule, path_fill, path_stroke and image), so removing the draw-routine export costs no fidelity.

What is left of the removed code

PDFExport.render survives only as the capture-proposal preview painter
(ProposalPreview.swift) and GlyphRunRenderer.pdfData only as the export side
of the v2 parity harness. Both go with the v1 preview renderer in the follow-up.

Verification

Mac gate on mac-m1max-a under the fleet lock, real Rust release binaries
(FLASHTEX_PDF_EXACT, FLASHTEX_RENDER, …): swift build exit 0; swift test
exit 0; 1370 tests, 12 skipped, 0 failures
, against the 1364 / 11 / 0 baseline.
The +6 / +1 delta is this branch's own tests (RustPDFExportTests and
RustPDFExportPipeTests removed, PrintControllerTests rewritten and extended).

Both windowed tests ran rather than skipped, which is the point — the
re-render path passed in 0.094 s and the no-producer refusal in 0.007 s. Also
green: testDocumentPrintIsTheExactExportOfTheSameDisplayList (real tool; the
printed bytes compared against a direct flashtex-pdf-exact run) and the whole
V2WindowTests / V2WindowLiveTests suite including the 40-page over-limit
end-to-end case.

An earlier run showed two RuntimeTranscriptTests failures on a file this branch
does not touch. Confirmed environmental rather than assumed: run in isolation
under the lock, 3/3 green on origin/main and 3/3 green on this branch. The
one genuine failure that run (a fractional media box PDFKit reports rounded) was
mine and is fixed in e63bb84.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

Four PDF export affordances collapse to one. The three removed routes each
wrote a lower-fidelity version of the same document:

- `File > Export PDF…` (⌘⇧E) drew the runtime-v1 page items with CoreGraphics:
  Times fallback faces, no images, monochrome.
- `File > Export PDF via Rust Writer…` (⌘⌥E) piped the v1 envelope to
  `flashtex-pdf`, which re-encodes by character (a self-described SHIM).
- `Export PDF (v2)…` in the v2 pane ran the preview's own draw routine
  (labelled experimental).

What stays is the exact route, now plain `File > Export PDF…` on ⌘⇧E: the
loaded display list through `flashtex-pdf-exact from-v2` — original GIDs,
embedded font programs, verbatim decimals, typed rules, `path_fill`/
`path_stroke` and image XObjects. `flashtex build` already standardised on it.
The README's "the exact route refuses images / TikZ" notes were stale; crates/
pdf `v2.rs` paints both today.

`File > Print…` (⌘P) now prints exactly those bytes instead of a parallel
CoreGraphics rendering, so Print and Export can no longer disagree. Producing
them runs the tool, so `PrintController.printableDocument` is async and
`prepareDocument` takes finished bytes rather than a `CompileResult`.

Print and Export share one predicate (`ShellModel.exportPDFRefusal()`): a
historical preview refuses, a windowed display list refuses by name rather
than writing blank pages, and a missing `flashtex-pdf-exact` is reported.
Menu enablement reads a new change-only mirror, `toolbarExportable`, so the
File menu does not re-evaluate on every v2 frame.

`PDFExport.render` survives only as the capture-proposal preview painter and
`GlyphRunRenderer.pdfData` only as the export side of the parity harness;
both go with the v1 preview renderer in the follow-up.

Implementation-Agent: claude-opus-5 (export-consolidation lane)
Commit-Executor: claude-opus-5 direct git (Cursor usage limit)
Co-authored-by: GoKubar <[email protected]>
… media box)

Implementation-Agent: claude-opus-5 (export-consolidation lane)
Commit-Executor: claude-opus-5 direct git (Cursor usage limit)
Co-authored-by: GoKubar <[email protected]>
Without this, collapsing to the exact route would have *introduced* a
regression: a document long enough to engage `display-list-v2-window` could
still be exported today through the (bad) v1 route, and after the collapse
could not be exported from the app at all.

Re-requesting an unwindowed display list does not work: the window engages
only after the producer has already refused the unwindowed reply as over the
16 MiB reply limit, so the same request would be refused again. That ceiling
belongs to the JSON Lines transport, not to the document.

The producer's own `--v2 FILE` side output has no line limit, and
`flashtex-render` writes the complete list of the last render to it even when
the reply it sent was the over-limit refusal — `Outputs::write` runs off
`Reply.rendered`, which that refusal still carries (render-pipeline
protocol.rs). So Export and Print now run the same producer binary one-shot in
worker mode, hand it the current buffers on stdin, ignore the reply, and take
the complete list from the file. This is what `flashtex build --v2` does. The
list is produced from the request the app just sent, so it matches the editor
by construction; the file is private to the run and read only after the process
exited, so there is no freshness check and no torn read. No Rust change.

The refusal copy now distinguishes the two situations the coordinator asked to
separate: "windowed for viewing" is not a refusal at all, while a windowed
document with no discoverable `flashtex-render` says it is too large to send in
one reply and names both fixes (attach with ⌘⇧R, or `flashtex build`).

Implementation-Agent: claude-opus-5 (export-consolidation lane)
Commit-Executor: claude-opus-5 direct git (Cursor usage limit)
Co-authored-by: GoKubar <[email protected]>
Implementation-Agent: claude-opus-5 (export-consolidation lane)
Commit-Executor: claude-opus-5 direct git (Cursor usage limit)
Co-authored-by: GoKubar <[email protected]>
Also neutral progress wording: the same resolver serves Print.

Implementation-Agent: claude-opus-5 (export-consolidation lane)
Commit-Executor: claude-opus-5 direct git (Cursor usage limit)
Co-authored-by: GoKubar <[email protected]>
@GoKubar GoKubar changed the title Export PDF: four routes collapse to one (flashtex-pdf-exact), and Print sends its bytes Export PDF: four routes collapse to one (flashtex-pdf-exact), Print sends its bytes, long documents still export Sep 16, 2026
@GoKubar
GoKubar merged commit f0a38b7 into main Sep 16, 2026
20 of 21 checks passed
@GoKubar
GoKubar deleted the export-consolidation branch September 16, 2026 04:17
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.

1 participant