31 comments

[ 3.5 ms ] story [ 63.0 ms ] thread
A commenter left this on another HN post [0] and I thought it was worth its own.

[0] https://news.ycombinator.com/item?id=45701400

The commenter says pre-rendered/server-side-rendered mathematics (via katex) is great - I’ve found the opposite. It’s probably great if you have an article with one or two equations. On the other hand, if you have an article which uses mathematics pervasively, like many pure mathematics articles, it quickly becomes far more space efficient to render the mathematics on the client side. You can quickly get 200kB+ pages by pre-rendering.
But how is better space efficiency at this level better than worse rendering efficiency?
(comment deleted)
Super promising.
Probably I should have a bit more explicit why it is promising. Rendering speed is quite critical as it is related perception and human reaction time. If rendering is very slow then the engagement and iterating of writing maths will be interrupted. Imagine compiling of Latex would have taken 10 min, it won't be used widely like this. So it is promising, and maybe super promising indeed!
Disappointing that we still need those kinds of workarounds instead of just having native MathML support in all browsers.
Powering the math inference revolution given is used by every other LLM provider such as ………(name it).
I use KaTeX for my blog, and indeed KaTeX was faster than MathJax 2, but MathJax 3 (a complete rewrite) has significantly improved performance from the previous version and is now a bit faster than KaTeX in my experience.

This website has a comparison of the loading times of the same LaTeX rendered in both KaTeX and MathJax: https://www.intmath.com/cg5/katex-mathjax-comparison.php

"Page complete" never stops with either library for me. It just keeps counting milliseconds. Chrome on Windows, no change when I disabled uBlock Origin Lite.
Does anyone know why Google doesn’t adopt something like this in Google Docs / Slides? It’s amazing to me that after all these years Google Docs still has some of the worst equation editing of all word processors. I was hopeful when they added markdown support that first class equation editing was near, but it’s been a while now and still nothing.
I am curious, if there is any library for inline formula like KaTeX, but supporting Typst syntax?
It may or may not be as fast, but MathJax has broader support for LaTeX features, better accessibility features, and has slightly better typography in my very subjective opinion, and that's more important to me than a bit of rendering time.
I switched from MathJax to KaTeX earlier this year for my blog. So far, it has been working out well.

The only feature I really missed was the ability to use \label and \eqref for equation referencing, since KaTeX doesn't support these commands [1]. I worked around this limitation with a small custom setup defining my own \label and a custom \eqnref (not exactly \eqref though) [2].

Another thing that bothered me a little was that the KaTeX autorender extension does not recognise \begin{align*}, \begin{alignat*}, etc. as top-level delimiters by default [3] but this was trivial to fix by customising the set of default delimiters [2].

I know KaTeX supports server-side rendering but I don't use that yet [4]. I still use client-side rendering. Despite that my maths pages [5][6] render quickly since they are usually small, with only a single reflow from the initial load to the rendered page, without the continual reflows or jitter I used to see with MathJax. Overall, I am quite happy with the switch from MathJax to KaTeX.

[1] https://katex.org/docs/supported.html

[2] https://github.com/susam/susam.net/blob/0.3.0/layout/include...

[3] https://katex.org/docs/autorender#api

[4] https://news.ycombinator.com/item?id=44615271

[5] https://susam.net/mutually-attacking-knights.html

[6] https://susam.net/zigzag-number-spiral.html

I use this all the time when editing markdown in vscodium. It's fast enough for the side preview and supports all the LaTeX commands I need so far. When I need a PDF Pandoc handles the conversion well enough for me. I've tried using Quarto's preview but it's so slow in comparison.
[dead]
As a very much work-in-progress, yesterday, I started working on interactive equations https://p.migdal.pl/equations-explained-colorfully/ (it uses KaTeX under the hood).

The idea is similar to https://betterexplained.com/articles/colorized-math-equation..., but with mouseover interaction (both for further description, but also for accessibility). For a deeper dive in the topic of explorable explanations, I wrote https://p.migdal.pl/blog/2024/05/science-games-explorable-ex... (was here on the HN as well).

(comment deleted)
I think the latest version of MathJax (v4) has rendering speed comparable to, if not faster than, KaTeX. It also looks (subjectively) significantly better than KaTeX, and supports a wide array of accessibility features.
MathJax does not even let you select text, so it seems less accessible to me.
A few years ago I was evaluating options to move away from a deprecated external latex library my company relied on in Confluence, and tested Notion. I was super impressed at the rendering speed of their latex implementation (KaTex of course). As other have mentioned, not everything is there, but it was sufficiently good for our purposes. The switch was a pain, I hoped that Notion had good tools to move over from Confluence, but we had to do a custom job relying on sketchy undocumented APIs
We used KaTeX via a React plugin to render math formulas as part of the AI response for our AI Writing Chrome extension (Jetwriter AI). We faced many challenges, especially with how different AI models syntax formulas, and had to do some string manipulation to make it work. Sadly, there isn't a go-to KaTeX library that would just work for AI chat apps.
KaTeX has always seemed pretty inferior to me compared with MathJax. The most significant flaw is that it is very unstable, frequently failing at rendering rendering large documents with many equations. This happens across several applications, though I suppose it could be machine-specific. It also doesn't support several basic packages that MathJax supports. Without measuring the speed difference, I've never noticed a gap anyways.