Documentation

yaml

Reads structured data from a YAML file.

The file must contain a valid YAML object or array. The YAML values will be converted into corresponding Typst values as listed in the table below.

The function returns a dictionary, an array or, depending on the YAML file, another YAML data type.

The YAML files in the example contain objects with authors as keys, each with a sequence of their own submapping with the keys "title" and "published".

Example

#let bookshelf(contents) = {
  for (author, works) in contents {
    author
    for work in works [
      - #work.title (#work.published)
    ]
  }
}

#bookshelf(
  yaml("scifi-authors.yaml")
)
Preview

Conversion details

YAML valueConverted into Typst
null-values (null, ~ or empty )none
booleanbool
numberfloat or int
stringstr
sequencearray
mappingdictionary
Typst valueConverted into YAML
types that can be converted from YAMLcorresponding YAML value
bytesstring via repr
symbolstring
contenta mapping describing the content
other types (length, etc.)string via repr

Notes

Parameters
Question mark

yaml() -> any

source
str or bytes
Required Positional
Question mark

A path to a YAML file or raw YAML bytes.

Definitions
Question mark

decode
Warning
yaml.decode is deprecated, directly pass bytes to yaml instead; it will be removed in Typst 0.15.0

Reads structured data from a YAML string/bytes.

yaml.decode() -> any

data
str or bytes
Required Positional
Question mark

YAML data.

encode

Encode structured data into a YAML string.

yaml.encode(
any
) -> str

value
any
Required Positional
Question mark

Value to be encoded.