Strange interactions (bugs?) between cloze and mathjax

Anki seems to struggle with mathjax inside the selected area when using CRTL+Shift(+Alt)+C (“CSC”), especially when using CRTL+Z (“CZ”) afterwards:
(Some examples have a line of how the card looks in the editor and in the next line its underlying HTML. mathjax-Parts are cursive to distinguish them.)

Example 1: Mathjax between text, creating a cloze using CSC, then removing it using CZ
=> CZ duplicates the Mathjax to the start of the selection
Starting card:
ATest math TestZ
ATest math TestZ

  • Select text from A to Z, CSC -
    {{c1::ATest math TestZ}}
    {{c1::ATest math TestZ}}
    -(correct result), try CZ now -
    mathATest math TestZ
    mathATest math TestZ
  • Anki has correctly removed the cloze, but added the mathjax to the start of the selection

Example 2: Example 1, but the line has text in front of the selection (still A to Z selected)
=> CZ duplicates the Mathjax where it is
Text ATest math TestZ
Text ATest math TestZ

  • CSC, CZ -
    Text ATest math**math TestZ
    Text ATest mathmath TestZ

Example 3: Mathjax at the end of the selection
Starting card can be the same as above, but this time the latter “TextZ” won’t be part of the selection
3.1: Select the Mathjax including its hair space (U+200A): Same result as Example 1/2
3.2: Select the Mathjax without its hair space (e. g. by moving the mouse more than halfway across the mathjax, after which this is the default selection; or by using Shift+Arrow keys, where selecting the hair space seems to be impossible):
=> Using CSC removes the mathjax and adds inverted cloze to beginning of selection (same result with starting card from 1 or 2)
Starting card: Example 1

  • Select content as described, use CSC -
    }}{{c1::ATest TestZ
    }}{{c1::ATest  TestZ
  • Use CZ -
    Nothing happens after 1 CZ, 2nd CZ removes previously changed content and doesn’t revert the cloze. Mathjax never returns.

Example 4: Example 3.2 + The effects of other text modifications
4.1: Bolden parts of the pre-Mathjax text, then use CSC
4.1.1: All of the previous text
Test AText math TextZ

  • CSC -
    Test }} AText{{c1:: TextZ
  • CZ does nothing. -

4.1.2 Only parts of the text
=> boldened parts land inside of the inverted cloze, if there’s more, even stranger things happen
4.1.2.1:
Test AText math TextZ

  • CSC -
    Test }}t Tex{{c1::A TextZ
  • CZ does nothing. -
    4.1.2.2:
    Test A longer Test math TestZ
  • CSC -
    Test }}t es Tlonger{{c1::A  TestZ
  • CZ does nothing. -

*CZ actually does something! Just not what I would expect. If I copy the HTML, CZ stops working but if I don’t, 4.1.2.2 becomes
Test A }}t  T{{c1::A  TestZ
after CZ.

4.2: Other mathjax
4.2.1: Only other mathjax:
Text like this also exists, as parts may be important or contain other stuff instead of just math

  • CSC -
    }} instead of just {{c1::Text like this also exists, as parts may be important or contain other 

4.2.2: Mathjax and reasonable text formatting:
Text like this also exists, as parts1 may be important or contain other stuff instead of just math

  • CSC -
    }} instead of just  or contain other important may be 1 also exists, as partsthis{{c1::Text like

Example 5: “All of the above” and more
Text like this also exists1, as parts may be important1  instead of just math

  • CSC -
    }}  instead of just 1important be may parts, as 1 existsalso this{{c1::Text like
    => Especially super-/subscriped parts are moved around

I’ve tried a few other things, but it mostly seems to come down to that hair space (which is why display mode Mathjax seems to not have this issue), if only the Mathjax itself is copied, one of the varied issues above manifests.

(Side note: [this forum]/t/mangled-cloze-deletion-when-cloze-includes-mathjax/21121 seems to be the same issue, but with an older Anki version, I’m using Anki 23.12.1.)

As this forum seems to format HTML inside posts: pastebin yLs1DDdp with password Anki has the unformatted version.

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