Inserting a line break in a display equation cause equation to not work

Using the card browser, I am editing a card that has a MathJax display equation \[ ... \].


I prefer to put the equation delimiters on different lines than the equation contents, so I added a line break at the location of my cursor in the above image.
When I do this, Anki adds &nbsp;</div><div> to the HTML code, causing the equation to stop working, as shown here:


Changing </div><div> to <br> fixes the problem.

I don’t know why Anki uses a div block here, instead of using <br> (it seems to be because the code already has div blocks), but inserting <br> would fix this problem.

Version <U+2068>24.11 (87ccd24e)<U+2069>
Python 3.9.18 Qt 6.6.2 PyQt 6.6.1

If you want to use newlines in a MathJax expression, please use Shift+Enter instead of just Enter, as a normal newline will prevent MathJax from working correctly. [Math & Symbols - Anki Manual]

1 Like

You could use \displaylines{} and then use \\ to denote a linebreak.

That is a solution for inserting a line break in the displayed equation, but I was talking about just code line breaks. (I’ve never heard of \displayedlines, though. I’ll have to check that out!)

I don’t think that’s always true. Sometimes ENTER inserts <br>, which works fine. Anyway, it seems like a bug (or at least bad UI design that) that Anki sometimes inserts div tags inside MathJax equations when this causes them to break

You didn’t code-block whatever you were trying to say, so the forum interface ate it – but I think I get the gist.

If it “sometimes” works, then just insert the word “sometimes” in the advisement from the manual. You get to the same place!

It’s displaylines, not displayedlines.