# 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.

KaTeX

Source code on GitHub

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

KaTeX and MathJax comparison demo

• #### Christian Lawson-Perfect

Mathematician, koala fan, Aperiodical editor. Usually found paddling in the North Sea, or fiddling with computers.

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

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 [https://github.com/Khan/KaTeX/issues/66] and it’s not inferred from delimiters like $vs$\$ because KaTeX doesn’t recognize math by delimiters yet [https://github.com/Khan/KaTeX/issues/26])

2. 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.