| Crates.io | bevy_typst_textures |
| lib.rs | bevy_typst_textures |
| version | 0.1.1 |
| created_at | 2025-07-17 11:56:30.423739+00 |
| updated_at | 2025-07-17 12:06:48.929841+00 |
| description | A simple Resource for generating rasterized textures out of either standalone .typ files or structured, zipped typst projects, built on typst-as-lib. |
| homepage | https://github.com/fallible-algebra/bevy_typst_textures |
| repository | https://github.com/fallible-algebra/bevy_typst_textures |
| max_upload_size | |
| id | 1757384 |
| size | 1,016,600 |
A simple Resource for generating rasterized textures (Handle<Image>) out of either standalone .typ files or structured, zipped typst projects, built on typst-as-lib.
To use this crate, add the TypstTexturesPlugin to your bevy app then request textures through TypstTextureServer:
use bevy::prelude::*;
use bevy_typst_textures::{TypstJobOptions, TypstTextureServer, TypstTexturesPlugin};
fn main() {
App::new()
.add_plugins((DefaultPlugins, TypstTexturesPlugin::default()))
.add_systems(Startup, start)
.run();
}
fn start(mut commands: Commands, mut typst_server: ResMut<TypstTextureServer>) {
commands.spawn(Camera2d);
commands.spawn(Sprite {
image: typst_server.add_job("my_zip_in_the_asset_folder.zip".into(), TypstJobOptions::default()),
..default()
});
}
Standalone .typ files can be loaded, but they will not have access to the bevy asset/ folder or any other .typ files and if you want to display text then either the typst-search-system-fonts or typst-asset-fonts features must be enabled.
For complex typst projects that need access to guaranteed, specific fonts as well as other assets, you'll need to create a .zip archive containing:
main.typ file.package.toml file:
asset/ folder asset requests (doesn't do anything right now)fonts/ folder is a good idea)
typst-search-system-fonts or typst-asset-fonts crate features are enabled, which will enable use of system fonts or the "default" typst fonts as embedded assets, respectively. This does still put the onus on you and your users to have these fonts either installed or bundled.This project is built on top of the typst-as-lib crate, which provides a nice wrapper over the internals of typst for standalone projects. The limitations of typst-as-lib are inherited by this crate.
This package expects typst assets as zip archives to simplify the asset-fetching process (as outlined above).
Packages are supported, but not on web. This may change in the future, but for now this does not work.
The archive unzipping is a bit fragile right now. Lots of unwraps and assumptions about how different OSs handle zip archives, and some ad-hoc dealing with how they pollute filesystems with metadata (__MACOS/ delenda est). Because zipping manually is a pain, I'd suggest setting up something to create zips of your typst assets folders in a build.rs script or as part of a watch command on your project.
add_job_with_data uses serde to serialize the input data type to json before then de-seralizing it to typst's Dict type. This presents the regular serde overhead, mostly.
All these features are pass-through features to typst-as-lib features. typst-asset-fonts is the only default feature.
typst-packages: Enable access to Universe packages. Package fetching is blocking, doesn't work on web, and relies on you also enabling one of the following:
typst-resolve-ureq: Use ureq to resolve packages.typst-resolve-reqwest: Use reqwest to resolve packages.typst-search-system-fonts: Allow access to system fonts from Typst.typst-asset-fonts: Embed the "default" fonts of typst, embedding them directly in the program's executable.Remember to set appropriate getrandom build configuration if you try to run this on web.
Velyst?This crate sits in the niche of needing rasterized textures rather than full & interactive typst integration. Velyst is much more powerful than this crate, but also exists in a different niche.
Planned features:
typst-as-lib supports packages in the browser, support packages in the browser.This is published under a dual MIT & Apache 2.0 licence, as is generally kosher for the bevy ecosystem.