New version of Anki doesn't seem to support Mathjax macros definitions

I have recently upgrade Anki to 2.1.43, and latex rendered with mathjax doesn’t work anymore with macros.
Previously, if I included

<script>
MathJax.Hub.Config({
  TeX: {
    Macros: {
      d: "\\mathrm{d}"
    }
  }
})
</script>

in the template, I could use \d in a mathjax source, and it would show a right d.

After the update, it just shows \d in red, as if it was an undefined command…

1 Like

Linked from the change notes: Upgrade to Mathjax 3 (ankitects/help-wanted#19) by hgiesel · Pull Request #809 · ankitects/anki · GitHub

Ok, so MathJax has been upgraded to Mathjax 3, and I have tried converting my configuration using this tool, but it didn’t really work out. With the new configuration, the cards simply don’t render. Here is the configuration in my template, after migrating to Mathjax 3.

<script data-name="MathJax Macros" data-version="v0.3">
  window.MathJax = {
    tex: {
      macros: {
        d: "\\mathrm d",
        // ...
      }
    }
  };
</script>

I couldn’t find any other informations to make it work in the PR discussion.

Maybe you need to tell MathJax to reload things, as described on Configuring and Loading MathJax — MathJax 3.1 documentation which is linked from the previous link.

Yes, I saw the link and I read the documentation but it didn’t change anything. I have tried adding MathJax.startup.getComponents(); at the end of the script (which is supposed to regenerate every object, taking into account the configuration), but it still doesn’t work.
However, I don’t think it’s an issue of Mathjax not taking into account configuration. Here is the minimal code that leads to this issue:

<script>
MathJax = {};
</script>

I am not a JavaScripte programmer, so I be wrong, but I think that I am overwriting MathJax, which seems to be a critical variable… (nonetheless this is the way it is supposed to be configured). To patch that, I tried instead of setting the configuration by setting attributes instead of overwriting the whole object:

<script>
MathJax.tex.macros = {
   d: "\\mathrm d",
   // ...
};
</script>

This allows the page to be rendered, but it stills doesn’t define macros (I get the same result as in the beginning).
Hence, I tried what was told in the documentation

<script>
MathJax.tex.macros.options = { /* ... */ };
</script>

which is supposed to work for certain fields. Oc, it didn’t work. So I tried the hard way, telling MathJax to reload every object

<script>
MathJax.tex.macros = { /* ... */ };
MathJax.startup.getComponents();
</script>

Didn’t work…

At this point, I just tried every possible combination of the aforementioned “solutions”.

This one worked…

<script>
MathJax.config.tex.macros = { /* ... */ };
MathJax.startup.getComponents();
</script>

that took some time :sweat_smile: and the answer was in the first post you sent me, I feel like an idiot. An idiot that took way too much time trying to read the doc and too few reading what an other user did. Hope it helps anyone else that has the same problem.

3 Likes

Any suggestions for changing the delimiters? I know it’s not recommended but it works well for my setup.

I tried a couple methods here but haven’t gotten it to work. Thanks!