typst-watch is an Emacs minor mode for Typst
projects. It starts one buffer-local typst watch process per Typst
file and stops that process when the buffer dies.
When a major-mode preview keybinding runs, typst-watch opens the
generated PDF in a viewer if it is not already open. The original
preview command is not called, so typst-ts-mode browser previews are
bypassed. By default it tries
zathura first and
falls back to evince.
- Emacs 27.1 or newer
- Typst on
PATH - A PDF viewer, usually
zathuraorevince typst-ts-modeortypst-modefor automatic activation
Put typst-watch.el on your load-path:
(add-to-list 'load-path "/path/to/typst-watch")
(require 'typst-watch)Enable automatic watching for Typst buffers:
(typst-watch-auto-mode 1)Or enable it per buffer:
(add-hook 'typst-ts-mode-hook #'typst-watch-mode)
(add-hook 'typst-mode-hook #'typst-watch-mode)typst-watch-modestartstypst watchwhen enabled and stops it when disabled.- Closing the Typst buffer stops the buffer-local watch process.
typst-watch-auto-modeenablestypst-watch-modeintypst-ts-modeandtypst-modebuffers.- Major-mode preview commands listed in
typst-watch-preview-commandsare remapped totypst-watch-preview, which opens the PDF viewer when needed. Compile-only commands are left to the major mode.
Use a specific viewer:
(setq typst-watch-pdf-viewer "zathura")Change the fallback viewer:
(setq typst-watch-fallback-pdf-viewer "evince")Use a different Typst executable:
(setq typst-watch-typst-command "/usr/local/bin/typst")Disable automatic watcher startup while keeping preview integration:
(setq typst-watch-start-on-enable nil)Change the preview commands whose keybindings open the PDF viewer:
(setq typst-watch-preview-commands
'(typst-ts-preview typst-ts-mode-preview))Change the output path rule:
(setq typst-watch-output-file-function
(lambda (source)
(expand-file-name
(concat (file-name-base source) ".pdf")
(expand-file-name "build" (file-name-directory source)))))Run the full local gate:
make allRun only the tests:
make test