KaTeX vs LaTeX: What KaTeX Supports and What It Can't

November 11, 2026 · 12 min read

KaTeX vs LaTeX: What KaTeX Is and What It Can't Render

KaTeX vs LaTeX isn't a contest between two versions of one tool. LaTeX is a document preparation system that compiles a whole .tex file into a typeset PDF. KaTeX is a JavaScript library that renders LaTeX's math syntax as HTML in your browser. It handles most everyday math, but not packages, labels or document commands.

What Is KaTeX, and How Is It Different From LaTeX?

KaTeX is an open-source JavaScript library, MIT licensed and originally built at Khan Academy, that turns LaTeX math syntax into HTML and MathML. According to its GitHub README, it renders synchronously without reflowing the page. It runs in the browser, or in Node.js when a site wants to pre-render math on the server.

LaTeX is something else. The LaTeX Project calls it a document preparation system for high-quality typesetting. You write a full .tex file with a preamble, sections and references, and a TeX engine such as pdfTeX or LuaTeX compiles it into pages.

The short version: KaTeX reads the math part of LaTeX's language and nothing else. It never sees a \documentclass line, a bibliography or a page. MathJax is the other common browser renderer, and our guide to math in Markdown covers how the two renderers differ. Our walkthrough on rendering LaTeX with MathJax shows how to add it to a page of your own.

KaTeX vs LaTeX Side by Side

Put side by side, KaTeX vs LaTeX isn't a like-for-like match, because the two tools work at different layers. One draws formulas inside a web page, and the other produces the whole document around them.

KaTeXLaTeX
What it isJavaScript math rendererDocument preparation system on a TeX engine
InputOne math expression at a timeA complete .tex document with a preamble
OutputHTML plus MathML by defaultPDF (or DVI)
Where it runsBrowser, or Node.js for pre-renderingA TeX distribution or an online compiler
ScopeMath expressions onlyText, math, figures, references and page layout
PackagesA fixed command set, plus extensions such as mhchem\usepackage and the packages on CTAN
Custom macros\newcommand and \def, scoped to one expressionPreamble macros for the whole document
NumberingAuto-numbered display environments and \tag, no \label or \eqref\label, \ref and \eqref
ErrorsThrows a ParseError, or shows the source in the error colourA compile log with line numbers
SetupAn npm package or a CDN scriptTeX Live, MiKTeX or MacTeX

The output row matters most. Per the KaTeX options page, the default htmlAndMathml setting emits HTML for the visual result and MathML for screen readers. LaTeX produces fixed pages instead. To put a whole .tex document on the web, you need a LaTeX to HTML converter such as make4ht or LaTeXML.

Which LaTeX Math Does KaTeX Support?

KaTeX covers the math most people write: fractions, roots, Greek letters, operators, matrices, multi-line environments and custom macros. As a rule of thumb, if a command lives in core LaTeX math or amsmath, KaTeX probably has it, though a few amsmath pieces are missing (see the next section). If it needs another package, check the KaTeX support table first.

FeatureExampleWhere it works
Fractions, roots, scripts\frac{a}{b}, \sqrt[3]{x}, x_i^2Inline and display
Greek letters, symbols, arrows\alpha, \to, \xrightarrow{f}Inline and display
Operator names\operatorname{rank}, \operatorname*{arg\,max}Inline and display
Text inside math\text{if } x \gt 0Inline and display
Matricespmatrix, bmatrix, arrayInline and display
Piecewise and stacked rowscases, aligned, gatheredInline and display
Display environmentsalign and align*, gather, alignat, equation, splitDisplay mode only
Equation tags\tag{1}, \tag*{A}, \nonumber, \notagDisplay mode
Macros\newcommand, \renewcommand, \def, \gdefInline and display
Colour and boxes\color, \textcolor, \boxed, \cancelInline and display
Commutative diagrams\begin{CD}Display mode only

You may read that KaTeX can't do align or \newcommand. Both work in KaTeX itself. When they fail, the cause is usually inline math or the way a particular site wires KaTeX in.

The CD environment is a small surprise for people coming from tikz-cd. It draws simple square diagrams:

$$
\begin{CD}
A @>f>> B \\
@VgVV @VVhV \\
C @>>k> D
\end{CD}
$$

That renders a square with f across the top, k along the bottom, and down arrows labelled g and h on the sides. Curved or diagonal arrows are out of reach. Paste your own math into the demo below to see what KaTeX accepts:

KaTeX math that works:

Inline: Hom⁡(A,B)\operatorname{Hom}(A,B) and x3\sqrt[3]{x}

F=ma\def\vect#1{\mathbf{#1}} \vect{F} = m\vect{a} f(x)=(x+1)2=x2+2x+1\begin{aligned} f(x) &= (x+1)^2 \\ &= x^2 + 2x + 1 \end{aligned} ∣x∣={xx≥0−xx<0\lvert x \rvert = \begin{cases} x & x \ge 0 \\ -x & x \lt 0 \end{cases} E=mc2(1)E = mc^2 \tag{1}

Now add \label{eq:1} to the last block and compare.

62 words356 characters24 lines
Markdown

What LaTeX Features Does KaTeX Not Support?

KaTeX rejects anything that depends on a preamble, a package it doesn't bundle, or a second pass over the document. The table below lists the gaps people hit most, with the closest working substitute. Each status comes from the KaTeX support table.

