# Math/LaTeX support for rustdoc, now with MathML

**URL:** <https://internals.rust-lang.org/t/math-latex-support-for-rustdoc-now-with-mathml/22463>\
**Category:** tools and infrastructure\
**Created:** [February 25, 2025, 12:33am UTC](https://internals.rust-lang.org/t/math-latex-support-for-rustdoc-now-with-mathml/22463 "2025-02-25T00:33:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![J-M0](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/j-m0/32/8672_2.png) [@J-M0](https://internals.rust-lang.org/u/J-M0)\
**Post date:** [February 25, 2025, 12:33am UTC](https://internals.rust-lang.org/t/math-latex-support-for-rustdoc-now-with-mathml/22463/1 "2025-02-25T00:33:54Z")

</div>

I'd like to propose (again) adding LaTeX support to `rustdoc`. This has been a [long requested](https://github.com/rust-lang/rust/issues/12989) feature with [several](https://github.com/rust-lang/rust/issues/34261)[attempts](https://github.com/rust-lang/rust/issues/97543) [over](https://github.com/rust-lang/rust/issues/16300) the [years](https://github.com/rust-lang/rust/pull/17390). 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](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math) 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](https://github.com/J-M0/rust/tree/rustdoc-math). It's based the [latex2mathml crate](https://crates.io/crates/latex2mathml) with a few patches from me.

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

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)\
**Post date:** [February 25, 2025, 6:08am UTC](https://internals.rust-lang.org/t/math-latex-support-for-rustdoc-now-with-mathml/22463/2 "2025-02-25T06:08:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jules-Bertholet](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jules-bertholet/32/10671_2.png) [@Jules-Bertholet](https://internals.rust-lang.org/u/Jules-Bertholet)\
**Post date:** [February 25, 2025, 6:20am UTC](https://internals.rust-lang.org/t/math-latex-support-for-rustdoc-now-with-mathml/22463/3 "2025-02-25T06:20:24Z")

</div>

The [`katex` crate](https://crates.io/crates/katex) is another option, though it means adding a JS interpreter as a dependency to Rustdoc.

---

<div class="post-metadata">

**Author:** ![J-M0](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/j-m0/32/8672_2.png) [@J-M0](https://internals.rust-lang.org/u/J-M0)\
**Post date:** [March 3, 2025, 3:42pm UTC](https://internals.rust-lang.org/t/math-latex-support-for-rustdoc-now-with-mathml/22463/4 "2025-03-03T15:42:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![J-M0](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/j-m0/32/8672_2.png) [@J-M0](https://internals.rust-lang.org/u/J-M0)\
**Post date:** [March 3, 2025, 3:43pm UTC](https://internals.rust-lang.org/t/math-latex-support-for-rustdoc-now-with-mathml/22463/5 "2025-03-03T15:43:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![J-M0](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/j-m0/32/8672_2.png) [@J-M0](https://internals.rust-lang.org/u/J-M0)\
**Post date:** [March 3, 2025, 3:45pm UTC](https://internals.rust-lang.org/t/math-latex-support-for-rustdoc-now-with-mathml/22463/6 "2025-03-03T15:45:24Z")

</div>

What would be the next steps for getting more momentum on this? Should I open an issue in [rust-lang/rust](https://github.com/rust-lang/rust)?

---

<div class="post-metadata">

**Author:** ![Jules-Bertholet](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jules-bertholet/32/10671_2.png) [@Jules-Bertholet](https://internals.rust-lang.org/u/Jules-Bertholet)\
**Post date:** [March 3, 2025, 4:07pm UTC](https://internals.rust-lang.org/t/math-latex-support-for-rustdoc-now-with-mathml/22463/7 "2025-03-03T16:07:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![notriddle](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/notriddle/32/14082_2.png) [@notriddle](https://internals.rust-lang.org/u/notriddle)\
**Post date:** [March 4, 2025, 5:44am UTC](https://internals.rust-lang.org/t/math-latex-support-for-rustdoc-now-with-mathml/22463/8 "2025-03-04T05:44:40Z")

</div>

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

> **[GitHub - tmke8/math-core](https://github.com/tmke8/math-core)**
>
> Contribute to tmke8/math-core development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [August 26, 2026, 5:44am UTC](https://internals.rust-lang.org/t/math-latex-support-for-rustdoc-now-with-mathml/22463/9 "2026-08-26T05:44:51Z")

</div>

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.
