MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

Math isn’t respecting the boundaries of containers

Open dac514 opened this issue 5 years ago • 1 comments

Can someone help me understand what's going on here?

width-problem-1

I'm using the defaults, expecting width: "container" to do some magic for me, but it isn't. Any ideas?

Here's the test page:

  • https://dactest1.textopress.com/chapter/mathjax-common-html-problems/

(Note to future selves, test page is temporary, will disappear once problem is resolved)

dac514 avatar Jul 04 '19 19:07 dac514

There are several things involved, here. First, math expressions can easily run over the width of a container, especially when those containers are relatively small, as in your example. MathJax will only break lines to fit the container when automatic line breaking is activated, which is not the case in your configuration. You would need to include

MathJax.Hub.Config({
  CommonHTML: {
    linebreaks: {
      automatic: true
    }
  }
});

in order to get automatic line breaks.

Note, however, that MathJax's line break algorithm is based on the MathML line breaking algorithm, which means that breaks only occur at certain places, namely at operators. MathJax does not break within a \text{} element, for example (unless there is math within that). So your explanations would not break even if you turn on line breaking. In addition, MathJax doesn't line break table cells very well, as it only breaks a cell if the cell is too wide for the container (without considering the widths of other cells in the table). So only first explanation would line break, and then it would break ti the full width of the container, not to the size of its column. Finally, automatic line breaking only occurs within displayed equations, and your expression is an in-line one, not a display expression, so it would not normally have automatic line breaks. In-line expressions only break when the entire expression is wider than the container, which is true in this case, but would not be true of an in-line expression near the right-hand side of the container, as with your (p - 1) = 0, which is moved to the next line in its entirety, rather than (say) breaking at the equal sign.

So this is the expected behavior of MathJax's current line breaking algorithm. Better handling of table cells and \text{} contents would be nice, but the result you are seeing is correct for the current implementation.

dpvc avatar Jul 04 '19 21:07 dpvc