New Plugin: MathJax extended + preamble

I’ve added support for the MathJax mhchem and bussproofs packages, extending the usefulness of the Obsidian MathJax engine. I’ve also added support for a MathJax preamble, useful for defining common macros.
The preamble is defined in a preamble.sty file in the root of the vault.

I’ve got plans for this plugin, including optionally using Latex rather than MathJax to have access to all the usual goodies and packages.

Github: https://github.com/xldenis/obsidian-latex

12 Likes

I can’t wait to see that implemented! It would be a big time saver!

Great plugin. The preamble is a must have because writing pure Latex without macros is time consuming. Is there any way to get the preamble through to Obsidian Publish? I couldn’t get it to work because the .sty file couldn’t be found to be published.

Hey, sorry I forgot to check this forum and I’m not getting email notifications. I’ll take a look at getting it working with Obsidian Publish, but since I don’t have access to that it may take a little while.

1 Like

Coming Soon :tm:! I have a hacky local version “working” right now.

3 Likes

Thank you for the great work, I love this!

Is it possible to add different packages in the preamble somehow? It is straightforward to edit the plugin to load the packages, e.g. in main.ts I could load the tensor package:

        o.loader = { load: ['[tex]/mhchem', '[tex]/bussproofs', '[tex]/tensor'] };
        o.tex.packages = { '[+]': ['mhchem', 'bussproofs', 'tensor']};

But then I would need to fork it, create my own plug in, and then pull from upstream every time you update. And presumably every user would need to do the same depending on what packages they need, which would be a bit of a mess. I’d love for a way to add MathJax extensions within this plugin!

1 Like

Have you tried using \require? For example I can load the braket package quite easily like this:

$\require{braket}\bra{x + y}$

I’ve enabled email notifications to be more responsive here.

Hi, this plugin is really wonderful! However, it stops working in my Obsidian note since last update (v0.11.3). Does anyone encounter similar problem?

Hello @shenghan, you’re not the first person to report this though each time the issue seems to be transitory. Can you confirm that you are on Windows (10)? Are you able to reproduce this in a fresh vault?

I’m going to take a deeper look into this during the weekend, see if maybe something changed in initialization of obsidian plugins?

Does this plug-in allow one to number equations? Currently $$ x^2 $$ shows as an equation but doesn’t have an equation number. Thanks.

Related forum topics: here, here

1 Like

Hi @xldenis , thanks for your reply. I am using Windows 10.
I follow your suggestion to try a new vault, and the problem disappear. In the current vault, I reinstall the plugin, and the problem also disappear. Thanks!

Hey, I’m having the same problem. I’m in version 0.11.5, also on Windows 10. When I made a new vault for testing it worked as you said. So I tried copying my old vault’s folder to another location, deleting the .obsidian folder, and opening the copied folder as a new vault. This worked, so the next step was deleting the .obsidian folder from my original vault, removing it from Obsidian, and opening the folder as a new vault. This worked too, but then I tried editing the preamble. Since nothing changed, and I wasn’t able to refresh Obsidian (Ctrl+R doesn’t seem to do anything [anymore?]) I closed and re-opened the program, but now the plugin doesn’t seem to work anymore. Some comments:

  • Reinstalling doesn’t work for me like it does for @shenghan, apparently.

  • Some times when testing MathJax would break completely, and the equations would display as plain text.

By the way, thanks for making this much needed package.

Thanks for the report, I’ll investigate this over the weekend, I wonder if there have been changes to plug-in loading or file access… I’m curious why it only happens on windows 10 though.

Hey. Just wanted to tell that your plugin is great. It is exactly what I was looking for, just thought of something like this and here it is! The open-source community at its best.

1 Like

To load the package “physics” you can use \require{physics} in the preamble. For example, when I use \require{physics} in the preamble, I see $\op{a}{b}$ rendered globally and it is not rendered globally otherwise.

Also trying to find out why $\ip{a}{b}$ from physics does not work, while $\innerproduct{a}{b}$ does. In physics readme \ip is said to be the shorthand version of \innerproduct.

2 Likes

Could it be a library version issue?

I didn’t get the chance to debug the windows issue yet, but it’s high on my todo list