RaTeX: KaTeX-compatible LaTeX rendering engine in pure Rust
125 points
3 days ago
| 19 comments
| ratex.lites.dev
| HN
Hendrikto
5 hours ago
[-]
I used LaTeX for approximately 10 years, for little things to relatively complex, including my bachelor’s and master’s theses. It never felt natural at reliable or consistent. Every customization required weird \makeatletter \makeatother hacks and was very brittle. Everything seemed more complicated than necessary and hard to grok, with weird interdependencies and interactions.

There are probably good reasons for all of that, but it is just both bad DX and bad UX. It feels like you need to be a hardcore LaTeX expert or consult with one, in order to accomplish the most mundane things. Especially in a reliable way, that won’t break upon making seemingly unrelated changes, or won’t break other things itself.

I used Typst for a few weeks. It already feels much more understandable, consistent, hackable, and customizable. I guess that is the difference between an ad hoc macro system and an actually thought through programming language.

The only drawback I can see is the ecosystem being smaller and less mature. That is, however, counteracted by being able to do things on your own, without immersing yourself deeply in LaTeX for years. Also, it will improve with time.

LaTeX is great, don’t get me wrong. But its heritage and historical baggage is really dragging it down.

reply
ngriffiths
4 hours ago
[-]
It's kinda fascinating how dominant LaTeX is, how nice its output is, how respected Knuth is as a computer scientist, and at the same time how totally awful it feels to use it. Hard to figure out how it can be so good and so bad at once.

Posts/discussion I found interesting:

- http://www.goodmath.org/blog/2008/01/10/the-genius-of-donald...

- https://tex.stackexchange.com/q/24671

- https://news.ycombinator.com/item?id=15733381

In particular it's interesting how people seem to think TeX itself is actually quite nice to use but its popularity and LaTeX packages created a huge mess of a system.

reply
ajkjk
3 hours ago
[-]
Well -- TeX is "80s good". We've gotten better at designing ergonomic software since and it really doesn't meet the modern standard. But it's good enough for most people, and sufficiently hard to replace, that it has stuck around.

Added to that, academics specifically are more willing to suffer old crufty stuff than software engineers tend to be. After all their job is to absorb fields of material whether good or bad, and the technology tends to be lagging behind the bleeding edge in many subfields anyway so TeX doesn't even necessarily stand out.

reply
queuebert
25 minutes ago
[-]
> TeX is "80s good"

Bingo. Compared to troff and what preceded, TeX was amazing just in its usage. But its real value was in the quality of its typesetting. Knuth put a lot of effort into the beauty and historical correctness of the output, so much so that it was solving optimization problems to calculate line breaks. MS Word still can't break a line properly in 2026.

reply
bb88
2 hours ago
[-]
There was a point in the 1990's where microsoft word wasn't truly WYSIWYG. IIRC it was like an infinite page and the line breaks and page breaks were "estimates"

Further many docs from that era are plagued with abandonware.

TeX did one thing well for an era when often the only interface to the machine was over a Xyplex terminal server connecting to a tty at 9600 baud.

reply
alphabeta3r56
19 minutes ago
[-]
The dichotomy comes from conflating the TeX syntax with tex macro system, both use backslash.

The backslash based syntax allows for some really powerful typesetting which is far above anything that exists today. At the same time, the use of backslash-based langauge right to the bottom in terms of macros is what is causing the frustration.

Typst kind of solves that by having backslash based syntax implemented in Rust.

reply
forlorn_mammoth
4 hours ago
[-]
part of the challenge is the inherent irreducible complexity of the domain. "Make text look good on page" leaves lots of details unspecified.

another part is many people built their own solution to their own corner of this domain, and not all of them had the deep appreciation for how the rest of the TeX system works.

I hear similar complaints about "Make web page look good", which is popular but also a huge mess of a system.

reply
zem
2 hours ago
[-]
to be fair to knuth, he had nothing to do with latex. it's conceivable that one could start over from plain tex and build up a different high level system. (then again perhaps some of the brittleness of latex comes from unavoidable issues with the tex layer; lamport is a very respected computer scientist too!)
reply
einpoklum
1 hour ago
[-]
You're linking to posts from 15 and from 18 years ago. And the post from 2011 is about how Donald Knuth wrote TeX (not LaTeX) in the early 1980s. While TeX and LaTeX have fundamental design flaws, it is much less awful to use them these days, with a rich selection of rather robust packages available, that vastly reduce the need to go into hard-core LaTeX programming yourself.

I won't lie: It takes getting used to and you need to learn a lot if you want to achieve fancy complex typesetting effects. But - it's not half as inconvenient as it once was.

