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.
| KaTeX | LaTeX | |
|---|---|---|
| What it is | JavaScript math renderer | Document preparation system on a TeX engine |
| Input | One math expression at a time | A complete .tex document with a preamble |
| Output | HTML plus MathML by default | PDF (or DVI) |
| Where it runs | Browser, or Node.js for pre-rendering | A TeX distribution or an online compiler |
| Scope | Math expressions only | Text, math, figures, references and page layout |
| Packages | A fixed command set, plus extensions such as mhchem | \usepackage and the packages on CTAN |
| Custom macros | \newcommand and \def, scoped to one expression | Preamble macros for the whole document |
| Numbering | Auto-numbered display environments and \tag, no \label or \eqref | \label, \ref and \eqref |
| Errors | Throws a ParseError, or shows the source in the error colour | A compile log with line numbers |
| Setup | An npm package or a CDN script | TeX 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.
| Feature | Example | Where it works |
|---|---|---|
| Fractions, roots, scripts | \frac{a}{b}, \sqrt[3]{x}, x_i^2 | Inline 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 0 | Inline and display |
| Matrices | pmatrix, bmatrix, array | Inline and display |
| Piecewise and stacked rows | cases, aligned, gathered | Inline and display |
| Display environments | align and align*, gather, alignat, equation, split | Display mode only |
| Equation tags | \tag{1}, \tag*{A}, \nonumber, \notag | Display mode |
| Macros | \newcommand, \renewcommand, \def, \gdef | Inline and display |
| Colour and boxes | \color, \textcolor, \boxed, \cancel | Inline 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:
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 feature | KaTeX status | Use instead |
|---|---|---|
\label, \ref, \eqref | Not supported (issue #350) | Number with \tag and type the number in your text |
\DeclareMathOperator | Not supported | \operatorname{rank} |
\newenvironment | Not supported (issue #37) | A \newcommand covers some cases |
multline | No such environment | aligned or gather |
eqnarray | Not supported | aligned |
\multicolumn, \cline in array | Not supported (issue #269) | Restructure the array, or use a Markdown table |
\cancelto | Not supported | \cancel{x}^{0} |
\ce, \pu (chemistry) | Needs the mhchem extension | Only works if the site loads it |
\usepackage, siunitx, TikZ | Not supported | CD for basic arrows, otherwise an image |
\href, \url, \includegraphics | Need the trust option | A 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.
- Your preamble didn't come along. Packages,
\DeclareMathOperatorlines and preamble macros never reach KaTeX. Rewrite them with\operatornameor a local\newcommand. - A display-only environment sits in inline math. KaTeX reports that
aligncan be used only in display mode. Move it into$$or switch toaligned. - 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.
- The command needs trust. Unless the site enables the
trustoption,\hrefand\includegraphicsrender as the command name in the error colour. - 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.