Typst + Markdown via Pandoc

Why?

I want to write a simple article using an editor that seamlessly renders as I type, and control typographical details.

Example

Write main.md:

```{=typst}
// typst here
#import "template.typ": project
#show: project.with(…)
```

# Heading

markdown here.

```{=typst}
#figure(
  table(…),  // some complex table
  caption: […],
) <tab>
```

You can reference the figure as `@tab`{=typst}.

Convert it to main.typ by running pandoc main.md --from markdown+raw_attribute --output main.typ. (:point_right: pandoc.org/try.)

// typst here
#import "template.typ": project
#show: project.with(…)
= Heading
<heading>
markdown here.

#figure(
  table(…),  // some complex table
  caption: […],
) <tab>
You can reference the figure as @tab.

Then typst compile main.typ.

Additional information

  • Refer to pandoc doc on the raw_attribute extension.

  • Get rid of auxiliary files by leveraging - (stdin/stdout):

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

    (Typst is so fast that it is not really necessary to typst watch for simple documents.)

1 Like

Maybe this is obvious to someone who has more experience with Pandoc, but can you explain a bit more of the Why?
There are several options for editors that render a Typst document as you type, and of course Typst allows a lot of control over typographical details.

Hmm, I mean live previewing without a preview window, e.g., Typora, Obsidian for markdown and LyX for LaTeX. As far as I know, there is no such editor yet for typst?

I don’t know about the other editors you mention, but at least for obsidian there is a typst plugin which has worked for me in the past (just remember to enable the “override math blocks” setting, otherwise math blocks will use latex syntax by default)

Edit: I just realised this wasn’t posted in the #questions category. whoops.)

Thanks for sharing it, but it does not provide live previewing without a preview window. If I read its docs right, then it just gives results below typst code blocks.