Skip to content

Bundle export - #7964

Merged
laurmaedje merged 45 commits into
mainfrom
bundle-export
Mar 11, 2026
Merged

laurmaedje merged 45 commits into
mainfrom
bundle-export

Conversation

@laurmaedje

Copy link
Copy Markdown
Member

This pull request implements a new experimental export target that can emit multiple files from a single Typst project. The implementation mostly follows the design laid out in #7735.

The new export target is primarily useful for multi-page websites, but is not limited to that. You can create bundles containing any combination of HTML pages, PDFs, PNGs, SVGs, and arbitrary assets.

The primary motivation to ship this new target now is to use it in the ongoing work on porting the Typst documentation to Typst. However, it's also a big step in generally making HTML export more practically useful.

Example

typst compile main.typ --format bundle --features bundle,html
#document("index.html", title: "Home")[
  #title()
  - #link(<blog>)[Go to blog]
]

#document("blog.html", title: "Blog")[
  #title()
  Welcome to my blog!

  ...

  This blog also exists as a
  #link(<blog-pdf>)[single PDF].
] <blog>

#document("blog.pdf", title: "Blog")[
  ...
] <blog-pdf>

#asset(
  "favicon.ico",
  read("images/favicon.ico", encoding: none),
)

In the example, we create two HTML documents: A home page and a blog. The home page links to the blog through a label link. Typst's built-in linking mechanism natively supports cross-document links and resolves the correct relative paths for you. The bundle also contains a PDF version of the blog, which is linked from the HTML version. In practice, you could now share the content between the HTML and PDF version by storing it in a variable and using it in both. This is omitted here for brevity. Finally, the bundle contains an icon asset for the website. In this case, we're providing the asset's data by reading a file from disk. Alternatively, it's also possible to generate asset data from within Typst (e.g. via a function like json.encode).

Scope

Compared to the design issue, this is a slightly scoped down version. Specifically, for now, I omitted the ppi, pages, and pdf parameters to document. Instead, export of individual documents respects the usual CLI parameters. In principle, I still want to expose these configuration options at the Typst level, but it's not blocking for landing the work itself and also not necessary for the docs work. Moreover, to make CLI settings and in-document settings interact cleanly, a few things need sorting out first.1

As mentioned in the issue, I've also decided to accept that introspections are always global to the bundle for the time being. Often, this is exactly what you want, but in some cases, it's unwieldy. I don't think there's a simple clean "fix" for that. Rather, improving this will be more of a long-term process of evolving the introspection subsystem.

Notes

The history is carefully crafted with jj :), so if you want to take a look at what's changed / how it's implemented, I invite you to read the commits in isolation.

Linked issues

Closes #7735

Footnotes

  1. Primarily that SOURCE_DATE_EPOCH is not perfectly handled at the moment. It behaves exactly like --creation-timestamp while in reality it should behave more like if the system clock happened to be it at its timestamp. I'll open a separate issue about that. ↩

@Andrew15-5

Copy link
Copy Markdown
Contributor

One step closer to docs in Typst!


After reading a bit about counters in #7735 (comment), I'm wondering if this "solves" #7342 as well. If you somehow can get counter(page.from(<doc>)).get().first(), then you can combine #7735 (comment) with #7342 (comment) and loop over document with different document.page and document.path. This should be enough to be a cumbersome workaround for the shell script, but run pages times faster, as the compiler is only run once.

