top | item 35588985

The fastest math typesetting library for the web

237 points| jayhoon | 2 years ago |katex.org | reply

123 comments

order
[+] giraj|2 years ago|reply
The speed of KaTeX is great, but the lack of support for diagrams (a la tikz-cd) is what makes KaTeX unsuitable for general adoption by mathematicians (e.g., mathoverflow.net and all online mathematical wikis I know use MathJax). KaTeX has some rudimentary support for diagrams though the {CD} environment, but something more fully fledged akin to tizk-cd or xymatrix is needed. There's been some discussion on their github (https://github.com/KaTeX/KaTeX/issues/219), but I wouldn't hold my breath.
[+] xeonmc|2 years ago|reply
Wait, MathJax supports tikz?
[+] lilgreenland|2 years ago|reply
what is the advantage of tikz over SVG?
[+] mk12|2 years ago|reply
You can compare MathJax, KaTeX, and your browser's MathML support with this website I made: https://mk12.github.io/web-math-demo/
[+] xworld21|2 years ago|reply
Cool!

Would you consider adding a web font with the proper OpenType features to render the MathML content? The Igalia work in Chrome is quite decent when the font is good, but for now it needs to be set via CSS (presumably Chrome does not feel like bundling a math font just yet).

Some nice demos are at https://fred-wang.github.io/MathFonts/mozilla_mathml_test/ (with Latin Modern, the TeX Gyre's, FiraMath – other fonts are still glitchy).

[+] runarberg|2 years ago|reply
Nice. Do you accept PRs for other libraries. I wrote one myself a bit ago and wouldn’t mind seeing it there
[+] Paul-Craft|2 years ago|reply
Neat. Have you considered adding latex.js to the site?
[+] MontyCarloHall|2 years ago|reply
This is amazing. Probably the final nail in the coffin of MathML; what’s the point of a non-human readable intermediary language that other higher-level languages get compiled to, that only works in certain browsers (and with browser-dependent rendering/implementation), when you can instead write directly in LaTeX and have KaTeX work identically everywhere?
[+] tannhaeuser|2 years ago|reply
MathML support in Chrome has been greatly enhanced just in January [1].

I don't have strong opinions, but I guess the advantage over TeX is, as always, that MathML is much better integrated with the web stack and markup such that you can target math formulas using CSS, that it has much better accessibility, internationalization, and search, that you can use JS/DOM access with MathML for educational and science presentation apps, etc.

It's not like TeX is uncontroversially better (eg Turing completeness, terse, lacking editor support, print-oriented, purely presentational, ...)

[1]: https://mathml.igalia.com/news/2023/01/10/mathml-in-chromium...

Edit: arguably MathML is excessive as well but at least its XMLism such as insistence on enclosing every operand in tags as the primary source of bloat and incomprehensibility in presentational math can be somewhat mitigated using SGML, as was already suggested with MathML's precursor in 1995 or so [2] for high school math and/or custom math fragments.

[2]: https://www.w3.org/MarkUp/html3/maths.html

[+] the__alchemist|2 years ago|reply
I don't understand MathML's intent; likely because I have a different design mentality or model.

I like to represent things like this in 3 forms:

#1: Rendered notation for reading; what all these tools produce for people reading the document

#2: A clean, well-documented API for writing. This is the Latex, Mathjax, katex syntax etc, replete with backslashes.

#3: A representation in a computing language used to create the rendered form from the API. Depends on the language, but ie something like a set of structs and enums that can be manipulated by a compiler.

MathML is none of these; it's neither readable, nor writable, nor manipulable natively by a programming language.

[+] mkl|2 years ago|reply
MathML is not just for presentation. It encodes a lot of semantic information that Latex leaves out, and that information can be useful for accessibility, computer algebra system interoperability, etc. That said, I don't think it's used much for those things. I had really high hopes for MathML when it was first announced, but the poor browser support and consequential lack of use has been really disappointing.
[+] camdenreslink|2 years ago|reply
KaTeX is really old (like 9 or 10 years?). So if it was going to kill MathML, it probably already did it.
[+] simplotek|2 years ago|reply
I believe MathML is still the only way to get proper math typesetting in epub, and I doubt katex is an option.
[+] RyEgswuCsn|2 years ago|reply
I am not that familiar with MathML, but I can imagine programmatically manipulate math expressions with MathML; can TeX math expressions be manipulated in the same way?
[+] nomemory|2 years ago|reply
It is fast, I was previously using mathjax, and for a significant document I had to wait for a few seconds until the formulas were parsed and rendered. For the same document with katex, everything happens in less than a second.
[+] garganzol|2 years ago|reply
I love the websites like katex.org - so useful while being static. If you take a look under the cover, you'll find that the website is built using Docusaurus - yet another cool project. So so useful. I want to live in the Web like that, without SEO noise, ads, cookie popups and all that nonsense.

Personally this is what I call Web 3.0 - fast, useful, mostly static websites.

[+] gwgundersen|2 years ago|reply
I really like Katex. I used to use MathJax for my blog, but the page reflow was annoying. Now I use Katex with server-side rendering, and even pages with a lot of math load quickly and without reflow.
[+] universemaster|2 years ago|reply
I am using temml for MathML. MUCH smaller output than katex: https://temml.org/
[+] xigoi|2 years ago|reply
Looks great! Is there a benchmark for comparison?

Edit: It seems that Temml is a fork of KaTeX, so the difference compared to KaTeX's MathML rendering should be minimal?

[+] the__alchemist|2 years ago|reply
Nice! I hadn't heard of this. I have a plainly coded blog that uses math notation. MathJax was previously the speed limfac. I replaced the mathjax script with the ones recommended on the Katex installation page; drop-in replacement.
[+] keithalewis|2 years ago|reply
MathJax got a tune-up. It is much faster now
[+] thangalin|2 years ago|reply
A while ago I optimized KeenType, which is a Java-based fork of NTS that can convert TeX commands into SVG images:

https://github.com/DaveJarvis/keentype

The following tutorial shows the real-time rendering speed of KeenType within my text editor, KeenWrite:

https://youtu.be/vgyYXwwF_lc?list=PLB-WIt1cZYLm1MMx2FBG9KWzP...

KeenWrite can produce web pages from Markdown with the TeX commands included as either as plain TeX macros (usable by JavaScript TeX renderers) or as pre-rendered SVG elements (no JavaScript required).

[+] garbagecoder|2 years ago|reply
I am working on a project that needs to put latex in a browser. We are currently trying out different libraries, but so far Katex does seem the fastest.
[+] 3rd3|2 years ago|reply
I wonder how does it render synchronously without needing to reflow the page?
[+] mkl|2 years ago|reply
Server-side rendering will do that.
[+] larodi|2 years ago|reply
The lib behind chatGpt rendering of latex script
[+] rosebay|2 years ago|reply
Katex is truly great. Fun trivia facts - one of its developers also played a core role in React (she is a legend)