Fix MathJax in Cloze

AnkiWeb addon 1066972223

Fixes cloze conflicts by replacing internal }} with } }, handling trailing braces and nested clozes, and removing non-breaking spaces inside MathJax, with browser and reviewer bulk-fix actions.
AI-generated summary; may contain mistakes.

note-managementformattingclozebugfix-workaround

Open on AnkiWeb GitHub Forum topic Find alternatives

AnkiWeb

Votes
1 (πŸ‘ 1 Β· πŸ‘Ž 0)
Updated
2026-04-20
Anki versions
2.1.1~
License
Not found (this does not mean that the addon has no license)
Virus scan
No ClamAV match A match does not prove malware. No match does not prove that the code is safe.
Languages
Python, JSON
Description language
en

Maintenance

stale

  • Last update or commit: 2026-04-20 (195 days before the snapshot).
  • Test files: 2.
  • Commits in the last year: 14.
  • Issues: 0 open, 0 closed.
  • Pull requests: 0 open, 0 merged.

Will it work on my Anki?

Version branches
Min AnkiMax AnkiUpdated
2.1.1+2026-04-20
History across monthly snapshots

Loading…

Similar addons

Description

Fix MathJax in Cloze

An Anki add-on that fixes cloze conflicts where }} inside MathJax (or other cloze text) is interpreted as the end of a cloze deletion.

Cloze Conflict Background

Cloze deletions are terminated with }}. If }} appears inside cloze content, Anki may close the cloze too early.

  • Problematic:
{{c1::[$]\frac{foo}{\frac{bar}{baz}}[/$] blah blah blah.}}
  • Works (space workaround):
{{c1::[$]\frac{foo}{\frac{bar}{baz} }[/$] blah blah blah.}}

LaTeX math mode ignores extra spaces, so rendering remains the same.

Alternative workaround (for cases where visible spaces matter):

{{c1::[$]\frac{foo}{\frac{bar}{baz}<!-- -->}[/$] blah blah blah.}}

The same idea also helps when :: needs to appear in cloze-deleted text, e.g.:

{{c1::std:<!-- -->:variant::~type~}} in C++ is a {{c2::type-safe union}}

What this add-on does

This add-on applies the space workaround by default:

  • Replaces internal }} inside cloze content and hints with } }
  • Handles trailing }}} boundary conflicts by rewriting them to safe output
  • Preserves nested cloze terminators like {{{c1::c}}}
  • Overrides Anki's contenteditable default spacing issue by removing non-breaking spaces &nbsp; exclusively from MathJax tags to prevent rendering breakage.
  • Adds quick actions in the Browser menu bar, Browser right-click context menu, and reviewer context menu
  • Includes a Settings tab and a Support tab with QR codes, copy buttons, and a Ko-fi widget

Usage

1. Bulk fix from Browser (menu bar)

  1. Open Browse.
  2. Select one or more notes.
  3. Click Notes β†’ Fix MathJax in Cloze (selected notes).
  4. A tooltip shows how many notes and replacements were updated.

2. Bulk fix from Browser (right-click)

  1. Open Browse.
  2. Select one or more notes.
  3. Right-click on the selection.
  4. Click Fix MathJax in Cloze (selected notes).
  5. A tooltip shows how many notes and replacements were updated.

3. Fix current review note

  1. While reviewing a card, right-click.
  2. Click Fix MathJax in This Note.
  3. The current note is updated immediately.
Screenshot_20260307_232051 Screenshot_20260307_232059

Configuration

Open Tools -> Add-ons -> Fix MathJax in Cloze -> Config.

  • Settings tab: update the replacement token used for unsafe internal }}
  • Support tab: use the embedded Ko-fi button, QR codes, or copy buttons

config.json:

