Info
This site is generated using the static site generator developed by the Typst Community. Please adjust the text content of this banner according to your usage requirements. At Typst GmbH's request, when publishing documentation, you must clearly indicate that it is non-official and display the version of Typst being documented. For details, refer to Issue #874 on typst/typst.
TypstDocumentEnglish
v0.dev.2026-03-11

asset
Element
Element
Element functions can be customized with set and show rules.

Adds a custom file to a bundle.

This function creates a single file in a bundle, from raw byte data. Unlike documents, assets will be emitted as-is without undergoing compilation.

The asset function can be combined with read to copy a file from the project into the output bundle. The first argument to asset defines the output path for the asset in the bundle, while the path passed to read defines where in the project to read the data from.

// Copy the file `styles.css` into the bundle.
#asset("styles.css", read("styles.css"))

That said, asset is not tied to read. You can also generate bytes directly or use a function like json.encode to emit serialized data.

// Emits a JSON file with the number
// of headings in the document.
#context {
  let headings = query(heading)
  let meta = (
    count: headings.len(),
  )
  asset("meta.json", json.encode(meta))
}

#document("doc.pdf")[
  = Introduction
  = Conclusion
]

This would emit a meta.json file with the following contents into the resulting bundle:

{
  "count": 2
}

This function may only be used in the bundle target.

Parameter
Parameter
Parameters are input values for functions. Specify them in parentheses after the function name.

asset(,)->

path
Required
Required
Required parameters must be specified when calling the function.
Positional
Positional
Positional parameters can be set by specifying them in order, omitting the parameter name.

The path in the bundle at which the asset will be placed.

May contain interior slashes, in which case intermediate directories will be automatically created.

data
Required
Required
Required parameters must be specified when calling the function.
Positional
Positional
Positional parameters can be set by specifying them in order, omitting the parameter name.

The raw data that will be written into the file at the specified path.

If a string is given, it will be encoded using UTF-8.

Open official docs

Search