Documentation

toml

Reads structured data from a TOML file.

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

The function returns a dictionary representing the TOML table.

The TOML file in the example consists of a table with the keys title, version, and authors.

Example

#let details = toml("details.toml")

Title: #details.title \
Version: #details.version \
Authors: #(details.authors
  .join(", ", last: " and "))
Preview

Conversion details

First of all, TOML documents are tables. Other values must be put in a table to be encoded or decoded.

TOML valueConverted into Typst
stringstr
integerint
floatfloat
booleanbool
datetimedatetime
arrayarray
tabledictionary
Typst valueConverted into TOML
types that can be converted from TOMLcorresponding TOML value
noneignored
bytesstring via repr
symbolstring
contenta table describing the content
other types (length, etc.)string via repr

Notes

Parameters
Question mark

toml() -> dictionary

source
str or bytes
Required Positional
Question mark

A path to a TOML file or raw TOML bytes.

Definitions
Question mark

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

Reads structured data from a TOML string/bytes.

toml.decode() -> dictionary

data
str or bytes
Required Positional
Question mark

TOML data.

encode

Encodes structured data into a TOML string.

toml.encode() -> str

value
dictionary
Required Positional
Question mark

Value to be encoded.

TOML documents are tables. Therefore, only dictionaries are suitable.

pretty

Whether to pretty-print the resulting TOML.

Default: true