Migrating to Typsite 0.1.6
Migrating to Typsite 0.1.6
In version 0.1.6, Typsite introduced a series of major updates, inevitably including some breaking-changes. This document aims to help users migrate to the new version smoothly.
1 Typsite Packages
Parts of the Typst library that are closely related to Typsite have been extracted into separate Typst packages. You can find them under typsite/packages. Typsite bundles these packages into the binary and automatically installs them to the
@local
@local
directory during each
typsite compile
typsite compile
.
To facilitate debugging and using packages, Typsite also supports local package auto-installation. Just specify the
--packages
--packages
flag when running
typsite compile
typsite compile
.
- In
watch-modewatch-mode, Typsite will also automatically update these local packages and recompile the site.
So now, the Typsite Typst libraries are split into two parts:
-
@local/typsite:0.1.0@local/typsite:0.1.0: Contains core functionality of Typsite, provides basic functions, and acts as an interface between Typsite and site libraries.- Thanks to this layer, it is unlikely for future updates to introduce more breaking-changes.
-
root/lib/root/lib/: The site library of each Typsite site. Users are free to customize anything here.
2 Migration
If you’re relying on site libraries from before version 0.1.6, you’ll need to make the following replacements when migrating:
-
import "lib.typ"import "lib.typ"|->import "/lib/lib.typ"import "/lib/lib.typ" -
html-texthtml-text|->html.texthtml.text -
text-aligntext-align|->html.alignhtml.align- (Make sure not- to replace
text-aligntext-aligninside/lib/site.typ/lib/site.typ)
- (Make sure not- to replace
It’s recommended to import
lib.typ
lib.typ
using an absolute path. If you’re using tinymist as your LSP, you’ll need to specify the Typst
root-path
root-path
for better experience:
-
In VSCode, you can add the following to
.vscode/settings.json.vscode/settings.jsonin your site directory:"tinymist.rootPath": "absolute path of your site/root""tinymist.rootPath": "absolute path of your site/root"
For any breaking-changes not anticipated here, you can easily detect them by launching
watch-mode
watch-mode
with
typsite compile --port 8000
typsite compile --port 8000
. Typsite will provide helpful error messages whenever you modify a file, allowing you to fix issues quickly.
3 Other Updates
-
Added support for converting Typst math to MathML.
- This improves the rendering of math formulas, and the MathML conversion will detect Typst math fonts in-place for compatibility.
-
inlineinlinefunction has a newfit-fontfit-fontparameter, which can adapt to Typst’scontext text.sizecontext text.size. - For pages containing backlinks and references, duplicate tags in the
<head><head>section are now removed, resulting in a much cleaner structure. - In the default site library,
show-rulesshow-ruleshave been modularized. You can easily add/remove/modifyshow-ruleshow-ruleitems in/lib/lib.typ/lib/lib.typ. - In the default site configuration, link titles have been optimized. You can now preview links as
Link Title [Link URL]Link Title [Link URL].
Backlinks
Backlinks
Typsite Documentation [index]
Typsite Documentation [index]
1 Introduction
Typsite is a tool for building static websites. It uses pure Typst to write content and processes it through Typsite to generate a fully functional static site.
2 Features
- Standard Typst expressions
- Framework support: hierarchical headings, section templates, sidebar, footer
- Rich text: paragraphs, sections, quotes, code blocks, math formulas, footnotes, page embedding
- Typst math -> Mathml (auto detected math-font)
- Supports modern web standards such as HTML5, CSS3, and JavaScript (ES6+)
- Incremental compilation and real-time preview
3
Introduction to Typst
[typst]
Typst is a modern typesetting system, similar to LaTeX, but designed to be more concise and easier to learn. It is primarily used to create beautifully typeset documents such as academic papers, books, and reports.
You can find the official English documentation here: Typst Document
For a Chinese tutorial on Typst, I highly recommend: The Typst Blue Book
[Oh my, the author is clearly aware that they’re explaining an ontology!].
Typst
🔥has risen!🔥
🚀Did the TeX folks miss the memo?🚀
The rest of this section will introduce Typst & HTML → Typsite
3.1 Typst’s HTML Export Feature
In version
0.13
0.13
, Typst added HTML export capabilities, including an html-export mode and two core functions:
html.elem
html.elem
and
html.frame
html.frame
— using these, we can write Typst documents targeting HTML+CSS output.
3.2 Typsite: A Static Site Generator Based on Typst
Inspired by this, I developed a static site generator in Rust called Typsite.
Currently, Typst’s HTML export:
- Has good support for basic rich text
- Requires users to manually write complex styles using the
html.elemhtml.elemfunction - Cannot automatically convert all Typst ecosystem content into HTML
- For content with complex Typst styles,
html.framehtml.framecan be used to convert them into SVG and embed them into HTML - Only supports single-file HTML output per compilation
For details on supported features and the roadmap, follow this issue: HTML export #5512
Although the official team plans to support automatic typst style → HTML+CSS in the future, this won’t conflict with Typsite. On the contrary, Typst’s development will make Typsite even more useful, because Typsite’s main role is to coordinate interaction between articles and ultimately build a fully functional static website.
4 Installation
-
Download the binary from the release
- Make sure you have Typst 0.13+ installed
-
Build via Nix & Flakes
- Ensure you’ve enabled
experimental-features = nix-command flakesexperimental-features = nix-command flakes
- Ensure you’ve enabled
git clone https://github.com/Glomzzz/typsite.git
cd typsite
nix build .
git clone https://github.com/Glomzzz/typsite.git
cd typsite
nix build .
5 Initialization
Run
typsite init
typsite init
to initialize a Typsite project in the current directory.
.
├── root --- Typst root directory
│ ├── index.typ --- Main article
│ └── lib.typ --- Typsite library file
├── .typsite --- Typsite configuration directory
│ ├── assets --- Resources (synced to output directory)
│ ├── components --- Component templates
│ ├── themes --- Code highlighting themes
│ ├── rewrite --- Rewrite templates
│ ├── schemas --- Page templates
│ └── options.toml --- Project configuration
├── .cache --- Cache directory
└── publish --- Output directory
.
├── root --- Typst root directory
│ ├── index.typ --- Main article
│ └── lib.typ --- Typsite library file
├── .typsite --- Typsite configuration directory
│ ├── assets --- Resources (synced to output directory)
│ ├── components --- Component templates
│ ├── themes --- Code highlighting themes
│ ├── rewrite --- Rewrite templates
│ ├── schemas --- Page templates
│ └── options.toml --- Project configuration
├── .cache --- Cache directory
└── publish --- Output directory
7 CLI (Command Line Interface)
Usage: typsite <COMMAND>
Commands:
init Initialize a new Typsite project in the specified directory
compile Compile or watch a project; specify input/output [alias: c]
clean Clear cache and output directories
syntect Check the list of supported syntax and code highlighting
help Print this message or help info for a subcommand
Options:
-h, --help Print help
-V, --version Print version info
Usage: typsite <COMMAND>
Commands:
init Initialize a new Typsite project in the specified directory
compile Compile or watch a project; specify input/output [alias: c]
clean Clear cache and output directories
syntect Check the list of supported syntax and code highlighting
help Print this message or help info for a subcommand
Options:
-h, --help Print help
-V, --version Print version info
7.1 init
Initialize a new Typsite project in the specified directory
Usage: typsite init [OPTIONS]
Options:
-d, --dir <DIR> Project root directory [default: ./]
-h, --help Print help
Initialize a new Typsite project in the specified directory
Usage: typsite init [OPTIONS]
Options:
-d, --dir <DIR> Project root directory [default: ./]
-h, --help Print help
7.2 compile
Compile or watch the project with specified input and output directories
Usage: typsite compile [OPTIONS]
Options:
--host <HOST> Serve host [default: localhost]
--port <PORT> Serve port, must be specified to watch mode [default: 0]
--config <CONFIG> Project config [default: ./.typsite]
--cache <CACHE> Cache dir [default: ./.cache]
-i, --input <INPUT> Typst root dir, where your typst files are stored [default: ./root] [aliases: --i]
-o, --output <OUTPUT> Output dir [default: ./publish] [aliases: --o]
-p, --packages <PACKAGES> Packages dir, will be installed to @local and will be synced to @local in watch mode, skip if empty or not found [default: ] [aliases: --p]
--no-pretty-url
--no-short-slug
-h, --help Print help
Compile or watch the project with specified input and output directories
Usage: typsite compile [OPTIONS]
Options:
--host <HOST> Serve host [default: localhost]
--port <PORT> Serve port, must be specified to watch mode [default: 0]
--config <CONFIG> Project config [default: ./.typsite]
--cache <CACHE> Cache dir [default: ./.cache]
-i, --input <INPUT> Typst root dir, where your typst files are stored [default: ./root] [aliases: --i]
-o, --output <OUTPUT> Output dir [default: ./publish] [aliases: --o]
-p, --packages <PACKAGES> Packages dir, will be installed to @local and will be synced to @local in watch mode, skip if empty or not found [default: ] [aliases: --p]
--no-pretty-url
--no-short-slug
-h, --help Print help
7.3 clean
Clear cache and output directories
Usage: typsite clean [OPTIONS]
Options:
-o, --output <OUTPUT> Output directory [default: ./publish]
-c, --cache <CACHE> Cache directory for typst_html_export content [default: ./.cache]
-h, --help Print help
Clear cache and output directories
Usage: typsite clean [OPTIONS]
Options:
-o, --output <OUTPUT> Output directory [default: ./publish]
-c, --cache <CACHE> Cache directory for typst_html_export content [default: ./.cache]
-h, --help Print help
7.4 syntect
View the list of syntax highlighting and supported languages
Usage: typsite syntect [OPTIONS]
Options:
--config <CONFIG> Config path [default: ./.typsite]
-h, --help Print help
View the list of syntax highlighting and supported languages
Usage: typsite syntect [OPTIONS]
Options:
--config <CONFIG> Config path [default: ./.typsite]
-h, --help Print help
8 Architecture & Flow
9 Configuration
You can view all default configurations here:
Based on these, you can fully customize your entire site.
- schema: Page templates, handling page structure
- components / rewrites: Components/Rewriters, build up the page content
- assets: Resource files, automatically synced during compilation
- themes: Code highlighting files
- syntaxes: Code syntaxes files
10
Article
[article]
10.1 Metadata
10.1.1 Page Settings
10.1.2 Meta Content
10.1.3 Article Relations
10.2 Sidebar
10.3 Main Content
10.3.1 Headings
10.3.2 Paragraphs
10.3.3 Breadcrumbs
10.3.4 Embeds
10.3.5 Footnotes
10.3.6 Links
10.3.7 Formulas
10.3.8 Inline Content
10.3.9 Code
10.3.9.1 Theme
10.3.9.2 Syntax
10.3.10 Styles
10.3.10.1 Alignment
10.3.10.2 Highlight
10.3.10.3 Colored Text
10.3.10.4 Bold
10.3.10.5 Italic
10.4 Footer
10.4.1 Backlinks
10.4.2 References
Migrating to Typsite 0.1.7 [migrate-to-017]
Migrating to Typsite 0.1.7 [migrate-to-017]
In version 0.1.7, Typsite introduced a series of major updates about SVG-compat, inevitably including some breaking-changes. This document aims to help users migrate to the new version smoothly.
1 0.1.6 Migration
Make sure you’ve done: Migrating to Typsite 0.1.6
2 .typsite Configuration Migration
In version 0.1.7, the following new components and rewrites were added to the .typsite directory:
-
.typsite/components/anchor_def_svg.html.typsite/components/anchor_def_svg.html: SVG anchor definition component -
.typsite/components/anchor_goto_svg.html.typsite/components/anchor_goto_svg.html: SVG anchor goto component -
.typsite/rewrite/footnote-ref-svg.html.typsite/rewrite/footnote-ref-svg.html: Footnote reference rewrite for SVG
If you’re upgrading from an older version, make sure to copy these new files to your site’s .typsite directory.
3 /root/lib Library Migration
3.1 inline Function Signature Change
The
fit-font
fit-font
parameter semantics of the
inline
inline
function have changed:
- Before 0.1.7:
fit-fontfit-fontwas aboolbooltype - After 0.1.7:
fit-fontfit-fontis a1em1emtype (can betruetrue,falsefalse, or values like1em1em,2em2em)
Migration:
-
inline(content, fit-font: true)inline(content, fit-font: true)|->inline(content, fit-font: 1em)inline(content, fit-font: 1em) -
inline(content, fit-font: false)inline(content, fit-font: false)|->inline(content)inline(content)orinline(content, fit-font: false)inline(content, fit-font: false)
3.2 Library Import Changes
If you’ve customized the
inline
inline
function in your site library, you need to update the call signature:
// Old version
#import "@local/typsite:0.1.0": inline
// New version
#let footnotes = state("footnotes", ())
#let inline(..args) = context {
import "@local/typsite:0.1.0": inline
inline(..args, footnotes: footnotes.get())
}
// Old version
#import "@local/typsite:0.1.0": inline
// New version
#let footnotes = state("footnotes", ())
#let inline(..args) = context {
import "@local/typsite:0.1.0": inline
inline(..args, footnotes: footnotes.get())
}
3.3 rule Function Signature Changes
The following functions in
rule.typ
rule.typ
now need to receive the
footnotes
footnotes
parameter:
-
rule-ref(footnotes)rule-ref(footnotes)instead of the oldrule-refrule-ref -
rule-footnote(footnotes)rule-footnote(footnotes)instead of the oldrule-footnoterule-footnote
In the
schema
schema
function, you need to fetch footnotes first and then pass them to the rules:
let _footnotes = query(footnote).map(it => it.at("label", default: none)).filter(it => it != none)
show: rule-footnote(_footnotes)
show: rule-ref(_footnotes)
let _footnotes = query(footnote).map(it => it.at("label", default: none)).filter(it => it != none)
show: rule-footnote(_footnotes)
show: rule-ref(_footnotes)
4 /packages Package Migration
4.1 inline Function New footnotes Parameter
The
inline
inline
function in
@local/typsite:0.1.0
@local/typsite:0.1.0
now requires a
footnotes
footnotes
parameter:
// Old version
inline(content, fit-font: true, scale: 100%)
// New version
inline(content, fit-font: 1em, scale: 100%, footnotes: ())
// Old version
inline(content, fit-font: true, scale: 100%)
// New version
inline(content, fit-font: 1em, scale: 100%, footnotes: ())
4.2 auto-sized-svg New fit-font Parameter
The
auto-sized-svg
auto-sized-svg
function now has a
fit-font
fit-font
parameter with more flexible font size control:
-
truetrue: Use CSS font-size inheritance -
falsefalse: Use fixed font-size: 1rem -
1em1em: Use relative em value
5 Zed Editor Compatibility
5.1 Zed LSP Configuration
If you’re using Zed as your editor, you can add the following configuration for a better Typst development experience:
Add to
.zed/settings.json
.zed/settings.json
:
{
"lsp": {
"tinymist": {
"initialization_options": {
"exportPdf": "never",
"rootPath": "your/site/root/path",
},
},
},
}
{
"lsp": {
"tinymist": {
"initialization_options": {
"exportPdf": "never",
"rootPath": "your/site/root/path",
},
},
},
}
5.2 VSCode Settings Migration
If you were previously using VSCode with tinymist configured, you need to update
rootPath
rootPath
to an absolute path:
In
.vscode/settings.json
.vscode/settings.json
:
{
"tinymist.rootPath": "/absolute/path/to/your/site/root"
}
{
"tinymist.rootPath": "/absolute/path/to/your/site/root"
}
6 0.1.6 Migration Link
If you’re migrating from version 0.1.6, make sure you’ve also completed the 0.1.6 migration steps:
-
import "lib.typ"import "lib.typ"|->import "/lib/lib.typ"import "/lib/lib.typ" -
html-texthtml-text|->html.texthtml.text -
text-aligntext-align|->html.alignhtml.align
7 Other Updates
- Added SVG anchor support, allowing creation of jumpable anchors in Typst content
- Footnote references now support SVG inline rendering
- Improved the font size adaptation mechanism for the
inlineinlinefunction - Added support for more flexible
fit-fontfit-fontparameter, allowing specific em values