Skip to content

Rework and expand typst-kit - #7710

Merged
laurmaedje merged 1 commit into
mainfrom
rework-typst-kit
Jan 19, 2026
Merged

laurmaedje merged 1 commit into
mainfrom
rework-typst-kit

Conversation

@laurmaedje

@laurmaedje laurmaedje commented Jan 16, 2026 •

Copy link
Copy Markdown
Member

Typst Kit provides reusable building blocks to downstream Typst integrations. This PR improves the API of existing functionality and adds a bunch of additional functionality. The original motivation for this was reusing some stuff from the CLI in the upcoming Typst-based docs.

Overview

I have attempted to design APIs that are as general and flexible as possible, supporting varied use cases. I'll give a brief overview over the changes and additions in each subsystem below. I've also remodelled the feature flags for more flexibility and naming consistency.

Fonts

Font loading is now a bit more generic: The new FontStore can still load embedded, path, and system fonts, but things can be composed somewhat more freely than before, and a font can also be loaded generically through a trait.

Files

The largest (and probably most useful) additions is the new FileStore, which is backed by a FileLoader. It takes care of creating, caching, and manages Typst source files, while delegating the raw loading to an underlying loader. From what I've seen, getting this right is (understandibly) the most difficult part about building a World. The new implementation is also a bit more efficient and correct than the old CLI's. When a file is used both as a source file and raw bytes, it's only read once now and the backing storage is reused as much as possible.

Packages

The previous PackageStorage is now broken up into three package providers: FsPackages, UniversePackages, and SystemPackages (which combines the two). Instead of being coupled to a fixed downloader implementation, UniversePackages depends on a generic impl Downloader.

Diagnostics

typst-kit now has a diagnostics::emit function, which emits formatted CLI-style diagnostics to a colorized writable. It's backed by the new DiagnosticsWorld (an extension to the World which can resolve names of files). This is similar in spirit to typst_ide::IdeWorld which adds extra requirements to the World for usage with IDE functionality.

Downloader

As already mentioned, the concrete provided downloader (based on ureq) is now decoupled from abstract downloading. I've also decoupled downloading itself from progress reporting by adding a new ProgressDownloader that wraps a generic downloader. Now, individual download calls do not decide whether progress reporting is desired. Instead, they provide a dynamic key, which the progress downloader can use to decide whether it wants to emit something (e.g. printing to the console). I've also fixed a bug with the download status printing, which would swallow the initial "downloading ..." line on the first update and show the status line twice when finishing.

Watcher

The file watching implementation of the CLI is now exposed in typst-kit.

Server

The live-reloading HTTP server implementation of the CLI is now also exposed in typst-kit.

Breakage

Given that the PR reworks the full API surface, it's obviously breaking. Beyond that, I've changed the default features from all to none. It is actually not that common to need all and selecting exactly what one needs is encouraged by this new default.

Beyond typst-kit, in the process of adjusting the feature flags, I've also renamed the CLI's embed-fonts feature flag to embedded-fonts.

Checking the API surface

For the best experience when browsing the new API's docs, I recommend the docsrs cfg because it gives nice docs for the future flag:

RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc -p typst-kit --no-deps

Why now?

I fell down a rabbit hole while working on the Docs-in-Typst. While it took a couple of days, I am quite happy with the new APIs and in particular the FileStore should make it considerably easier to build a World.

Issues

@laurmaedje

Copy link
Copy Markdown
Member Author

cc @tingerrr who originally introduced typst-kit, in case you want to take a look :)

@tingerrr tingerrr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've taken a quick look, quick for two reasons:

  • The code is actually fairly familiar, I've written very similar things for Tytanic. So reviewing it feels like reviewing my own code.
  • Stress at work means I have less energy in my free time.

Here's what I've done similarly:

  • file storage and package access
  • font loading
  • terminal diagnostics

I think your implementations take care of the same problems mine faced and work quite nicely. For example, I had initially implemented a virtual storage and a system storage both implementing my equivalent of the FileStore trait, the Loader trait is a clever abstraction there.

There are some things I haven't implemented in Tytanic, like file watching and HTML support, so the server and watcher are things I generally skipped over due to my lack of experience.

I don't think I can try these out as a dirty implementation in Tytanic, I won't have time until next weekend. And since they are so similar to mine, I likely wouldn't find any issues with API being inflexible.

I suggest @Myriad-Dreamin and co take a look, perhaps some requirements for tinymist can be satisfied here.

Comment thread crates/typst-kit/Cargo.toml Resolved
@laurmaedje
laurmaedje enabled auto-merge January 19, 2026 13:45
@laurmaedje
laurmaedje added this pull request to the merge queue Jan 19, 2026
Merged via the queue into main with commit 2b489a4 Jan 19, 2026
16 checks passed
@laurmaedje
laurmaedje deleted the rework-typst-kit branch January 19, 2026 14:49
Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
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.

typst-kit: Allow adding custom fonts from bytes, similar to default embedded fonts Add implementation of SystemWorld to typst-kit

2 participants