← Back to blog

How to Render LaTeX and Mermaid Diagrams in Markdown Files (2026 Guide)

A practical guide to rendering LaTeX equations and Mermaid diagrams inside markdown — what each format supports, which tools render them well, and how to read them without copy-pasting into a web previewer.


Markdown is plain text. LaTeX equations and Mermaid diagrams are not. When the two meet — and they meet constantly in AI-generated docs, ML papers, system design notes, and engineering specs — the file on disk looks like this:

The expected loss is $\mathcal{L} = \mathbb{E}_{x \sim p}[-\log p(x)]$.

```mermaid
flowchart LR
    A[Input] --> B[Encoder]
    B --> C[Latent]
    C --> D[Decoder]

If your viewer doesn't know what to do with `$\mathcal{L}$` or `mermaid`, you read the syntax. If it does, you read the math and the diagram. The difference is enormous, and it's the single most common reason AI-generated technical docs feel painful to consume.

This guide covers how rendering actually works under the hood, which tools handle it well in 2026, and the practical setup for reading these files daily without copy-pasting into a web previewer.

## How LaTeX rendering in markdown works

Markdown itself has no math syntax. The `$...$` and `$$...$$` conventions are extensions, popularized by Pandoc and adopted by GitHub, Jupyter, and most modern viewers. Two libraries do the heavy lifting:

- **MathJax** — older, browser-based, supports more LaTeX commands, slower
- **KaTeX** — newer, designed for speed, covers ~95% of common math, much faster

For most documents you'll see in 2026 — research notes, technical explanations, equations in design docs — KaTeX is more than enough. It renders inline math (`$E = mc^2$`) and display math (`$$\sum_{i=1}^n x_i$$`) cleanly, supports the full LaTeX symbol set you actually use day-to-day, and renders fast enough that you don't notice it happening.

When a viewer "supports LaTeX," it usually means it ships KaTeX (or MathJax) and runs it on the rendered HTML. There's nothing more to configure — you open the file, the math renders.

What can go wrong:
- **Dollar signs in code blocks** — naive viewers try to render `$variable` inside a bash snippet as math. Good viewers know to skip code fences.
- **Escape edge cases** — some Markdown parsers eat backslashes before they reach the math renderer. `\\` becomes `\`, breaking `\\sum`. Look for KaTeX-aware parsers like `comrak`, `markdown-it`, or `remark-math`.
- **Display vs inline confusion** — a single `$` should be inline; double `$$` should be display. Some viewers misparse this when the math spans multiple lines.

For most readers, you don't need to know any of this — the right viewer just handles it. But if you ever wondered why one tool renders an equation correctly and another doesn't, this is usually why.

## How Mermaid rendering in markdown works

Mermaid is a JavaScript library that turns text descriptions into SVG diagrams. The format is simple — code fences with the language tag `mermaid`:

```markdown
```mermaid
flowchart TD
    Start --> Decision{Cache hit?}
    Decision -->|Yes| Return[Return cached]
    Decision -->|No| Fetch[Fetch from DB]
    Fetch --> Cache[Store in cache]
    Cache --> Return

```

A viewer that supports Mermaid runs this code through mermaid.js and replaces the code block with the rendered SVG. Diagram types include flowcharts, sequence diagrams, class diagrams, ER diagrams, Gantt charts, state diagrams, and pie charts.

What can go wrong: - Diagram doesn’t render at all — the viewer doesn’t have Mermaid integration, just shows the source - Diagram renders but is too wide — common for ER diagrams with many entities; the SVG overflows the column width - Diagram renders too small — sequence diagrams especially can render at a size that’s technically correct but unreadable - Theme mismatch — Mermaid renders with light defaults even when the surrounding doc is in dark mode

The first issue is binary — either the tool supports it or it doesn’t. The other three are quality-of-implementation problems that vary widely between viewers.

What “good” rendering looks like in 2026

If you’re reading AI-generated technical content regularly, here’s the bar to look for:

For LaTeX: - Inline and display math both render - Code fences are correctly skipped (no false-positive math rendering inside bash blocks) - Common commands (\sum, \int, \mathbb, \frac, \begin{cases}) all work - Renders fast enough that you don’t see flicker on doc load

For Mermaid: - Diagrams render as SVGs, not as raw code - Wide diagrams have a fullscreen mode with zoom and pan — scroll-wheel to zoom toward the cursor, click-drag to pan, 0 or button to reset view - Theme-aware: dark mode renders the diagram in a matching dark theme, not bright white - All diagram types supported, not just flowcharts

