# Fix MathJax in Cloze

**URL:** <https://forums.ankiweb.net/t/fix-mathjax-in-cloze/68948>\
**Category:** Add-ons\
**Created:** [February 22, 2026, 6:50am UTC](https://forums.ankiweb.net/t/fix-mathjax-in-cloze/68948 "2026-02-22T06:50:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dedicate](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/dedicate/32/31517_2.png) [@Dedicate](https://forums.ankiweb.net/u/Dedicate)\
**Post date:** [February 22, 2026, 6:50am UTC](https://forums.ankiweb.net/t/fix-mathjax-in-cloze/68948/1 "2026-02-22T06:50:34Z")

</div>

# [Fix MathJax in Cloze](https://ankiweb.net/shared/info/1066972223)

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:

```plaintext

{{c1::[$]\frac{foo}{\frac{bar}{baz}}[/$] blah blah blah.}}

```

- Works (space workaround):

```plaintext

{{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):

```plaintext

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

```

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

```plaintext

{{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 answer text with `} }`

- Leaves the actual cloze terminator untouched

- Supports cloze hints like `{{c1::answer::hint}}`

## Features

- Bulk fix from **Card Browser** on selected notes

- Single-note fix from **Review screen** context menu

- Safe cloze parsing with nesting awareness

- Configurable replacement token via `config.json`

## Usage

### 1. Bulk fix from Browser

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/replacements were updated.

### 2. 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.

## Configuration

`config.json`:

```json

{

"replacement": "} }"

}

```

- `replacement`: string used to replace internal `}}` inside cloze answers.

- Default is `} }` (space workaround).

## Files

- ` __init__.py` - Add-on logic, parser, and UI hooks

- `manifest.json` - Add-on metadata

- `config.json` - User-configurable replacement token

## Notes

- The add-on rewrites only `}}` found **inside cloze answer text**.

- Malformed cloze text is left unchanged for safety.
