TYPST: A new markup + page layout engine to take on LaTeX

There is a beautiful new markup + PDF output engine available called Typst. It has similar syntax to markdown, yet is actually a LaTex replacement. Look through this tutorial:

To see how layout like this becomes a nice PDF:

Typst is so much more elegant than LaTeX, yet as it can embed programming functions directly can be extended in many ways. There are of course still outstanding weaknesses compared to LaTeX (given decades of packages and development); you can read more on the comparison with LaTeX here: Guide for LaTeX users – Typst Documentation

You can install the command-line version using homebrew: brew install typst — there is an online editor too.

Pandoc now supports Typst input/output, so existing Pandoc projects can be configured to use Typst as the PDF engine. Scrivener could also easily output typst PDFs without needing Pandoc by using Styles, Section Types and the compiler post-processor directly.

3 Likes

Read about this in the release notes for the latest release of pandoc however Typst is still very much in development (0.4 at this moment in time) and much missing for seasoned LaTeX users. Maybe in time it will rival LaTeX but right now it has serious limitations. Worth reading John MacFarlane’s comments on his announcement that pandoc 3.1.3 now has preliminary support for Typst.

2 Likes

Typst is definitely a young project, with the chance that some of the core syntax may change. You can have a look at their Roadmap to see where they are heading (lots of really neat stuff). For most mortal humans LaTeX (powerful as it is) is a series of unintelligible incantantions that can work wonders, but requires a high cognitive load, inelegant markup (solved by using Pandoc or MMD of course) and tons of google searching to make “simple” changes. I honestly do not use most of the possible packages LaTeX offers, and sometimes just drop doing something in LaTeX as I can do it more simply in LibreOffice.

Can you link to John’s comments, thanks?

After working on SGML and LaTex for decades those incantations are my first language.

He made the comments in the email announcement to the pandoc mailing list; if Google hasn’t screwed it up this is the link to that message.

https://groups.google.com/g/pandoc-discuss/c/B7V9V2QVPQI/m/UFXIs4XdCgAJ

1 Like

I’m curious, what do the Typst folks envision scholars who use their platform will submit to journals? Not the pdf, right? But then what will the journals’ typesetters use? A Typst source file?

Seems to me that outputting to LaTeX or Word is needed before Typst will take off. What am I missing?

1 Like

Yes, the final submission puzzle for academics is still undefined from the Typst website at least, perhaps you can ask on their discord server? I assumed Pandoc would serve as that bridge, and thought i saw some interaction between Typst developers and John (Pandoc creator) but forget where I saw that. Typst is still in quite a state of flux, and as beautifully elegant as it is, I’ll stick to markdown for the time being for most projects :blush:

1 Like

I saw that as of the latest version of Pandoc, it can serve as a reader and writer of Typst. So perhaps you’re right that the Typst folks plan to rely on that.

It looks like Typst is not supported by the Quarto book format. When I compile I get :

WARNING: The typst format is not supported by book projects

So, alas, it can’t yet be used as an alternative to LaTeX for entire projects. Single files do work.

Paolo

You can just use Typst directly, without having to transcode to/from Markdown (Pandoc/Quarto etc.) — there is certainly enough in its layout engine to make book projects, though things will get much better as their roadmap gets filled out: Roadmap – Typst Documentation

Hi nontroppo,

Thanks for the ‘Homebrew’ Terminal command …

I’ll likely be keeping an eye on Typst development … could be interesting!

Thanks again,
scrive
:thinking:

Yup! But this would remove Scrivener from the equation, and I wouldn’t want to do it!

I’m very confident this missing part will be added together with others. It looks like Quarto and Typst are of the same ethos, trying to make modern tools for an old task.

Paolo

Not at all, I mean to use Scrivener’s compiler to output Typst and use the typst command as the post-processor, much like the direct-LaTeX template does. With careful structuring, you can use styles and section types to drive either markdown or typst outputs. Scrivener always stays in the driver’s seat, it is the compiler that is tasked with the work of translation…

1 Like

My original note about Typst not being compatibile with Quarto’s book format is particularly obtuse. This shows how confused I am with this matter.

Obviously, there is no reason to go through the book format, when all that Typst is called to do is a monolithic PDF file. So, the workflow is Scrivener → Pandoc → Quarto → Typst with a single .md file.

Paolo

Well, I’ve been able to compile my first PDF with Quarto and Typst. Only, it is just EVERYTHING I typed in Scrivener, including the markup codes.