{
  "replacement": "} }",
  "remove_nbsp_in_mathjax": true
}
  • replacement: string used to replace internal }} inside cloze content

  • Default: } }

  • If invalid (empty, non-string, or contains }}), the add-on falls back to } }

  • remove_nbsp_in_mathjax: boolean to enable scrubbing non-breaking spaces &nbsp; automatically generated by Anki's editor (e.g., from typing double spaces or pasting via web browser). This clears them exclusively inside MathJax blocks to avoid LaTeX compilation failures.

  • Default: true

Notes

  • The add-on rewrites }} found inside cloze content and at the immediate boundary before cloze termination.
  • Malformed cloze starts are left unchanged, and parsing continues so later valid clozes in the same field can still be fixed.
  • Development, packaging, and versioning notes live in DEVELOPMENT.md.

Support

If this add-on helps, you can support it from the in-app Support tab or here:

ko-fi

Changelog

2026-04-20

  • Added automatic removal of non-breaking spaces &nbsp; from inside native MathJax limits (\() and (\[) and Anki tags to prevent rendering errors caused by Anki's rich-text editor defaults, configurable via remove_nbsp_in_mathjax option and available natively in the settings UI.

2026-04-05

  • Added Fix MathJax in Cloze to the Browser right-click context menu
  • Refactored codebase into smaller modules for easier maintenance

2026-03-27

  • Added Settings tab with configurable replacement token
  • Added Support tab with QR codes, copy buttons, and Ko-fi widget
  • Added bump.py and make_ankiaddon.py build/packaging scripts
  • Added unit tests

2026-03-11

  • Refactored cloze parsing into reusable helpers for clearer nested-cloze handling
  • Fixed nested cloze cases like {{c3::\(\sin i_{{{c1::c}}} = ...\)}} so the add-on preserves {{c1::c}} and rewrites the outer brace boundary instead
  • Added a regression test for the nested-cloze brace case

2026-03-07

  • Added screenshots to README for visual guidance

2026-02-25

  • Added handling for trailing }}} cloze-boundary conflicts (for example, {{c1::\\mathbf{0}}} β†’ {{c1::\\mathbf{0} }})
  • Confirmed behavior applies to cloze content inside and outside MathJax
  • Added internal }} replacement in cloze hints (not just cloze answers)
  • Added safety fallback for invalid custom replacement values
  • Changed malformed-cloze handling to continue scanning later clozes
  • Updated documentation to describe boundary rewrite behavior

2026-02-22

  • Initial release
  • Core cloze rewriting engine (}} β†’ } })
  • Browser menu action for bulk-fixing selected notes
  • Reviewer right-click menu action for fixing current note
  • Fixed replacement string formatting in config.json
  • Fixed formatting issues in cloze handling functions
  • Improved README with cloze conflict background and examples

README

Fix MathJax in Cloze

An Anki add-on that fixes cloze conflicts where }} inside MathJax (or other cloze text) is interpreted as the end of a cloze deletion.

Cloze Conflict Background

Cloze deletions are terminated with }}. If }} appears inside cloze content, Anki may close the cloze too early.

  • Problematic:
{{c1::[$]\frac{foo}{\frac{bar}{baz}}[/$] blah blah blah.}}
  • Works (space workaround):
{{c1::[$]\frac{foo}{\frac{bar}{baz} }[/$] blah blah blah.}}

LaTeX math mode ignores extra spaces, so rendering remains the same.

Alternative workaround (for cases where visible spaces matter):

{{c1::[$]\frac{foo}{\frac{bar}{baz}<!-- -->}[/$] blah blah blah.}}

The same idea also helps when :: needs to appear in cloze-deleted text, e.g.:

{{c1::std:<!-- -->:variant::~type~}} in C++ is a {{c2::type-safe union}}

What this add-on does

This add-on applies the space workaround by default:

  • Replaces internal }} inside cloze content and hints with } }
  • Handles trailing }}} boundary conflicts by rewriting them to safe output
  • Preserves nested cloze terminators like {{{c1::c}}}
  • Overrides Anki's contenteditable default spacing issue by removing non-breaking spaces &nbsp; exclusively from MathJax tags to prevent rendering breakage.
  • Adds quick actions in the Browser menu bar, Browser right-click context menu, and reviewer context menu
  • Includes a Settings tab and a Support tab with QR codes, copy buttons, and a Ko-fi widget