That last point on Mermaid matters more than people expect. A flowchart that’s 800px wide looks fine in a viewer’s content column. An ER diagram with 20 tables is 2,400px wide and unreadable unless you can fullscreen it. If your daily reading involves system design docs, fullscreen + zoom + pan isn’t a nice-to-have — it’s the difference between using the diagrams and ignoring them.

Tools that render both well

Here’s the honest scorecard for tools that handle both LaTeX and Mermaid in markdown files on macOS:

Tool LaTeX Mermaid Native? Notes
VS Code + extensions Via plugin Via plugin No (Electron) Requires installing both extensions; preview is a side panel
Obsidian Built-in Via plugin No (Electron) Vault required; community Mermaid plugin needed
Typora Built-in Built-in No (Electron) Editor-first, not optimized for browsing
Marked 2 Via processor Via processor Yes Requires MultiMarkdown/preprocessor setup
Jupyter Lab Built-in Via plugin No Heavyweight if you’re not already using notebooks
GitHub web Built-in Built-in No Requires pushing to GitHub first
Meva Built-in (KaTeX) Built-in (Mermaid.js + fullscreen) Yes Both work out of the box, no plugins

The pattern: most tools require setup, plugins, or are the wrong shape for “just open a file and read.” A small number — Meva, Typora, Obsidian (with plugins), GitHub — handle it cleanly out of the box. Of those, Meva is the only one that’s both native and reading-focused.

I’m biased here (I built Meva specifically because the existing options either required configuration or were the wrong shape), so the more important takeaway is: pick whichever of those four fits your workflow. Don’t settle for raw mermaid source in a code block.

Practical setup: reading without configuration

If you want the lowest-friction path:

  1. Install a viewer that handles both formats natively — Meva, Typora, or set up Obsidian with the Mermaid community plugin
  2. Set it as your default .md openeropen -a [App] yourfile.md or right-click → Open With
  3. Open the folder, not the file — point the viewer at your AI-output directory so you can browse rather than open one at a time
  4. Use the keyboard — heading navigation (Cmd+]/Cmd+[), find-in-doc (Cmd+F), tab switching (Cmd+1-9)

For Meva specifically, the setup is zero — it ships with KaTeX and Mermaid built in, the fullscreen diagram viewer (zoom, pan, reset) works on every diagram type, and the Mermaid renderer is theme-aware so dark mode actually looks right.

The fullscreen Mermaid case

One specific feature is worth flagging because it changes the experience disproportionately: a fullscreen viewer for Mermaid diagrams.

When you read a long technical doc, the diagrams are often the densest information. A sequence diagram showing a 12-step authentication flow contains more useful detail per pixel than the surrounding paragraphs. Compressing it into the document’s content column wastes that information.

A fullscreen viewer that: - Auto-fits the diagram to the viewport on open - Lets you scroll-wheel zoom (with the zoom anchored to the cursor position, not the center) - Supports click-and-drag to pan - Stays crisp at any zoom level (vector graphics, no pixelation) - Resets to fit-view with 0 or a button

…turns “I sort of looked at the diagram” into “I actually understood the flow.” Meva ships this for every Mermaid diagram type, including the wide ER diagrams and tall sequence diagrams that are otherwise the worst to read.

When you don’t need any of this

A note on scope: if you only encounter LaTeX or Mermaid in markdown occasionally, you don’t need a dedicated viewer. GitHub renders both. Hosted Jupyter handles both. Even Typora’s free trial will read both for an evening.

The case for a dedicated viewer is frequency. If you’re reading 5–50 markdown files a week with math or diagrams in them — which is increasingly normal for anyone using Claude, ChatGPT, Cursor, or Copilot for technical work — the per-file friction adds up. The ROI on a tool that handles it natively shows up within a week.

Get a viewer that handles both

If you want LaTeX and Mermaid to render reliably without plugins or setup, download Meva for free. Both are built in, the Mermaid fullscreen viewer (zoom, pan, reset) works on every diagram type, and there’s no configuration step. Free version covers all rendering features; Pro ($14.99 one-time) adds unlimited tabs, all 12 themes, and PDF/HTML export.

Download Meva for Free →

For more on reading AI-generated content, see How to Read AI Notes Faster with Meva and Reading Claude Code Output Without Losing Your Mind.

Questions about specific LaTeX commands or Mermaid diagram types? Email hello@usemeva.com — I’ll add coverage to the post.


Try Meva Free

Turn your AI-generated markdown into beautifully rendered, searchable documents.

Download for Free
← All posts