28 ms·
The fastest math typesetting library for the web
- nomemory 3y agoIt 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.
- MontyCarloHall 3y agoThis 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?
- simplotek 3y agoI believe MathML is still the only way to get proper math typesetting in epub, and I doubt katex is an option.
- auggierose 3y agoUnfortunately MathML doesn't get you proper typesetting in epubs, so it has that in common with katex.
- Georgelemental 3y agoIt does if your EPUB reader supports it—which most don't, but a few do! I am partial to http://koreader.rocks/ http://koreader.rocks/
- auggierose 3y agoI have tried out a few readers, none I tried so far support it in satisfying quality comparable to what katex would deliver. Maybe koreader is an exception, but I doubt it. Will give it a try at some point.
- simplotek 3y ago> (...) comparable to what katex would deliver. You're comparing real world working implementations based on mathml with your hopeful expectations of how you wish katex could work in an epub implementation. It's good to have hopes and dreams and a positive outlook, but your perceived solution does not exist. It's hardly relevant to present it as a better alternative.
- auggierose 3y agoI have no need for real-world implementations that do not work as well as I need them to work. KaTeX is proof that math can be displayed properly in a browser-like environment. Anything less will not do it, at least for me. That's why I have exclusively PDFs in my digital library, except for books that are just text, like fiction. No hopes and dreams needed, just use PDF. But making epub work properly for math is not a problem in principle, just make katex work in an epub reader, problem solved. And people who are satisfied with substandard solutions are actually part of the problem, not the solution.
- Georgelemental 3y ago> just make katex work in an epub reader "Just write a full JavaScript and DOM implementation for your resource-constrained e-ink device"
- auggierose 3y agoI think you need that already if you want a compliant epub reader. Javascript is part of the epub standard.
- simplotek 3y ago> Unfortunately MathML doesn't get you proper typesetting in epubs (...) Wrong. MathML is a part of the Epub3 specification. All e-reader implementations that comply with the epub3 specs get you proper typesetting in books published in epub3 format.
- auggierose 3y agoI guess it is you that is living in a dream world. There are no epub3 compliant implementations then, because none of them display math properly. If they were compliant, they would also run KaTeX just fine, because Javascript and HTML are part of the standard, too.
- simplotek 3y ago> I guess it is you that is living in a dream world. There are no epub3 compliant implementations then, because none of them display math properly. To start off, you already have posts in this very discussion rejecting your misconception. Secondly, mathml works fine when we have an epub3 reader opening a epub3 doc created by epub3 generators from epub3+mathml input. If any of those requirements aren't met, you get issues. This happens with each and every single typesetting feature, not just mathml. Would you claim that epub fails to support tables if you open an epub doc with broken tables? Thirdly, a typical implementation shortcut taken by epub readers is to reuse whatever WebView they pick. If your epub reader uses an outdated or shitty WebView implementation, you get shitty epub docs. https://caniuse.com/?search=mathml https://caniuse.com/?search=mathml Why are you commenting on subjects you are clearly clueless about?
- deleted 3y ago[deleted]
- auggierose 3y agoI think I will indeed refrain from commenting in the future, as conversing with people as knowledgeable as you are is becoming a chore.
- mkl 3y agoKatex supports ahead-of-time server-side rendering which just generates HTML, so it may indeed be an option.
- mkl 3y agoMathML 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.
- edflsafoiewq 3y agoMarking up the semantic structure of all your mathematical formulas is about as likely as marking up the parse tree and parts of speech for all your regular prose sentences. Presentational MathML is the only thing that matters; Semantic MathML is W3C semantic web wank.
- mkl 3y agoThe idea is the MathML is generated by a computer algebra system or similar which has all that data, not manually.
- Kwpolska 3y agoWhat if you do not have any computer algebra system in your pipeline? LaTeX can be written and read by actual humans, MathML cannot.
- throwaway290 3y agoYou can use latex to author mathml, like we everywhere use markdown to author HTML.
- Kwpolska 3y agoThe first hit in Google for "latex mathml converter" is https://temml.org/ https://temml.org/ . The list of supported LaTeX constructs looks fine, but the output… The example LaTeX converts to 67 lines of MathML. The vectors (arrows above B, l, E) are built like this: <mover> <mi>B</mi> <mo stretchy="false" style="transform:scale(0.75) translate(10%, 30%);">→</mo> </mover> But the hat above n is: <mover> <mi>n</mi> <mo stretchy="false" style="math-style:normal;math-depth:0;">^</mo> </mover> Markdown is great, but I can always take the HTML produced by a Markdown→HTML converter and edit it by hand, since HTML is human-readable and human-editable. MathML is neither. The output of MathML is also uglier than KaTeX’s, with wonky spacing. In Firefox, there’s an ugly space after all \d's (derivative sign). It’s better in Edgium, but there is still an ugly space in \d\vec{l}. If I need an intermediary tooling/format for math, I’d prefer beautiful LaTeX-esque output, and keep LaTeX code that wold be converted by KaTeX on the fly to whatever ugly HTML is required.
- Georgelemental 3y agoMathML is faster to render. KaTex is a lot faster than MathJax but the difference remains noticeable. (Firefox extension to force native MathML rendering: https://addons.mozilla.org/en-US/firefox/addon/native-mathml/ https://addons.mozilla.org/en-US/firefox/addon/native-mathml...)
- esperent 3y agoYou can pre-build katex, or render server side.
- xigoi 3y agoThat's better, but it generates a lot of markup, causing the sites to be very heavy (several megabytes). I know this because I'm using pre-rendered KaTeX to write my school notes, see for example: https://kmlinux.fjfi.cvut.cz/~blazead5/school/difr/ https://kmlinux.fjfi.cvut.cz/~blazead5/school/difr/ Notice that the page takes a while to load, even though it's mostly text.
- g8oz 3y agoIgalia is doing amazing work shipping native MathML support for Chromium based browsers. https://www.igalia.com/2023/01/10/Igalia-Brings-MathML-Back-to-Chromium.html https://www.igalia.com/2023/01/10/Igalia-Brings-MathML-Back-...
- tannhaeuser 3y agoMathML 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-project-is-completed/#new 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 https://www.w3.org/MarkUp/html3/maths.html
- the__alchemist 3y agoI 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.
- runarberg 3y agoThink of MathML like SVG. It is a target language which browsers understand. With SVG you can write it in hand, but most likely you are gonna use a special editor (Inkscape) or a library (d3). With MathML you can write your equations e.g. in libreOffice or pick a library like MathJax or TeXZilla. In fact I wrote a library my self which compiles a AsciiMath derived language to MathML, it was my first time writing a compiler, and it was an absolute joy targeting MathML. The mapping between DOM nodes and XML nodes is a perfect fit for the web as it allows my to implement DOM as a direct target (`mathup(expression).toString()` vs. `mathup(expression).toDOM()` and even `mathup(expression).updateDOM(parentNode)`. The documentation for MathML on MDN if fine actually, good enough for me to write a compiler. The structure of the language is much easier to compile to than LaTeX by nature of actually having a standard (as opposed to an implementation which functions as a standard). MathML is a unique fit for what it was intended to do, which is a targeting language which browsers understand.
- camdenreslink 3y agoKaTeX is really old (like 9 or 10 years?). So if it was going to kill MathML, it probably already did it.
- RyEgswuCsn 3y agoI 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?
- deleted 3y ago[deleted]
- rosebay 3y agoKatex is truly great. Fun trivia facts - one of its developers also played a core role in React (she is a legend)
- kerkeslager 3y agoIs there a way to get this as just a single JS file, so I don't have to use node? I can probably figure it out but if anyone already knows how it would save me some time. EDIT: Figured it out: https://unpkg.com/katex https://unpkg.com/katex
- Timon3 3y agoThey have a wonderful section on just this in their installation guide: https://katex.org/docs/browser.html#download--host-things-yourself https://katex.org/docs/browser.html#download--host-things-yo...
- kerkeslager 3y agoAh, nice. I'm glad to see it's an officially-supported way of doing things.
- mkl 3y agoThere have been quite a few past discussions of Katex: https://news.ycombinator.com/item?id=8320439 https://news.ycombinator.com/item?id=8320439 9 years ago, 98 comments. https://news.ycombinator.com/item?id=19475273 https://news.ycombinator.com/item?id=19475273 4 years ago, 40 comments. https://news.ycombinator.com/item?id=24742518 https://news.ycombinator.com/item?id=24742518 3 years ago, 87 comments.
- gwgundersen 3y agoI 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.
- ihodes 3y agoGreg's blog is a great example of Katex in the wild: http://gregorygundersen.com/ http://gregorygundersen.com/
- 3rd3 3y agoI wonder how does it render synchronously without needing to reflow the page?
- mkl 3y agoServer-side rendering will do that.
- 3rd3 3y agoSo this only refers to the server-side rendering mode, not in-browser rendering (which KaTeX supports too)?
- mkl 3y agoIf by "this" you mean "no reflowing", yes. If the maths is laid out client-side at run time, the exact dimensions of the formula are not known until the Latex code is interpreted.
- 3rd3 3y agoThanks. I was hoping there was a way to manipulate the DOM on the client before it is rendered, but this seems to be impossible with JS. Currently, I render various things during page load with NodeObserver. It mostly performs well on modern devices, but it can get sluggish on very large HTML pages (like 5MB+ of HTML code), so it looks like I have to resort to infinite scrolling with automatic unloading.
- chinaman425 3y ago[dead]
- the__alchemist 3y agoNice! 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.
- larodi 3y agoThe lib behind chatGpt rendering of latex script
- keithalewis 3y agoMathJax got a tune-up. It is much faster now
- moffkalast 3y agoIt may be fastest to render, but with that syntax I sure doubt it's fastest to write. It's barely human readable.
- CrazyStat 3y agoIt's standard LaTeX syntax. Almost everyone who writes a lot of math already knows it.
- moffkalast 3y agoAh yes why make something good when you can make it standard instead and force everyone bang their heads against the wall.
- CrazyStat 3y agoIs there another math typesetting language that you prefer?
- ssivark 3y agoIt’s about the same as typing out code when programming :shrug: That said, if you have a concrete proposal for a slicker alternative, I’m sure lots of folks would be curious.
- wiseowise 3y agoYou surely have a better standard written out somewhere, right?
- moffkalast 3y agoSure thing, a quick search yields Asciimath which seems at least at first glance as huge improvement in the syntax department: http://asciimath.org http://asciimath.org As for LaTeX in general, Markdown beats it soundly in most aspects.
- 3y ago
- BrandiATMuhkuh 3y agoWe use Katex extensively at Amy.app Being able to render latex super fast is very important for us as we use it for live tutoring. Shameless plug: We currently offer 2 free tutoring for Fractions and Calculus. Perfect to revise or even learn those topics. The cool thing is, Amy will find knowledge gaps from previous years/subjects as well. (No account need to try it out) Fractions: https://learn.amy.app?inviteCode=f2d7h https://learn.amy.app?inviteCode=f2d7h Calculus: https://learn.amy.app?inviteCode=zkjus https://learn.amy.app?inviteCode=zkjus
- xpe 3y agoIf you are able to write “shameless plug:”, you are probably also able to not write the commercial plug that came after that prefix. Your comment serves you, not the general audience here. Every action of the kind above degrades the core purpose of HN.* * It is not even necessary to appeal to the “if everyone did X” argument.
- mk12 3y agoYou can compare MathJax, KaTeX, and your browser's MathML support with this website I made: https://mk12.github.io/web-math-demo/ https://mk12.github.io/web-math-demo/
- xworld21 3y agoCool! 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/ https://fred-wang.github.io/MathFonts/mozilla_mathml_test/ (with Latin Modern, the TeX Gyre's, FiraMath – other fonts are still glitchy).
- mk12 3y agoOh interesting, I didn't realize that. I will try to look into that sometime (or would accept a patch if anyone else wants to).
- runarberg 3y agoNice. Do you accept PRs for other libraries. I wrote one myself a bit ago and wouldn’t mind seeing it there
- mk12 3y agoSure, if it's a viable alternative (e.g. can at least handle all the examples in the dropdown), I'd accept a PR to include it.
- Paul-Craft 3y agoNeat. Have you considered adding latex.js to the site?
- mk12 3y agoThanks. I hadn't heard of latex.js before, but I just looked it up now, and it says "Math is typeset using KaTeX."
- universemaster 3y agoI am using temml for MathML. MUCH smaller output than katex: https://temml.org/ https://temml.org/
- xigoi 3y agoLooks 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?
- photochemsyn 3y agoThis is also a great aid to learing LaTex. I wonder if anyone has ever tried to make an OCR system that generates the appropriate LaTex from an picture of an equation? Turns out the answer is yes: https://github.com/lukas-blecher/LaTeX-OCR https://github.com/lukas-blecher/LaTeX-OCR
- smohare 3y ago[dead]
- thangalin 3y agoA 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 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-WIt1cZYLm1MMx2FBG9KWzPIoWZMKu_&t=12 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).
- vrglvrglvrgl 3y ago[dead]
- giraj 3y agoThe 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 https://github.com/KaTeX/KaTeX/issues/219), but I wouldn't hold my breath.
- xeonmc 3y agoWait, MathJax supports tikz?
- bmacho 3y agoAsciiMath has AsciiSvg: http://www1.chapman.edu/~jipsen/svg/asciisvgeditor.html http://www1.chapman.edu/~jipsen/svg/asciisvgeditor.html (Well, no, rather the other way around, but sister projects.)
- lilgreenland 3y agowhat is the advantage of tikz over SVG?
- alephaleph 3y agomathematician-writable.
- runarberg 3y agoThis is a bold claim. In theory any library that defers rendering to MathML should be faster (including my own MathUp https://runarberg.github.io/mathup/ https://runarberg.github.io/mathup/). Has anyone run benchmarks to test this claim?
- garbagecoder 3y agoI 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.
- garganzol 3y agoI 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.