Add "enable Mathjax" macro for Confluence

Issue #55 resolved
Jason Sachs created an issue

My company has been using two different MathJax macros for Confluence; the Keysight plugin and https://github.com/dawbarton/confluence-mathjax. We were using these on different Confluence instances, but now we have merged them together and they are not working. We need a way to migrate to one of them (hopefully the Keysight plugin, since it is actively maintained and the dawbarton one is not) and keep our math content maintainable.

Yours appears to require an explicit macro used in each instance. The dawbarton plugin requires one macro added to the page, but then if you use appropriate delimiters elsewhere in the page (\(...\) or \[...\] or or $...$ or $$...$$) then you can just type the MathJax directly; you don't need to insert a macro instance for each usage.

I have a number of pages where in each one there are dozens of instances of MathJax expressions, and going in to each page and changing each instance of MathJax to an explicit macro is too much work.

Is there any way you could add a macro that just enables MathJax in the HTML heading?

Comments (7)

  1. Scott Selberg

    Hi, mathjax is loaded on every page. It's scanning the content for a start and end string. I think the defaults are $...$ and $$..$$. This was causing problems with some sql on pages that use that syntax and mathjax was converting the contents which it should not have done. I therefore added a configuration to the macro and made the default start and end tags quite unique. I think to accomplish what you want, you would have to change the start and end delimiters in the mathjax configuration back to $...$ and $$...$$. I believe it will then behave as you wish with no need for modification of the plugin.

  2. Jason Sachs reporter

    I'll work with our Confluence admin to see what it is... the start/end delimiters should be adjustable. (I generally use \( \) \[ \] to avoid conflict with prices)

  3. Jason Sachs reporter

    I therefore added a configuration to the macro and made the default start and end tags quite unique.

    Just to clarify: is this configuration option located...

    • in the plugin (global, accessible by Confluence administrators only)
    • in the macro on a per-page basis
    • in the macro on a per-instance basis

    I see this when looking at the generated HTML for our instance:

    <script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [ ['(mathjax-inline(', ')mathjax-inline)' ] ], displayMath: [ ['(mathjax-block(', ')mathjax-block)' ] ], } }); </script> <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"> </script>
    

    so it looks like the delimiters are (mathjax-inline( ... )mathjax-inline) etc.

    It would be nice if there was a macro that could be inserted on a page to configure on a per-page basis... I can ask our admin to use \( \) and \[ \], but not sure if that's a good idea on pages that aren't expecting to use mathjax.

  4. Scott Selberg

    The configuration is made by the admin in the Mathjax Plugin configuration. There is a bit of a chicken and egg scenario in that the code to load mathjax is executed before the page is loaded so it's hard to tell if there are macros on the page that need it or not.

    One idea you could try, as you have the html that loads mathjax, is to put it in the header for your space. I'm not sure what happens if the code is loaded twice or which will get loaded first, but it may be a way to set the delimiters on a per space basis.

  5. Log in to comment