How to force MathJax equations to wrap to next line?

Things I have tried

Searching the forum for similar questions.

What I’m trying to do

I am trying to have long equations (i.e., equations that go past the point where normal text wraps) wrap in the same way that text does in Obsidian.

For example, the equation $2Fe_3Si_2O_5(OH)_4+6Mg(OH)2 → 2H{2~(aq)}+2Mg_3Si_2O_5(OH)_4+2Fe_3O_4+4H_2O$ extends past the limit where normal text wraps, and while I can see the full equation if the Obsidian note is full-screened, this equation will be cut off by the side of the note window if I have multiple notes open (side-by-side) or if my Obsidian window is not full-screened.

AFAIK you can’t force MathJax to automatically wrap inline equations. But in this case I would use display math (notice two dollar signs) instead of inline math syntax:

$$2Fe_3Si_2O_5(OH)_4+6Mg(OH)*2 → 2H* {2~(aq)}+2Mg_3Si_2O_5(OH)_4+2Fe_3O_4+4H_2O$$

You can make display math scrollable using the following CSS snippet:

.markdown-rendered mjx-container {
    overflow-x: scroll;

Thanks for the reply! It seems that yours is the best solution.

Any idea why MathJax doesn’t do text wrapping? I am just curious what’s stopping it from doing so.

@eyemarrs According to this answer from the MathJax GitHub repository

it is due to the fact that line-breaking hasn’t been ported to v3 yet, so there is no code in v3 to do line breaking yet. it is on the to-do list, but the font update that is currently underway come before that.

@eyemarrs I also would recommend to use the \ce{...} command from the mhchem extension (already loaded by MathJax in Obsidian) for chemical formulae:

$$\ce{2Fe3Si2O_5(OH)4 + 6Mg(OH)*2 -> 2H*{2(aq)} + 2Mg3Si2O5(OH)4 + 2Fe3O4 + 4H2O}$$

It’s easier to type and will give you a nicely (and correctly) formatted output:

Screenshot 2022-11-11 at 21.23.56

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