I added a configuration block at the beginning of the .md file to be processed, but maybe I lack some more information about what to add there. For example, the template is probably just a placeholder.

---
title: "My Project"
format:
  typst:
    toc: true
    section-numbering: false
    columns: 1
    papersize: a5
    fontsize: 9.5
---

But not even the page format was considered. Let’s look for some additional manuals…

Paolo

For example, when running a quarto typst compile [filename] command, I get several errors of this type:

error: expected expression
   ┌─ Documents/[filename and path]:13:1
   │
13 │ # This is a title
   │  ^

I don’t see anything wrong, according to the Pandoc markdown syntax. So, I wouldn’t know what to fix.

I also get several errors from asterisks (*) used by the compiler for bullet lists. And hashtags (#) inserted in the text (representing note names with a sharp symbol, for example in ‘C#’) are reported as errors by Quarto/Typst. And text between strong/bold markup (**[text]**) is reported as “no text”, and “unnecessary multiple consecutive stars”.

Really mysterious.

Paolo

Can you make a simple project that is failing. It is always helpful for others as they can quickly test what may be not working in your setup…

Here is a simple test, uses Pandoc → Typst

typst.scriv.zip (237.2 KB)

I use brew to install pandoc and typst, and even though I do add /opt/homebrew/bin (where both pandoc and typst commands are found) to the environment, Scrivener causes Pandoc to fail to find Typst.

UPDATE: in fact I can get the PDF directly from Scrivener now:

typst.pdf.zip (236.6 KB)

Headings, inline styles, figures, footnotes etc. are working; more advanced features will need more tweaking and some method to inject typst markup directly to change the layout etc. is still required.

The one I tried was the simplest one (a title, a body text). But now I understand what could have been wrong: I presumed that the source markdown file had to be in Pandoc markdown syntax. Apparently, it has to be in the Typst syntax.

In fact, when I replaced the hashtag (#) with an equali sign (=) in the source file, the document sections were understood, and the PDF file generated. Only, it also contained the configuration block. I’m using the most up-to-date versions of Quarto, Typst and Pandoc, as from their official installers (even if beta).

So, I guess compiling from Scrivener should require something similar to the LaTeX Modern template. It is not just a matter of letting Quarto convert a Pandoc MMD file generated by Scrivener. I understand it will be quite a work, even if probably much easier than with LaTeX.

At this point, I’m not sure what the Pandoc Typst writer is doing.
EDIT: Or, maybe I should tell the compile format, in Scrivener, that it should use Typst for conversion? Writing it in the document’s configuration head is not enough, even for Quarto?

Paolo

quarto-typst-right-wrong.zip (1.6 KB)

No, your new presumption is wrong, the old one was fine! :stuck_out_tongue_winking_eye:

The ideal workflow:

  1. The text in Scrivener should use Scrivener’s styles and Section Types, so emphasis for italic etc. and use appropriate Section Types.
  2. Then you compile to Pandoc markdown.
  3. Scrivener compiler makes a Pandoc MD file.
  4. The pandoc command is: pandoc -f markdown -t typst -o out.pdf in.md – this command can be done in the post-processing pane of the compiler or you can run it yourself in Terminal…
  5. You will get a PDF next to the MD file. See above for the sample I made direct from Scrivener.

I attached a working Scrivener project that demonstrates how to do this above. I have an Apple Silicon Mac so my homebrew is /opt/homebrew/bin so if you have an Intel you’ll need to change the post-processing commands. But that project demonstrates what you need.

We can build from that, as we can use Styles or Section Types to inject the formatting markup for e.g. one/two columns, fonts etc. So that just as for Quarto compile formats, we can do detailed layout using Scrivener’s editing features… The limits for this workflow will be reached when we bump up to Typst limitations or the fact Pandoc may not fully support all typst features…

Just to clarify: Quarto may not support Typst properly yet, so using Quarto instead of Pandoc adds lots of additional complexity, just stick to pandoc for the moment. Again open my project and see exactly what is done there…

2 Likes

And to really reinforce the power of this, I just slightly tweaked the post-processing to use PrinceXML:

pandoc -t html5 --pdf-engine=prince -o prince.pdf -i in.md

And so the same Scrivener project (no editor changes) can now compile automagically to either HTML+PDF or Typst+PDF…

prince.pdf.zip (110.8 KB)

For Typst you’d use injected typst markup for layout changes, and for Prince you’d use injected CSS, but this now gives you maximum flexibility without any editor changes…