Usage

1. Bulk fix from Browser (menu bar)

  1. Open Browse.
  2. Select one or more notes.
  3. Click Notes β†’ Fix MathJax in Cloze (selected notes).
  4. A tooltip shows how many notes and replacements were updated.

2. Bulk fix from Browser (right-click)

  1. Open Browse.
  2. Select one or more notes.
  3. Right-click on the selection.
  4. Click Fix MathJax in Cloze (selected notes).
  5. A tooltip shows how many notes and replacements were updated.

3. Fix current review note

  1. While reviewing a card, right-click.
  2. Click Fix MathJax in This Note.
  3. The current note is updated immediately.
Screenshot_20260307_232051 Screenshot_20260307_232059

Configuration

Open Tools -> Add-ons -> Fix MathJax in Cloze -> Config.

  • Settings tab: update the replacement token used for unsafe internal }}
  • Support tab: use the embedded Ko-fi button, QR codes, or copy buttons

config.json:

{
  "replacement": "} }",
  "remove_nbsp_in_mathjax": true
}
  • replacement: string used to replace internal }} inside cloze content

  • Default: } }

  • If invalid (empty, non-string, or contains }}), the add-on falls back to } }

  • remove_nbsp_in_mathjax: boolean to enable scrubbing non-breaking spaces &nbsp; automatically generated by Anki's editor (e.g., from typing double spaces or pasting via web browser). This clears them exclusively inside MathJax blocks to avoid LaTeX compilation failures.

  • Default: true

Notes

  • The add-on rewrites }} found inside cloze content and at the immediate boundary before cloze termination.
  • Malformed cloze starts are left unchanged, and parsing continues so later valid clozes in the same field can still be fixed.
  • Development, packaging, and versioning notes live in DEVELOPMENT.md.

Support

If this add-on helps, you can support it from the in-app Support tab or here:

ko-fi

Changelog

2026-04-20

  • Added automatic removal of non-breaking spaces &nbsp; from inside native MathJax limits (\() and (\[) and Anki tags to prevent rendering errors caused by Anki's rich-text editor defaults, configurable via remove_nbsp_in_mathjax option and available natively in the settings UI.

2026-04-05

  • Added Fix MathJax in Cloze to the Browser right-click context menu
  • Refactored codebase into smaller modules for easier maintenance

2026-03-27

  • Added Settings tab with configurable replacement token
  • Added Support tab with QR codes, copy buttons, and Ko-fi widget
  • Added bump.py and make_ankiaddon.py build/packaging scripts
  • Added unit tests

2026-03-11

  • Refactored cloze parsing into reusable helpers for clearer nested-cloze handling
  • Fixed nested cloze cases like {{c3::\(\sin i_{{{c1::c}}} = ...\)}} so the add-on preserves {{c1::c}} and rewrites the outer brace boundary instead
  • Added a regression test for the nested-cloze brace case

2026-03-07

  • Added screenshots to README for visual guidance

2026-02-25

  • Added handling for trailing }}} cloze-boundary conflicts (for example, {{c1::\\mathbf{0}}} β†’ {{c1::\\mathbf{0} }})
  • Confirmed behavior applies to cloze content inside and outside MathJax
  • Added internal }} replacement in cloze hints (not just cloze answers)
  • Added safety fallback for invalid custom replacement values
  • Changed malformed-cloze handling to continue scanning later clozes
  • Updated documentation to describe boundary rewrite behavior

2026-02-22

  • Initial release
  • Core cloze rewriting engine (}} β†’ } })
  • Browser menu action for bulk-fixing selected notes
  • Reviewer right-click menu action for fixing current note
  • Fixed replacement string formatting in config.json
  • Fixed formatting issues in cloze handling functions
  • Improved README with cloze conflict background and examples