52
$\begingroup$

Khan Academy has just published KaTeX, a Math typesetting library. From what I can see on their site this seems to be pretty much a MathJax replacement with much better performance.

The performance improvements compared to MathJax seem pretty impressive, in this test KaTeX was 20-30 times faster than MathJax for me.

I don't know if it has feature parity with MathJax, I'd assume not simply due to being a new library.

It might be worthwile to observe this project and investigate whether it could be used on the SE network at some point. Or the other way around, if the methods they use to achieve these speedups could be ported to MathJax.

$\endgroup$
  • 3
    $\begingroup$ This is the thread they used for illustration. $\endgroup$ – user147263 Sep 15 '14 at 21:51
  • 19
    $\begingroup$ At present, they support enough markup for Calculus, but not beyond that. No matrices (or any begin...end environments), no fonts like mathbb, no symbols like $\forall$ or $\implies$, etc. $\endgroup$ – user147263 Sep 15 '14 at 22:09
  • 1
    $\begingroup$ And here is the full list of supported functions $\endgroup$ – Lipis Sep 15 '14 at 23:06
  • $\begingroup$ I was on my way to ask the exact same question! And as excepted it doesn't support a lot of features but will it be possible to use katex and fallback in mathjax if necessary? $\endgroup$ – razpeitia Sep 15 '14 at 23:36
  • $\begingroup$ @Thursday read the CONTRIBUTING.md you can easily add new functions and symbols. $\endgroup$ – razpeitia Sep 15 '14 at 23:47
  • 6
    $\begingroup$ Nice to see people continue to dev browser TeX implementations. At the moment, speed improvements may be due to the lightweight built in library as compared to the current features of MathJaX. It may slow down once it is set to encompass the full functionality of MathJaX. I think it is worth keeping an eye on in general, if for no other reason than to support their cause. $\endgroup$ – J. W. Perry Sep 16 '14 at 0:27
  • $\begingroup$ Nice! Since this concerns more than one SE site, I pushed the matter upstream. $\endgroup$ – Raphael Sep 16 '14 at 6:31
  • 6
    $\begingroup$ KeTeX cannot render $\sqrt[3]{2}$ and misplaced the lower integration bound in $\displaystyle{\large\int}_0^\infty\frac{x}{\sqrt{1-\frac1{x^2}}}dx$. I wouldn't want to use it now. $\endgroup$ – Vladimir Reshetnikov Sep 19 '14 at 16:05
  • 5
    $\begingroup$ @VladimirReshetnikov KaTeX's rendering of {\int}_0^\infty matches TeX's and LaTeX's -- MathJax's behavior is arguably wrong here. If you remove the curly braces, the bottom limit is placed correctly. $\endgroup$ – Sophie Alpert Nov 14 '14 at 0:11
  • $\begingroup$ One more: tag is also missing so you can't label equations. Katex may be faster, but not noticeable. The feature set as well as typesetting quality is nowhere near that of MathJax. While it might be okay for more elementary math which Khan Academy uses (though I do not see much reason to use it even there), it is definitely not suitable here. $\endgroup$ – KalEl Feb 24 '16 at 16:36
  • 1
    $\begingroup$ I just came to ask the exact same question. Bumping. MathJax is slow and awful (especially the incremental formatting) and I would love to have math.SE and other SE sites using MathJax switch to KaTeX. $\endgroup$ – R.. Sep 1 '17 at 18:04
  • 1
    $\begingroup$ I have tried the examples above on the KaTeX site and all work (June 2018). Probably the developers added them. It even supports \mathbb{R} now. $\endgroup$ – Kai Noack Jun 21 '18 at 15:42
  • $\begingroup$ Here you can compare the performance of KaTeX and MathJax. List of supported functions by KaTeX. (older links are broken) $\endgroup$ – Arpi May 3 at 10:13
38
$\begingroup$

At present: I do not think KaTeX is yet a viable option. At issue is feature parity. For comparison: MathJax supports on the order of ~800 built-in commands, plus the ability to define new macros using \def or \newcommand. Currently, the link given in Lipis's comment shows around ~250 commands supported. Mathjax also supports environments defined in the AMSMath (loaded by default here) and AMSCD extensions which involve vertical alignment.

Until feature parity is achieved we cannot expect KaTeX to be a drop-in replacement.

A few specific things missing that will break many of the pages on Math.SE at the moment:

  • The lack of \mathbb and \mathrm commands (at least one of our 100K users will not stand for the lack of the latter :-)).
  • No matrix or array environments.
  • A rather limited set of arrows.
  • Very limited support for basic elementary set theory and logic notations.
  • It does not support unicode input.

Also I am not particularly impressed with how they deal with really long math expressions (scroll bar rather than overflow or line break).


I am also not entirely convinced that when feature parity is reached, KaTeX will still exhibit the same speed-up compared to MathJax, since both are based on a JavaScript backend.

One interesting aspect which is related to KaTeX's claim that it runs on all major web browsers with identical output, is that KaTeX outputs are, as far as I can tell, only using the HTML-CSS paradigm. Whether that contributes to the speed-up I don't know, but I find it somewhat disingenuous that on the KaTeX test page they chose to use the TeX-AMS-MML_HTMLorMML configuration (which accepts both LaTeX-style and MathML input and outputs to configurable HTML or MathML output) instead of the TeX-AMS_HTML configuration (which is still more feature-rich than what KaTeX provides, but is a better approximation of what KaTeX supports). There should be some (perhaps minor) speed up for MathJax just by loading a smaller set of features.

