Tiago is a Typst package for rendering diagrams with Diago, a D2-compatible diagram engine implemented in MoonBit. It can render a D2 diagram to SVG, ASCII or Unicode text.
The typst package removed embedded fonts and font metrics data from the WASM, and uses release build with --strip tag compared to diago’s WASM demo, which reduces its binary size from ~21 MiB to ~5 MiB unzipped.
Examples
| architecture.typ | c4.typ | containers.typ |
| isomorphic.typ | sequence.typ | sql_tables.typ |
| styles.typ | markdown.typ | security.typ |
Installation
#import "@preview/tiago:0.1.0": *
API
render(source, engine: none, ..args)
Renders diagram source to an SVG-backed Typst image. Extra arguments are forwarded to Typst’s image(...), so you can pass values like width, height, or alt.
#render(
"a -> b: hello",
// engine: "elk",
// width: 220pt,
// height: ...
)
render-svg(source, engine: none)
Renders diagram source to raw SVG bytes.
#let svg = render-svg("a -> b")
render-ascii(source)
Renders diagram source to ASCII text.
#raw(render-ascii("a -> b"))
render-unicode(source)
Renders diagram source to Unicode box-drawing text.
#raw(render-unicode("a -> b"))
Layout Engines
engine is optional. When omitted, the package uses Diago’s default layout engine.
Supported engine names:
dagreelkrailway
Example
#import "@preview/tiago:0.1.0": *
= Tiago Example
#let source = ```
server: Web Server
database: Database {
shape: cylinder
}
cache: Cache
server -> database: queries
server -> cache: reads
cache -> database: fallback
```.text
== SVG
#render(
source,
engine: "elk",
width: 300pt,
)
== ASCII
#raw(render-ascii(source))
== Unicode
#raw(render-unicode(source))
For a sample document, see example.typ.
Limitations
- Image paths in D2 diagrams are linked images. Path to linked images are relative to the
--rootdirectory. Linked SVG images are not supported yet. - Some features are not properly supported. Switching rendering engines may help.
License
Apache-2.0. See LICENSE.