To show LaTeX math on a web page, you do not run TeX in the browser — you use a JavaScript math renderer. The two standards are MathJax (most complete) and KaTeX (fastest). Both accept LaTeX math syntax. This page compares them.
MathJax
MathJax (v3) renders LaTeX math — plus MathML and AsciiMath — to HTML/CSS, SVG, and MathML. The MathML output is valuable for screen-reader accessibility. It has the broadest LaTeX-math compatibility (amsmath, custom macros, even \label/\eqref), and v3’s rewrite closed much of the old speed gap. Configure it via a window.MathJax object (delimiters, packages) before loading the script.
<script>
window.MathJax = { tex: { inlineMath: [["$","$"]], displayMath: [["$$","$$"]] } };
</script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>KaTeX
KaTeX (by Khan Academy) is the fast, lightweight renderer — synchronous, no reflow, small. It supports a large subset of LaTeX math, but not all of it (notably no \label/\eqref equation referencing). Best when you have many formulas and speed matters. Load its CSS and JS plus the auto-render extension (renderMathInElement).
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css">
<script defer src="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex/dist/contrib/auto-render.min.js"
onload="renderMathInElement(document.body);"></script>Configuration, compatibility, and choosing
Delimiters: inline $...$ or \(...\); display $$...$$ or \[...\]. Choose which are active (MathJax via its config object, KaTeX via renderMathInElement’s delimiters). Compatibility: both accept LaTeX math only (not whole documents) and neither runs a real TeX engine — they reimplement math typesetting in JS. MathJax covers more commands. To put a whole LaTeX document on the web with fidelity, use a converter (tex4ht/LaTeXML) — see “LaTeX → HTML.”
- Compatibility, MathML (accessibility),
\eqref→ MathJax. - Speed, small size, many formulas → KaTeX.
- A whole document on the web → a converter (see “LaTeX → HTML”).