Discourse Math

:discourse2: Summary Discourse Math uses MathJax (default) or KaTeX to render maths in your Discourse forum.
:hammer_and_wrench: Repository Link https://github.com/discourse/discourse-math
:open_book: Install Guide How to install plugins in Discourse

Enabling Math

The Math plugin can be enabled from its settings, accessed from your admin/plugins page:


Once enabled, you can render inline math by wrapping with a single $ like so: $E=mc^2$.

You can render blocks of maths by wrapping with $$

\sqrt{(-1)} \; 2^3 \; \sum \; \pi

Discourse Math uses a heuristic to ensure that sentences such as: “I spent 20$ and another 100$” do not get converted.

When using MathJax, you can also enable asciimath processing which uses % as a delimiter: %E=mc^2%

Site Settings

  • See all relevant site settings by searching your admin settings for “math”
Name Description
discourse math enabled Enable Discourse Math plugin (will add special processing to $ and $$ blocks)
discourse math provider Default math rendering provider [mathjax/katex]
discourse math zoom on hover Zoom 200% on hover (MathJax only)
discourse math enable accessibility Enable accessibility features (MathJax only)
discourse math enable asciimath Enable asciimath (will add special processing to % delimited input) (MathJax only)

:discourse2: Hosted by us? This plugin is available on all of our hosting tiers Math | Discourse - Civilized Discussion


Hi, the Math plugin seems to rely on the frontend for rendering. Therefore, our email users cannot receive the rendered math formula.
Is there any way to solve this problem?

Technically, yes… but it is tricky. We would need to load mathjax in mini racer (or node) simulate the DOM and render to an SVG.

I am sure it was done before by some people but can not find easy examples in the wild that are maintained. Probably worth testing if the node package even works for starters.


Is there a way to use MathJax 3 instead? It’s much smaller and can therefore reduce load times and improve page speed.

What’s New in MathJax v3.0 — MathJax 3.2 documentation

I tried switching the URL, but I don’t know exactly which version to pick from the modular build.

1 Like

You might be interested in @sam’s reply to my query a few months back regarding plans to update the plugin to MathJax 3:

Absolutely open to it, if someone feels like helping out I would be delighted.

As I’d tracked down in that thread, because MathJax 3 handles its config file differently than MathJax 2.x does, upgrading this plugin will require more than just changing the URL.


artificial intelligence gives answers in latex format. I wrote a prompt to convert this latex format to mathjax format, but the prompt is not always implemented and responds in latex format. When I wrote my problem to the openai community, the following suggestion came.

"I decided it wasn’t even worth the effort of cluttering up a system prompt, when I could just do the following on my end with the results:

    translateLaTex = (val: string): string => {
        if (val.indexOf("\\") == -1) return val;

        return val.replaceAll("\\(", "$")//
            .replaceAll("\\)", "$")//
            .replaceAll("\\[", "$")//
            .replaceAll("\\]", "$");

Can you apply this solution in the next update?

1 Like

I like this idea, agree latex can be annoying in AI replies and system prompting out if it is hard. Double so cause GPT4o is fine tuned on latex. Totally support making some sort of PR with a switch to support “latex mode” if you check a box in site settings.

1 Like

I don’t know if I’m talking about same thing, but for me this worked. I don’t use any really difficult formulas, though.

You fully understand MathJax and generate it.

When presenting mathematical expressions, use the following rules:
1. For inline mathematical expressions, use single dollar signs `$...$`.
2. For display-style mathematical expressions, use double dollar signs `$$...$$`.

For example:
- Inline: The equation of mass-energy equivalence is $e=mc^2$.
- Display: 
1 Like