Top
Best
New

Posted by suioir 10/29/2025

KaTeX – The fastest math typesetting library for the web(katex.org)
181 points | 74 comments
taylorgibson 11/3/2025|
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.
Lord-Jobo 11/3/2025||
Speculation: Google has a moderate amount of “core” applications that are clearly getting indefinite support, but all of those services also have a very conservative feature and update roadmap. New features are going to be limited to things that alphabet has in its global focus, so crap like Gemini and not much else.

I’m sure engineers working on products like the google web suite would love to implement this kind of thing but have zero authorization or resources for that.

Experimental applications, the ones that bloom rapidly and get shut down in a cycle that google has become known for, are ironically way more likely to see this kind of cool niche update.

Twisted company has a whacky way of managing their products, because advertisement drives their revenue so everything else is just freestyle jazz.

drob518 11/3/2025||
"Freestyle jazz" is pretty accurate, IMO.
apwheele 11/3/2025|||
This is very obnoxious when transferring documents from Gemini to google docs (and not just math, tables/code sections are often not transferred correctly as well).

I have a javascript hack from the dev console where I can at least print the chat to PDF, https://andrewpwheeler.com/2025/08/28/deep-research-and-open... (that at least worked 2 months ago)

esafak 11/3/2025||
If only they'd added it in the first iteration when they had a free hand.
susam 11/3/2025||
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

smohare 11/3/2025|
I’ve never been able to switch since the feature set, whenever I’ve looked over the years, doesn’t seem geared toward serious mathematical exposition. I think I want to carry over habits from papers to blog pages though, which perhaps is misguided.
stared 11/3/2025||
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).

sleepyams 11/3/2025|
This is really awesome! I've been really interested in creating an interactive introduction to basic algebra where parts of the equation can be manipulated using drag-and-drop, but I couldn't really figure out the best way to do it. Maybe using Katex is the way to go?
subset 11/3/2025||
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.
silverwind 11/3/2025|
MathJax does not even let you select text, so it seems less accessible to me.
mkl 11/4/2025||
MathJax lets you select text more often than KaTeX as far as I can tell (some KaTeX formulas act dead unless you start selecting outside them), not that either library give you anything especially useful if you try to copy and paste. MathJax will happily give you useful copy-to-clipboard if you right click.

MathJax has way more accessibility features: https://docs.mathjax.org/en/latest/basic/accessibility.html

xigoi 11/3/2025||
Also see Temml, a fork of KaTeX that compiles to MathML instead of styled HTML.

https://temml.org/

sureglymop 11/3/2025||
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.
koito17 11/3/2025||
I've been using katex-rs, a Rust rewrite, to implement LaTeX rendering for a Rust web app. It was easy enough to hook into pulldown_cmark, so that $ and $$ and render a decent subset of LaTeX. Since pulldown_cmark is a proper Markdown parser, you listen for Event::InlineMath and Event::DisplayMath then call KaTeX directly. No regex or HTML escaping necessary. In my web app, this is all encapsulated into a single function that I can call within Tera templates. It's as SSR as it gets; no Node.js or client-side JavaScript necessary.

The costliest asset is a minified stylesheet served through a CDN. (I do this out of laziness, and because the web app as-is needs nothing more than the standard Rust toolchain).

https://github.com/katex-rs/katex-rs

nicoburns 11/3/2025||
Do you have a reference on how to hook it into pulldown_cmark? I'd love to add math support into to my markdown rendering app but I haven't had time to investigate this myself yet.
koito17 11/3/2025||
https://gist.github.com/akar1ngo/7d4ea6e9dfc369526beb75092cb...
sureglymop 11/3/2025||
Thank you for your account and reply! Awesome stuff :)
MillironX 11/3/2025|||
Hugo includes native KaTeX: https://gohugo.io/functions/transform/tomath/

The docs recommend setting up KaTeX CSS (which requires either a CDN link or Node), but by changing output to 'mathml,' you can have the browser render equations with zero dependencies.

sureglymop 11/3/2025||
That's news to me! The last time I used Hugo it didn't support that yet and I had to serve the js bundle to run in the browser.
generichuman 11/3/2025|||
If your use case is generating html, MathML is supported in all modern browsers: https://developer.mozilla.org/en-US/docs/Web/MathML#browser_...
rustybolt 11/3/2025|||
I use it in my static site generator in Python via https://github.com/rubenvannieuwpoort/PyKaTeX.

Disclaimer: I am the author of PyKaTeX.

notpushkin 11/3/2025||
Port it? Or maybe bundle a tiny interpreter instead of Node.
creata 11/3/2025||
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.
stared 11/3/2025||
I am curious, if there is any library for inline formula like KaTeX, but supporting Typst syntax?
runarberg 11/3/2025||
I wrote a library with a syntax similar to Typst (actually inspired by AsciiMath; and predates Typst by about a decade). Then there are Markdown-It plugins around it.

https://mathup.xyz/

https://github.com/runarberg/markdown-it-math

jeremyscanvic 11/3/2025||
I would assume you pretty much get that out of the box given Typst compiles to HTML natively?
stared 11/3/2025|||
I was more looking for things I can use with blogs with Markdown and frameworks like Astro.

But with the development of Typst, maybe the way to go is to use Typst rather than Markdown.

sprinkly-dust 11/3/2025|||
Currently that feature is unsupported or I just can't figure out how to do it. With the latest compiler version 0.14 any .typ file I try to compile will incur warnings about skipping the equations (skipping the main reason I'd want to compile a Typst file to HTML...).

As per their GitHub they haven't included MathJax or KaTeX support yet as they were more focused on semantic and structural accuracy of HTML output with this release.

s20n 11/3/2025||
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

lifthrasiir 11/3/2025||
It is amusing that, in my particular environment, KaTeX is slower than MathJax 3 in processing time but actually faster when font loading time is accounted for. Both loads from your domain so there should be no routing issue; KaTeX fonts turned out to be substantially smaller than MathJax 3 at least in this particular case. Is this intentional or just a lucky coincidence for KaTeX? (KaTeX is also ~70% smaller than MathJax 3 in their gzipped forms, so it might well be intentional!)
mkl 11/4/2025|||
"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.
esafak 11/3/2025||
So if speed is comparable, which is best?
tommoor 11/3/2025|
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...

More comments...