Skip to content

Typst Back-End for Org Export Engine

License

Notifications You must be signed in to change notification settings

emacsmirror/ox-typst

 
 

Repository files navigation

ox-typst

Org-mode to Typst exporter.

Install

Manual

(use-package ox-typst
  :after org)

Usage

If you use org-export-dispatch, then the Typst exporter is available with the y prefix.

Insert Typst Code

Typst code can be directly used within org-mode by using the #+TYPST:. The provided string is not escaped by the exporter and is put directly into the output file.

#+TYPST: #set page(paper: "a4")

Alternatively use an export block.

#+BEGIN_EXPORT typst
#set page(paper: "a4")
#+END_EXPORT

Themes

Use Typst rules to change the appearance of your document. Include these rules at the top level of the document or above the target element. It might be useful to create a file containing Typst rules and include them like below.

#+INCLUDE: "./my-theme.typ" export typst

Alternatively, rules can be put into an export block (Insert Typst Code).

Cite

Typst supports citing and bibliography by default.

#+BIBLIOGRAPHY: ./test.bib
#+print_bibliography: :title Custom Bibliography Title
#+CITE_EXPORT: typst apa

Supported styles are listed here. The second argument (in this case apa) is stringified and put into the bibliography function as the style argument (like bibliography("./test.bib", style: "apa")).

Math

Currently LaTeX math snippets are not supported. It is currently not possible for us to translate these elements into Typst code.

Mabye we should one of the following projects for that:

https://github.com/msakuta/latypst
Translate LaTeX snippets to roughly equivalent Typst snippets
https://github.com/mitex-rs/mitex
Emulate LaTeX inside Typst

Examples

Take a look at test/test.org to get an idea how to use the different org-mode statements with Typst. For real examples look in the examples folder.

Writing a Letter

If you want to write a letter using a third party package (e.g. https://github.com/Sematre/typst-letter-pro), then take a look at examples/letter.org.

Tests

If you want more examples, maybe look into the tests. The tests contain small Org snippets and their Typst representation.

Development

Tests

The tests contain small Org snippets and their Typst output. Changing the exporter requires to re-run the exporter on all Org files. One should manually check if the output matches the expectation. If the output matches the expectation, the newly generated files become the new golden output.

Generate

emacs --batch -l tests/test.el -f org-typst-test-generate

Run

emacs --batch -l tests/test.el -f org-typst-test-run

With Emacs

It is also possible to use these functions inside Emacs. Navigate to the tests/test.el file and run eval-buffer. The ox-typst.el file is automatically re-loaded from the current Git repository when evaluating the test buffer.

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 59.8%
  • Typst 29.5%
  • Nix 10.2%
  • TeX 0.5%