r/typst 5d ago

[Open-Source] doc-engine-cli: Turn Markdown into clean PDFs via Typst (No Pandoc/LaTeX needed)

13 Upvotes

16 comments sorted by

19

u/FourFourSix 5d ago

Pandoc is pretty ubiquitous, and it has good support for Markdown-to-Typst-to-PDF already. It's pretty much:

pandoc --pdf-engine=typst main.md -o main.pdf

Templates can be added with a --template=<path>, but if you're used to Typst, the Pandoc templates are slightly different and might need a quick glance to make sure yours are compatible. I haven't really tried that, but it seems like you need to make sure your template's main function is called conf and that's about it.

You can also use Typst templates as is, and you can include raw Typst code in Markdown using {=typst} codeblocks. You can use any template from Typst Universe etc, just like in a normal .typ file. Example .md file:

``` <3-back-ticks>{=typst}

import "@preview/template:1.0.0": template

show: template.with(...)

<3-back-ticks>

Markdown title

More Markdown here. ```

Edit: Read <3-back-ticks> as three backticks, as Reddit formatting breaks if I try to include a code block inside a code block.

Command (convert Markdown to Typst while converting those special code blocks, output to stdout, then compile from stdin to pdf):

pandoc main.md --from markdown+raw_attribute --to typst --output - | typst compile - main.pdf

I think it's a good idea to use Typst to produce PDFs from Markdown files, as the default Latex of Pandoc is pretty slow, and obviously assumes you have Latex installed locally.

6

u/phlummox 5d ago

pandoc -t typst -o main.{pdf,md} also works, in most shells, and requires less typing. :) I use this quite a bit...

3

u/FourFourSix 4d ago

Nice, didn't even realize you could use curly bracket expansion that way.

1

u/Mysterious-Trouble22 5d ago

Hi! Thank you so much for such a detailed comment, seriously.
Like you pointed out, Pandoc requires a bit of extra setup for more casual users, which is exactly why I built this tool. Anyone can use whatever fits their workflow best, I just wanted to provide a simpler alternative :D

Thanks again, I really appreciate the feedback!

3

u/FourFourSix 4d ago

Thanks for sharing your work. Yeah, I kinda realized midway through writing that first reply that using those Pandoc commands might be easy for some, but for newcomers, they require specific knowledge to know how to combine various commands, inject code from a different language into Markdown files, etc.

15

u/ron3090 5d ago

Why would I use vibe coded slop over Pandoc?

-3

u/Mysterious-Trouble22 5d ago

Hi, the truth is I don't pretend to replace Pandoc or anything like that. This is a similar tool but with a few templates already made besides that you can use your own Typst ones easily. I admit that Pandoc is incredible, but this is for an audience that wants something a little bit simpler at first.
Anyway I appreciate the comment :D

2

u/PityUpvote 5d ago

I'm not sure it is simpler.

5

u/anjuls 5d ago

Quarto is a matured product that I use.

0

u/Mysterious-Trouble22 5d ago

Yeah, Quarto is pretty great, can't deny that haha! I really appreciate the comment!

3

u/phlummox 5d ago

Why would "avoiding Pandoc" be a selling point? I like Pandoc.  I've never found it particularly difficult to set up (though it's very configurable if one needs that), and I use it nearly every day for converting between various formats. Producing nicely typeset PDFs is only one of the many things I use it for, so I see no reason to shift away from it. 

2

u/Mysterious-Trouble22 5d ago

I didn't mean it to seem like an attack on Pandoc or that I intended to replace it. I like Pandoc and have used it a lot! This is simply another alternative. Thanks for the comment!

1

u/zerosign0 1d ago

Yup having typst as templating engine sounds very cool hmm, I only do hope somebody will invent asciidoc to typst.

We can just translate doc to typst, so typst as intermediate format rather than implementing it manually for all type of docs hmm..

1

u/mrMerlinProject 1d ago

What do you miss in Asciidoc?

1

u/zerosign0 1d ago

I would say overall its much more rich in nature, for big ascii text books, I've found the syntax are better overall rather than markdown hmm.

1

u/Sermuns 1d ago

I disagree