Static assets
Calling read, json, or image in Typst only reads files at compile time and does not publish them to browsers. Static files served to clients come from [assets], compiler-emitted derivatives (@tola/image, @tola/icon, asset(...)), or [[hooks.generate-outputs]] and module hooks.
Static assets
Declare individual files under files and directory trees under trees in tola.toml:
[assets]
cache-busting = true
files = [
{ source = "static/robots.txt", url = "/robots.txt" },
{ source = "static/logo.svg", url = "/media/logo.svg" },
]
trees = [
{ source = "static/styles", url-prefix = "/styles", include = ["static/styles/**/*.css"] },
]include defaults to ["."] (the full source directory) and matches nothing when set to []; include and exclude resolve relative to the site (or module) root. When a source file matches both files and trees, the explicit files entry wins—even when enable = false. Trees skip symlinks by default; enable follow-file-symlinks = true on a trees entry to follow file symlinks (directory symlinks are never traversed; add another trees entry instead).
Reference declared assets in Typst with asset-url("/styles/main.css"). It verifies that the asset is enabled, prepends site.base-path, and appends ?h=<hash> when cache-busting is enabled.
Fonts
Typst compiler fonts and browser web fonts are configured independently:
# Compiler fonts for PDF, html.frame math/diagrams, and SVG rasterization
[typst.fonts]
paths = ["fonts/compiler"]
system = false
# Web fonts served to browsers via CSS @font-face
[assets]
trees = [{ source = "static/fonts", url-prefix = "/fonts" }]@font-face {
font-family: "Inter";
src: url("../fonts/inter.woff2") format("woff2");
font-display: swap;
}Run tola inspect fonts to list fonts visible to Typst. Because --pure disables host system fonts, place fonts required in offline or CI builds inside the site or a module’s [typst] fonts.
Images
Pick the right mechanism per target:
| Use case | Mechanism |
|---|---|
PDF or inside html.frame | Native image("..."). |
| Verbatim static images or SVGs | Declare in [assets] and render html.img(src: asset-url(...)). |
On-demand resize & responsive srcset | Use @tola/image:0.0.0 (img, image-srcset, resize-image, image-metadata). |
Batch-resize all [assets] images | Add the official resize-images module. |
@tola/image generates and caches derived images on demand under _tola/images/ (returned URLs already include base-path), so original high-res files do not need to sit in [assets]:
#import "@tola/image:0.0.0": img, image-metadata, resize-image
// Responsive srcset with intrinsic width/height to avoid layout shift
#img(
path("/images/cover.png"),
alt: "Cover image",
widths: (480, 960, 1440),
sizes: "(max-width: 760px) 100vw, 720px",
format: "webp",
quality: 82,
)
// Single cropped thumbnail (e.g. article card or Open Graph image)
#let thumb = resize-image(
path("/images/cover.png"),
width: 1200,
height: 630,
op: "cover",
format: "png",
)
#html.img(src: thumb.url, width: thumb.width, height: thumb.height, alt: "Social card")img and image-srcset accept raster bitmaps only, not SVG; resize-image rasterizes SVG only when webp, png, or jpg is specified explicitly. Use image-metadata(path(...)) to inspect EXIF-oriented dimensions and alpha channels. Keep source images outside [assets] when you only want resized outputs published.