/typst-mode.el

An Emacs major mode for `typst`, a markup-based typesetting system.

Primary LanguageEmacs LispGNU General Public License v3.0GPL-3.0

Typst Mode

An Emacs major mode for typst, a markup-based typesetting system.

Requirements

external executable: typst (least version: typst 0.1.0 (1c324765), which has typst compile subcommand)

Emacs package: polymode (if you use straight, it will automatically download this requirement for you)

Installation

Use-package and straight

(use-package typst-mode
  :straight (:type git :host github :repo "Ziqi-Yang/typst-mode.el"))

Manually

;; push typst-mode directory to the load-path like this
(push (expand-file-name "modules/languages/typst-mode" user-emacs-directory) load-path)
;; load tyspt-mode
(require 'typst-mode)

Current Features

Functions

  1. typst-compile (default bind: C-c C-c; also provide typst-compile-preview)
  2. typst-preview (default bind: C-c C-p)
  3. typst-toggle-watch (default bind: C-c C-w; also provide typst-watch and typst-stop-watch)

Style

Markup

featuresupportExample
Paragraph break
Strong emphasisstrong
Emphasisemphasis
Raw textinline`print(1)`
Linkhttps://typst.app/
Label<intro>
Reference@intro
Heading== Heading=
Bullet list- item
Numbered list+ item
Term list/ Term: description
Math$x^2$
Line break\
Smart quote‘single’ or “double”
Symbol shorthand~, —
Code expressionname#rect(width: 1cm)
Character escapeTweet at us \#ad
Comment/* block */, // line

Math Mode

Math inside pair of $ notation. Currently not supported

Code Mode

Supported.

Customization

faces and custom variables with prefix typst or typst-mode

To Dos

  1. [ ] fix math mode
  2. [ ] add treesit mode
  3. [ ] show compile errors at real time when in Typst watch mode

Current Shortages

For those stuffs cannot be done in short future.

  1. no syntax support for the context block [ ] which is located in the code block { }
    this problem possibly can be solved with nested polymode. However, currently there is no official support for this function?
  2. indentation in the first line of code mode(contents between ‘{’ and ‘}’) may not works well, like this:
    (hitting `tab` to indent has problem, but it works well when directly call `typst-mode-indent-line`)
    begin_code {
     [ // wrong indentation 
         [ // indentation works well
         ]
     ]
    }
        

    The issue may caused by Polymode. I have created an issue here: polymode/polymode#328