Unmarkdown
Markdown

KaTeX Math in Markdown: How to Write Beautiful Equations

Updated Feb 25, 2026 · 13 min read

KaTeX math in markdown lets you write beautiful equations using a LaTeX-based syntax that renders directly alongside your text. Instead of creating equations in a separate tool and pasting screenshots into your document, you type the math inline: $E = mc^2$ becomes a properly rendered equation. For display equations that stand alone on their own line, you wrap them in double dollar signs: $$\int_0^\infty e^{-x} dx = 1$$. KaTeX (pronounced "KA-tech") is the rendering engine that makes this work, and it has become the standard for math in markdown across platforms like Notion, Obsidian, and Unmarkdown™.

If you write academic papers, technical documentation, educational content, or data science notebooks, understanding how to use KaTeX math in markdown eliminates one of the last major gaps in the plain text writing workflow. This guide covers everything from basic syntax to advanced expressions, platform compatibility, and the practical challenges of publishing math content.

What is KaTeX and how it works with markdown

KaTeX is an open-source JavaScript library that renders LaTeX math notation in web browsers. It was created by Khan Academy (the "KA" in KaTeX) as a fast alternative to MathJax. The library takes a LaTeX expression as input and produces HTML and CSS output that looks identical to typeset mathematics.

In a markdown context, KaTeX integrates through two processing steps:

  1. A markdown parser (like remark-math) identifies math delimiters ($...$ for inline, $$...$$ for display) and marks them as math nodes
  2. A rendering plugin (like rehype-katex) takes those math nodes and converts them to KaTeX HTML output

The result: you write LaTeX in your markdown source, and readers see beautifully rendered equations. Understanding what markdown is and why every AI tool uses it helps contextualize why this matters. Markdown handles text formatting, and KaTeX extends it to handle mathematical notation with the same plain-text-in, formatted-output approach.

Key characteristics of KaTeX:

  • Synchronous rendering. Unlike MathJax, which renders asynchronously, KaTeX produces output in a single pass. This means no layout shifts or flash of unrendered content.
  • Zero dependencies. KaTeX is self-contained with no external library requirements.
  • Small bundle size. The core library is significantly smaller than MathJax, which matters for page load performance.
  • LaTeX-based syntax. If you know LaTeX math notation, you already know KaTeX. The syntax is the same.

Inline vs display math syntax in KaTeX markdown

KaTeX math in markdown uses two modes: inline and display. The distinction is important because it affects both the visual rendering and the semantic meaning.

Inline math with single dollar signs

Inline math appears within a line of text. Wrap the expression in single dollar signs:

The quadratic formula is $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$ where $a \neq 0$.

The equation renders at the same size as the surrounding text and flows naturally within the paragraph. Use inline math for:

  • Variable references ($x$, $n$, $\theta$)
  • Simple expressions ($a + b = c$)
  • Conditions and constraints ($n \geq 0$)
  • Units with proper formatting ($9.8 , \text{m/s}^2$)

Display math with double dollar signs

Display math appears centered on its own line, with larger formatting. Wrap the expression in double dollar signs:

The normal distribution probability density function:

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

Display math renders larger and centered, making complex expressions easier to read. Use display math for:

  • Important equations you want to highlight
  • Multi-line derivations
  • Expressions with tall elements (fractions, summations, integrals)
  • Any formula that is the focal point of a paragraph

Syntax rules to remember

  • There must be no space between the dollar sign and the expression: $x+1$ works, $ x+1 $ may not
  • Display math ($$...$$) should be on its own line with blank lines before and after
  • Backslashes are the escape character for LaTeX commands: \frac, \sqrt, \sum
  • Curly braces group elements: x^{10} gives $x^{10}$, while x^10 gives $x^1$ followed by a literal 0

Common KaTeX math expressions with copy-paste examples

Here is a reference of the most frequently used KaTeX expressions. Copy any of these directly into your markdown.

Fractions

$\frac{a}{b}$                    % Simple fraction
$\frac{x^2 + 1}{x - 1}$         % Polynomial fraction
$\cfrac{1}{1+\cfrac{1}{2}}$      % Continued fraction

Superscripts and subscripts

$x^2$                   % Superscript
$x_i$                   % Subscript
$x_i^2$                 % Both
$a_{n+1}$               % Subscript with group
$x^{2n+1}$              % Superscript with group

Square roots and nth roots

$\sqrt{x}$              % Square root
$\sqrt{x^2 + y^2}$      % Root of expression
$\sqrt[3]{8}$            % Cube root
$\sqrt[n]{x}$            % nth root

Summations and products

$$\sum_{i=1}^{n} x_i$$                    % Summation
$$\prod_{i=1}^{n} x_i$$                   % Product
$$\sum_{k=0}^{\infty} \frac{x^k}{k!}$$    % Infinite series (e^x)

Integrals

