Use KaTeX instead of MathJax

Anki as well as AnkiDroid use MathJax to render latex maths. In my, as well as others experience, MathJax is extremely slow, some of my cards with maths on them (And not a lot, just like one fraction) took about 5 seconds to load on mobile. KaTeX is a lot faster, I have integrated it in one of my card templates and those cads now take less than a second to load, and I think a lot of that time is actually spent on loading the js file. The code for this template is needlessly complicated, a lot of it is for downloading the js file.

Changing the behaviour of anki to use KaTeX instead of MathJax would get rid of all of those problems.

Is there any reason MathJax is used over KaTeX, like missing features in KaTeX, or would there be any interest in switching to KaTeX?

1 Like

MathJax 3 is reasonably fast. 5 seconds sounds excessive, and may be because you’re downloading the libraries from the internet on each card display, due to the fact that AnkiDroid reloads the webview for every card.

Is MathJax not included with AnkiDroid? I had a brief look at the desktop clients source and if I remember correctly the MathJax.js file was included locally.

My info was out of date - it appears it has been in AnkiDroid for a while. I am still surprised it’s taking 5 seconds to load though, and I’d recommend you follow this up on the AnkiDroid issue tracker.

this page times the loading of mathjax3 vs katex and it looks like mathjax is much faster

I cannot say that’s true. I get this:
mathjax3:

Process MathJax3 	4917 ms
Fonts loaded	5200 ms

Katex:

Process KaTeX 	133 ms
Fonts loaded	183 ms

But it varies a lot with every reload of the page.

I came here because I included some mathjax that should display π (pi). It looked more like a roman II (2) though because it wasn’t rendered yet and took more then 5 seconds to render.

It would be great if loading time could be vastly improved somehow, especially considering I’m likely going to add more complex math cards in the future too. And if π took so much time, then more complex things probably take even more time.