reply
huijzer
4 hours ago
[-]
I’ve been using Typst for years now. Wrote my PhD thesis in it [1] as well as a book. Works great; can’t recommend it enough. I usually barely use plugins because it’s either already included or pretty easy to write a bit of code yourself

[1]: https://github.com/rikhuijzer/phd-thesis

reply
quantummagic
4 hours ago
[-]
Didn't see a pdf of your thesis, except on your web-site[1]. But the version there (at least as it renders on my machine), has numerous formatting issues. For one egregious example, look at the letter spacing in the title and legend of Figure 2.2 (page 27): "civilia ns", "Pe rs ona lity s core". I'm sure the content is great, but using it as an example of Typst prowess, seems ill-advised.

[1] https://huijzer.xyz/files/f72fa09561f20162.pdf

reply
ForceBru
3 hours ago
[-]
I don't see any issues with the title of Figure 2.2, but the legend and the x-axis label have weird letter spacing indeed. It seems like images like this are standalone (https://github.com/rikhuijzer/phd-thesis/blob/main/images/pe...) and probably aren't generated by Typst. So perhaps the weird spacing is not Typst's fault.
reply
bscphil
1 hour ago
[-]
Looks like the SVG was converted from an EPS file, and the resulting SVG contains individual glyph positions (advances) for the characters in "Personality score", but it doesn't specify a valid font, probably because the font name was mangled in the original EPS file (which is pretty typical).

So whether the resulting file looks right depends on whether the rendering engine chooses the correct font. Looks like it's supposed to be Nimbus Sans or something metric compatible with that, but the serif font chosen by Typst looks obviously wrong.

reply
dev_hugepages
3 hours ago
[-]
I took a look at the repo and it's probably the fault of the the SVG of the graphs, not of typist itself. Now, you could have used typst libraries to generate the graphs but back then (2 years ago I think?) it was probably a struggle.
reply
NewsaHackO
3 hours ago
[-]
Yea, I don’t see a point of criticizing minutiae from a thesis that has already been accepted, but I agree, the graphs look out of place and generally not in the same style of the other text. Also, I guess I am just really used to latex’s font, it just automatically gives an academic style that I do t get from this. Again, pure personal bias.
reply
dev_hugepages
1 hour ago
[-]
If anyone else is looking to make graph with typst, this can be done with https://cetz-package.github.io/ -- which is inspired by Tikz from the LaTeX world -- or https://lilaq.org/ which seems more appropriate for this type of data plotting
reply
abdullahkhalids
59 minutes ago
[-]
Someone willing to use AI to convert the thesis to Latex so we can compare?
reply
auggierose
4 hours ago
[-]
How about adding a PDF release ;-)
reply
bee_rider
5 hours ago
[-]
I like LaTeX for the most part (I have had to use some weird hacks but usually once they are done they are stuck in a macro and turned ignorable).

But I think the main things it has going for it are that it: produces nice output, and all the journals accept it. Does there exist a tool that renders Typist to LaTeX? That could play nicely with the existing ecosystem.

reply
echoangle
1 hour ago
[-]
Pandoc can convert LaTeX to Typst and back but probably only for simple snippets without any obscure packages. It’s not lossless.
reply
noelwelsh
5 hours ago
[-]
This mirrors my experience.

It's worth noting that TeX was developed in the same time period that the details of lexical scope were being nailed down by Guy Steele in the Rabbit compiler for Scheme. It's not that TeX is an ad hoc system; it's more the case that people didn't actually know how to implement a better system at the time.

reply
groos
4 hours ago
[-]
'People' in this case were Don Knuth (TeX) and Leslie Lamport (LaTeX). Both are Turing Award winners.
reply
tialaramex
4 hours ago
[-]
That's true. Do you know who else won a Turing Award? Tony Hoare.

What is Tony famous for? Well, lots of things, including his very important comparison sort algorithm Quicksort, but, in this context how about the Billion Dollar Mistake ? That's a pretty nasty booboo in many programming languages for which Tony blames himself because it was his idea.

Like your parent said, TeX shipped a long time ago and we learned a lot since then, it is not a surprise that we know how to do better today, in fact it would be a serious black mark for Computer Science if we couldn't.

reply
drob518
3 hours ago
[-]
Which means what, exactly.
reply
CJefferson
3 hours ago
[-]
Not a latex post with someone talking about typst. Come back when the html output works. Not having good accessible output was more acceptable back when Tex was invented, it definitely isn’t now, and they made a new system and somehow got this worse then modern latex.
reply
savq
1 hour ago
[-]
Typst does have have accessibility features.[1]

