Documentation

read

Reads plain text or data from a file.

By default, the file will be read as UTF-8 and returned as a string.

If you specify encoding: none, this returns raw bytes instead.

Example

An example for a HTML file: \
#let text = read("example.html")
#raw(text, lang: "html")

Raw bytes:
#read("tiger.jpg", encoding: none)
Preview

Parameters
🌐 Read Function – Typst DocumentationTypstGitHubDiscordMastodonBlueskyLinkedInTypstQuestion markQuestion mark - typst.app

path
str
Required Positional
🌐 Read Function – Typst DocumentationTypstGitHubDiscordMastodonBlueskyLinkedInTypstQuestion markQuestion mark - typst.app

Path to a file.

For more details, see the Paths section.

encoding
none or str

The encoding to read the file with.

If set to none, this function returns raw bytes.

VariantDetails
"utf8"

The Unicode UTF-8 encoding.

Default: "utf8"