viniciusmuller
ExTypst - Elixir bindings for the Typst typesetting system
Hello! This weekend I’ve discovered the Typst typesetting system and decided to create the necessary elixir bindings to use it.
The source code and examples can be found in this repository, and the library is already available in Hex under the name ex_typst.
I think there’s space for some awesome projects using it, like generating reports in web applications or creating collaborative writing applications.
If you have any questions, feel free to comment in this thread.
Most Liked
steffend
I successfully integrated typst into an elixir app a while ago by just putting the correct binary in the priv directory in releases and running it through System.cmd. Of course installing it into the PATH is also possible. Getting data into typst is also quite easy by passing JSON through stdin, which also has the benefit of not being prone to code injection. So that’s what I’d recommend doing, especially since the library doesn’t look maintained at the moment.
def generate_pdf!(item) do
path = System.find_executable("typst") || Application.app_dir(:my_app, "priv/typst")
template = Application.app_dir(:my_app, "priv/pdf_template.typ")
tmp_file = Path.join(System.tmp_dir!(), "typst-output-#{item.id}.pdf")
{_, 0} =
System.cmd(path, ["compile", "--input", "data=#{Jason.encode!(item)}", template, tmp_file])
tmp_file
end
And in the typst file, the data can be accessed as
#let item = json.decode(sys.inputs.item)
jkwchui
As a long-time LaTeX user, I was secretly pleased with myself, shelling out from Elixir to do elaborate typesetting and bringing it back. I am blown away by what the Typst project and ExTypst could do together.
I’m still exploring the setup, but I feel that this could also go back towards Elixir documentation (some kind of mix task), or enhancing some of the CMS (OrangeCMS, Phoenix Pages, Beacon, Nimble Publisher) to auto-generate PDF (would need some markdown → typst conversion).
christhekeele
If you’re exploring the space of integration with existing Elixir tooling, check out:
-
makeup, the Elixir syntax highlighter thatex_docuses. It has clear instructions for creating a custom library for highlighting new syntax, so you might make amakeup_typsthighlighter library based onex_typstto maketypstsnippets beautiful in, say,ex_typst’s own documentation. -
The
nimble_publisherstatic site generator’s instructions for custom parsers for SSG support. I think their file format does require supporting frontmatter before the file content in question. -
The
phoenix_templateinstructions for developing a custom Phoenix Template Engine for a new filetype that could useex_typst
steffend
You need to have Rust installed on your system, see: Install Rust - Rust Programming Language
Cargo (what the error says it cannot find) is the Rust build tool.
In the future ex_typst could probably use rustler_precompiled, then this wouldn’t be needed.
asianfilm
JSON handling is one of the big improvements in Typst 0.13. In Typst 0.12, it is recommended to use the command line version if you want to create unique documents from JSON payloads. Typst 0.13 can decode JSON sent as a parameter to a function.