$$\int_0^1 x^2 \, dx$$                          % Definite integral
$$\int_{-\infty}^{\infty} e^{-x^2} \, dx$$      % Gaussian integral
$$\iint_D f(x,y) \, dx \, dy$$                   % Double integral
$$\oint_C \mathbf{F} \cdot d\mathbf{r}$$         % Line integral

Matrices

$$\begin{pmatrix} a & b \\ c & d \end{pmatrix}$$     % Round brackets

$$\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}$$  % Square brackets

$$\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc$$  % Determinant

Matrix environments:

  • pmatrix for round parentheses
  • bmatrix for square brackets
  • vmatrix for vertical bars (determinant)
  • Bmatrix for curly braces
  • matrix for no delimiters

Greek letters

$\alpha \beta \gamma \delta \epsilon$        % Lowercase
$\Alpha \Beta \Gamma \Delta \Epsilon$        % Uppercase
$\theta \lambda \mu \sigma \omega$           % Common in statistics
$\pi \approx 3.14159$                        % Pi
$\phi \varphi$                               % Phi variants
SymbolCodeSymbolCode
$\alpha$\alpha$\nu$\nu
$\beta$\beta$\xi$\xi
$\gamma$\gamma$\pi$\pi
$\delta$\delta$\rho$\rho
$\epsilon$\epsilon$\sigma$\sigma
$\zeta$\zeta$\tau$\tau
$\eta$\eta$\phi$\phi
$\theta$\theta$\chi$\chi
$\lambda$\lambda$\psi$\psi
$\mu$\mu$\omega$\omega

Comparison and logic operators

$x \leq y$              % Less than or equal
$x \geq y$              % Greater than or equal
$x \neq y$              % Not equal
$x \approx y$           % Approximately equal
$A \subset B$           % Subset
$x \in S$               % Element of
$\forall x$             % For all
$\exists x$             % There exists
$\neg p$                % Negation
$p \land q$             % Logical AND
$p \lor q$              % Logical OR
$p \implies q$          % Implies

Text within math

$x = 5 \text{ if } n > 0$
$$\text{Revenue} = \text{Price} \times \text{Quantity}$$
$$f(x) = \begin{cases} x^2 & \text{if } x \geq 0 \\ -x^2 & \text{if } x < 0 \end{cases}$$

The \text{} command switches to text mode within a math expression. This is essential for readable formulas that mix mathematical notation with English words.

KaTeX vs MathJax: which math renderer to use

KaTeX and MathJax are the two dominant math rendering engines for the web. They both render LaTeX syntax, but they make different tradeoffs.

FeatureKaTeXMathJax
Rendering speedSynchronous (fast)Asynchronous (slower)
Bundle size~300KB~1MB+
DependenciesZeroZero
LaTeX coverageMost common commandsBroader coverage
MathML outputNoYes (accessibility)
Dollar sign handlingCan conflict with currencyBetter conflict resolution
Used byNotion, Khan Academy, Unmarkdown™GitHub, Obsidian, Wikipedia
Server-side renderingYesYes (with Node.js)

When to choose KaTeX

KaTeX is the right choice when performance matters. Its synchronous rendering means equations appear instantly, with no layout shift. This makes it ideal for:

  • Web applications where users are editing live (the equation renders as you type)
  • Published pages where fast page load is critical
  • Documents with many equations (the cumulative performance difference adds up)
  • Environments where simplicity is valued (zero dependencies, single-pass rendering)

When to choose MathJax

MathJax handles a wider set of LaTeX commands and produces MathML output alongside HTML. Choose it when:

  • You need obscure LaTeX commands that KaTeX does not support
  • Accessibility is a strict requirement (MathML is screen-reader friendly)
  • You are working on a platform that already uses MathJax (GitHub, for instance)
  • You need to handle the dollar sign currency conflict gracefully (MathJax has more configuration options for delimiter handling)

For most markdown publishing use cases, KaTeX provides the better balance of speed, simplicity, and rendering quality. The LaTeX coverage gap has narrowed significantly in recent versions, and KaTeX now supports the vast majority of expressions that non-academic users need.

Where KaTeX math works: platform support table

Here is the current state of math rendering across major markdown platforms:

PlatformMath EngineInline SyntaxDisplay Syntax
GitHubMathJax$...$$$...$$
NotionKaTeXInline equation blockBlock equation
ObsidianMathJax$...$$$...$$
VS CodeKaTeX (extension)$...$$$...$$
Jupyter NotebooksMathJax$...$$$...$$
Unmarkdown™KaTeX$...$$$...$$
HugoKaTeX or MathJaxConfigurableConfigurable
TyporaMathJax$...$$$...$$
HackMD / CodiMDMathJax$...$$$...$$

Note that GitHub only added math support in May 2022, after the feature had been requested for more than 8 years. The fact that it was such a long-requested feature speaks to how essential math rendering is for technical documentation.

The dollar sign problem in KaTeX markdown

The single biggest practical challenge with KaTeX math in markdown is the dollar sign conflict. The $ character serves double duty: it is the delimiter for inline math and the universal symbol for US currency. This creates ambiguity.

Consider this sentence:

The product costs $50 and the premium version costs $100.

A naive math processor might try to parse $50 and the premium version costs $ as an inline math expression, producing garbled output. Different platforms handle this differently:

How platforms resolve the dollar sign conflict

GitHub (MathJax): Requires a non-space character immediately after the opening $ and before the closing $. So $50 is not parsed as math (space or end-of-word follows the number), but $x^2$ is.

Obsidian: Uses MathJax with similar heuristics. Currency amounts like $50 are generally handled correctly, but edge cases exist with expressions like $5 + $10.

Unmarkdown™: Uses a preprocessor (escapeCurrencyDollars()) that detects common currency patterns and escapes them before the math parser runs. Patterns like $50, $1,000, and $99.99 are recognized as currency and left as plain text.

Best practices for avoiding dollar sign conflicts

  1. Use \$ to escape currency amounts when in doubt: The product costs \$50
  2. Leave no space inside math delimiters: $x+1$ is math, $ 50 is less likely to be parsed as math
  3. Use display mode for important equations: $$...$$ on its own line is unambiguous
  4. Test your content in the target platform before publishing

Some tools use alternative delimiters to avoid the conflict entirely. LaTeX's \(...\) for inline and \[...\] for display are unambiguous but harder to type. Most markdown platforms have standardized on dollar signs despite the ambiguity, since the math use case is more common in contexts where math appears than the currency use case.

Publishing markdown with KaTeX math equations

Writing math in your local editor is the first step. Getting those equations into a published, shareable format is where many workflows break down. Math equations are particularly challenging to publish because:

  1. Not all platforms render math. Google Docs has no native LaTeX or KaTeX support. Word has its own equation editor that does not accept LaTeX input. Slack ignores math delimiters entirely. This is part of the broader AI formatting problem that affects all structured content.
  2. Copy-paste strips math formatting. If you copy a rendered equation from one tool and paste it into another, you often get either the raw LaTeX source or garbled characters.
  3. Image-based math is fragile. Exporting equations as images works but creates accessibility problems, scaling issues, and makes the content impossible to search or edit.

Math is not the only markdown extension that faces this challenge. Mermaid diagrams have the same portability problem: they render in some tools but not others. For a full reference of all markdown syntax including math, see the markdown cheat sheet.

Publishing math on the web

For web publishing, KaTeX is the clear winner. Unmarkdown™ renders KaTeX math on all published pages, both inline and display equations. The equations render client-side using KaTeX's JavaScript library and CSS, producing crisp output at any zoom level. Because the rendering happens in the browser, there is no need to pre-generate images or run a server-side math processor.

When you publish a document with math through Unmarkdown™, the equations automatically adapt to your chosen template. A dark template produces light-colored math. A serif template produces math that harmonizes with the surrounding typography.

For the best markdown publishing tools that handle math, KaTeX support is a key differentiator. Not every publishing tool can render math, and those that can vary in quality and coverage.

Math in professional documents

For documents destined for Google Docs or Word, the math publishing challenge is harder. These applications have their own equation editors (Google Docs uses a built-in editor; Word uses the Equation Editor) that do not accept LaTeX input. The practical options are:

  1. Publish as a web page and share the URL instead of a document file
  2. Export as PDF (which preserves the rendered math as vector graphics)
  3. Screenshot individual equations and paste them as images (not recommended for anything more than a quick share)

The web publishing path is increasingly the better choice for math-heavy content. A URL is easier to share than a Word file, the equations render perfectly, and the content remains searchable and editable.

Advanced KaTeX patterns for markdown

A few advanced patterns that come up frequently in technical and academic writing.

Aligned equations

$$\begin{aligned}
  (a + b)^2 &= (a + b)(a + b) \\
             &= a^2 + ab + ba + b^2 \\
             &= a^2 + 2ab + b^2
\end{aligned}$$

The & character marks the alignment point (typically at the = sign), and \\ creates a new line.

Piecewise functions

$$|x| = \begin{cases}
  x & \text{if } x \geq 0 \\
  -x & \text{if } x < 0
\end{cases}$$

Annotated expressions

$$\underbrace{a + b + \cdots + z}_{26 \text{ terms}}$$

$$\overbrace{1 + 2 + \cdots + n}^{\frac{n(n+1)}{2}}$$

Colored math

$$\textcolor{blue}{x^2} + \textcolor{red}{y^2} = \textcolor{green}{z^2}$$

Color support varies by platform. KaTeX supports named colors and hex codes. MathJax has similar support. Use color sparingly and always ensure the equation is readable without color (for accessibility and for contexts where color is not rendered).

Your markdown deserves a beautiful home.

Start publishing for free. Upgrade when you need more.

View pricing