MathJax Not Displaying Correctly in Anki Desktop (v24.06.3) - Inconsistent Rendering Issue

Hi everyone, I’m having an issue with cards that use MathJax in Anki, and I can’t figure out what’s going wrong.

Cards that include MathJax are not rendering correctly. When I click on the card editor of an open card, sometimes the MathJax equations get rendered, but this only happens inconsistently. Often, only the second text field (answer side) gets rendered properly (after I opened the editor - not in the first place), while the first field (question side) doesn’t display the MathJax at all.

What I’ve Tried:

  • I launched Anki in Safe Mode (no add-ons), but the issue still persists.
  • I sent the deck to a friend, and they were able to reproduce the issue on a different machine.

Here’s my current Anki setup:

  • Version: 24.06.3 (d678e393)
  • Python: 3.9.18
  • Qt: 6.6.2
  • PyQt: 6.6.1
  • OS: Windows 11 Pro

I have a link for a video showing the problem and a link to the deck that I’ve used. Unfortunately I cannot share links or add attachments in this forum, maybe someone has another idea how I could share the files.

I think I’ve just earned the basic Trust level. So I can share links:

1 Like

<anki-mathjax> is not valid syntax, and is only used internally by Anki. You should use \( ... \) instead if you are importing material into Anki.

2 Likes

I believe I am experiencing something similar. It seems like the first time something latex is displayed, it will be correct, and all subsequent times the rendering is absent or partial.

Tried with 24.06.3 Qt6 and 24.06.3 Qt5.

  • Are you using the same incorrect syntax as OP?
  • Are you using MathJax or LaTeX? – see the page linked above

So these are quite old cards, which I’ve only just recently decided to open up again. I know they used to work as-is, but no longer do.

The way I was doing it was that the card templates had a script section:

<script>
  MathJax.config.tex.inlineMath = [['$', '$'], ['\\(', '\\)']];
  MathJax.config.tex.displayMath = [['$$', '$$'], ['\\[', '\\]']];
  MathJax.config.tex.processEnvironments = true;
  MathJax.config.tex.macros = {
    'N': '{\\mathbb{N}}',
    'Z': '{\\mathbb{Z}}',
    'Q': '{\\mathbb{Q}}',
    'R': '{\\mathbb{R}}',
    'C': '{\\mathbb{C}}',
    'RR': '{\\mathcal{R}}',
    'OO': '{\\mathcal{O}}',
    'eps': '{\\epsilon}'
  };
  MathJax.startup.getComponents();
</script>

Most of my equations are delimited by:

$ \ldots $

I see that if I now use \( and \) that it is automatically replaced with <anki-mathjax></anki-mathjax> and this seems to work consistently if I remove the script section.

Is it necessary export, regex, reimport?

Further edit: my original cards still continue to work as-is on AnkiDroid.

Possibly related: Mathjax renders badly - #7 by dae

I can confirm that adding the check for getComponents as described in the linked issue seems to solve my problem.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.