Markpad icon indicating copy to clipboard operation
Markpad copied to clipboard

Typst support

Open abdullohraupov opened this issue 3 months ago • 1 comments

What problem would this solve?

Rendering mathematical formulas or technical document using LaTeX in Markdown can be slow and clunky. Using Typst:

  • It provides fast compilation speed.
  • It has a much cleaner, modern syntax for math and markup compared to LaTeX.

What would you like?

Built-in Typst syntax support and preview.

What have you tried instead?

LaTeX, but it feels outdated.

abdullohraupov avatar Aug 14 '26 06:08 abdullohraupov

Worth separating two readings of this, because only one of them is a Markpad feature.

Typst as a document format — opening and previewing .typ files — isn't a shape this app has. Everything travels source → comrak → HTML; there is no notion of a non-Markdown document, so that version wouldn't be a feature so much as a second application sharing the window.

Typst inside a Markdown document — a ```typst fence rendered to SVG, the way ```mermaid already is — does fit. So that's the version worth pricing, and everything below is about it.

First, a correction to the premise. Markpad doesn't run LaTeX. Math goes through KaTeX in the webview: no compile step, no toolchain, a formula costs a millisecond or two. Whatever is slow in your current LaTeX setup, it isn't what happens here. If the real complaint is the syntax — \frac{a}{b} against a/b — that's a fair complaint, but it's a different one, and saying which it is changes what a good answer looks like.

The wiring is the cheap half. renderRichContent already recognises a fenced block by class, renders it to SVG, puts the result through DOMPurify, carries sourcepos across so scroll sync survives the replacement, caches it so a keystroke doesn't redraw everything, and has its own export and print branches. Typst emits SVG, so it could follow that road.

The engine is the bill. Measured rather than estimated:

@myriaddreamin/[email protected], the wasm alone 27.0 MB raw, 10.2 MB gzipped
Markpad's entire frontend bundle today 5.8 MB gzipped

The frontend ships inside every platform's package, so that ~10 MB is paid on all of them (v2.7.4 assets):

Windows setup    7 MB  →  ~17 MB
deb / rpm        9 MB  →  ~19 MB
macOS dmg       17 MB  →  ~27 MB   (universal — two binary slices)

Installed, it's the uncompressed 27 MB sitting in the bundle.

Two things also close the cheaper routes:

  • CSP is script-src 'self' 'unsafe-inline' — no wasm-unsafe-eval, so the module doesn't start without a CSP change.
  • typst.ts's slim bundle keeps its size down by fetching fonts and wasm from a CDN, which default-src 'self' / connect-src 'self' refuse. It's the full embed or nothing.

Linking the typst crate into the Tauri backend instead avoids both, and trades them for a large Rust dependency tree, per-platform binary growth, and moving rendering across IPC on a path that currently re-renders roughly once per keystroke.

One more, if the actual wish is Typst math replacing $…$. That's the most expensive version. The TeX delimiters have a subsystem behind them in markdown.rs — find_math_spans, mask_math_spans, restore_math_spans and the rest — whose whole job is keeping $ from colliding with CommonMark's emphasis, inline code and escapes, with regression tests tied to #174, #177 and #197 ($100 and $200 is not a math span, \$ never opens one, dollars inside code don't either). A second math language either reuses those delimiters, which changes what existing documents mean, or needs its own set with the same problems solved again.

None of this is an argument about Typst, which is a fine tool. It's that in this app the renderer has to live in the webview and travel inside every package, so the cost is fixed regardless of how many users ever open a Typst block. That's a property of how Markpad renders today rather than of the request — a different rendering path would produce a different number. Whether the trade is worth making is the maintainer's call; the above is just what it currently costs.

PathGao avatar Aug 21 '26 10:08 PathGao