A new release of Discourse Math

AI-generated summary

sam announces a major upgrade to the Discourse Math plugin, upgrading MathJax from version 2.x to 4.1, bringing years of new features and improvements. The update improves compatibility with LLM outputs by supporting LaTeX-style inline math (e.g., e=mc^2) and offers greater configurability—users can choose between MathJax or KaTeX rendering and disable () handling if desired. The post includes visually rich examples showcasing MathJax 4.1’s capabilities, such as the quadratic formula, Euler’s identity, Maxwell’s equations, a colorful integral, an infinite series, and the new \U{} macro for inserting Unicode characters (e.g., ⊞). Simon_Manning reports display issues on iOS PWA due to web font blocking (via Firefox Focus), causing misaligned or clipped math content. sam responds that while web font blocking isn’t ideal, Discourse Math supports SVG rendering as an alternative for sites with users who block custom fonts—though it comes with trade-offs and isn’t recommended as default. The update also simplifies future plugin upgrades, making maintenance easier for administrators.

I am very happy to announce a major upgrade to our Discourse Math plugin!

Special thanks goes to @mcmcclur who helped test and build much of the new and upgraded discourse-math.

This is a very significant change – we upgraded all the way from version 2.x up to version 4.1 of MathJax, catching up with years of features and advances.

Additionally, we amended our design to make it significantly easier to upgrade the plugin in the future.

Our new iteration is much friendlier to LLM outputs, which prefer using LaTeX-style math inlines such as e=mc^2.

The plugin remains very configurable – you can use MathJax or KaTeX for math rendering and even disable the handling of \( if you wish.


Some Fun Examples to Show Off MathJax 4.1

The Quadratic Formula:

x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}

Euler’s Identity:

e^{i\pi} + 1 = 0

Maxwell’s Equations:

\nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t}

A Colorful Integral:

\int_{-\infty}^{\infty} {\color{red}e}^{{\color{blue}-x}^{\color{green}2}} \, {\color{orange}dx} = {\color{purple}\sqrt{\pi}}

An Infinite Series:

\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}

New in MathJax 4 – The \U{} Macro:

You can now insert Unicode characters directly into TeX input! For example:

A \U{229E} B = C

$$A \U{229E} B = C$$

This produces U+229E (⊞, a squared plus).

32 Likes

Looking at this post in a PWA on iOS, I was seeing the examples at wrong sizes/positions and being clipped as shown:

I’ve confirmed that disabling the Firefox Focus extension (content blocker) prevented this from happening. Looking closer, unsurprisingly it’s the setting for blocking web fonts.

I suspect people blocking web fonts isn’t something you want to cater for but figured I’d bring it up since it looks weirdly almost right but off in various places.

1 Like

We actually do, you can choose svg rendering as a site owner, it comes with some downsides so I am not sure it should be default but you are hosting a site that has users that refuse custom fonts you could use this feature.