mathjax/MathJax-docs

Doc idea: Show how nesting of LaTeX expressions can control line-breaking

Closed this issue · 2 comments

Hi

I have been experimenting with automatic line-breaking and LaTeX for some time now. It has been a bit of a challenge to control where the line-breaks were made. I just discovered that you can control it with nesting, i.e. you can get nice line-breaking (i.e. only breaks at the equal-signs) of
\[ D = b^2 - 4ac = 4^2 - 4 \cdot 5 \cdot 20 \]
by writing it like
\[ {D} = {b^2 - 4ac} = {4^2 - 4 \cdot 5 \cdot 20} \]
I don't know if this is obvious (it wasn't for me), but perhaps it should be mentioned/shown in the docs? :)

pkra commented

It's not complete control but you are right that grouping (even more importantly: \left ... \right) helps a lot with line-breaking.

dpvc commented

You are correct that nesting can be used to help control line breaking, and since braces introduce nesting into the underlying MathML that MathJAx generates, braces can be used to influence line breaks. So {x-1} is less likely to break at the minus sign than x-1 and {{x-1}} is even less likely.

Note that breaks occur only at operations and relations (like - and =) or at explicit space (like \,), so you will never get a break in the middle of ax in x2+ax+b, for example. So there is no need for the extra bracing you have for {D}, which just introduces extra nesting for nothing.

Finally, I suggested some macros that can be used to control line breaking in a post in the user forum. If you use these, then \goodbreak can be used to encourage a break at a particular location, \invisibletimes can be used to allow a break in a\invisibletimes b even though it appears without an visible operation, and \badbreak{...} and \nobreak{...} can be used around operations to discourage or prevent breaks at them. E.g., a\nobreak{+}b would not allow a break at the +.