Anki add-on: Fix MathJax in Cloze

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) Open Browse. Select one or more notes. Click Notes → Fix MathJax in Cloze (selected notes) . A tooltip shows how many notes and replacements were updated. 2. Bulk fix from Browser (right-click) Open Browse. Select one or more notes. Right-click on the selection. Click Fix MathJax in Cloze (selected notes) . A tooltip shows how many notes and replacements were updated. 3. Fix current review note While reviewing a card, right-click. Click Fix MathJax in This Note . The current note is updated immediately. 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: 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

GitHub repository: athulkrishna2015/fix-mathjax-in-cloze
Repository description: https://ankiweb.net/shared/info/1066972223
Languages: Python