MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

incorrect line breaking of pmatrix

Open pzinn opened this issue 7 years ago • 2 comments

with line breaking on, if I try to typeset a matrix with \begin{pmatrix}...\end{pmatrix} that's just a bit too wide for the window, the right parenthesis will appear all alone on the next line. (this happens both if surrounded with \[ \] or \( \), though it is worse in the former case since the right parenthesis sits in the middle of the window) can this behavior be prevented?

pzinn avatar Apr 01 '18 11:04 pzinn

If the pmatrix is the only thing in the expression, then the only breakpoint is at the final paren (or bracket, or whatever), and so MathJax is forced to use the breakpoint if the line is too long. MathJax doesn't consider the end of the line as a breakpoint (though this example suggests that it should), so there is no direct way to prevent the break at the only breakpoint in the expression.

The only thing I can think of is to set the penalty for line breaks that occur past the end of the line to large enough to prevent them from occurring. That should take care of this situation (provided the start of the parentheses is past the end of the line), but may prevent breaks that you might want at other locations (e.g., a line with no breakpoints inside the container, but one later on).

To do this, add

<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("CommonHTML multiline Ready", function () {
  var PENALTY = MathJax.ElementJax.mml.mbase.prototype.CHTMLlinebreakPenalty;
  PENALTY.toobig = PENALTY.nobreak;
});
</script>

to your page just before the script that loads MathJax itself.

dpvc avatar Apr 02 '18 13:04 dpvc

I still think this is an "issue". Clearly, the line break shouldn't be there. There should be a better way to locally prevent line breaks within a given block, otherwise I find the whole line breaking mechanism unusable.

pzinn avatar Apr 03 '18 03:04 pzinn