logoalt Hacker News

KaTeX – The fastest math typesetting library for the web

163 pointsby suioirlast Wednesday at 12:40 PM66 commentsview on HN

Comments

taylorgibsonyesterday at 11:51 AM

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.

show 3 replies
susamyesterday at 12:42 PM

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

show 1 reply
subsetyesterday at 3:02 PM

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.

show 1 reply
staredyesterday at 1:53 PM

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

show 1 reply
sureglymopyesterday at 11:28 AM

I wish there was a native version of this. Every SSG seems to have the problem of having to depend on node in order to prerender html for math with katex.

show 5 replies
xigoiyesterday at 12:23 PM

Also see Temml, a fork of KaTeX that compiles to MathML instead of styled HTML.

https://temml.org/

staredyesterday at 11:53 AM

I am curious, if there is any library for inline formula like KaTeX, but supporting Typst syntax?

show 2 replies
creatayesterday at 12:19 PM

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.

s20nyesterday at 10:50 AM

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

show 2 replies
inasioyesterday at 5:29 PM

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

tommooryesterday at 1:17 PM

Outline (https://www.getoutline.com) includes the KaTeX renderer in it's documents if you're interested in trying a knowledge base that has great direct support.

https://docs.getoutline.com/s/guide/doc/formatting-kn6wBtxlQ...

suioirlast Wednesday at 12:40 PM

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

show 1 reply
bobajeffyesterday at 12:54 PM

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.

larodiyesterday at 10:35 AM

Powering the math inference revolution given is used by every other LLM provider such as ………(name it).

thomasahleyesterday at 10:50 AM

Some earlier discussions (2022): https://news.ycombinator.com/item?id=31441979

Most critique of KaTeX over MathJax is reduced support for LaTeX features.

holowoodmanyesterday at 10:12 AM

Disappointing that we still need those kinds of workarounds instead of just having native MathML support in all browsers.

show 3 replies
zaoui_amineyesterday at 2:13 PM

KaTeX is solid;

delfyesterday at 1:50 PM

[dead]

sherinjosephroyyesterday at 1:37 PM

[dead]

northlondoneryesterday at 9:53 AM

Super promising.