LaTeX featureKaTeX statusUse instead
\label, \ref, \eqrefNot supported (issue #350)Number with \tag and type the number in your text
\DeclareMathOperatorNot supported\operatorname{rank}
\newenvironmentNot supported (issue #37)A \newcommand covers some cases
multlineNo such environmentaligned or gather
eqnarrayNot supportedaligned
\multicolumn, \cline in arrayNot supported (issue #269)Restructure the array, or use a Markdown table
\canceltoNot supported\cancel{x}^{0}
\ce, \pu (chemistry)Needs the mhchem extensionOnly works if the site loads it
\usepackage, siunitx, TikZNot supportedCD for basic arrows, otherwise an image
\href, \url, \includegraphicsNeed the trust optionA Markdown link or image outside the math

Here's a typical swap. In a LaTeX paper you'd declare an operator in the preamble and cite the equation by label:

\DeclareMathOperator{\rank}{rank}
...
\begin{equation}\label{eq:rank}
  \rank(A) = n
\end{equation}
As \eqref{eq:rank} shows, ...

The KaTeX version drops the preamble and fixes the number by hand:

$$
\operatorname{rank}(A) = n \tag{3}
$$

As equation (3) shows, ...

Both render rank in upright type with operator spacing and an equation number at the right margin. The difference is upkeep: in KaTeX, the number in your sentence won't update when the equations move. MathJax does support \label and \eqref, and our MathJax examples list other commands it renders that KaTeX doesn't.

Then there are document commands. \documentclass, \section, \cite, \bibliography and figure or table floats aren't on any KaTeX list, because KaTeX isn't a document system. In Markdown, headings and links do those jobs.

Why Does My LaTeX Work in Overleaf but Not in KaTeX?

Code that compiles in a LaTeX editor can fail in a browser for five common reasons. Each one has a quick fix.

  1. Your preamble didn't come along. Packages, \DeclareMathOperator lines and preamble macros never reach KaTeX. Rewrite them with \operatorname or a local \newcommand.
  2. A display-only environment sits in inline math. KaTeX reports that align can be used only in display mode. Move it into $$ or switch to aligned.
  3. The macro belongs to another expression. KaTeX renders each expression on its own, so a definition doesn't carry forward by default. Repeat it in every block that uses it.
  4. The command needs trust. Unless the site enables the trust option, \href and \includegraphics render as the command name in the error colour.
  5. The delimiters differ. Our editor reads $...$ and $$...$$, but not the \(...\) and \[...\] forms common in LaTeX. Swap them for dollar signs.

Point 3 catches people out the most. In a default KaTeX setup, this pair fails on the second block:

$$
\newcommand{\vect}[1]{\mathbf{#1}} \vect{F} = m\vect{a}
$$

$$
\vect{p} = m\vect{v}
$$

The first block draws bold F and a. The second reports an undefined control sequence, because \vect died with the first expression. Sites can share macros through the macros and globalGroup options, but you can't switch that on from the page itself.

Some LaTeX has no KaTeX fix at all. TikZ pictures, siunitx units and true cross-references need a TeX engine, so simplify the math or render it elsewhere.

Can KaTeX Produce a PDF Like LaTeX?

No. KaTeX outputs HTML, so any PDF comes from printing or exporting the web page, not from typesetting a document. You won't get page-aware layout, running heads or a generated bibliography.

That's fine for notes and handouts. Our editor has Export as PDF in its Download/Export menu. It runs on the server and shares the free pool of 3 server-side operations a day, and Pro removes that daily cap. Check the formulas in the exported file before you send it.

For a properly typeset paper, go the other way. The Markdown to LaTeX converter turns your Markdown into a .tex file in the browser, passing $ and $$ math through unchanged. It doesn't compile a PDF, so you finish in a TeX distribution.

When Should You Use KaTeX and When Do You Need a TeX Engine?

Settle KaTeX vs LaTeX by output, not by syntax, since the math syntax is mostly shared. Ask where the formula will live.

KaTeX fits when the math lives on a screen:

  • Web pages, documentation sites and Markdown notes
  • Chat apps and live previews that redraw as you type
  • Pages with dozens of formulas that need to render fast

A TeX engine is the right call when the output is a document:

  • Papers, theses and journal templates
  • Citations and a bibliography
  • Automatic equation numbers with cross-references
  • TikZ figures and precise page layout

We prefer to write math in the subset both tools share: aligned over align, \operatorname over \DeclareMathOperator, a typed \tag over \label. Then the same formula renders on a web page and moves into a paper with little more than a delimiter change. For the wider choice between the two writing formats, read Markdown vs LaTeX.

Where You'll Run Into KaTeX in Markdown and Web Apps

You've likely used KaTeX without knowing it. Our editor renders inline $...$ and display $$...$$ math with KaTeX, in a split view with Markdown on the left and the live preview on the right.

For a single formula, the LaTeX equation editor renders with KaTeX in your browser. It has a symbol palette, exports PNG or SVG and copies a Markdown math snippet.

Developers add KaTeX to marked or markdown-it through a math plugin, as shown in our JavaScript Markdown guide. In React, react-markdown does the same job by pairing remark-math with rehype-katex.

Quick Answers on KaTeX and LaTeX

The KaTeX vs LaTeX question is really about scope. KaTeX renders LaTeX math on the web, quickly and without an install, and LaTeX typesets whole documents. Write your formulas once, check them against the support table, and reach for a TeX engine only when you need packages, labels or a typeset PDF. To test a formula right now, paste it into the LaTeX equation editor.