I don't worry too much about HTML output still being WIP. Even if TeX had a massive head start, Typst has a good development speed, and a little bit of slope makes up for a lot of y-intercept.

[1]: https://typst.app/docs/guides/accessibility/

reply
ashivkum
3 hours ago
[-]
as long as the arXiv doesn't accept Typst, it's never going to be a real alternative to LaTeX. and the arXiv maintainers seem either hostile or indifferent to Typst
reply
tcfhgj
1 hour ago
[-]
https://www.youtube.com/watch?v=zNZlAbCOjd8

doesn't appear indifferent or hostile

reply
ashivkum
2 minutes ago
[-]
haven't watched it but my only data point for that claim is this post: https://www.reddit.com/r/typst/comments/1dcu3p8/i_contacted_...
reply
alterom
1 hour ago
[-]
TL;DW: there is interest in supporting Typst, but there are roadblocks:

* Higher priority work currently being done on ArXiV (moving from Perl to Python/cloud)

* No "standard" Typst distro

* Support team needs to be re-trained for a new language

* Persistency: TeX has 30+ years of history; will Typst be around in 30 years? Will current code compile? Will existing documents be supported?

reply
abdullahkhalids
4 hours ago
[-]
Latex is used because writing math in latex is very good, and despite how everything else (like tables and figures) is so bad.

That's why people take the math subset of latex and use it in other contexts - exactly like this product.

reply
davrosthedalek
5 minutes ago
[-]
I agree that tables are not great, but figures? Seems to work pretty well, better than word for sure.
reply
sombragris
3 hours ago
[-]
Not necessarily my experience. I wrote (and I am writing) several academic documents with it. There are its quirks, of course, but with good classes such as memoir, I don't feel the need to do a lot more than basic customization in the preamble. Still is a good tool for me.
reply
eddieh
1 hour ago
[-]
For me the memoir class made LaTeX worse. The titlesec package is more customizable, easier to use, and reduced the size of the preamble significantly.
reply
troyvit
4 hours ago
[-]
Huh. My special lady friend is in the process of finishing up her thesis using LaTeX after ditching LibreOffice. It was nightmare for some of the same reasons: bad UX, bad portability and crippling bugs. There was a ramping up period, and she had an out of date GitHub repo to help her, but she is incredibly happy that she switched. Collaboration could be smoother I guess.
reply
_blk
1 hour ago
[-]
Agree. Love latex and LLMs made it a lot more accessible but DX wise it's still a huge hassle, esp when it feels that it's easier to just generate HTML and PDF it from there.. I mean the best workflow is probably to write markdown, take a site you like, pick a color scheme and have Claude do the transformation along with a script to make it repeatable
reply
wmkn
4 hours ago
[-]
Yups, I love the idea of LaTeX, LaTeX itself not so much.
reply
adamnemecek
2 hours ago
[-]
+1 for Typst being amazing.

I can actually like write my own functions when I need to. I don't think I have ever written a LaTeX macro without having to look up a lot of stuff.

reply
LoganDark
5 hours ago
[-]
I hope Typst eventually gets some equivalent to tkz-euclide, as I've never seen anything even remotely comparable.
reply
xienze
4 hours ago
[-]
> The only drawback I can see is the ecosystem being smaller and less mature.

This seems like the _perfect_ use for an LLM: systematically porting over as much of the "ecosystem" to Typst as possible. Is anyone doing that?

reply
luz666
4 hours ago
[-]
Two hours ago a coworker told me that he let an llm port his latex template to typst. According to him, it was perfect.
reply
esafak
5 hours ago
[-]
Is Typst appropriate for web apps; e.g., the input forms here?
reply
noelwelsh
4 hours ago
[-]
Nope. Typst's primary output is PDF, and it is a stand-alone binary. It's a replacement for most uses of LaTeX to produce documents. It is not a replacement for this project, which focuses only on rendering LaTeX math code and can be embedded in multiple different runtimes.
reply
krater23
5 hours ago
[-]
I know exactly what you mean, and that paired with a community that is absolutely sure that they know exactly how things need to be done and everyone that wants it in another way is dumb.
reply
magnio
5 hours ago
[-]
You want Typst: https://github.com/typst/typst

It's like the JSX of Latex: markup in a programming language, not a programming language pretends to be markup.

reply
DoctorOW
4 hours ago
[-]
> I used Typst for a few weeks. It already feels much more understandable, consistent, hackable, and customizable. I guess that is the difference between an ad hoc macro system and an actually thought through programming language.

