Documentation

tomlGo to source

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 "))

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

source
str or path or bytes
RequiredPositional
Question mark

A path to a TOML file or raw TOML bytes.

Definitions
Question mark

encodeGo to source

Encodes structured data into a TOML string.

toml.encode() → str

value
dictionary
RequiredPositional
Question mark

Value to be encoded.

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

prettyDefault: true

Whether to pretty-print the resulting TOML.