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.)

2 Likes

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.

Personally, I would like to stay in Markdown for as long as possible, until I need the control over typographical details. Markdown is super handy for all kinds of things.

Typst could not support the level of control it does if we were limited to Markdown, but it’s nice there’s a way to get at least a preview of markdown documents before we give them the full Typst treatment.

1 Like

Just noticing this now, but I’m working on a LyX-like experience for Typst called TyX.

It’s very unstable now, I’m working for a long time now to try to make it stable and hopefully we’ll see some results soon :)

EDIT: If I’m not mistaken we discussed it, so I’m just writing this for anyone reading the thread.

2 Likes

Hi! I’ve heard TyX before and I appreciate your work. However, TyX seems not quite the same as the kind of editor I expected. TyX uses a *.tyx format, which looks like a wrapper of *.typ. I guess it’s a trade-off made for the scripting capability of typst?

Typora’s design is as follows.

  • I can insert HTML fragments between regular paragraphs by entering <tag>…</tag>.
  • If my cursor is outside the HTML, the HTML is displayed as the result. (screenshot #1)
  • If my cursor is inside the HTML, the HTML is displayed the source code. (screenshot #2)


1 Like

Yeah, it’s different in that sense. It has some similaries tho