Typst
Typst is a markup-based typesetting system that is designed to be as powerful as LaTeX while being much easier to learn and use.
LiveCodes supports Typst with a live preview of the typeset document. Documents can use Typst's markup, styling, scripting and math features, as well as packages from the Typst Universe.
Basic Demo
show code
- JS
- TS
- React
- Vue
- Svelte
- Solid
- Preact
- Web Components
import { createPlayground } from 'livecodes';
const options = {
"config": {
"markup": {
"language": "typst",
"content": "= Typst\n\n*Typst* is a markup-based typesetting system that is designed to be as powerful as LaTeX while being much easier to learn and use.\n\n== Features\n\n- Markup with headings, lists, tables and figures\n- Scripting with variables, functions and loops\n- Inline and displayed math\n- Packages from the Typst Universe\n\n#let fib(n) = if n < 2 { n } else { fib(n - 1) + fib(n - 2) }\n\nThe first ten Fibonacci numbers are #range(10).map(n => str(fib(n))).join(\", \").\n\n$ sum_(i=1)^n i = (n (n + 1)) / 2 $\n\n#table(\n columns: 2,\n [*Language*], [*LiveCodes*],\n [Typst], [Runs in your browser],\n)\n"
},
"style": {
"language": "css",
"content": "body {\n display: flex;\n justify-content: center;\n align-items: flex-start;\n margin: 0;\n padding: 1rem;\n background: #ececec;\n box-sizing: border-box;\n}\n\nsvg {\n display: block;\n max-width: 100%;\n height: auto;\n background: #fff;\n box-shadow: 0 0 8px rgba(0, 0, 0, 0.15);\n}"
},
"editor": "auto"
}
};
createPlayground('#container', options);
import { createPlayground, type EmbedOptions } from 'livecodes';
const options: EmbedOptions = {
"config": {
"markup": {
"language": "typst",
"content": "= Typst\n\n*Typst* is a markup-based typesetting system that is designed to be as powerful as LaTeX while being much easier to learn and use.\n\n== Features\n\n- Markup with headings, lists, tables and figures\n- Scripting with variables, functions and loops\n- Inline and displayed math\n- Packages from the Typst Universe\n\n#let fib(n) = if n < 2 { n } else { fib(n - 1) + fib(n - 2) }\n\nThe first ten Fibonacci numbers are #range(10).map(n => str(fib(n))).join(\", \").\n\n$ sum_(i=1)^n i = (n (n + 1)) / 2 $\n\n#table(\n columns: 2,\n [*Language*], [*LiveCodes*],\n [Typst], [Runs in your browser],\n)\n"
},
"style": {
"language": "css",
"content": "body {\n display: flex;\n justify-content: center;\n align-items: flex-start;\n margin: 0;\n padding: 1rem;\n background: #ececec;\n box-sizing: border-box;\n}\n\nsvg {\n display: block;\n max-width: 100%;\n height: auto;\n background: #fff;\n box-shadow: 0 0 8px rgba(0, 0, 0, 0.15);\n}"
},
"editor": "auto"
}
};
createPlayground('#container', options);
import LiveCodes from 'livecodes/react';
export default function App() {
const options = {
"config": {
"markup": {
"language": "typst",
"content": "= Typst\n\n*Typst* is a markup-based typesetting system that is designed to be as powerful as LaTeX while being much easier to learn and use.\n\n== Features\n\n- Markup with headings, lists, tables and figures\n- Scripting with variables, functions and loops\n- Inline and displayed math\n- Packages from the Typst Universe\n\n#let fib(n) = if n < 2 { n } else { fib(n - 1) + fib(n - 2) }\n\nThe first ten Fibonacci numbers are #range(10).map(n => str(fib(n))).join(\", \").\n\n$ sum_(i=1)^n i = (n (n + 1)) / 2 $\n\n#table(\n columns: 2,\n [*Language*], [*LiveCodes*],\n [Typst], [Runs in your browser],\n)\n"
},
"style": {
"language": "css",
"content": "body {\n display: flex;\n justify-content: center;\n align-items: flex-start;\n margin: 0;\n padding: 1rem;\n background: #ececec;\n box-sizing: border-box;\n}\n\nsvg {\n display: block;\n max-width: 100%;\n height: auto;\n background: #fff;\n box-shadow: 0 0 8px rgba(0, 0, 0, 0.15);\n}"
},
"editor": "auto"
}
};
return (<LiveCodes {...options} />);
}
<script setup>
import LiveCodes from "livecodes/vue";
const options = {
"config": {
"markup": {
"language": "typst",
"content": "= Typst\n\n*Typst* is a markup-based typesetting system that is designed to be as powerful as LaTeX while being much easier to learn and use.\n\n== Features\n\n- Markup with headings, lists, tables and figures\n- Scripting with variables, functions and loops\n- Inline and displayed math\n- Packages from the Typst Universe\n\n#let fib(n) = if n < 2 { n } else { fib(n - 1) + fib(n - 2) }\n\nThe first ten Fibonacci numbers are #range(10).map(n => str(fib(n))).join(\", \").\n\n$ sum_(i=1)^n i = (n (n + 1)) / 2 $\n\n#table(\n columns: 2,\n [*Language*], [*LiveCodes*],\n [Typst], [Runs in your browser],\n)\n"
},
"style": {
"language": "css",
"content": "body {\n display: flex;\n justify-content: center;\n align-items: flex-start;\n margin: 0;\n padding: 1rem;\n background: #ececec;\n box-sizing: border-box;\n}\n\nsvg {\n display: block;\n max-width: 100%;\n height: auto;\n background: #fff;\n box-shadow: 0 0 8px rgba(0, 0, 0, 0.15);\n}"
},
"editor": "auto"
}
};
</script>
<template>
<LiveCodes v-bind="options" />
</template>
<script>
import LiveCodes from 'livecodes/svelte';
const options = {
"config": {
"markup": {
"language": "typst",
"content": "= Typst\n\n*Typst* is a markup-based typesetting system that is designed to be as powerful as LaTeX while being much easier to learn and use.\n\n== Features\n\n- Markup with headings, lists, tables and figures\n- Scripting with variables, functions and loops\n- Inline and displayed math\n- Packages from the Typst Universe\n\n#let fib(n) = if n < 2 { n } else { fib(n - 1) + fib(n - 2) }\n\nThe first ten Fibonacci numbers are #range(10).map(n => str(fib(n))).join(\", \").\n\n$ sum_(i=1)^n i = (n (n + 1)) / 2 $\n\n#table(\n columns: 2,\n [*Language*], [*LiveCodes*],\n [Typst], [Runs in your browser],\n)\n"
},
"style": {
"language": "css",
"content": "body {\n display: flex;\n justify-content: center;\n align-items: flex-start;\n margin: 0;\n padding: 1rem;\n background: #ececec;\n box-sizing: border-box;\n}\n\nsvg {\n display: block;\n max-width: 100%;\n height: auto;\n background: #fff;\n box-shadow: 0 0 8px rgba(0, 0, 0, 0.15);\n}"
},
"editor": "auto"
}
};
</script>
<LiveCodes {...options} />
import LiveCodes from 'livecodes/solid';
export default function App() {
const options = {
"config": {
"markup": {
"language": "typst",
"content": "= Typst\n\n*Typst* is a markup-based typesetting system that is designed to be as powerful as LaTeX while being much easier to learn and use.\n\n== Features\n\n- Markup with headings, lists, tables and figures\n- Scripting with variables, functions and loops\n- Inline and displayed math\n- Packages from the Typst Universe\n\n#let fib(n) = if n < 2 { n } else { fib(n - 1) + fib(n - 2) }\n\nThe first ten Fibonacci numbers are #range(10).map(n => str(fib(n))).join(\", \").\n\n$ sum_(i=1)^n i = (n (n + 1)) / 2 $\n\n#table(\n columns: 2,\n [*Language*], [*LiveCodes*],\n [Typst], [Runs in your browser],\n)\n"
},
"style": {
"language": "css",
"content": "body {\n display: flex;\n justify-content: center;\n align-items: flex-start;\n margin: 0;\n padding: 1rem;\n background: #ececec;\n box-sizing: border-box;\n}\n\nsvg {\n display: block;\n max-width: 100%;\n height: auto;\n background: #fff;\n box-shadow: 0 0 8px rgba(0, 0, 0, 0.15);\n}"
},
"editor": "auto"
}
};
return (<LiveCodes {...options} />);
}
import LiveCodes from 'livecodes/preact';
export default function App() {
const options = {
"config": {
"markup": {
"language": "typst",
"content": "= Typst\n\n*Typst* is a markup-based typesetting system that is designed to be as powerful as LaTeX while being much easier to learn and use.\n\n== Features\n\n- Markup with headings, lists, tables and figures\n- Scripting with variables, functions and loops\n- Inline and displayed math\n- Packages from the Typst Universe\n\n#let fib(n) = if n < 2 { n } else { fib(n - 1) + fib(n - 2) }\n\nThe first ten Fibonacci numbers are #range(10).map(n => str(fib(n))).join(\", \").\n\n$ sum_(i=1)^n i = (n (n + 1)) / 2 $\n\n#table(\n columns: 2,\n [*Language*], [*LiveCodes*],\n [Typst], [Runs in your browser],\n)\n"
},
"style": {
"language": "css",
"content": "body {\n display: flex;\n justify-content: center;\n align-items: flex-start;\n margin: 0;\n padding: 1rem;\n background: #ececec;\n box-sizing: border-box;\n}\n\nsvg {\n display: block;\n max-width: 100%;\n height: auto;\n background: #fff;\n box-shadow: 0 0 8px rgba(0, 0, 0, 0.15);\n}"
},
"editor": "auto"
}
};
return (<LiveCodes {...options} />);
}
<live-codes></live-codes>
<script type="module">
import "livecodes/web-components";
const playground = document.querySelector("live-codes");
playground.config = {
"markup": {
"language": "typst",
"content": "= Typst\n\n*Typst* is a markup-based typesetting system that is designed to be as powerful as LaTeX while being much easier to learn and use.\n\n== Features\n\n- Markup with headings, lists, tables and figures\n- Scripting with variables, functions and loops\n- Inline and displayed math\n- Packages from the Typst Universe\n\n#let fib(n) = if n < 2 { n } else { fib(n - 1) + fib(n - 2) }\n\nThe first ten Fibonacci numbers are #range(10).map(n => str(fib(n))).join(\", \").\n\n$ sum_(i=1)^n i = (n (n + 1)) / 2 $\n\n#table(\n columns: 2,\n [*Language*], [*LiveCodes*],\n [Typst], [Runs in your browser],\n)\n"
},
"style": {
"language": "css",
"content": "body {\n display: flex;\n justify-content: center;\n align-items: flex-start;\n margin: 0;\n padding: 1rem;\n background: #ececec;\n box-sizing: border-box;\n}\n\nsvg {\n display: block;\n max-width: 100%;\n height: auto;\n background: #fff;\n box-shadow: 0 0 8px rgba(0, 0, 0, 0.15);\n}"
},
"editor": "auto"
};
</script>
Usage
Typst documents are written in the markup editor and previewed live as you type. See the starter template for an example covering markup, styling, scripting, math, tables, figures and packages.
show code
- JS
- TS
- React
- Vue
- Svelte
- Solid
- Preact
- Web Components
import { createPlayground } from 'livecodes';
const options = {
"template": "typst"
};
createPlayground('#container', options);
import { createPlayground, type EmbedOptions } from 'livecodes';
const options: EmbedOptions = {
"template": "typst"
};
createPlayground('#container', options);
import LiveCodes from 'livecodes/react';
export default function App() {
const options = {
"template": "typst"
};
return (<LiveCodes {...options} />);
}
<script setup>
import LiveCodes from "livecodes/vue";
const options = {
"template": "typst"
};
</script>
<template>
<LiveCodes v-bind="options" />
</template>
<script>
import LiveCodes from 'livecodes/svelte';
const options = {
"template": "typst"
};
</script>
<LiveCodes {...options} />
import LiveCodes from 'livecodes/solid';
export default function App() {
const options = {
"template": "typst"
};
return (<LiveCodes {...options} />);
}
import LiveCodes from 'livecodes/preact';
export default function App() {
const options = {
"template": "typst"
};
return (<LiveCodes {...options} />);
}
<live-codes
template="typst"></live-codes>
<script type="module">
import "livecodes/web-components";
</script>
Packages
Typst packages can be imported directly in the document and are fetched from the Typst Universe when first used:
#import "@preview/mmdr:0.2.2": mermaid
#figure(
mermaid("graph LR; A[Typst markup] --> B[Compiler]; B --> C[SVG result];"),
caption: [A Mermaid diagram rendered by the mmdr package.],
)
The example above uses mmdr, which renders
Mermaid diagrams.
Packages are addressed as @namespace/name:version; the packages in the Typst Universe use the
@preview namespace. The first compile that imports a package downloads it, so it may take longer
and requires a network connection. Packages must be compatible with the bundled Typst version (see
Compiler).
Language Info
Name
typst
Extension
typ
Editor
markup
Compiler
The Typst compiler and renderer are compiled to WebAssembly and packaged by typst.ts.
Version
typst.ts v0.7.0 (Typst v0.14.2)
Limitations
- Because the result is rendered as SVG, interactive PDF features (such as links and forms) are not available.
Starter Template
https://livecodes.io/?template=typst