Quarto Extension
A Quarto filter extension that compiles ```{typst} code blocks to images (PNG, SVG, or PDF) using the Typst binary bundled with Quarto. This makes Typst diagrams, figures, tables, and equations usable across all output formats (HTML, PDF via LaTeX, DOCX, RevealJS, and more).
When the output format is Typst, blocks pass through natively without image conversion.
This will install the extension under the _extensions subdirectory.
If you are using version control, you will want to check in this directory.
To use the extension, add the following to your document’s front matter:
For cross-referencing support, use timing control:
Then write Typst code blocks in your document:
A simple Typst block rendered as an image:
Use comment+pipe syntax (//| key: value) at the top of the code block to set per-block options.
Control the width, height, and margin of the rendered image page. These options set the Typst page dimensions for image compilation (non-Typst output formats). In native Typst output, width and height are ignored; margin is applied as block inset.
Set the output image format and resolution:
Set a fill colour for the rendered image page. In native Typst output, the colour is applied as block fill.
Use //| label: and //| cap: for Quarto cross-references. Generic cap and alt options work with any label prefix. Prefix-specific variants (e.g., fig-cap, tbl-alt) override the generic options when the label matches. Any Quarto cross-reference type is supported (fig-, tbl-, lst-, etc.), including custom types.
See Figure 1 for a captioned figure.
```{typst}
//| label: fig-typst-shapes
//| cap: "A simple Typst diagram with shapes."
//| alt: "A blue circle and orange rectangle arranged horizontally."
#set text(size: 12pt)
#align(center)[
#stack(dir: ltr, spacing: 1em)[
#circle(radius: 1cm, fill: blue.lighten(60%))
][
#rect(width: 2cm, height: 2cm, fill: orange.lighten(60%))
]
]
```Figure 1: A simple Typst diagram with shapes.
The echo and eval options control whether source code is displayed and whether the block is compiled.
Show the source code followed by the rendered output with echo: true:
Use echo: fenced to display source code wrapped in fenced code block markers (```{typst}), including any comment+pipe options (except echo itself). This mirrors Quarto’s native echo: fenced behaviour for computational cells.
Display the source code without compiling with eval: false:
With eval: true (the default), the block is compiled:
Setting eval: false and echo: false hides the block entirely. Nothing is rendered.
Setting include: false suppresses all output (both source and rendered image). The block is completely hidden from the document, regardless of other options.
Setting output: false skips compilation and suppresses the rendered image. When combined with echo: true, only the source code is shown.
The output-location option controls where rendered output appears in Reveal.js presentations.
Pass key-value pairs to Typst code via sys.inputs. Global inputs are set in YAML; per-block inputs override them using comma-separated syntax.
When Typst produces multiple pages, all pages are included by default. Use pages to select specific pages and layout-ncol to arrange them in columns.
Render an external .typ file instead of inline code:
Typst code can be prepended before each block using the preamble option. This is useful for setting global styles or importing packages.
Any value ending in .typ is treated as a file path:
Configure the filter globally in your document YAML. Most options can be set globally and overridden per block using comment+pipe syntax (//| key: value). See Global-Only Options for options that cannot be overridden per block.
| Option | Type | Default | Description |
|---|---|---|---|
format |
string | (auto) | Image format: png, svg, pdf. |
dpi |
string | "144" |
Pixels per inch (PNG only). |
width |
string | "auto" |
Page width for image compilation (ignored in Typst output). |
height |
string | "auto" |
Page height for image compilation (ignored in Typst output). |
margin |
string | "0.5em" |
Page margin for image compilation; block inset in Typst output. |
background |
string | "none" |
Page fill for image compilation; block fill in Typst output. |
preamble |
string | "" |
Typst code or path to a .typ file prepended before user code. |
cache |
boolean|string | true |
Cache compiled images. Use "clean" to also remove stale cache files. |
input |
object | (none) | Key-value pairs passed as --input flags to Typst CLI. |
file |
string | (none) | Path to external .typ file to render. |
echo |
boolean|string | false |
Show Typst source code alongside output (true, false, fenced). |
eval |
boolean | true |
Compile Typst code to image. |
include |
boolean | true |
Include block in output. Set false to suppress entirely. |
output |
boolean | true |
Show rendered output. Set false to skip compilation. |
output-location |
string | (none) | Output placement in Reveal.js (fragment, slide, column, column-fragment). |
classes |
string | (none) | Space-separated CSS classes on the output image (e.g., r-stretch). |
pages |
string | "all" |
Pages to include from multi-page output: all, 1, 1-3, 2,5, 3-. |
layout-ncol |
string | (none) | Number of columns for arranging multi-page output. Omit for vertical stack. |
Any unknown option with a string value is forwarded as an HTML attribute on the output image element (e.g., //| style: "max-height: 300px;"). Values that look like booleans (true/false) must be quoted to be forwarded (e.g., //| data-lazy: "true").
These options can only be set in the document YAML and cannot be overridden per block.
| Option | Type | Default | Description |
|---|---|---|---|
root |
string | (project directory) | Root directory for Typst compilation. |
font-path |
string|array | (none) | Path or list of paths to directories containing additional fonts. |
package-path |
string | (none) | Path to a directory containing Typst packages (offline/reproducible). |
| Option | Type | Description |
|---|---|---|
label |
string | Quarto cross-ref label (e.g., fig-x, tbl-y, lst-z). |
cap |
string | Caption text for the labelled block. |
alt |
string | Alternative text for accessibility. |
<prefix>-cap |
string | Prefix-specific caption (e.g., fig-cap). Overrides cap for matching labels. |
<prefix>-alt |
string | Prefix-specific alt text (e.g., fig-alt). Overrides alt for matching labels. |
| Output Format | Default Image Format |
|---|---|
| HTML / RevealJS | svg |
| LaTeX / Beamer | pdf |
| Typst | (native pass-through) |
| DOCX / PPTX | png |
| Other | png |
eval |
echo |
Result |
|---|---|---|
true |
false |
Image only (default). |
true |
true |
Source code block + image below. |
true |
fenced |
Fenced source code block (with markers) + image. |
false |
true |
Source code listing only. |
false |
fenced |
Fenced source code listing only (with markers). |
false |
false |
Nothing rendered (hidden block). |
The include and output options take precedence over the eval/echo matrix:
include: false hides the entire block regardless of eval/echo settings.output: false skips compilation and shows only the source code (if echo is enabled).
Social Card
A repository social card built entirely in Typst, rendered as a high-resolution PNG.
Figure 2: Social card for quarto-typst-render.