Expand description
§typst-pack
Portable single-file packs of Typst projects: sources, resources, packages, and fonts.
A pack (.typk) captures the compilation contract of one Typst project:
- the packed project files: the entrypoint, other Typst sources, images, and data files,
- optionally the files of the Typst Universe packages the project imports, so compiling needs no network access,
- optionally the fonts the document uses, so compiling produces identical output on machines without those fonts.
Use it as a CLI to distribute finished Typst projects, or as a library to produce and consume packs programmatically (e.g. offering a “download project” pack in a web-based Typst editor).
Note: this is unrelated to Typst’s own bundle export (the typst-bundle
crate), which is a multi-file output target. A pack is an input
archive: a portable form of a project’s sources and resources.
§Features
- Portable project archives: bundle Typst sources, resources, packages, and
fonts into one
.typkfile. - Structural project closure: include every eligible regular file beneath the selected project root, independently of compiler control flow.
- Reproducible compilation: compile without network or system font access, with support for fixed timestamps and vendored packages.
- Pack Overrides: replace any contained project file for one compilation without mutating the Pack.
- Library and CLI interfaces: create, inspect, compile, and extract packs in memory or on the file system.
§CLI
Install the command-line tool:
cargo install typst-pack-cli# Pack a named source file, vendoring all observed packages:
typst-pack create path/to/project/main.typ
# Pack a specific entrypoint, embedding the fonts the document uses:
typst-pack create letter.typ --embed-fonts
# See what a pack contains:
typst-pack inspect project.typk
# Compile a pack without network access:
typst-pack compile project.typk output.pdf
# Replace a contained placeholder for one compilation:
typst-pack compile invoice.typk customer.pdf --override assets/logo.png customer-logo.png
# PNG or SVG output, page selection, reproducible builds:
typst-pack compile project.typk "page-{0p}.png" --ppi 300 --pages 1-3
typst-pack compile project.typk reproducible.pdf --creation-timestamp 1700000000
# Guarantee no network access (fails instead of downloading packages):
typst-pack compile project.typk --offline
# Experimental HTML export (the output format enables its required feature):
typst-pack compile project.typk out.html
# An HTML representative creation compile still selects the feature explicitly:
typst-pack create project/main.typ --target html --features html
# Unpack a pack back into an editable project directory:
typst-pack extract project.typk -o project/For Page Formats, {p} expands to the one-based Source Page Number, {0p} and
{n} are zero-padded aliases, and {t} is the total source-document page
count before page selection. Multi-page output requires an explicit {p},
{0p}, or {n} template. All target paths are checked for duplicates before
writing. Document Format output paths are literal.
§Project files
create stabilizes every eligible regular file beneath the physical project
root before compiling. Project membership is independent of the representative
compile’s target, inputs, date, features, and control flow. The root
.typkignore applies Gitignore-style ordered rules; it is always packed, nested
.typkignore files are ordinary project files, and every .typk path is always
excluded. Symlinks and other unignored non-regular entries are rejected.
Creation runs one representative compile from those stabilized bytes to select
exact package and font dependencies. --target paged|html is optional and
defaults to paged; it does not restrict later output formats. This concrete
evaluation is a temporary dependency-selection mechanism because Typst does not
report every package or font a different request might reach.
Every project path in a Pack has contained bytes. For per-document variation,
pack a valid placeholder and use compile-time --override PACK_PATH FILE.
Overrides may replace source, assets, data, or the entrypoint, but cannot add or
delete paths or authorize undeclared packages and fonts.
§Packages
All observed package dependencies are vendored into the pack by default.
With --no-vendor-packages, each dependency is instead recorded as an exact
package specification and Complete Package Tree identity. Compilation acquires
the whole tree from the configured package directory, cache, or Typst Universe,
verifies it before invoking Typst, and exposes only the verified paths and bytes.
Undeclared package locations and ambient caches cannot satisfy imports.
--offline (on both create and compile) disables the download step
entirely: dependencies must come from the pack or the local package
directories, and anything else fails as not found. Use
typst-pack compile --offline to verify that a pack is truly
self-contained.
§Fonts
Every selected face is recorded in the ordered Pack Font Catalog with its exact
container identity. Fonts are not embedded by default: compilation must find
the declared exact containers among the configured system, Typst-embedded, or
--font-path sources. Other available fonts are not exposed to Typst.
With --embed-fonts, selected containers are stored in the pack, except those
identical to Typst’s embedded fonts. Pass --include-typst-embedded-fonts to
store those too. Mind font licenses when redistributing embedded containers;
licensing and acquisition metadata do not change font selection.
§Output formats
PDF and HTML are Document Formats and produce one Compilation Output Artifact without a Source Page Number. PNG and SVG are Page Formats and produce one artifact per selected source page. Page artifacts retain their original Source Page Number and are emitted once each in source-document order.
HTML export is experimental in Typst itself, and Typst emits a warning that its
behavior may change. Pack compilation derives the required engine feature from
CompilationOutputSpecification::Html; HTML creation still requires
--features html (or TYPST_FEATURES=html).
The Dagger compile function returns a directory for every format. Document
Formats use output.pdf or output.html; Page Formats use deterministic names
such as page-2.png, derived from Source Page Numbers. Its typed mapping,
staging, failure boundary, and intentional transport omissions are documented
in the Dagger adapter contract.
Maintainers changing the embedded compiler must follow the embedded Typst upgrade procedure. CI enforces the approved crate graph, classified differential matrix, official CLI oracle, and the packaged release binary.
§Library
Add the crate with filesystem-backed packing support and Typst’s embedded fonts:
[dependencies]
typst-pack = { version = "0.4", features = ["embedded-fonts", "fs"] }The core in-memory packing and compilation APIs require no crate features.
use typst_pack::{
compile, CompilationOutputSpecification, OutputFormat, Pack,
PackCompilationRequest, Packer, PdfOutputSpecification,
};
// Pack a project directory (requires the `fs` feature).
let outcome = Packer::new("path/to/project", "main.typ")
.embed_fonts(true)
.pack()?;
let bytes = outcome.pack.to_bytes()?;
// ... ship the bytes somewhere, then compile without a file system:
let pack = Pack::from_bytes(bytes)?;
let request = PackCompilationRequest::new(
pack,
CompilationOutputSpecification::Pdf(PdfOutputSpecification::default()),
);
let report = compile(request)?;
let output = report.result().expect("semantic compilation result");
assert_eq!(output.engine_identity().implementation(), "typst");
assert_eq!(output.exporter_identity().implementation(), "typst-pdf");
let artifact = output.artifacts().first().expect("PDF artifact");
assert_eq!(artifact.format(), OutputFormat::Pdf);
assert_eq!(artifact.source_page_number(), None);
let pdf = artifact.bytes();PackOutcome::warnings retains warnings from the representative creation
compile. Inspect PackOutcome::pack for authoritative project files, package
requirements and their embedding disposition, and the Pack Font Catalog; that
static inventory is not duplicated in the creation outcome.
compile always returns a CompilationReport after accepting the semantic
request. Its outcome contains either the immutable semantic result or an
operational dependency failure, and its fulfillment report retains
caller-supplied package and font provenance, cache disposition, and licensing
metadata without including those operational values in Compilation Identity or
Compilation Result Identity. Request rejection is the outer error and retains
the complete request inventory. Every semantic result also exposes its document
summary and canonical Compilation Access Trace.
For PNG and SVG, source_page_number() identifies each artifact independently
of its collection position. bytes() borrows the artifact bytes and
into_bytes() extracts them without cloning.
Packs can also be assembled fully in memory, with no file system involved, which is what a web editor wants:
use typst_pack::Pack;
let pack = Pack::builder("main.typ")
.file("main.typ", source_text.as_bytes().to_vec())?
.file("figure.png", image_bytes)?
.build()?;
let bytes = pack.to_bytes()?;Compilation-time Pack Overrides replace contained project-file bytes in memory:
let pack = Pack::builder("main.typ")
.file("main.typ", source_text.as_bytes().to_vec())?
.file("assets/logo.png", placeholder_png)?
.build()?;
let overrides = PackOverrideSet::new(&pack)
.replace("assets/logo.png", customer_png)?;
let request = PackCompilationRequest::new(
pack,
CompilationOutputSpecification::Pdf(PdfOutputSpecification::default()),
).overrides(overrides);
let report = compile(request)?;
let output = report.result().expect("semantic compilation result");§Compilation authority
The public compilation boundary accepts only a validated Pack bound into a
PackCompilationRequest. The Pack-backed Typst World, compilation kernel,
and embedded compiler and exporter adapter are private. In particular, callers
cannot substitute a typst::World, language library, compiler, or exporter:
use typst_pack::PackWorld;use typst_pack::compile_pack;use typst_pack::compile;
fn arbitrary_world(world: &dyn typst::World) {
let _ = compile(world);
}Typst 0.15.0 owns language evaluation, layout, official diagnostics, document structures, and PDF, PNG, SVG, and HTML export behavior. typst-pack owns Pack creation and validity, the fixed set of contained project paths, exact package and font verification, Pack Overrides, request identities and reports, and later CLI or Dagger publication. Artifact bytes and official diagnostics are not reinterpreted by destination, transport, cache, or presentation code.
Intentional differences from typst compile are Pack confinement, Pack input
instead of a source root, a fixed contained project namespace, exact dependency
fulfillment, Pack Overrides, unsupported Bundle output, and publication rules
for immutable artifacts. The complete version-bound inventory is in
docs/cli-parity.md.
§Migrating to 0.4
Version 0.4 makes clean naming and invariant-boundary breaks without retaining compatibility aliases:
- Remove Resource Slot and Resource Provider APIs; pack valid baseline placeholders and replace contained files with Pack Overrides.
- Rename Dagger arguments:
source->project,entrypoint->input,inputs->sysInputs,noPackages->noVendorPackages,sourceDateEpoch->creationTimestamp, andCreationTarget->TypstTarget. Removed resource and inclusion arguments have no replacements. - Change creation from a directory plus
--entrypoint/--outputtocreate <INPUT> [OUTPUT]. - Replace
compile_pack(request)withcompile(request). The provisional arbitrary-Worldcompileoverload and publicPackWorldbuilder are removed; configure semantic values onPackCompilationRequest. compilereturnsCompilationReport; inspectreport.outcome()orreport.result().compile_report,PackCompileError,CompilationAttempt, and the emptyCompilationExecutionControlsare removed. Request rejection now owns its inventory and orderedCompilationRequestIssuevalues.- Replace
CreationTargetandCompilationTargetwithTypstTarget. - Configure document time with one
DocumentTimevalue.Absent,Fixed, andUnixTimestampreplace the former date/timestamp fields and setters. - Read representative-compile warnings from
PackOutcome::warnings; the one-fieldPackReportis removed. - Pack Manifest fields and
PackFontfields are read-only. Use accessors such asmanifest.project(),project.entrypoint(),font.manifest(), andfont.data(). Package declarations are reached only throughmanifest.packages().vendored()and.unvendored(). - Shared Pack consistency failures are available as
PackInvariantError, wrapped byPackBuildError::InvariantorPackReadError::Invariant. - Replace
OutputFormatplusCompileOptionsrequest construction with the correspondingCompilationOutputSpecificationvariant and format-specific structure. PDF creation time is configured throughPdfOutputSpecification::creation_timestamp; useCreationTimestamp::Omitto suppress PDF creation datetime metadata. ExtractErroraddsPlannedPathConflictandDestinationConflict; exhaustive matches must handle both variants.
The unstable Pack format remains version 1, but discovery and Resource Slot fields are removed in place. Old fields and aliases are not accepted.
§Feature flags
fs:Packer,extract, package download and caching, system font scanning. Requires a file system, so disable this for wasm targets.embedded-fonts: make Typst’s bundled fonts available as intentional creation and external-fulfillment sources.diagnostics: retain source context for first-party diagnostic presentation adapters.parallel: export independent page artifacts in parallel.
All library crate features are opt-in. Fixed timestamp conversion for DocumentTime
is part of the featureless core and remains available on wasm targets.
§Pack format
A pack is a Zip archive (Deflate), conventionally named *.typk, with this
layout:
typst-pack.toml manifest (always first)
project/<path> project files, root-relative
packages/<ns>/<name>/<version>/<path> vendored package files
fonts/<file> embedded font filesThe manifest looks like this:
format-version = 1
[project]
entrypoint = "main.typ"
[[packages.vendored]]
spec = "@preview/cetz:0.3.4"
tree-digest = "0123456789abcdef0123456789abcdef"
tree-identity-kind = "complete-package-tree"
tree-identity-schema = "typst-pack-complete-package-tree-v1"
tree-identity-algorithm = "typst-hash128-0.15"
file-count = 12
byte-length = 34567
[[packages.unvendored]]
spec = "@preview/tablex:0.0.9"
tree-digest = "fedcba9876543210fedcba9876543210"
tree-identity-kind = "complete-package-tree"
tree-identity-schema = "typst-pack-complete-package-tree-v1"
tree-identity-algorithm = "typst-hash128-0.15"
file-count = 8
byte-length = 23456
[[fonts]]
path = "fonts/ibm-plex-sans.ttf"
families = ["IBM Plex Sans"]
[metadata]
name = "Quarterly report"
authors = ["Jane Doe"]Readers ignore unknown top-level archive entries and reject manifests whose
format-version is not the exact supported version. Paths inside the archive
are validated, root-relative virtual paths. Extraction rejects existing
symlinked entries within the selected destination before writing.
The format version remains 1 and is explicitly unstable: readers reject old
discovery, Resource Slot, external-resources, and packages.external fields
rather than retaining aliases.
§Development
Minimum verification:
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features -- -D warningscargo test --workspace --all-features
Run CI’s containerized checks with Dagger:
dagger check
The containerized suite includes the embedded Typst CLI differential gate, pinned to the exact official release used by the library.
§License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
§Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Structs§
- Compilation
Access Observation - One canonical dependency observation made by the embedded engine.
- Compilation
Access Trace - Canonical accesses retained by a semantic compilation result.
- Compilation
Artifact - One file produced by compiling a pack.
- Compilation
Diagnostic - A structured compiler or exporter diagnostic.
- Compilation
Document Summary - The stable document facts reached before complete export.
- Compilation
Fulfillment Report - Operational dependency evidence surrounding one official semantic result.
- Compilation
Identity - The pre-execution identity of a fully specified semantic compilation.
- Compilation
Report - The immutable account of an accepted compilation through complete export.
- Compilation
Request Inventory - Every effective shared semantic value passed to the embedded Typst engine.
- Compilation
Request Rejection - A rejected semantic request and its complete effective inventory.
- Compilation
Result - The semantic result of an accepted Pack compilation request.
- Compilation
Result Identity - The identity of one complete compiler and exporter result.
- Diagnostic
Hint - A structured hint attached to an official diagnostic.
- Diagnostic
Tracepoint - One structured tracepoint attached to an official diagnostic.
- Effective
Engine Feature - One enabled Typst engine feature and why it is enabled.
- Effective
Request Value - One effective request value together with its provenance.
- Engine
Identity - The exact embedded Typst compiler implementation that produced a result.
- Exporter
Identity - The exact official exporter implementation that produced a result.
- Font
Container Fulfillment - Exact externally supplied Font Container bytes and non-semantic metadata.
- Font
Container Identity - The canonical content identity of one exact Font Container.
- Font
Face Identity - The exact identity of one face within a Font Container.
- Font
Fulfillment Report - Operational evidence retained for one exact font fulfillment.
- Font
Manifest - One
[[fonts]]entry. - Font
Requirement - One exact Font Container and the faces required from it.
- Html
Output Specification - Semantic controls for HTML output.
- Logical
Span - A source location expressed in the Pack’s logical namespace.
- Pack
- A portable pack of a Typst project.
- Pack
Builder - Builds a
Packfrom in-memory data. - Pack
Compilation Request - An explicit semantic compilation request bound to one validated
Pack. - Pack
Compilation Warning - A Pack-owned semantic request warning.
- Pack
Font - A font embedded in a pack.
- Pack
Font Catalog Face - One ordered face in the exact Pack Font Catalog.
- Pack
Identity - The canonical semantic identity of a
Pack. - Pack
Manifest - The parsed contents of
typst-pack.toml. - Pack
Metadata - The optional
[metadata]section. - Pack
Override Inventory Entry - Safe, role-bound evidence for one replacement in a Pack Override Set.
- Pack
Override Set - An immutable set of contained project-file replacements bound to one Pack.
- Pack
Overrides Inventory - Safe evidence for an immutable Pack Override Set.
- Package
Fulfillment Report - Operational evidence retained for one exact package fulfillment.
- Package
Manifest - One exact Complete Package Tree declaration.
- Package
Requirement - One exact package specification and Complete Package Tree identity.
- Package
Tree Fulfillment - One externally acquired Complete Package Tree and operational metadata.
- Package
Tree Identity - The canonical content identity of one Complete Package Tree.
- Packages
Manifest - The
[packages]section. - Page
Selection - A selection of one-indexed source page ranges.
- PdfOutput
Specification - Semantic controls for PDF output.
- PdfStandards
Validation Error - A lossless projection of an official PDF standards validation error.
- PngOutput
Specification - Semantic controls for PNG output.
- Project
Manifest - The
[project]section. - SvgOutput
Specification - Semantic controls for SVG output.
- Typst
Inputs Inventory - Safe, role-bound evidence for potentially sensitive Typst inputs.
Enums§
- Compilation
Access Kind - The kind of dependency request made by the embedded engine.
- Compilation
Access Outcome - The stable outcome of one dependency request.
- Compilation
Operation Outcome - A Pack-owned operational outcome before official compilation begins.
- Compilation
Output Origins - Format-specific provenance for output controls resolved during preparation.
- Compilation
Output Specification - The required tagged semantic output request.
- Compilation
Report Outcome - Compilation
Request Issue - One independently detectable issue in a rejected semantic request.
- Compilation
Status - Whether the official compiler and exporter accepted the compilation.
- Creation
Timestamp - The source of the document creation datetime recorded in PDF metadata.
- Diagnostic
Phase - The official phase that emitted a diagnostic.
- Diagnostic
Producer - The exact embedded implementation that emitted a diagnostic.
- Diagnostic
Severity - Official Typst diagnostic severity.
- Document
Time - The exact or explicitly absent time used by Typst document-time requests.
- Font
Catalog Error - A Pack-owned failure to materialize its exact Font Catalog.
- Output
Format - The Document Formats and Page Formats a pack can be compiled to.
- Pack
Build Error - A failure while building a pack in memory.
- Pack
Invariant Error - A violation of the invariants shared by every
Packconstruction path. - Pack
Manifest Error - A manifest that could not be accepted.
- Pack
Override SetError - A Pack-owned Pack Override preflight rejection.
- Pack
Path Role - The role a path plays in a Pack invariant.
- Pack
Read Error - A failure while reading a pack archive.
- Pack
Write Error - A failure while writing a pack archive.
- Package
Tree Error - A Pack-owned failure to materialize exact Complete Package Trees.
- Request
Value Origin - How an effective compilation request value was established.
- Tracepoint
Kind - The kind of one official diagnostic tracepoint.
- Typst
Target - The Typst document model selected for creation or compilation.
Constants§
- FILE_
EXTENSION - The conventional file extension for packs.
- FORMAT_
VERSION - The pack format version this crate reads and writes.
- MANIFEST_
PATH - The archive entry name of the manifest.
- VERSION
- The typst-pack release and embedded Typst engine versions.
Functions§
- compile
- Compiles a validated Pack and retains operational fulfillment evidence.
- parse_
page_ selection - Parses a textual page selection like
1,3-5,9-.
Type Aliases§
- Page
Range - A one-indexed, inclusive page range with optional open ends.