← All posts

How to Add Formulas in Markdown (KaTeX and MathML)

Technical notes, homework and AI drafts often need real math — not screenshots of equations. In MD Workbox you write formulas as TeX-style Markdown, preview them with MathML or KaTeX, then export without uploading the document.

The short version

  1. Open the Editor.
  2. Use $...$ for inline math and $$...$$ for display math (or the toolbar $ / $$ buttons).
  3. Choose MathML or KaTeX in the math options.
  4. Export from the Editor or a convert tool when the preview looks right.

Everything in that path runs in your browser.

Delimiters you can use

MD Workbox accepts the common TeX math delimiters:

Kind Dollars Brackets
Inline $E = mc^2$ \(E = mc^2\)
Display $$...$$ on their own lines \[...\]

Example:

Inline $E = mc^2$ and a display integral:

$$
\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}
$$

Tips that save time:

  • Put display math on its own lines — a blank line before and after $$ keeps parsing reliable.
  • Escape literal dollar signs in prose when needed (currency) so they are not treated as math.
  • Keep complex LaTeX inside the delimiters; the preview uses KaTeX under the hood for both MathML and HTML output modes.

MathML vs KaTeX

In the Editor and convert tools you can pick:

  • MathML — native browser math markup. Good for accessibility and embedding where you prefer semantic math over CSS.
  • KaTeX — HTML + CSS rendering for a consistent look across browsers. Full HTML documents can include a KaTeX stylesheet link.
  • Off — skip formula rendering when you only need plain Markdown structure.

If you are unsure, start with KaTeX for previews and screenshots; switch to MathML when you care about native math in HTML.

Insert from the toolbar

In the Editor toolbar:

  • $ wraps the selection as inline math (or inserts a sample).
  • $$ inserts a display math block.

Paste AI-generated Markdown with formulas as-is, then skim the live preview. If spacing looks noisy after a chat copy, run Clean Markdown first — cleanup preserves content inside code fences and is safe for most math blocks.

Export formulas to other formats

Same source, different outputs:

Goal Tool
HTML (fragment or full page) Markdown to HTML
PDF Markdown to PDF
Word DOCX (equation zones) Markdown to DOCX
PNG / JPEG / WebP Markdown to Image

Fidelity varies by format: HTML and image capture follow the live MathML/KaTeX preview closely; DOCX maps TeX delimiters into Word equation (OMML) zones — very complex LaTeX may still need a touch-up in Word’s equation editor.

Checklist before you ship

  1. Preview every display equation once at the width you will export.
  2. Confirm math mode (MathML / KaTeX / off) matches the destination.
  3. Prefer local export for drafts that should stay on your machine — see Privacy.

Write the formula once in Markdown; reuse it across preview, HTML, PDF, DOCX and images.