Discourse Math Plugin

So something weird. I just created a new post to test again. In the first 5 seconds or so while the pos was up it DID render the equation properly then a moment later it reverted to raw latex. It always renders correctly in the preview however.

My guess is that this is strongly related to your non-standard install, we only really support the docker based setup.

Why isnt this standard? I removed all the non-standard plugins as you said.

I am afraid the only “production” support we offer here is for people who use this guide:

discourse/INSTALL-cloud.md at master · discourse/discourse · GitHub

What I think you have done though you are not explicitly telling me so is swang an install by hand by kicking off unicorn launching sidekiq and orchestrating NGINX.

Am I mistaken? Or are you using our official install?

1 Like

Ohhh you meant how discourse was insalled or how the plugin was installed?

I wanted to provide a solution to my own problem in case it helps anyone else.

Ultimately I couldnt get the Discourse-math plugin working. In case anyone else completely fails at getting it working one option is to uninstall it and instead go to your customize tab and edit your theme in the Web UI. If you add the following to the head tab it should work (either disable CSP in your setting or add the domain to the acceptable sources, both can be done in the settings).

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js","TeX/AMSmath.js","TeX/AMSsymbols.js", "TeX/noErrors.js"],
    jax: ["input/TeX","output/HTML-CSS"],
    tex2jax: {
        inlineMath: [['$','$'], ["\\(","\\)"]],
        displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
        processEscapes: true,
    },
  });
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_HTML"></script>
<script type="text/javascript">
    var observer = new MutationObserver(function(mutations) {
        var refresh = false;
        refresh = false;
        mutations.forEach(function(mutation) {
            if(mutation.target.id == "topic" || mutation.target.id == "reply-control") {
                refresh = true;
            }
        });
        
        if(refresh) {
            MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
        }
    });
    
    observer.observe(document, { childList: true, subtree: true});
</script>
1 Like

Super wide equations will now scroll horizontally instead of being cut off. This works on both desktop and mobile devices.

10 Likes

Hi I have an issue with multiple inline math commands. e.g.:

$v(t_1) =$ space under $a(t)$ between $0$ and $t_1$

$v(t_1) =$ space under $a(t)$ between $0$ and $t_1$

Any clue how to solve this?

What issue exactly? :slight_smile: Can you provide a screenshot, or does it simply not render at all?

It renders for me fine with both KaTeX and MathJax.

3 Likes

And it seems it also doesn’t work for previews?

1 Like

Edit: Turns out it’s not the math plugin loading KaTeX for me…but anyways, I’ll just leave this here in the event someone searches for CSP.


Is it possible for a plugin to add to whitelisted sites for CSP?

With this installed, and CSP on by default, things broke when I just updated. In case others need it:

  • Add cdn.jsdelivr.net to the content security whitelist before updating to 2.0beta8 (or was it 9?)
  • If you’ve already updated, get to the Rails console, then run SiteSetting.content_security_policy = false.
  • Then go back in an add to the CSP whitelist, and turn CSP back on.
2 Likes

I think it is possible a plugin can amend CSP… not 100% sure if we have APIs though maybe @xrav3nz knows?

2 Likes

Yup, plugins can extend the CSP via:

3 Likes

Also note that I think your issue might be somewhere else. This plugin doesn’t load the mathjax files from jsdelivr. They’re served from your server.

So they shouldn’t need any whitelisting. I would check the plugins / theme / components on your site to see which of them needs files to be loaded from jsdelivr.

4 Likes

Blehhh, my bad…:frowning: Sorry! We used to have the Discourse math plugin, but my forum now has a different KaTeX setup.

Well, there’s a good reason to things back to the plugin. (If only I knew why it wasn’t being used…)

3 Likes

I remember you made a comment on a KaTEX PR some time ago…

https://github.com/discourse/discourse-math/pull/13#issuecomment-451389210

Do you still need custom delimiters?

5 Likes

Right. :smile: I remember messing with the plugin and installing it – I do think custom delimiters would be useful, but perhaps I can live without them for now.

I would like to also report the problem with the math plugin installation where mathjax math shows in post/topic previews, but not in the posts themselves. I’m using the out of the box latest bitnami docker-compose, with only discourse-math plugin installed using

RAILS_ENV=production bundle exec rake plugin:install repo=https://github.com/discourse/discourse-math.git 
RAILS_ENV=production bundle exec rake assets:precompile

The plugin shows up in the settings, and is enabled. The example page failing to render is here.

Anton, I am afraid bitnami is very much unsupported here, I strongly recommend you swap to our official install. If you are lucky this is simply a CSP issue cause you are using the assets from some CDN, if you are unlucky this is some issue with bitnami not supporting plugins properly.

4 Likes

I have issue thai language wrong on mobile iphone 6s+ and ipad gen7

But on notebook correct.