Typst for Obsidian is a Typst editor integrated directly into Obsidian, enabling you to create and preview Typst documents seamlessly within your notes. Create .typ files, edit with syntax highlighting, and render PDFs that adapt to your Obsidian theme.
- Open
.typfiles in Obsidian - VSCode-Like editor with Typst syntax highlighting
- Customizable syntax highlighting colors for dark and light themes
- Toggle between source and PDF preview modes
- PDF export to vault
- Theme integration - rendered PDFs adapt to Obsidian themes
- Template variables for dynamic theming (
%THEMECOLOR%,%FONTSIZE%, etc.) - Package support - use local packages from data directory or auto-download from preview namespace
- System font support (desktop only)
- Create a new
.typfile or open an existing one - Edit in source mode with syntax highlighting
- Click the preview icon to render PDF
- Click the export icon to save PDF to vault
Use these variables in your Typst documents to match Obsidian themes:
#set text(fill: rgb("#%THEMECOLOR%"), size: %FONTSIZE%)
#set page(fill: rgb("#%BGCOLOR%"), width: %LINEWIDTH%)Available variables:
%THEMECOLOR%- Primary text color%FONTSIZE%- Text size in pt%BGCOLOR%- Background color%LINEWIDTH%- Page width%ACCENTCOLOR%,%FAINTCOLOR%,%MUTEDCOLOR%%BGPRIMARY%,%BGPRIMARYALT%,%BGSECONDARY%,%BGSECONDARYALT%%SUCCESSCOLOR%,%WARNINGCOLOR%,%ERRORCOLOR%%FONTTEXT%,%FONTMONO%,%HEADINGCOLOR%
Configure default page layouts in settings:
- Default Layout Functions - Applied to all internal previews
- PDF Export Layout Functions - Applied only when exporting PDFs
You can add custom Typst snippets as JSON for autocomplete in settings. Each snippet has a prefix (trigger) and body (lines to insert). Use $1, $2, etc., for tab stops.
Example (inserting a table aligned to the center):
{
"table": {
"prefix": "tbl",
"body": [
"#align(center,",
"\ttable(",
"\t\tcolumns: $1,",
"\t\t[$2],",
"\t)",
")"
]
}
}- Default Mode - Open files in source or reading mode
- Auto-download Packages - Automatically fetch packages from Typst registry
- Font Families - System fonts to load (desktop only)
- Layout Functions - Custom Typst preambles for formatting
- Enable Text Layer - Enable text selection in PDF preview. Disabling this setting may improve performance
- Custom Snippets - Add custom Typst snippets for autocomplete
- Syntax Highlighting - Customize colors for 28 different syntax categories, separately for dark and light themes. Import/export color configurations as JSON
- Create new Typst file - Create
.typfile at specified path - Toggle source/reading mode - Switch between editing and preview
- Export to PDF - Export current document to PDF file
- Toggle bold - Wrap selection with
*text* - Toggle italic - Wrap selection with
_text_ - Toggle underline - Wrap selection with
#underline[text] - Increase heading level - Add one
=to heading (max 6 levels) - Decrease heading level - Remove one
=from heading (min 2 levels)
Note
Since Obsidian doesn't let you use the same hotkeys for different views, to use Ctrl+B and Ctrl+I in both Typst files and Markdown files, unbind the default bold and italic hotkeys, and bind Toggle bold and Toggle italic to Ctrl+B and Ctrl+I. It will work for both Typst files and Markdown files. Alternatively, you can just use two different hotkeys.
You can use the official template designed for Typst in Obsidian. It includes support for light/dark modes, titles, headers, and useful functions for displaying notes.
To get started, import the template at the top of your Typst file:
#import "@preview/typsidian:0.0.2": *;
#show: typsidian.with(
theme: "dark",
title: "My Document",
course: "CS4999",
standalone: false
)This template is an Obsidian-like theme for Typst, with support for light/dark modes, titles, headers, and some useful functions for displaying notes.
When using this template, I recommend setting the custom layout function in the settings to:
#set page(
width: %LINEWIDTH%,
height: auto,
margin: (x: 0.25em, y: 0.25em),
fill: rgb("%BGCOLOR%")
)Make sure to set standalone: false. This will prevent the template from adding its own page layout. Additionally, make sure you have the required fonts installed and added to the font families in settings:
- Download the latest release from the Releases page
- Extract
main.js,manifest.json,styles.css, andobsidian_typst_bg.wasmto your Obsidian plugins folder (.obsidian/plugins/typst-for-obsidian) - Enable the plugin in Obsidian settings
Feel free to open issues or submit pull requests for bug fixes and new features.
- Since the plugin uses a Rust WebAssembly module for the Typst compiler, you'll need to have Rust and
wasm-packinstalled. - Clone the repository and navigate to the project directory.
- Install the necessary npm packages and build the WebAssembly module:
npm install
cd compiler
cargo build --release
wasm-pack build --target web --out-dir ../pkg
cd ..
npm run build- Create a folder for the plugin in your Obsidian vault's plugins directory:
.obsidian/plugins/typst-for-obsidian. - Copy the built files (
main.js,manifest.json,styles.css, and thepkgfolder) to the plugin folder you created. - Restart Obsidian and enable the plugin in settings.
For easier deployment during development:
- Install the Hot Reload plugin and create a
.hotreloadfile in the root directory of the plugin in your vault. - Create a
.envfile in the root directory of the repo with the following content:
SOURCE_DIR="path/to/the/source/directory"
TARGET_DIR="path/to/your-vault/.obsidian/plugins/typst-for-obsidian"
- Run the build script to copy files to your Obsidian plugins folder:
npm run build:deploy- Implement incremental PDF rendering and proper editor-preview split view
- Improve performance of PDF rendering
- Polish PDF viewer, fix text layers, add annotation layers
- Finish Monaco snippet integration for autocomplete
- Formatter for Typst code
- Add support for jumping from PDF to source by clicking on text
- Add backlink support in PDF preview
- Support for more template variables
- Improve error handling and reporting
- Support Typst packages that use WebAssembly modules
- Packages that import WebAssembly modules (like CeTZ) don't work
- Scroll position restoration when toggling modes is jittery
Compiler implementation inspired by fenjalien/obsidian-typst.
MIT


