# Typstry.jl: The Julia to Typst Interface

**URL:** <https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381>\
**Category:** Package Announcements\
**Tags:** package, announcement, strings\
**Created:** [May 17, 2024, 12:55am UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381 "2024-05-17T00:55:17Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakobjpeters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobjpeters/32/207797_2.png) [@jakobjpeters](https://discourse.julialang.org/u/jakobjpeters)\
**Post date:** [May 17, 2024, 12:55am UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381/1 "2024-05-17T00:55:17Z")

</div>

## Introduction

Hi everyone! I’m excited to announce [Typstry.jl](https://github.com/jakobjpeters/Typstry.jl), which helps you create Typst formatted strings and render documents from Julia. If you are familiar with LaTeXStrings.jl and Latexify.jl, then Typstry.jl aims to provide similar features, and more.

## What is Typst?

Typst is an open-source and relatively new typesetting system (written in Rust 🚀), [designed to improve upon the performance and usability of LaTeX](https://typst.app/about/). Documents can currently be compiled to PDF, PNG, and SVG, with plans to support HTML in the future. See also the Typst [repository](https://github.com/typst/typst) and [documentation](https://github.com/typst/typst) for examples and how to get started.

## Features

### Strings

Use the `TypstString` constructor to print Julia values to a Typst formatted string, with optional Julia settings and Typst parameters.

```julia
julia> TypstString("Hi everyone!")
typst"\"Hi everyone!\""

julia> TypstString(r"[a-z]", :mode => code)
typst"regex(\"[a-z]\")"

```

Write Typst directly using `@typst_str` with escaped control characters, such as the dollar signs used in Typst’s math mode. It supports formatted interpolation by calling `TypstString`.

```julia
julia> typst"$ 1 / x $"
typst"$ 1 / x $"

julia> typst"\(1 + 2im, :inline => true)"
typst"$1 + 2i$"

```

Instead of constructing a string, print in Typst format using `show` with the `"text/typst"` MIME type. Settings and parameters may be specified in an `IOContext`.

```julia
julia> show(IOContext(stdout, :mode => math), "text/typst", 1 // 2)
1 / 2

julia> show(stdout, "text/typst", [true 1; 1.0 [Any[true 1; 1.0 nothing]]])
$ mat(
    "true", 1;
    1.0, mat(
        "true", 1;
        1.0, ""
    )
) $

```

This `show` method provides a default `IOContext` for `show_typst`, which specifies the Typst formatting for each type.

```julia
julia> import Typstry: show_typst

julia> struct X end

julia> show_typst(io, ::X) = print(io, "everyone", io[:excited]::Bool ? "!" : ".");

julia> typst"Hi \(X(), :excited => true)"
typst"Hi everyone!"

```

Environments, such as this Pluto.jl notebook, can render `TypstString`s.

 ![pluto](https://global.discourse-cdn.com/julialang/original/3X/b/2/b2baa2eb888a1f8012e14732d2e693e9e6ebe343.png)

### Commands

Construct and run `TypstCommand`s using the constructor or `@typst_cmd`.

```julia
julia> TypstCommand(["help"])
typst`help`

julia> typst`help compile`
typst`help compile`

```

Rendered documents can also use the [JuliaMono](https://github.com/cormullion/juliamono) typeface.

```julia
julia> addenv(typst`compile input.typ output.pdf`, "TYPST_FONT_PATHS" => julia_mono)
typst`compile input.typ output.pdf`

```

## Conclusion

Please reach out with comments, questions, suggestions, issues, and contributions. I’m active in the [Humans of Julia Discord server](https://discord.gg/C5h9D4j) and the [Julia Slack](https://julialang.org/slack/). Thank you for taking the time to check out Typstry.jl!

### Contribute

#### More `show_typst` methods

A relatively small number of types are currently supported. Please file an issue or create a pull request for unsupported types in `Base` and the Standard Library. I am also happy to help with implementations for external packages and extensions.

#### IJulia.jl Notebook Support

Please help me resolve [this problem](https://julialang.slack.com/archives/CL40XQ4QG/p1715452167321569?thread_ts=1715376685.424749&cid=CL40XQ4QG) to render `TypstString`s in IJulia.jl notebooks!

---

<div class="post-metadata">

**Author:** ![jakobjpeters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobjpeters/32/207797_2.png) [@jakobjpeters](https://discourse.julialang.org/u/jakobjpeters)\
**Post date:** [May 30, 2024, 7:49pm UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381/2 "2024-05-30T19:49:33Z")

</div>

Typstry.jl v0.2.0 is now released! See the [news](https://github.com/jakobjpeters/Typstry.jl/blob/v0.2.0/NEWS.md) for a detailed list of updates.

### Highlights

- A tutorial illustrating the Julia to Typst [Interface](https://jakobjpeters.github.io/Typstry.jl/stable/tutorials/interface/)
- A [potential fix](https://github.com/JuliaLang/IJulia.jl/pull/1114) to render `TypstString`s in IJulia.jl notebooks
- Remove type piracy of `show` with the `text/typst` MIME type
  - Values may instead be wrapped in `Typst`
  - Formatting may be configured by implementing a custom `context`

- Several new and improved `show_typst` methods
- Easily `render` a Julia value to a Typst source file and compiled document
- A few bug fixes

---

<div class="post-metadata">

**Author:** ![jakobjpeters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobjpeters/32/207797_2.png) [@jakobjpeters](https://discourse.julialang.org/u/jakobjpeters)\
**Post date:** [August 13, 2024, 12:45pm UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381/3 "2024-08-13T12:45:09Z")

</div>

Typstry.jl v0.3.0 is now released! See the [news](https://github.com/jakobjpeters/Typstry.jl/blob/v0.3.0/NEWS.md) for a detailed list of updates.

### Highlights

- Several new and improved `show_typst` methods
  - Implemented for types from Dates.jl, LaTeXStrings.jl, and Markdown.jl

- A customizable `preamble` for `render`
- Package interoperability
  - Use `TypstString`s in Makie using MakieTeX.jl
  - Use Julia and `TypstString`s in Typst using TypstJlyfish.jl

- Better documentation and testing
- Several bug fixes
  - Fixed escaped interpolation and corresponding pretty-printing

### Fun Facts

- `show_typst` has ~29 methods implementing the Julia to Typst interface for ~159 concrete types
- Including Typstry.jl, there are now at least 5 registered Julia packages specifically for Typst and another 2 with Typst support

---

<div class="post-metadata">

**Author:** ![jakobjpeters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobjpeters/32/207797_2.png) [@jakobjpeters](https://discourse.julialang.org/u/jakobjpeters)\
**Post date:** [November 1, 2024, 8:50am UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381/4 "2024-11-01T08:50:44Z")

</div>

Typstry.jl v0.4.0 is now released! See the [news](https://github.com/jakobjpeters/Typstry.jl/blob/v0.4.0/NEWS.md) for a detailed list of updates.

### Highlights

- Support for Typst v0.12
- The ability to `set_preamble`
- Automatically run, handle errors, and catch interrupts from the command-line interface using the `typst` function by @GunnarFarneback
- A few bug fixes

---

<div class="post-metadata">

**Author:** ![jakobjpeters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobjpeters/32/207797_2.png) [@jakobjpeters](https://discourse.julialang.org/u/jakobjpeters)\
**Post date:** [March 2, 2025, 12:45am UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381/5 "2025-03-02T00:45:56Z")

</div>

Typstry.jl v0.5.0 is now released! This is a small update for Typst v0.13 and to [Support read for TypstCommand #14](https://github.com/jakobjpeters/Typstry.jl/issues/14).

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [March 18, 2025, 11:31pm UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381/6 "2025-03-18T23:31:52Z")

</div>

Any example of how to use this package to make an actual document?

I believe it might have flown right over my head, but I was hoping I could use Typstry to make a document

Thanks!

---

<div class="post-metadata">

**Author:** ![jakobjpeters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobjpeters/32/207797_2.png) [@jakobjpeters](https://discourse.julialang.org/u/jakobjpeters)\
**Post date:** [March 19, 2025, 12:34am UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381/7 "2025-03-19T00:34:02Z")

</div>

Good question! This package uses the Typst command-line interface under the hood and provides a couple of wrappers over it. These are each documented [here](https://jakobjpeters.github.io/Typstry.jl/stable/references/commands/).

### `TypstCommand`

This is used in a similar manner as constructing and running a `Cmd`, for example `run(Cmd(["echo", "1"]))`.

```julia-repl
julia> write("test_1.typ", "hi");

julia> run(TypstCommand(["compile", "test_1.typ"]));

```

### `@typst_cmd`

This is the same as before, but is comparable to `@cmd s` with backticks.

```julia-repl
julia> write("test_2.typ", "hey");

julia> run(typst`compile test_2.typ`);

```

### `typst`

This function is similar to running commands, but with a few additional features. It’s intended to be used in the REPL.

- Run the command immediately
- By default, doesn’t throw a large error after an interrupt `ctrl + c`
- By default, doesn’t throw a large error when the Typst command-line interface throws an error
- Uses the JuliaMono typeface unless the `TYPST_FONT_PATHS` environment variable is set

```julia-repl
julia> write("test_3.typ", "hello");

julia> typst("compile test_3.typ")

```

### `render`

Instead of formatting a value to a `TypstString`, writing the string to a file, and then compiling that file, this function does all of that in a single step. It also automatically fits the page size, enables using the JuliaMono typeface, accepts a formatting context, and can ignore errors from Typst.

```julia-repl
julia> render(typst"heyo"; output = "test_4.pdf");

```

After running this code, each of `test_$n.pdf` should be a document. Please let me know if this answers your question! 🙂

---

<div class="post-metadata">

**Author:** ![andreeco](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@andreeco](https://discourse.julialang.org/u/andreeco)\
**Post date:** [March 22, 2025, 9:58am UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381/8 "2025-03-22T09:58:10Z")

</div>

Thanks for writing a package to integrate Typst better into Julia. I use both Julia and Typst a lot for my work. Basically, I have two Julia packages which do calculations and write Typst code. Then I compile it and have my reports.

Typst is amazingly designed and even at 0.13 it’s reliable for production.

---

<div class="post-metadata">

**Author:** ![jakobjpeters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobjpeters/32/207797_2.png) [@jakobjpeters](https://discourse.julialang.org/u/jakobjpeters)\
**Post date:** [March 22, 2025, 9:46pm UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381/9 "2025-03-22T21:46:39Z")

</div>

You’re welcome, I’m happy to hear you’re having a good time with both languages \<3

---

<div class="post-metadata">

**Author:** ![jakobjpeters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobjpeters/32/207797_2.png) [@jakobjpeters](https://discourse.julialang.org/u/jakobjpeters)\
**Post date:** [December 6, 2025, 8:46am UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381/11 "2025-12-06T08:46:52Z")

</div>

[Typstry.jl](https://juliaregistries.github.io/General/packages/redirect_to_repo/Typstry) v0.6.0 - v0.6.2 got released a few months ago! I was thrilled to present this package at this year’s JuliaCon, [Typstry: The Julia to Typst Interface](https://www.youtube.com/watch?v=3Ocgztq05lo), and to discuss Typst with several fellow attendees. See the [history](https://github.com/jakobjpeters/Typstry.jl/blob/main/HISTORY.md#v062) for a detailed list of those updates

## Highlights

- New methods for `show_typst`, `TypstString`, and `render` to accept context information with either a `TypstContext` or keyword parameters
- Implementing `show_typst` now requires a `TypstContext`
- `TypstError` renamed to `TypstCommandError`
- `preamble` and `set_preamble` has been generalized to `context::TypstContext` and `reset_context`
- `TypstContext` implements the dictionary and iteration interfaces
  - Use `IOContext(::IO, TypstContext(; ...))`
  - `reset_context` will return the `context` to its default state

---

<div class="post-metadata">

**Author:** ![jakobjpeters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobjpeters/32/207797_2.png) [@jakobjpeters](https://discourse.julialang.org/u/jakobjpeters)\
**Post date:** [December 6, 2025, 8:54am UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381/12 "2025-12-06T08:54:48Z")

</div>

Typstry.jl v0.7.0 is now released! I want to especially thank @cormullion for designing this _awesome_ improved logo ✨

 ![logo](https://global.discourse-cdn.com/julialang/original/3X/4/7/4705361da65944aa980face71154b5d9678b5e86.svg)

See the [news](https://github.com/jakobjpeters/Typstry.jl/blob/v0.7.0/NEWS.md) for a detailed list of updates.

## Highlights

- Update Typst\_jll.jl to support v0.14
  - Drop support for Typst\_jll.jl v0.1 - 0.11

- Many `show_typst` methods are now implemented in terms of a `TypstFunction`, which lowers to a Typst function call
- Updated JuliaMono from version 0.55 to 0.61
- Documentation for image-in-terminal support
- Several bug fixes

## Plans for version 0.8

- Experiment with recursive `lower`ing to base cases, instead of using an `IO` in `show_typst`
  - Hopefully, this will simplify the interface and `TypstContext` precedence

- An experimental implementation of partial Julia-to-Typst transpilation via `@equation` and `lower(::TypstContext, ::Equation)`
  - The basic functionality is working, I just need to polish it up!

---

<div class="post-metadata">

**Author:** ![cable729](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cable729/32/220979_2.png) [@cable729](https://discourse.julialang.org/u/cable729)\
**Post date:** [February 26, 2026, 5:05pm UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381/13 "2026-02-26T17:05:02Z")

</div>

Hello, I’ve been trying to use this in my pluto notebook and when I use `.render()`, it just creates a pdf and opens it. Is there a way to render to the cell output? Sorry, I’m new to Julia and Pluto and I didn’t find anything in the repo that tells me how to do it.

---

<div class="post-metadata">

**Author:** ![cable729](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cable729/32/220979_2.png) [@cable729](https://discourse.julialang.org/u/cable729)\
**Post date:** [February 26, 2026, 5:09pm UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381/14 "2026-02-26T17:09:01Z")

</div>

Ah. ChatGPT figured it out 🙂

```julia
typst"""
$ f(x) = x^2 e^x $
"""

```

---

<div class="post-metadata">

**Author:** ![jakobjpeters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobjpeters/32/207797_2.png) [@jakobjpeters](https://discourse.julialang.org/u/jakobjpeters)\
**Post date:** [February 26, 2026, 8:01pm UTC](https://discourse.julialang.org/t/typstry-jl-the-julia-to-typst-interface/114381/15 "2026-02-26T20:01:38Z")

</div>

Hi! The exported types related to strings define `show` methods that will pretty-print in notebooks. You can also set the default context to adjust how these get rendered.