> The only drawback I can see is the ecosystem being smaller and less mature. That is, however, counteracted by being able to do things on your own, without immersing yourself deeply in LaTeX for years. Also, it will improve with time.

reply
azverev
5 hours ago
[-]
Pixel-diff CI against a golden suite is the right discipline for layout libraries, and it's noticeably rare in the JS ecosystem.

Most "matches KaTeX" claims I've seen in the wild rely on screenshot eyeballing, which collapses on edge cases like spacing primes, integral subscripts, and matrix delimiters that scale.

One thing I'd be curious about: how are font fallbacks handled when the same Rust core ships to platforms with different system font availability?

KaTeX bundles fonts and assumes they load cleanly; CoreGraphics and Skia bring their own glyph caches and metrics.

Does the display list carry metric snapshots from the host text shaper, or does the core compute layout from a bundled metric file independent of the backend?

reply
tabbott
5 hours ago
[-]
It's interesting to me that the page doesn't describe the size of the rust binary (relevant for mobile app use cases where you would need to add the Rust binary to your app) or performance.

The webpage also does read like it was at least heavily LLM assisted, which makes it a bit hard to trust it.

That all said, this is definitely something I'd be interested in using for Zulip if is indeed going to be a well maintained open source project.

(We currently have a node server component that the Zulip server runs only the render LaTeX).

reply
thangalin
2 hours ago
[-]
When developing KeenWrite[1], I opted to support only plain TeX. This is because I wanted math typesetting to work for either LaTeX or ConTeXt[2]. To render TeX in the preview panel, I forked NTS[3] into a highly optimized Java version. The lack of cross-platform event-based UI system is what kept me from writing the entire application in Rust (some ten years ago). Has the Rust ecosystem improved with respect to Markdown processing, event-based UIs, and now TeX support?

[1]: https://keenwrite.com/screenshots.html

[2]: https://wiki.contextgarden.net

[3]: https://ctan.org/tex-archive/systems/nts

reply
nixpulvis
1 hour ago
[-]
I'm not sure how much overlap there is between this project and Tectonic [1], but that's what I use personally for local PDF generation, and it's also using a good bit of Rust.

Just thought I'd mention since it's related and I really like the project.

[1] https://github.com/tectonic-typesetting/tectonic

reply
xworld21
3 hours ago
[-]
I suppose somebody has to ask (and most likely complain) about this: what does RaTeX do for accessibility? I gather that it produces images. I checked the demo, and there's not even an alternative text or an ARIA label, so this seems completely invisible to anybody relying on a screen reader. This is quite a step backwards compared to modern LaTeX, which can now tag equations with MathML within the PDF, or using MathJax, or any other serious tool targeting HTML, like pandoc or LaTeXML.

Is accessibility anywhere on the roadmap for RaTeX?

reply
nkmnz
3 hours ago
[-]
AFAIK, KaTex has accessibility via MathML included, but it doesn't provide an export as image - it rather renders as html. So why would you want the utility that you use to render an additional image to take care of something that KaTeX already does?
reply
xworld21
2 hours ago
[-]
True, my knee jerk reaction came from seeing this run in the browser... but that does not change the question. RaTeX advertises itself as a renderer for native apps, but how are those apps supposed to implement accessible controls? Does RaTeX offer anything towards that?
reply
nkmnz
2 hours ago
[-]
Honestly, I have no idea how native apps for desktop or mobile handle accessibility. There is katex-rs[0] that outputs html and mathML. I'd assume the two could work together and the mathML would be fed to whatever the screen reader receives instead of the image?

On a related note: is mathML more accessible than an AI generated text of how a human would read the mathematical or chemical formula?

[0] https://crates.io/crates/katex-rs

reply
xworld21
1 hour ago
[-]
> On a related note: is mathML more accessible than an AI generated text of how a human would read the mathematical or chemical formula?

