Render math (LaTeX) and Mermaid diagrams in Markdown on a Mac

proof.mdmath + diagrams

Markdown by itself has no math and no diagrams. Tools bolt them on with LaTeX-style dollar signs and Mermaid code blocks, but most Mac viewers show those as raw text. This guide covers where they render and how MarkPeek shows both in the app, in exports and in Quick Look without a network connection.

MarkPeek in Split mode with the Serif theme in dark appearance, source on the left and the rendered page on the right

The syntax most tools agree on

Math is written with dollar signs: single ones for inline math, double ones for a display block. Diagrams are written as a fenced code block whose language is mermaid. If a tool supports these, the same file renders the same way elsewhere.

Inline: $E = mc^2$

$$
\int_0^1 x^2 \, dx = \tfrac{1}{3}
$$

```mermaid
graph LR
  A[Write] --> B[Preview]
```

Option 1: Push it to GitHub

GitHub renders both math and Mermaid in Markdown files on its website. That is handy for a README, but it means committing and pushing a file just to see how it looks, and the content has to live in a repository.

Option 2: A code editor with extensions

Editors such as VS Code render Markdown in a side preview, and extensions add Mermaid support. This works well for people already living in an editor, but each feature depends on the extension you chose and its version, and none of it helps Finder or Quick Look.

Option 3: pandoc and mermaid-cli

pandoc can convert Markdown math to HTML with MathJax or to PDF through LaTeX. Mermaid diagrams need the separate mermaid-cli tool, which runs a headless browser, to turn each diagram into an image first. It is flexible and scriptable, and heavy for reading one document.

Where it falls down: the setup is a pipeline, not a viewer. You see results only after running commands.

The MarkPeek way

MarkPeek renders math with MathJax 3.2.2 and diagrams with Mermaid 11.4.1, both bundled in the app. There is no CDN call, so it works offline. The engines load only for documents that use them.

  1. Write inline math between single dollar signs and display math between double dollar signs.
  2. Write a diagram as a fenced code block whose language is mermaid. The language name is not case sensitive.
  3. Open the file in MarkPeek in Preview, or in Split (⌘2) to edit the source beside the rendered page.
  4. Press Space on the file in Finder to see it in Quick Look, or choose File ▸ "Export as PDF…" (⇧⌘E) or "Export as HTML…" (⌥⌘E). Math and diagrams render in all of them.
Quick Look previewing a Markdown file with an inline formula, a rendered integral and a Mermaid flowchart

Rules for dollar signs

To keep prices from turning into math, MarkPeek applies a simple rule to inline math: the opening dollar sign must not be followed by whitespace, and the closing one must not be preceded by whitespace or followed by a word character. So "costs $5 or $10" is left alone, while $x + y$ is rendered. Dollar signs inside code spans and fenced code blocks are skipped.

Mermaid runs in its strict security mode, and its colors follow the light or dark scheme of the document.

Writing math and diagrams that stay readable

Keep display math on its own lines between the double dollar signs, and leave a blank line before and after it. For diagrams, start small: a short left-to-right graph reads better in a preview than a sprawling one. If a diagram does not appear, check the fence first: it must open with three backticks and the word mermaid, and close with three backticks on their own line. Dollar signs in prose, such as prices, are safe as long as there is no stray pair that looks like a formula.

Because Split view (⌘2) shows the source beside the rendered page, it is the easiest place to fix a formula: change a symbol, look right, and adjust. Quick Look is best for checking the finished file in Finder, and the app is best for the iteration in between.

Settings and limits

Frequently asked questions

Does MarkPeek need an internet connection for math and diagrams?

No. MathJax and Mermaid are bundled in the app. Only remote images referenced by URL come from the web.

Which math syntax does it use?

TeX-style math between dollar signs, rendered by MathJax. Single dollar signs make inline math, double dollar signs make a display block.

Does Quick Look show Mermaid diagrams?

Yes, rendered offscreen when the preview opens. If rendering times out, the preview falls back to the source.

Do math and Mermaid appear in exported files?

Yes. PDF export renders them, and the exported HTML file includes MathJax or Mermaid when the document uses them.

Related guides