Comment thread crates/typst-svg/src/lib.rs Resolved
Comment thread tests/suite/introspection/query.typ Resolved
Comment thread tests/suite/layout/flow/footnote.typ Resolved
@laurmaedje laurmaedje added interface PRs that add to or change Typst's user-facing interface as opposed to internals or docs changes. bundle Related to bundle export. labels Mar 11, 2026
Comment thread docs/reference/export/bundle.md Resolved
Comment thread docs/reference/export/bundle.md Resolved
Comment thread docs/reference/export/bundle.md Resolved
Comment thread docs/reference/export/bundle.md Resolved
Comment thread crates/typst-library/src/model/asset.rs Resolved
Comment thread crates/typst-library/src/model/link.rs Resolved
Comment thread crates/typst-bundle/src/export.rs Resolved
This will be used in bundle export.
If you're using `typst` as a crate, you now need to depend on `typst-layout` separately to compile a paged document.
Not every output must be a document, c.f. the upcoming bundle output.
Documents are cloned due to memoization and deep-cloning the introspector isn't great.
The generic term `Position` being the more specific struct compared to `DocumentPosition` isn't great.
There is a name collision with link anchors here.
Previously, they were only emitted when linked to (at least since krilla). This was, however, not the original design intent.
In preparation of the bundle introspector working quite differently from the existing ones.
This will be useful for making paged documents hashable without hashing the introspector.
This will be useful for memoizing paged exports during bundle export.
ParaN3xus added a commit to ParaN3xus/typstyle that referenced this pull request Jun 4, 2026
QuadnucYard added a commit to typstyle-rs/typstyle that referenced this pull request Jun 6, 2026
commit 65301b2
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Fri Jun 5 00:57:12 2026 +0000

    build: update tinymist to 0.14.23

commit 3ac7c69
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Thu Jun 4 23:30:34 2026 +0000

    build: update tinymist to 0.14.23-rc1

commit 4f5efbf
Author: paran3xus <[email protected]>
Date:   Thu Jun 4 12:41:19 2026 +0000

    feat: add compatibility for typst/typst#7865 and typst/typst#8116

commit cb25b2e
Author: paran3xus <[email protected]>
Date:   Sat May 16 10:06:29 2026 +0000

    fix: adapt typstyle-consistency to typst/typst#7964

commit ae25cb3
Author: paran3xus <[email protected]>
Date:   Sat May 16 10:06:22 2026 +0000

    fix: adapt today to typst/typst#7691

commit c5702de
Author: paran3xus <[email protected]>
Date:   Sat May 16 05:14:33 2026 +0000

    build: patch typst-bundle

commit aeffa37
Author: paran3xus <[email protected]>
Date:   Fri May 15 05:09:16 2026 +0000

    build: bump tinymist-world to nightly (remote branch)

commit 8ea80b1
Author: paran3xus <[email protected]>
Date:   Thu May 14 05:08:26 2026 +0000

    build: bump typst to nightly (local patch)

    a
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin added a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 14, 2026
This PR is part of the Typst 0.15 cleanup stack. It sits on top of the
dependency/toolchain group and covers the first world/document output
API adaptation slice.

## Upstream Typst Changes