Yes, screen readers would typically allow you to navigate the formulas in ways that are more sophisticated than text (not to mention the issues with translating to Braille, which I don't claim to understand, at all). In fact alternative text is a poor substitute for structured information about the formula, which is what you get with MathML.

Plus, the MathML + screen reader combo is deterministic and debuggable, as opposed to OCR'ing an image.

> There is katex-rs[0] that outputs html and mathML. I'd assume the two could work together and the mathML would be fed to whatever the screen reader receives instead of the image?

Maybe! You are parsing the input twice, but it could be a pragmatic solution. I don't know myself how native apps are supposed to expose MathML to screen readers (or if it is even possible without an embedded browser!).

reply
DominikPeters
6 hours ago
[-]
The landing page (clearly to a large part written by LLM) does not mention that both KaTeX and mathjax can render to SVG in node. This wasm approach might still be lighter, but the advantage is not as clear as the page makes it seem. (It also contains LLM dishonesties like that the bundle size is 0 KB.)
reply
nicoburns
4 hours ago
[-]
Where this clearly wins is native rendering use cases where there is no browser or JS engine involved at all.
reply
stusmall
3 hours ago
[-]
> It also contains LLM dishonesties like that the bundle size is KB

That one jumped out to me too. The phrasing is so wiggly but technically correct it feels intentional. When I saw it I didn't blame it on the LLM, which is worse.

Otherwise it's a super cool looking project

reply
rafram
4 hours ago
[-]
If RaTeX gets to brag about having a 0 KB JS bundle, the other libraries should be able to say they have 0 KB WASM bundles!
reply
Rochus
2 days ago
[-]
Interesting. Reminds me of Typst (both implemented in Rust and replacing TeX to some degree) and Microtex.
reply
jason_s
5 hours ago
[-]
I greatly prefer Typst's clean architecture than TeX's macro-centric hell pounded into passable utility.
reply
ocimbote
4 hours ago
[-]
I've discovered typst in the last year and used to build a resume and cover letter template that feeds from a YAML file.

After a bit of tinkering and understanding the idiosyncracies of Typst, the joy of having reliable, consistent, beautiful, data-driven resumes and cover letters is not measurable. It basically lifted any barrier to applications, while whatever I had before I had always considered a burden.

On top of that, I can add hiring process data directly to the yaml file to run further analysis.

Can LaTeX do this? Most probably, but the learning curve is the difference.

reply
evilmonkey19
5 hours ago
[-]
I have been using Typst for creating notes and it is an awesome tool. I use it to create notes on welding for my students. It makes my life so much easier compared to badsoft and its not-word-ing (you understand me).
reply
danborn26
2 hours ago
[-]
A native Rust alternative to KaTeX is a welcome addition. This should make math rendering much easier to integrate into Rust based static site generators.
reply
umvi
5 hours ago
[-]
We recently switched from Node.js + Mathjax for rendering latex to Goja (https://github.com/dop251/goja) + Mathjax, and surprisingly it worked really well. We did this because the app is already 99% golang, and this allows us to eliminate the remaining non-go pieces, greatly simplifying the SBOM. And yes, we tried go-latex, but it's not nearly as feature complete as Mathjax. Not to mention using goja + Mathjax adds 10MB to binary size while Node.js adds 200MB+
reply
jedberg
2 hours ago
[-]
I don't know why but this chain amuses me: RaTeX -> KaTeX -> LaTeX.

I guess it shows how everyone loves but hates LaTeX and is always trying to bolt on that one last thing that will make it good.

reply
blenderob
2 hours ago
[-]
Aren't these 3 different implementations with totally different use cases? Katex is latex-like implementation for web. Ratex is really 'rewrite katex in rust'. I don't understand what is getting "bolted on" to what here.
reply
mrichman
4 hours ago
[-]
I switched to Typst a year ago and never looked back
reply
marvinified
4 hours ago
[-]
Interesting! Would love to see how RaTeX evolves.
reply
IshKebab
49 minutes ago
[-]
I wish it was standard for projects to say the extent to which they were vibe coded, in the same way that they give a license.
reply
Piterniel
5 hours ago
[-]
> JS bundle (typical) 0 kB JS (core is WASM)

I guess you should mention how much is WASM, right?

reply
TheRealPomax
3 hours ago
[-]
I am so confused. There's already a native version of LaTeX... it's... it's LaTeX. Why would a Rust implementation need to match KaTeX instead of properly implementing a real (and modern, so unicode-out-of-the-box) TeX engine, that LaTeX (which is a set of convenience macros) then trivially runs on top of?
reply
red_trumpet
1 hour ago
[-]
Btw, the unicode-out-of-the-box version of LaTeX is called LuaLaTeX and ships with TeX Live.
reply
flakiness
2 hours ago
[-]
> JS bundle (typical) 0 kB JS (core is WASM)

Hello?

Trolling aside, I found this kind of Rust-powered typeset modernization promising. I used Typst and liked it. This one would have its own niche too.

reply
colechristensen
5 hours ago
[-]
Anybody embed it in a markdown renderer yet?
reply
ceayo
3 hours ago
[-]
I'm sorry but the only thing that truly understands TeX, is, and will forever be, TeX.
reply
flossly
57 minutes ago
[-]
And 64kb should be enough for anyone.
reply