Repository navigation
Description
Description
Typst currently fully decodes images and evaluates diagrams before producing output. I’d like an opt-in draft mode that produces a layout-accurate but visually simplified preview by replacing heavy content with same-size placeholders. The first draft compile would record each element’s final size and source location; later draft compiles would reuse that cache and substitute placeholders before layout. Normal compilation and export would stay unchanged.
The key constraint is that substitution has to happen before layout. Replacing images and diagram groups in the finished PagedDocument only speeds up PDF export, because the expensive work has already happened. Images can be handled automatically since FrameItem::Image already has a final Size and a Span. Complex drawings need an explicit marker or a small compiler hook because they become groups of shapes without a direct source span.
Draft mode should preserve width, height, baseline, inline/block behavior, and breakability so pagination stays accurate, and the cache should invalidate when source or assets change. I don’t have a strong opinion on whether this belongs in the compiler, CLI, or library; I mainly want a supported path that editors and build tools can share. The main open question is how to mark complex content without forcing users to rewrite the document.
I checked for duplicates: #2096 is related but closed after incremental SVG improvements, #6508 is about memoization, #5278 and #7668 are about PDF image embedding, and #5710 is about debug/release semantics. None of them proposes a pre-layout draft cache.
Use Case
I maintain Typsastra, an open-source desktop Typst editor aimed at long-form research writing. Typsastra already has a Draft Preview feature that replaces supported image calls, Fletcher diagrams, and CeTZ canvases with layout-preserving placeholders in a private render mirror; hovering over a placeholder reveals a cached thumbnail. You can see the current behavior in the Draft Preview docs and the v0.10.2 release notes. It works well enough that I use it constantly, but it’s fundamentally an editor-level workaround: it has to understand Typst source, rewrite a private copy, maintain its own size cache, and duplicate compiler-adjacent logic. Every other editor or build tool that wants the same feature would have to reinvent most of that.
I also built a stress benchmark to understand where the time actually goes. It was 19 A4 pages with 100 real images from Wikimedia Commons and 100 unique complex diagrams, split between CeTZ and Fletcher. A release build took about 5.3 seconds and produced a 60 MB PDF. Source-level replacement brought the whole compile and export down to about 130 ms and a 30 KB PDF, roughly a 40× speedup. Replacing only images got it to about 4.1 seconds, while replacing only diagrams got it to about 1.35 seconds, so both parts matter. The source-level placeholders matched the original page positions and sizes within 0.1 pt.
| Scenario | Layout | PDF export | Total | PDF size |
|---|---|---|---|---|
| Full render | 5.11 s | 143 ms | 5.26 s | 60 MB |
| Post-layout placeholders | 5.13 s | 1 ms | 5.13 s | 42 KB |
| Source-level draft | 0.13 s | 0.8 ms | 0.13 s | 30 KB |
| Images drafted only | 4.05 s | 8 ms | 4.06 s | 124 KB |
| Diagrams drafted only | 1.21 s | 141 ms | 1.35 s | 60 MB |
This would be useful well beyond my test document. Books, reports, theses, and diagram-heavy notes often have a slow “real” compile but a much faster “just show me the page layout” mode. It could also help typst watch, CI previews, the web app, and lower-powered machines where people mainly care about page breaks, spacing, and overall flow rather than the final artwork. Typsastra already demonstrates that people want this enough to maintain a workaround, and I’d rather see the capability become a supported part of Typst than have every editor implement its own version.
I’m happy to share more details from the Typsastra implementation and the benchmark, or help turn this into a PR if the direction sounds reasonable. I’m mostly opening this to discuss whether a first-class draft mode belongs in Typst, and if so, what shape it should take.
Activity
laurmaedje commentedon Nov 6, 2026
See #4035 for prior discussion about a draft mode.
To me, it's not so clear how your proposal would work for things that don't have a defined size (cetz diagrams). Your top-level issue a bit verbose and clearly AI-written and I'm having trouble extracting the concrete proposal.
Sovichea commentedon Nov 6, 2026
Thanks for pointing me to #4035. I was thinking more of LaTeX's "graphicx" draft mode, which replaces images with bounding boxes while preserving layout. For CeTZ and Fletcher, Typsastra handles the unknown dimensions by caching measurements from normal compilation and reusing them for placeholders in subsequent draft compilations, with background remeasurement when needed.
The goal is to skip expensive content evaluation when only the surrounding text changes. This reduced compilation time from 5.26s to 0.13s in my benchmark. I agree that arbitrary diagrams are challenging, so perhaps an opt-in mechanism for packages would be a reasonable starting point.
And yes, I used AI to help structure the issue, but the implementation and benchmarks come from my actual work on Typsastra. I probably made the explanation longer than necessary.