- [`typst/typst#7964` Bundle
export](typst/typst#7964) splits document output
into target-specific APIs.
- Tinymist now works with `typst_layout::PagedDocument`,
`typst_html::HtmlDocument`, `typst::model::Document`, and
`typst::foundations::Output` instead of relying on the old broad
document surface.
- Document fields are private; callers need accessors such as `pages()`,
`info()`, `introspector()`, and `root_mut()`.
- Document introspection changes around `typst/typst@7d2edbdb3` move
consumers toward the target document's output introspector.
- `DocumentInfo` is the compiled-document metadata payload (`title`,
`author`, `description`, `keywords`, `date`, `locale`). Typst populates
it while creating the target document from document/text styles, not
from finished `Page` or `Frame` values.
- HTML/SVG conversion now goes through the bundle-aware `svg_in_html`
path with a `LateLinkResolver`.
- [`typst/typst#7691`](typst/typst#7691) changes
`World::today` from an hour offset to
`Option<typst::foundations::Duration>`.
- `typst/typst@acc3fed51` moves paged positions to
`typst::introspection::PagedPosition`.
- Typst 0.15 also requires protected engine introspection through
`typst::utils::Protected`.

## Tinymist Changes

- Adapts `tinymist-std`, `tinymist-world`, and `tinymist-task` to the
new `Document` / `Output` split and concrete paged/HTML document types.
- Updates query export for the new `eval_string` signature and uses
`SpanMode::Uniform(Span::detached())` for selector strings that do not
come from a `.typ` source range.
- Updates paged document access, output introspector access, debug
location typing, preview/outline consumers, and HTML root mutation to
the new accessor-based APIs.
- Preserves original compiled document metadata for merged PNG/SVG
exports with `doc.info().clone()` while still constructing a temporary
document from selected pages.
- Updates typlite SVG embedding to forward real `HtmlFrame` metadata
when available and use neutral standalone-frame defaults when only a
bare `Frame` is available.
- Updates `World::today` for Typst duration offsets while keeping
existing cached `now` initialization in place; only the
duration-to-second offset conversion is factored out.
- Refreshes the minimal `Cargo.lock` metadata needed by the new
`typst-layout` dependency path.

---------

Co-authored-by: paran3xus <[email protected]>
Myriad-Dreamin added a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 15, 2026
This PR is part of the Typst 0.15 nightly cleanup stack. It sits on top
of the analysis/eval API group and keeps this slice focused on bundle
export plumbing.

## Upstream Typst Changes

- [`typst/typst#7964` Bundle
export](typst/typst#7964) introduces bundle
output as a first-class target and changes how HTML/PDF/SVG/PNG export
paths are selected from compiled documents.
- Typst 0.15 exposes target information differently in
`dictionary(std)`: the `target` key is always present, so target checks
that relied only on key presence need to check for the actual HTML
target value.
- The broader export option changes from later Typst PRs remain outside
this slice; this PR is only the bundle export plumbing needed before
those option-level adaptations.

## Tinymist Changes

- Adds bundle export support through the compile/project/LSP pipeline so
bundle output can flow through tinymist's existing compilation tasks.
- Extends export task models and PDF/export compute paths for the bundle
target.
- Adds CLI export wiring and server command registration for
bundle-aware export tasks.
- Adds VS Code command/task integration and localized command text for
bundle export.
- Updates editor-tools exporter format metadata so the frontend can
surface the bundle target.
- Updates Typst templates that check whether the system target is HTML
to use the 0.15-compatible target value check.

---------

Co-authored-by: paran3xus <[email protected]>
Myriad-Dreamin added a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 15, 2026
This PR is part of the Typst 0.15 nightly cleanup stack. It sits on top
of the Typlite paragraph/linebreak adaptation and keeps this slice
focused on bundle export plumbing.

## Upstream Typst Changes

- [`typst/typst#7964` Bundle
export](typst/typst#7964) introduces bundle
output as a first-class target and changes how HTML/PDF/SVG/PNG export
paths are selected from compiled documents.
- Typst 0.15 exposes target information differently in
`dictionary(std)`: the `target` key is always present, so target checks
that relied only on key presence need to check for the actual HTML
target value.
- The broader export option changes from later Typst PRs remain outside
this slice; this PR is only the bundle export plumbing needed before
those option-level adaptations.

## Tinymist Changes

- Adds bundle export support through the compile/project/LSP pipeline so
bundle output can flow through tinymist's existing compilation tasks.
- Extends export task models and PDF/export compute paths for the bundle
target.
- Adds CLI export wiring and server command registration for
bundle-aware export tasks.
- Adds VS Code command/task integration and localized command text for
bundle export.
- Updates editor-tools exporter format metadata so the frontend can
surface the bundle target.
- Updates Typst templates that check whether the system target is HTML
to use the 0.15-compatible target value check.

---------

Co-authored-by: paran3xus <[email protected]>
Myriad-Dreamin pushed a commit to Myriad-Dreamin/typst.ts that referenced this pull request Jun 15, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/typst.ts that referenced this pull request Jun 15, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/typst.ts that referenced this pull request Jun 15, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/typst.ts that referenced this pull request Jun 15, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/typst.ts that referenced this pull request Jun 15, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/typst.ts that referenced this pull request Jun 15, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/typst.ts that referenced this pull request Jun 15, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/typst.ts that referenced this pull request Jun 15, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/typst.ts that referenced this pull request Jun 15, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/typst.ts that referenced this pull request Jun 15, 2026
Myriad-Dreamin added a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 15, 2026
This PR is part of the Typst 0.15 cleanup stack. It sits on top of the
dependency/toolchain group and covers the first world/document output
API adaptation slice.

- [`typst/typst#7964` Bundle
export](typst/typst#7964) splits document output
into target-specific APIs.
- Tinymist now works with `typst_layout::PagedDocument`,
`typst_html::HtmlDocument`, `typst::model::Document`, and
`typst::foundations::Output` instead of relying on the old broad
document surface.
- Document fields are private; callers need accessors such as `pages()`,
`info()`, `introspector()`, and `root_mut()`.
- Document introspection changes around `typst/typst@7d2edbdb3` move
consumers toward the target document's output introspector.
- `DocumentInfo` is the compiled-document metadata payload (`title`,
`author`, `description`, `keywords`, `date`, `locale`). Typst populates
it while creating the target document from document/text styles, not
from finished `Page` or `Frame` values.
- HTML/SVG conversion now goes through the bundle-aware `svg_in_html`
path with a `LateLinkResolver`.
- [`typst/typst#7691`](typst/typst#7691) changes
`World::today` from an hour offset to
`Option<typst::foundations::Duration>`.
- `typst/typst@acc3fed51` moves paged positions to
`typst::introspection::PagedPosition`.
- Typst 0.15 also requires protected engine introspection through
`typst::utils::Protected`.

- Adapts `tinymist-std`, `tinymist-world`, and `tinymist-task` to the
new `Document` / `Output` split and concrete paged/HTML document types.
- Updates query export for the new `eval_string` signature and uses
`SpanMode::Uniform(Span::detached())` for selector strings that do not
come from a `.typ` source range.
- Updates paged document access, output introspector access, debug
location typing, preview/outline consumers, and HTML root mutation to
the new accessor-based APIs.
- Preserves original compiled document metadata for merged PNG/SVG
exports with `doc.info().clone()` while still constructing a temporary
document from selected pages.
- Updates typlite SVG embedding to forward real `HtmlFrame` metadata
when available and use neutral standalone-frame defaults when only a
bare `Frame` is available.
- Updates `World::today` for Typst duration offsets while keeping
existing cached `now` initialization in place; only the
duration-to-second offset conversion is factored out.
- Refreshes the minimal `Cargo.lock` metadata needed by the new
`typst-layout` dependency path.

---------

Co-authored-by: paran3xus <[email protected]>
Myriad-Dreamin added a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 15, 2026
This PR is part of the Typst 0.15 cleanup stack. It sits on top of the
dependency/toolchain group and covers the first world/document output
API adaptation slice.

- [`typst/typst#7964` Bundle
export](typst/typst#7964) splits document output
into target-specific APIs.
- Tinymist now works with `typst_layout::PagedDocument`,
`typst_html::HtmlDocument`, `typst::model::Document`, and
`typst::foundations::Output` instead of relying on the old broad
document surface.
- Document fields are private; callers need accessors such as `pages()`,
`info()`, `introspector()`, and `root_mut()`.
- Document introspection changes around `typst/typst@7d2edbdb3` move
consumers toward the target document's output introspector.
- `DocumentInfo` is the compiled-document metadata payload (`title`,
`author`, `description`, `keywords`, `date`, `locale`). Typst populates
it while creating the target document from document/text styles, not
from finished `Page` or `Frame` values.
- HTML/SVG conversion now goes through the bundle-aware `svg_in_html`
path with a `LateLinkResolver`.
- [`typst/typst#7691`](typst/typst#7691) changes
`World::today` from an hour offset to
`Option<typst::foundations::Duration>`.
- `typst/typst@acc3fed51` moves paged positions to
`typst::introspection::PagedPosition`.
- Typst 0.15 also requires protected engine introspection through
`typst::utils::Protected`.

- Adapts `tinymist-std`, `tinymist-world`, and `tinymist-task` to the
new `Document` / `Output` split and concrete paged/HTML document types.
- Updates query export for the new `eval_string` signature and uses
`SpanMode::Uniform(Span::detached())` for selector strings that do not
come from a `.typ` source range.
- Updates paged document access, output introspector access, debug
location typing, preview/outline consumers, and HTML root mutation to
the new accessor-based APIs.
- Preserves original compiled document metadata for merged PNG/SVG
exports with `doc.info().clone()` while still constructing a temporary
document from selected pages.
- Updates typlite SVG embedding to forward real `HtmlFrame` metadata
when available and use neutral standalone-frame defaults when only a
bare `Frame` is available.
- Updates `World::today` for Typst duration offsets while keeping
existing cached `now` initialization in place; only the
duration-to-second offset conversion is factored out.
- Refreshes the minimal `Cargo.lock` metadata needed by the new
`typst-layout` dependency path.

---------

Co-authored-by: paran3xus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bundle Related to bundle export. interface PRs that add to or change Typst's user-facing interface as opposed to internals or docs changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi-file output

6 participants