You're reading: News

KaTeX is a (partial) alternative to (some of) MathJax

Khan Academy has released a new library to typeset mathematical notation on webpages, called KaTeX.

“But we already have MathJax!” you say, perhaps a little too enthusiastically. Well, Khan Academy has a lot of pages about maths, and they have a fairly rare set of requirements: the maths they use is relatively simple, they usually have a lot of it on the page, and their users are usually not techy types with zippy computers. For their purposes, MathJax has a couple of big design flaws: it likes to measure the text surrounding each equation very exactly so that its output is pixel-perfect, and it runs asynchronously, so you can see equations popping into existence as it works down the page.

Because of that, they’ve clearly decided it’s worthwhile writing a new library to typeset maths that suits them better than MathJax. KaTeX is much more limited in the kinds of output it supports than MathJax, sticking to inline-style rendering and a much smaller subset of TeX commands. It runs synchronously, which means it exchanges temporarily locking up the browser for taking much less time to finish. Importantly, it doesn’t get held up by asking the browser to take measurements, instead using much faster CSS rules to make sure the output matches surrounding text.

Murray Bourne has had a good look at KaTeX and written a blog post acting as an FAQ of sorts, and he’s also set up a page where you can compare the output of KaTeX with MathJax.

Khan Academy is using KaTeX as a first port of call to render maths, and using MathJax as a fallback for things it can’t render. So it looks like KaTeX really is worth having.

KaTeX very neatly fills its niche, but it’s not a complete replacement for MathJax. I’m sure it’ll come in useful on sites other than Khan Academy, so thanks to them for open-sourcing it.

Note: I did some paid freelance work for MathJax earlier this summer.

More information


Source code on GitHub

KaTeX – a new way to display math on the Web by Murray Bourne

KaTeX and MathJax comparison demo

3 Responses to “KaTeX is a (partial) alternative to (some of) MathJax”

  1. Avatar Beni Paskin-Cherniavsky

    Small correction: KaTeX can render display math too, e.g. if you feed \displaystyle \sum_0^\infty into it. (There is no direct API to select inline/display yet [] and it’s not inferred from delimiters like $ vs $$ because KaTeX doesn’t recognize math by delimiters yet [])

  2. Avatar Tom

    As of May 13, 2016, KaTeX supports both inline and display equations, so does some basic environments such as array, matrix, pmatrix, bmatrix, Bmatrix, vmatrix and Vmatrix. Equation alignment can get by with the aligned environment and a bunch of new symbols are added to the library as well. All in all, good for general purpose, stunning speed (but unclear how it’ll slow down as the library expands over time). It’s probably not for powering sites with very specific usage of LaTeX though.

  3. Avatar Anonymous

    > MathJax has a couple of big design flaws

    I wouldn’t call being perfect a design flaw. If at all, it is very well designed, extensible, and looks beautiful.

    Plus with my moderately powered computer (i3-4360), or on phones and any other device, I never remember being bugged by slow math rendering. As computing power progresses MathJax will only become faster without even any optimization – especially on pages with more equations due to parallel rendering. I have to question the wisdom of an uglier less complete tex rendering API which only optimizes speed.


(will not be published)

$\LaTeX$: You can use LaTeX in your comments. e.g. $ e^{\pi i} $ for inline maths; \[ e^{\pi i} \] for display-mode (on its own line) maths.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>