Math/LaTeX support for rustdoc, now with MathML

I'd like to propose (again) adding LaTeX support to rustdoc. This has been a long requested feature with several attempts over the years. Many of the concerns and roadblocks to enabling this have centered around what system to use (e.g. MathJax or KaTeX), making it work offline, and not bloating docs with tons of JavaScript. MathML and the <math> element have been available in all of the major browsers since Jan 2023. I believe supporting MathML will solve the previous concerns around KaTeX and MathJax in regards to offline viewing and file sizes.

I have a proof of concept here: GitHub - J-M0/rust at rustdoc-math. It's based the latex2mathml crate with a few patches from me.

Please take a look and let me know what you think.

9 Likes

The latex2mathml crate is unmaintained (laat release 5 years ago), so probably not a good idea to add a rustdoc dependency on it.

The katex crate is another option, though it means adding a JS interpreter as a dependency to Rustdoc.

1 Like

Yeah, it's not great, but I needed to start somewhere. If I can't get my fixes upstreamed, maybe I'll have to fork it.

That was one of my main motivators for proposing this. Past proposals all stalled at the idea of adding KaTeX as a dependency. My proposal is pure Rust and uses web standards which I thought would make adoption more palatable.

What would be the next steps for getting more momentum on this? Should I open an issue in rust-lang/rust?

To be clear, the crate I linked uses KaTeX for server-side rendering, the output can be configured to pure standards-compliant MathML with no JS

There’s a working fork of latex2mathml that I’ve been looking into.

5 Likes