Skip to content

Instantly share code, notes, and snippets.

@AyakoGFX
Created April 16, 2025 10:13
Show Gist options
  • Select an option

  • Save AyakoGFX/ebc86056b83c2a98707c1fa5a8ee5681 to your computer and use it in GitHub Desktop.

Select an option

Save AyakoGFX/ebc86056b83c2a98707c1fa5a8ee5681 to your computer and use it in GitHub Desktop.
Configure Typst In Emacs

Install

  • typst
  • tinymist

Run Preview Server

tinymist preview main.typ

Compile To PDF

typst compile test.typ

M-x typst-ts-lsp-download-binary to download the LSP in "~/.emacs.d/.cache/lsp/tinymist/tinymist"

Emacs Configuration

(use-package typst-ts-mode
  :ensure t)

(add-hook 'typst-ts-mode-hook 'eglot-ensure)

(setq typst-ts-lsp-download-path
      (string-trim (shell-command-to-string "which tinymist")))

(with-eval-after-load 'eglot
  (with-eval-after-load 'typst-ts-mode
    (add-to-list 'eglot-server-programs
                 `((typst-ts-mode) .
                   ,(eglot-alternatives `(,typst-ts-lsp-download-path
                                          "tinymist"
                                          "typst-lsp"))))))


(defun typst-ts-tinymist-preview ()
  "Run `tinymist preview` on the current file."
  (interactive)
  (let ((file (buffer-file-name)))
    (if file
        (compile (format "tinymist preview %s" (shell-quote-argument file)))
      (user-error "Buffer is not visiting a file"))))

(with-eval-after-load 'typst-ts-mode
  (define-key typst-ts-mode-map (kbd "C-c C-x") #'typst-ts-tinymist-preview))

useful keys

C-c C-c		typst-ts-compile
C-c C-p		typst-ts-preview
C-c C-w		typst-ts-watch-mode  = When you save or edit the file, it automatically recompiles
C-c C-S-c	typst-ts-compile-and-preview

DEMO

~/Videos/gob/typst/

#set heading(numbering: "1.a")

= Introduction
#lorem(100)

= Background
#lorem(100)

= Methods
#lorem(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment