— Writing & Creativity

Free KaTeX Equation Previewer

Type or paste LaTeX maths to see it typeset, copy the HTML or MathML, and find out exactly why an equation won’t render.

— Samples
Valid
Live

What is a KaTeX Equation Previewer?

KaTeX is the maths typesetting library Khan Academy released in 2014 to draw LaTeX equations on the web quickly. Notion and Visual Studio Code’s Markdown preview use it. This previewer typesets LaTeX as you type and gives you the HTML or MathML to paste elsewhere.

It runs KaTeX in your browser, removes $$, $, \[ and \( delimiters pasted from documents, and turns KaTeX’s parse errors into plain explanations with the character where typesetting stopped. A check view lists the commands and environments an equation uses, with strict-mode warnings about things real LaTeX would treat differently.

Key Features

Live Typesetting

Display and inline maths, drawn by KaTeX with its own fonts as you type.

HTML and MathML

Copy KaTeX’s HTML for a web page, or MathML alone for email, EPUB and documents.

Clear Errors

Missing braces, unknown commands and mismatched environments, with the character where KaTeX stopped.

Delimiters Removed

Paste $$…$$, $…$, \[…\] or \(…\) straight from a paper or a Markdown file.

Strict-Mode Warnings

Notes on comments, accented letters and line breaks that LaTeX would handle differently.

Perfect for everyone

  • Students
  • Teachers
  • Researchers
  • Technical writers and developers putting maths on the web

How to Use the KaTeX Equation Previewer

Type an equation or paste one from a paper, a Markdown note or a chat message. Every view comes from the same KaTeX run, so a fix you make shows up everywhere at once.

1

Type the Maths

Write LaTeX maths. Delimiters around it are removed for you.

2

Choose Display or Inline

Display centres the equation on its own line; inline sets it at text size.

3

Copy the Output

HTML needs KaTeX’s CSS on the page; MathML works without it.

4

Check for Problems

Fix any error shown, and read the check view for warnings.

Worked Examples

Equations Through KaTeX

Each row is maths as people paste it, from textbooks, lecture notes and Stack Exchange answers. Each answer is this tool’s output in the mode on the chip: the check view, MathML, or the error KaTeX reports for an equation it can’t typeset.

REF_001The quadratic formula, pasted with delimiters

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

REF_002Aligned equations with cases

“\begin{aligned} f(x) &= \begin{cases} x^2 & \text{if } x \ge 0 \\ -x & \text{otherwise} \end{cases} \\ \int_0^1 f(x)\,dx &= \tfrac{1}{3} \end{aligned}”

REF_003The Basel sum as MathML

“\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}”

REF_004A missing closing brace

“\frac{a}{b”

REF_005Two superscripts on one base

“x^2^3”

REF_006align in inline maths

“\begin{align} a &= b \\ c &= d \end{align}”

REF_007A siunitx command

“\SI{9.81}{\metre\per\second\squared}”

REF_008Accented text in maths mode

“\text{naïve} + é”

REF_009A comment with no newline

“x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} % Newton step”

REF_010A matrix as MathML

“\begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}”

Command Reference

LaTeX Maths Commands KaTeX Supports

KaTeX covers the maths most people write, from fractions and roots to matrices and aligned equations. These ten commands appear in almost every document, and each card shows the LaTeX to type for it.

01 / FRACTIONS

Fractions

\frac{a}{b} for a stacked fraction, \tfrac for a small one and \dfrac for a full-size one inline.

“How do you write a half?”

02 / POWERS

Powers and Indices

^ raises and _ lowers. Wrap anything longer than one character in braces.

“How do you write x to the 10?”

03 / ROOTS

Roots

\sqrt{x} for a square root and \sqrt[n]{x} for any other root.

“How do you write a cube root?”

04 / SUMS

Sums and Integrals

\sum, \prod and \int take limits with _ and ^, placed above and below in display mode.

“How do you write a sum from 1 to n?”

05 / GREEK

Greek Letters

\alpha to \omega, with capitals such as \Gamma and \Omega.

“How do you write pi?”

06 / BRACKETS

Brackets That Grow

\left( and \right) size brackets to fit what’s between them.

“What must every \left have?”

07 / TEXT

Text in Maths

\text{…} sets words in the body font with normal spacing.

“How do you write the word if?”

08 / FONTS

Fonts

\mathbb for blackboard bold, \mathcal for script and \mathbf for bold.

“How do you write the real numbers?”

09 / MATRICES

Matrices

pmatrix, bmatrix and vmatrix environments, with & between columns and \\ between rows.

“Which gives square brackets?”

10 / ALIGNED

Aligned Equations

aligned lines up equations at each &, and works inline as well as in display mode.

“Where do the equations line up?”

Which Output to Use

The same equation can leave this tool in five forms. Which one you need depends on where the maths is going and whether that place can load KaTeX’s stylesheet and fonts, since HTML output depends on them to look right.

Display

Centred on its own line at a larger size, like LaTeX’s \[…\] or an equation environment.

Inline

Set to sit inside a sentence, with limits beside sums and smaller fractions, like \(…\).

HTML

KaTeX’s spans plus a hidden MathML copy for screen readers. The page needs KaTeX’s CSS and fonts.

MathML

Standard maths markup that Firefox, Safari and Chrome 109 or later draw without any stylesheet.

Check

The commands and environments used, the delimiters removed and any strict-mode warnings.

Reading KaTeX Errors

KaTeX stops at the first thing it can’t parse and reports the character where it gave up. These are the errors people hit most often, what usually causes each one, and the quickest way to fix it before you paste the equation anywhere.

Tip 01

Missing Closing Brace

Usually a { opened in \frac or a subscript and never closed. Count the braces from the reported character backwards.

Tip 02

Unknown Command

A typo, or a command from a LaTeX package KaTeX doesn’t include, such as siunitx’s \SI or mhchem’s \ce.

Tip 03

Double Superscript

x^2^3 is ambiguous. Write x^{2^3} for a tower or {x^2}^3 for a power of a power.

Tip 04

Display-Only Environments

align, gather and equation need display mode. Inline, use aligned or gathered instead.

Tip 05

Mismatched Environments

A \begin closed by a different \end, often after copying half of a matrix.

Tip 06

Missing Arguments

\frac, \sqrt and \text need their argument in braces straight after the command.

Tip 07

Extra Closing Brace

A } with no matching {, often left over after deleting part of an equation.

Environments KaTeX Supports

Environments are the \begin…\end blocks that arrange several pieces of maths at once. KaTeX supports the common ones from LaTeX’s amsmath package, but some only work in display mode, and a few familiar ones are missing entirely.

Matrices

matrix, pmatrix, bmatrix, Bmatrix, vmatrix and Vmatrix, plus smallmatrix for inline use.

Cases

cases for piecewise functions, with rcases putting the brace on the right.

Alignment

aligned, alignedat and gathered work anywhere; align, alignat and gather need display mode.

Equation

equation and equation* work in display mode, though KaTeX doesn’t number them unless asked.

Arrays

array takes a column spec such as {c|c} for tables of values and augmented matrices.

Commutative Diagrams

CD draws arrows between objects, as in amscd. multline isn’t supported.

Maths Pitfalls on the Web

Equations that look fine in a LaTeX editor can still break or mislead once they reach a web page, a Markdown processor or a reader using a screen reader, which is why it pays to check them in the form your readers will actually get.

Tip 01

Markdown Eats Underscores

Some Markdown processors read _ as italics before maths is parsed. Use a maths-aware plugin.

Tip 02

Dollar Signs in Prose

Prices like $5 and $10 can be read as inline maths. Escape them or use \(…\).

Tip 03

Missing Stylesheet

KaTeX’s HTML looks broken without its CSS. MathML doesn’t need it.

Tip 04

Package Commands

Commands from siunitx, physics or tikz won’t work. Rewrite them with core commands.

Tip 05

Words in Maths

Typing words directly sets each letter as an italic variable. Wrap them in \text.

Tip 06

Images of Equations

Pictures of maths can’t be read aloud, searched or zoomed. Prefer HTML or MathML.

KaTeX or MathJax?

MathJax is the other major library for maths on the web, and the choice between them comes up on every docs site and blog that shows equations. They read the same LaTeX for everyday maths, but they differ in speed, coverage and how they draw the output.

Speed

KaTeX typesets synchronously in one pass, so equations appear with the page instead of shifting it after load.

Coverage

MathJax supports more of LaTeX, including \require for extensions and many more packages.

Output

KaTeX writes HTML with CSS, plus hidden MathML. MathJax can draw CHTML, SVG or MathML.

Where They’re Used

Notion and VS Code’s Markdown preview use KaTeX. GitHub, Jupyter and Obsidian use MathJax.

Moving Between Them

Plain amsmath maths moves both ways. Package commands and custom macros are what break.

When to Use a KaTeX Previewer

Whenever maths has to be right before it goes somewhere else, especially somewhere you can’t easily preview, such as a CMS field, a pull request, a slide deck or a course page that only shows the result after it’s published.

Docs and Blogs

Check equations for sites built with Docusaurus, Hugo or Astro that render maths with KaTeX.

Notes and Homework

Fix an equation that won’t render in Notion or a Markdown notes app.

Email and EPUB

Get MathML for places that can’t load scripts or stylesheets.

Teaching

Show students what each command does and why an equation fails.

Reviewing Pull Requests

Preview maths in documentation changes before they merge.

Frequently Asked Questions