9 min left

Render LaTeX in Markdown: KaTeX Math Equations Guide (2026)

How to render LaTeX in markdown with KaTeX — every inline and block syntax for markdown math equations, plus which markdown viewer renders math best.

tutorial · katex
In this guide

Render LaTeX in Markdown: KaTeX Math Equations Guide (2026)

On this page · 32 sections

You write a physics formula in your markdown file. You use the standard $...$ syntax — the same one LaTeX has used for decades. You open the file in a viewer and see… the raw LaTeX code staring back at you. Dollar signs, backslashes, curly braces. Not a rendered equation in sight.

This is the most common frustration with math in markdown. The syntax exists. The convention is well-established. But most viewers simply don’t render it.

This guide covers everything you need to render LaTeX in markdown using KaTeX — the inline syntax, the block syntax, a cheat sheet of common symbols, and which markdown viewers actually render the result. Bookmark this page. You’ll come back to it.

The problem: markdown math equations are invisible in most viewers

Markdown was designed for prose. Math support was never part of the original spec, so it was bolted on later through convention: wrap LaTeX in single dollar signs for inline math, double dollar signs for display blocks. GitHub adopted this syntax. Jupyter notebooks use it. Obsidian uses it. It’s the de facto standard.

But “de facto standard” doesn’t mean “universally supported.” Here’s what happens when you write $E = mc^2$ in your markdown:

The gap between “writing math in markdown” and “seeing math in markdown” is wider than it should be. KaTeX closes that gap.

What KaTeX is (and why it matters)

KaTeX is a JavaScript library that renders LaTeX math notation into clean, typeset equations. It was built by Khan Academy and is now one of the two main math rendering engines on the web — the other being MathJax.

KaTeX vs MathJax

KaTeX renders significantly faster than MathJax — often 2-3x faster on complex pages. It produces server-renderable HTML and CSS with no JavaScript needed after the initial render. MathJax supports more LaTeX commands and has better accessibility features, but for markdown viewers where speed matters, KaTeX is the better fit. MDHero uses KaTeX.

What makes KaTeX relevant to you as a markdown user:

MDHero ships with KaTeX built in. You write the LaTeX, you open the file, the math is rendered. No setup, no settings, no plugin manager — KaTeX markdown rendering happens automatically the moment a file with $...$ or $$...$$ opens.

Inline math syntax: $...$

Inline math sits within a line of text. Use single dollar signs to wrap the LaTeX expression.

What you type:

The energy equation $E = mc^2$ changed physics forever.

What you see:

The energy equation E = mc² changed physics forever — with the formula rendered in proper mathematical typesetting, right inline with the surrounding text.

Here are the inline expressions you’ll use most often:

Fractions

The probability is $\frac{1}{n}$ for each outcome.

Renders a proper stacked fraction with 1 over n.

Exponents and subscripts

Water is $H_2O$ and the quadratic term is $x^{2}$.

Use _ for subscripts and ^ for superscripts. Wrap multi-character exponents in braces: $x^{10}$, not $x^10$ (the second only raises the 1).

Square roots

The standard deviation is $\sqrt{\sigma^2}$.

Use \sqrt{} for square roots. For nth roots: $\sqrt[3]{x}$.

Greek letters

The angle $\theta$ is measured in radians, and $\pi \approx 3.14159$.

Just use the backslash followed by the letter name: \alpha, \beta, \gamma, \delta, \theta, \pi, \sigma, \omega.

Quick rule for inline math

If the expression fits naturally in the middle of a sentence, use inline $...$. If it deserves its own line — because it’s large, important, or multi-step — use display mode $$...$$.

Block math syntax: $$...$$

Display-mode math gets its own line, centered, with more vertical space. Wrap the expression in double dollar signs, each on their own line.

Quadratic formula

$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$

This renders the full quadratic formula — centered, large, with the square root spanning the discriminant and the entire numerator over 2a.

Summation

$$
\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
$$

The sigma symbol with limits above and below, equaling the closed-form expression.

Integral

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

The Gaussian integral — one of the most famous results in mathematics — rendered with proper integral sign, limits, and the exponential.

Matrix

$$
A = \begin{pmatrix}
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33}
\end{pmatrix}
$$

Renders a 3x3 matrix with parentheses. Use bmatrix for square brackets, vmatrix for vertical bars (determinant notation), or Bmatrix for curly braces.

Aligned equations

$$
\begin{aligned}
f(x) &= x^2 + 2x + 1 \\
      &= (x + 1)^2
\end{aligned}
$$

The & character marks the alignment point (usually the equals sign), and \\ breaks the line. This is how you show step-by-step derivations.

Common symbols cheat sheet

This is the table you’ll keep coming back to. Every symbol uses standard KaTeX/LaTeX syntax.

Greek letters

SymbolLaTeXSymbolLaTeX
α\alphaν\nu
β\betaξ\xi
γ\gammaπ\pi
δ\deltaρ\rho
ε\epsilonσ\sigma
θ\thetaτ\tau
λ\lambdaφ\phi
μ\muω\omega

Capitalize the first letter for uppercase: \Gamma (Γ), \Delta (Δ), \Theta (Θ), \Sigma (Σ), \Omega (Ω).

Operators

SymbolLaTeXDescription
\sumSummation
\prodProduct
\intIntegral
\partialPartial derivative
\nablaGradient / del
±\pmPlus-minus
×\timesMultiplication
÷\divDivision
·\cdotDot product

