[Proposal] MathJax provider API

There doesn’t seem to be a reliable way of customizing the MathJax configuration currently (the Extended MathJax plugin helps, but even that is a slightly hacky solution, and it only covers preambles).

There are a fair few feature requests surrounding MathJax in the Feature Requests category, but ultimately I think implementing totally customizable MathJax in Obsidian core will never feel elegant, since it would either involve a sizable effort in providing a good interface for it, or it would require the user to set up the MathJax object in JS themselves, which is scary for a large group of less technical users.

To cater to those who are heavy users of math in their vaults, full customization would be a very valuable thing.

The better solution I think would be implementing a MathJaxProvider, which could be subclassed and customised by plugins. The MathJaxProvider should:

  • Have a displayName attribute
  • Have a providerID attribute
  • Have a provide method, which would return an initialised MathJax3 object.

The default MathJax implementation would be turned into a MathJaxProvider (perhaps aptly named “Obsidian Default”).

Plugins could register MathJaxProviders.

In Options → Editor there would be a dropdown with:

  • Label: MathJax Provider (or perhaps something simpler like Math Provider)
  • Text: Which configuration of MathJax to use for rendering math
  • Options: List of registered MathJaxProviders

Relevant Feature Requests

Alternative Solutions

Alternatively there could be a mathjax.js file in .obsidian which would instanciate the MathJax object - this could then be overridden by users. This is less elegant and more prone to untechnical users breaking their configurations in hard-to-debug ways.

Considerations

This would be quite easy to implement in Obsidian, I’d imagine, and it likely wouldn’t require significant effort to implement or maintain.

  • Should verify that object returned by provider is a mathjax instance
  • If a plugin is removed such that the configured value to the mathjax provider setting is no longer valid, it should default back to ‘Obsidian Default’.

I really hope this is something that could be added to Obsidian. It already has really good math support, but this (along with WYSIWYG eventually :eyes: ) would bring it to the next level.

P.S. MathJax 3.2 will be out soon, perhaps implementing this could be implemented when MathJax is upgraded to 3.2 in Obsidian anyway?

9 Likes

I would also love this. Currently the only plugin that attempts to deal with the mathjax initialisation is the obsidian-latex plugin and this unfortunately is not able to deal with specific configuration changes (as linked above). This means even things like loading certain packages that mathjax comes bundled with hard (e.g. the setoptions package). Having an actual accessible instance to interface with would allow many more plugins and user specific settings to be added!

MathJax 4 is nearing completion and provides many really nice changes that have been missing from MathJax 3 (to the extent that some people still use MathJax 2!)

Hopefully when MathJax 4 is out and the MathJax code in Obsidian is updated they can add some way of initialising MathJax in a custom way. I think this would enable a very powerful MathJax plugin to be made. It would be nice if the math implementation in Obsidian was able to support references and labels in a similar way to Pandoc

1 Like

Yeah mathjax 4 would be a brilliant addition. A setting in settings to allow for arbitrary changes to the Mathjax configuration would be the godsend. It would allow for adding packages and additional things like

const {TooltipData} = MathJax._.output.common.Wrappers.maction
TooltipData.postDelay = 300

which speeds up tooltip appearance.

Hopefully when the changes to mathjax4 are made, this can be implemented!

If anyone else is interested in this, please do comment/like this thread!

1 Like

For example, could this be used to let the user alter a custom component and then load it in?