← Back to Guides
History & ConceptsKaTeX Math Equations in Markdown
Published on 2026-02-22

KaTeX Math Equations in Markdown

How to write and beautifully render LaTeX mathematics equations cleanly inside standard Markdown.

Writing mathematical and scientific equations digitally has long been a painful process. While Microsoft Word has tools, nothing beats the typographical beauty and efficiency of LaTeX.

MarkdownToPrettyPDF integrates KaTeX—a fast math typesetting library built by Khan Academy—to render LaTeX equations directly into your Markdown flow.

1. Inline Equations

To render an equation inline with your text, wrap the LaTeX expression in single dollar signs: $.

For example, asking the parser to render Let $x = y^2 + 5$ will seamlessly render $x = y^2 + 5$ without breaking the line. It is perfect for injecting variables or small formulas into a paragraph.

2. Block (Display) Equations

For larger, standalone equations, wrap the LaTeX expression in a math fenced code block. This will center the equation on its own line and give it more vertical space.

syntax
E = mc^2
$$E = mc^2$$

Supported LaTeX Commands

KaTeX supports a massive subset of standard LaTeX commands. Here are a few essential examples for academic writing:

Fractions and Integrals

syntax
\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
$$\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}$$

Matrices

syntax
\begin{pmatrix}
1 & 2 & 3 \\
a & b & c
\end{pmatrix}
$$\begin{pmatrix} 1 & 2 & 3 \\ a & b & c \end{pmatrix}$$

Limits and Summations

syntax
\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
$$\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$$
syntax
\lim_{x \to \infty} \exp(-x) = 0
$$\lim_{x \to \infty} \exp(-x) = 0$$

Why KaTeX over MathJax?

While MathJax has historically been the standard for web mathematics, KaTeX is utilized here because of its raw speed. Because MarkdownToPrettyPDF renders a live preview of your document as you type, waiting for complex equations to render creates a jarring experience. KaTeX compiles the DOM synchronously and incredibly quickly, ensuring your math updates in real-time alongside your text.