Skip to content

Conversation

@jeanas
Copy link

@jeanas jeanas commented Nov 29, 2025

Letting MathJax scrape the output HTML for math delimiters makes it awkward to write complex formulas because characters with a special meaning in Markdown must be escaped. This commit implements a new output.html.math option that uses the support for parsing $...$ and $$...$$ in Markdown introduced in pulldown-cmark 0.11.0. The old option output.html.mathjax-support is left for backwards compatibility.

pulldown-cmark renders formulas into <span> tags with special classes, so we have to configure MathJax to look for these instead of textual delimiters. The code for this was helpfully provided by David Cervone on https://groups.google.com/g/mathjax-users/c/6cMuCH2dgmQ.

The latest version of MathJax 4 is used rather than MathJax 2.7.1 like the mathjax-support option, because the way to do this configuration has changed between MathJax 2 and MathJax 3, I'm not sure how to do it on MathJax 2, and it is an old version anyway. The Cloudflare CDN doesn't seem to work for MathJax 4, so it uses the jsdelivr.net one recommended by the MathJax documentation. In the future, it would be good to use a bundled version of MathJax by default and/or make the CDN URL configurable.

Fixes #1402, fixes #662, fixes #400

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Nov 29, 2025
…-lang#400)

Letting MathJax scrape the output HTML for math delimiters makes it
awkward to write complex formulas because characters with a special
meaning in Markdown must be escaped. This commit implements a new
`output.html.math` option that uses the support for parsing `$...$`
and `$$...$$` in Markdown introduced in pulldown-cmark 0.11.0. The old
option `output.html.mathjax-support` is left for backwards compatibility.

pulldown-cmark renders formulas into `<span>` tags with special classes,
so we have to configure MathJax to look for these instead of textual
delimiters. The code for this was helpfully provided by David Cervone on
<https://groups.google.com/g/mathjax-users/c/6cMuCH2dgmQ>.

The latest version of MathJax 4 is used rather than MathJax 2.7.1
like the mathjax-support option, because the way to do this configuration
has changed between MathJax 2 and MathJax 3, I'm not sure how to do
it on MathJax 2, and it is an old version anyway. The Cloudflare
CDN doesn't seem to work for MathJax 4, so it uses the jsdelivr.net
one recommended by the MathJax documentation. In the future,
it would be good to use a bundled version of MathJax by default
and/or make the CDN URL configurable.

Fixes rust-lang#1402, fixes rust-lang#662, fixes rust-lang#400
@jeanas jeanas changed the title Support dollar math syntax (fixes #1402, #662, #400) Support dollar math syntax Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: waiting on a review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MathJax Support works unreliable Mathjax subscript colliding with markdown italics Improve MathJax support by enabling $$ for math equations

2 participants