Relations

SymbolLaTeXDescription
\leqLess than or equal
\geqGreater than or equal
\neqNot equal
\approxApproximately
\proptoProportional to
\inElement of
\subsetSubset
\cupUnion
\capIntersection
\inftyInfinity

Arrows

SymbolLaTeXSymbolLaTeX
\rightarrow\leftarrow
\Rightarrow\Leftarrow
\leftrightarrow\Leftrightarrow
\mapsto\uparrow

Real-world examples

Abstract syntax is hard to remember. Here are equations you’ve actually seen before, shown as the raw LaTeX you’d type and what the rendered output looks like.

Physics: Einstein’s mass-energy equivalence

You type:

$$
E^2 = (pc)^2 + (m_0 c^2)^2
$$

You see: The full relativistic energy-momentum relation, with the rest mass term and momentum term under a square — the generalized form most people never see beyond the simplified E = mc².

Statistics: Normal distribution

You type:

$$
f(x) = \frac{1}{\sigma\sqrt{2\pi}} \, e^{-\frac{(x - \mu)^2}{2\sigma^2}}
$$

You see: The bell curve formula — the probability density function of a normal distribution, with the mean μ and standard deviation σ controlling shape and position.

Computer science: Big-O with recurrence

You type:

$$
T(n) = 2T\left(\frac{n}{2}\right) + O(n)
$$

You see: The merge sort recurrence relation, rendered with the proper fraction and Big-O notation. This solves to O(n log n) by the Master Theorem.

Linear algebra: Eigenvalue equation

You type:

$$
A\mathbf{v} = \lambda\mathbf{v}
$$

You see: The eigenvalue equation, with the matrix A, eigenvector v in bold, and eigenvalue lambda — the foundation of PCA, spectral clustering, and half of machine learning.

Which markdown viewer renders math equations (KaTeX support compared)

Not all viewers are equal when it comes to math rendering. Here’s where things stand in 2026:

ViewerMath supportSetup required
MDHeroKaTeX built-inNone — works out of the box
TyporaMathJax built-inNone — toggle in preferences
ObsidianMathJax built-inNone — enabled by default
VS CodeKaTeX via extensionInstall “Markdown Math” extension
Marked 2MathJax built-inEnable in preferences
GitHub.comKaTeX server-sideNone — only works on github.com
Quick Look (Mac)NoneNo math support
MarkViewLimitedBasic support only

The key distinction: built-in vs extension. If you write math regularly, you want a markdown viewer with math equations support that just works. Hunting for the right extension, checking compatibility, and troubleshooting rendering bugs isn’t a productive use of your time. For a broader comparison of markdown viewers — including which ones handle math, diagrams, and code best — see our 2026 roundup. MDHero ships with KaTeX built in on both Mac and Windows — no plugin install, no extension hunt.

GitHub's limitation

GitHub renders math beautifully — but only in the browser on github.com. If you clone a repo and open the README locally, the math is raw LaTeX again. A local viewer with KaTeX support solves this completely.

Tips for writing math in markdown

A few things that will save you from debugging LaTeX rendering issues.

1. Put blank lines around $$ blocks

Some text above.

$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$

Some text below.

Without blank lines, some parsers treat the $$ as part of the surrounding paragraph and fail to enter display mode. Always add breathing room.

2. Escape special characters

The dollar sign $ is the math delimiter. If you need a literal dollar sign in your text, escape it: \$50. Same for other special LaTeX characters inside math mode — \%, \&, \#.

3. Use \text{} for words inside equations

$$
\text{distance} = \text{speed} \times \text{time}
$$

Without \text{}, LaTeX treats each letter as a separate variable and italicizes them with mathematical spacing. “distance” becomes d i s t a n c e — not what you want.

4. Use \left and \right for auto-sizing brackets

$$
\left( \frac{a}{b} \right)^2
$$

Standard parentheses () don’t scale with the content inside them. \left( and \right) automatically match the height of whatever they contain — fractions, matrices, tall expressions.

5. Use \displaystyle in inline math when needed

Sometimes you want a fraction or sum in inline mode to render at full size instead of being compressed:

The sum $\displaystyle\sum_{i=1}^{n} i^2$ is large.

This forces display-style rendering inside an inline expression. Use sparingly — it disrupts line spacing.

Watch your dollar signs

A common gotcha: if your markdown mentions prices (“costs $100”) next to other dollar-sign content, some parsers may try to start a math expression at the first $ and look for the closing one. Escape literal dollar signs with \$ to avoid accidental math mode.

6. Test with a real renderer

Writing math in a plain text editor and hoping it renders correctly is a recipe for frustration. Open your file in a viewer that supports KaTeX while you write — catch syntax errors as they happen, not after you push to GitHub.

Wrapping up

LaTeX math in markdown is a solved problem — the syntax is standardized, KaTeX is fast and accurate, and there are viewers that render it without any configuration. The friction isn’t in the writing. It’s in the viewing.

If you write equations in your markdown files — whether it’s homework, research notes, documentation, or algorithm analysis — pick a markdown viewer with math equations support that renders natively. Your files already have the right syntax. Your viewer just needs to understand it.

VK

Vaibhav Kakde

Building MDHero. Developer and open-source enthusiast.