$\endgroup$
  • 1
    $\begingroup$ I agree that it looks like there is still a lot to do for KaTeX. The part I find interesting is the option to render the Math server-side into HTML. This would avoid the whole JS implementation and the associated delay, as far as I understand it. $\endgroup$ – Mad Scientist Sep 16 '14 at 13:11
  • 1
    $\begingroup$ In principle server-side rendering should be doable also with MathJax: github.com/mathjax/MathJax-docs/wiki/Mathjax-server-side there there's some technicalities involved. $\endgroup$ – Willie Wong Sep 16 '14 at 13:48
  • 6
    $\begingroup$ We have been working on server-side rendering for MathJax in the MathJax-node project. This provides a node.js-based interface to MathJax's SVG and MathML output (but not HTML-CSS at the moment), which can be used to preprocess pages or individual equations using MathJax. $\endgroup$ – Davide Cervone Sep 16 '14 at 15:37
  • 16
    $\begingroup$ Coincidentally, we have been working on speed improvements in MathJax for the next release. We have an improvement of 30 to 50% in the HTML-CSS output, for example, and have been developing a faster replacement for the current HTML-CSS output renderer that is presently at around 10 times faster. It also produces browser-independent HTML, and doesn't need the browser to perform measurements, so can be used server-side as well (via MathJax-node). It is not yet complete, but is well under way. $\endgroup$ – Davide Cervone Sep 16 '14 at 16:34
  • 1
    $\begingroup$ @Willie Wong the link to the wiki page has been updated to point to MathJax-node. $\endgroup$ – Peter Krautzberger Sep 16 '14 at 17:22
  • 2
    $\begingroup$ to add to Davide's comment re work on 2.5 -- the roadmap at github.com/mathjax/MathJax/wiki/Mathjax-v2.5 has instructions for trying the new output mechanisms $\endgroup$ – Peter Krautzberger Sep 17 '14 at 18:35
  • 1
    $\begingroup$ Once more LaTeX commands are supported, server-side KaTeX (and MathJax!) would be great to overcome current problems with Prince XML when rendering print-ready PDFs from XML/HTML. Currently, I have to resort to ugly but functional MathML. I am also happy to learn that Pandoc's creator John MacFarlane earmarked future KaTeX support in Pandoc. That would make me a very happy Markdown writer! $\endgroup$ – on4aa Sep 21 '14 at 16:50
  • 1
    $\begingroup$ Now KaTeX supports a couple of environments, including array. In addition, it is helpful to have some examples of "A rather limited set of arrows" and "Very limited support for basic elementary set theory and logic notations". For instance, I know that KaTeX (still) don't support \overrightarrow. $\endgroup$ – Franklin Yu Oct 14 '16 at 23:25
  • 2
    $\begingroup$ What updates have occurred between then and now? $\endgroup$ – Akiva Weinberger Jan 18 '18 at 17:38
  • $\begingroup$ @AkivaWeinberger: having just took a look at their current feature set, I think all 5 of the bullet points in my post can be crossed out. (I think the vast majority of the math display things I've written on M.SE is probably now covered by KaTeX.) KaTeX is however still not supporting in-line custom commands (new macros must be defined in the header of the webpage); I think this is by choice. And as far as I can tell there's no support for AMS-CD type diagramming environments. Both of these will break quite a few pages on M.SE if we just drop KaTeX in directly without editing old pages. $\endgroup$ – Willie Wong Jan 19 '18 at 14:47
  • 1
    $\begingroup$ Now KaTeX has support for custom inline commands, but I don't think it will support commutative diagrams, given that MathJax and Mermaid already provide similar support. $\endgroup$ – GNUSupporter 8964民主女神 地下教會 Dec 4 '18 at 8:28
8
$\begingroup$

A little bit off-topic, but I think it is interesting for people that want to speed up MathJax. If you are using Firefox, and right click on a mathjax equation. You can choose Math Settings -> Math Render -> MathML. In this setting, MathJax is way faster. Unfortunately, this only works in firefox.

I've made a screencast of the same MSE page as you see at the KaTeX website:

enter image description here

$\endgroup$
  • $\begingroup$ While the MML rendering is much faster, there's a reason that MathJax defaults to HTML+CSS even on Firefox. (See also bugzilla.mozilla.org/show_bug.cgi?id=687809 .) $\endgroup$ – Willie Wong Sep 16 '14 at 13:48
  • 3
    $\begingroup$ @WillieWong actually, MathJax Native MathML output on Firefox tweaks the MathML to work around technical shortcomings in Firefox. The layout quality in Firefox is still not ideal and eventually our implementation might move too far ahead again. But at least right now, it's quite reasonable to use it. Just make sure to install a Firefox compatible font (this has changed since 34). $\endgroup$ – Peter Krautzberger Sep 17 '14 at 18:33
  • $\begingroup$ The screencast still shows reflow which is awful UX. KaTeX doesn't have that problem. $\endgroup$ – R.. Oct 10 at 15:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .