Typst

Hex.pmDocs

Elixir bindings for the Typst typesetting system, powered by a Rust NIF. Generate PDFs, PNGs, and SVGs from Typst markup directly in your Elixir application.

Features

Installation

Add typst to your list of dependencies in mix.exs:

def deps do
[
{:typst, "~> 0.4"}
]
end

Usage

Basic rendering

{:ok, pdf} = Typst.render_to_pdf("= Hello World")
{:ok, [png]} = Typst.render_to_png("= Hello World")
{:ok, [svg]} = Typst.render_to_svg("= Hello World")

EEx templating

{:ok, pdf} = Typst.render_to_pdf(
"= Report for <%= name %>\nDate: <%= date %>",
name: "Acme Corp",
date: "2026-03-07"
)

Tables

alias Typst.Format.Table
alias Typst.Format.Table.Header
table = %Table{
columns: 3,
content: [
%Header{repeat: true, content: ["Name", "Qty", "Price"]},
["Widget", "10", "$5.00"],
["Gadget", "3", "$12.50"]
]
}
{:ok, pdf} = Typst.render_to_pdf("<%= table %>", table: table)

Virtual assets

logo = File.read!("logo.svg")
{:ok, pdf} = Typst.render_to_pdf(
~S|#image(read("logo", encoding: none), width: 6cm)|,
[],
assets: [logo: logo]
)

Options

All render functions accept these options:

Documentation

Full documentation is available at typst.hexdocs.pm.

Building from Source

When you add this package to your mix.exs dependencies, it will by default attempt to use precompiled Rustler assets. To override this behaviour, add {:rustler, ">= 0.0.0"} to your mix.exs, and set the environment variable TYPST_BUILD=true. Alternatively, you can put the following in your config.exs:

config :rustler_precompiled, :force_build, typst: true

Building from source requires a rust toolchain of at least version 1.92.0.

Cutting a new release

License

Apache-2.0