Getting Started
Basics
Strings
Print Julia values in Typst
format using show
with the text/typst
MIME type.
julia> show(stdout, "text/typst", Typst(π))
+π
Some methods use an IOContext
to configure the formatting.
julia> show(IOContext(stdout, :mode => code), "text/typst", Typst(π))
+3.141592653589793
Instead of printing, create a TypstString
using its constructor or @typst_str
with formatted interpolation.
julia> TypstString(π)
+typst"π"
+
+julia> TypstString(π; mode = code)
+typst"3.141592653589793"
+
+julia> typst"$ \(pi) approx \(pi; mode = code) $"
+typst"$ π approx 3.141592653589793 $"
Commands
Use render
to easily generate a Typst source file and compile it into a document.
julia> render(Any[true 1; 1.2 1 // 2]);
Compile source files by run
ning a TypstCommand
created using its constructor or @typst_cmd
.
julia> TypstCommand(["help"])
+typst`help`
+
+julia> run(typst`compile input.typ output.pdf`);
Examples
This Typst source file was generated from Julia using show
with the text/typst
MIME type and compiled using a TypstCommand
.
Although many of the values are rendered similarly across modes, the generated Typst source code may differ between them.
#import table: cell, header
+
+#set page(margin: 1em, height: auto, width: auto, fill: white)
+#set text(16pt, font: "JuliaMono")
+
+#show cell: c => align(horizon, box(inset: 8pt,
+ if c.y < 2 { strong(c) }
+ else if c.x == 0 { raw(c.body.text, lang: "julia") }
+ else { c }
+))
+
+#table(columns: 5,
+ header(
+ cell(rowspan: 2)[Value],
+ cell(rowspan: 2)[Type],
+ cell(colspan: 3, align: center)[`Mode`],
+ `code`, `markup`, `math`
+ ),
+ "[true, 1, Any[1.2, 1//2]]", `AbstractArray`,
+ [#(true, 1, (1.2, 1 / 2))], [$vec(
+ "true", 1, vec(
+ 1.2, 1 / 2
+ )
+ )$], $vec(
+ "true", 1, vec(
+ 1.2, 1 / 2
+ )
+ )$,
+ "'a'", `AbstractChar`, [#"'a'"], ['a'], $'a'$,
+ "1.2", `AbstractFloat`, [#1.2], [1.2], $1.2$,
+ "Any[true 1; 1.2 1//2]", `AbstractMatrix`,
+ [#(true, 1.2, 1, (1 / 2))], [$mat(
+ "true", 1;
+ 1.2, 1 / 2
+ )$], $mat(
+ "true", 1;
+ 1.2, 1 / 2
+ )$,
+ "\"a\"", `AbstractString`, [#"\"a\""], ["a"], $"\"a\""$,
+ "true", `Bool`, [#true], [#true], $"true"$,
+ "im", `Complex{Bool}`, [#$i$], [$i$], $(i)$,
+ "1 + 2im", `Complex`, [#$1 + 2i$], [$1 + 2i$], $(1 + 2i)$,
+ "π", `Irrational`, [#3.141592653589793], [π], $π$,
+ "nothing", `Nothing`, [#none], [#none], $#none$,
+ "0:2:6", `OrdinalRange{<:Integer, <:Integer}`, [#range(0, 7, step: 2)], [$vec(
+ 0, 2, 4, 6
+ )$], $vec(
+ 0, 2, 4, 6
+ )$,
+ "1//2", `Rational`, [#(1 / 2)], [$1 / 2$], $(1 / 2)$,
+ "r\"[a-z]\"", `Regex`, [#regex("[a-z]")], [#regex("[a-z]")], $#regex("[a-z]")$,
+ "1", `Signed`, [#1], [1], $1$,
+ "StepRangeLen(0, 2, 4)", `StepRangeLen{<:Integer, <:Integer, <:Integer}`, [#range(0, 7, step: 2)], [$vec(
+ 0, 2, 4, 6
+ )$], $vec(
+ 0, 2, 4, 6
+ )$,
+ "text\"[\\\"a\\\"]\"", `Docs.Text`, [#"\"[\\\"a\\\"]\""], ["[\\\"a\\\"]"], $"\"[\\\"a\\\"]\""$,
+ "(true, 1, 1.2, 1//2)", `Tuple`, [#(true, 1, 1.2, 1 / 2)], [$vec(
+ "true", 1, 1.2, 1 / 2
+ )$], $vec(
+ "true", 1, 1.2, 1 / 2
+ )$,
+ "Typst(1)", `Typst`, [#1], [1], $1$,
+ "typst\"[\\\"a\\\"]\"", `TypstString`, [#["a"]], [["a"]], $["a"]$,
+ "TypstText([1, 2, 3, 4])", `TypstText`, [#[1, 2, 3, 4]], [[1, 2, 3, 4]], $[1, 2, 3, 4]$,
+ "0xff", `Unsigned`, [#0xff], [#0xff], $#0xff$
+)
+