MathJax: reflow in display math and optional line breaks

1,003 views
Skip to first unread message

Victor Ivrii

unread,
Mar 4, 2013, 11:12:03 AM3/4/13
to mathja...@googlegroups.com


DisplayMath does not allow reflow and if the width of the page decreases or fontsize increases formula gets unreadable. 

On the other hand uncontrolled reflow definitely is a cure worse than the disease as far a math formulae are concerned. It would be nice to have optional line breaks in DisplayMath which are activated only if page becomes too narrow, something like \\[opt] or \\[3pt, opt] 

Obviously it is not a proper LaTeX but LaTeX is not designed to produce documents allowing reflow.


Victor

Frédéric WANG

unread,
Mar 4, 2013, 11:26:34 AM3/4/13
to mathja...@googlegroups.com
Yes, it is one important point of MathML to be integrated in an
environment where reflow may happen and ensure that
rendering/linebreaking can be updated quickly according to windows or
font size change... Unfortunately, automatic update is something
difficult to achieve without native MathML support (mostly for
performance reason and communication with the browser).

I'm not sure to understand your idea. Currently line breaking is
disabled in MathJax by default. Are you suggesting to enable it only for
mathematical formula where the (initial) available width is too small?
Or to enable it when this width becomes too small (e.g. after user
interaction to resize windows or zoom the page)? The latter is likely to
be hard in MathJax.
> --
> You received this message because you are subscribed to the Google
> Groups "MathJax Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to mathjax-user...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>


--
Fr�d�ric Wang
maths-informatique-jeux.com/blog/frederic

Victor Ivrii

unread,
Mar 4, 2013, 11:54:46 AM3/4/13
to mathja...@googlegroups.com
My idea is simple and we are talking only about DisplayMath (not InlineMath)

Assume that I have a code like this:


\begin{equation*}
\tilde{u}_{\xi}= -\frac{1}{4c^2}\int^\eta \tilde{f}(\xi,\eta' )\,d\eta'=\\[opt]
 -\frac{1}{4c^2}\int_\xi ^\eta \tilde{f}(\xi,\eta' )\,d\eta' + \phi'(\xi)
\end{equation*}

then line break is not activated when the available width is sufficient; however if it is not sufficient then the line break happens ONLY at \\[opt] and not in any other place; meanwhile \\ without [opt] tag is ALWAYS a line break. 

This allows line breaks if needed in the predefined places

Victor



To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.





--
========================
Victor Ivrii, Professor, Department of Mathematics, University of Toronto
http://www.math.toronto.edu/ivrii

David Carlisle

unread,
Mar 4, 2013, 7:28:28 PM3/4/13
to mathja...@googlegroups.com
On 4 March 2013 16:54, Victor Ivrii <viv...@gmail.com> wrote:
> My idea is simple and we are talking only about DisplayMath (not InlineMath)
>
> Assume that I have a code like this:
>
> \\[opt]

I don't think it's a good idea to move too far from standard latex
syntax (or in particular syntax that could be used in standard latex
given a suitable package) One could of course overload the optional
argument of \\ to look for "opt" but it's a bit odd as it takes a
length in all other cases.

In MathML the line breaking is attached to the = operator not to the
point after it

<mo linebreak="auto">=</mo>

Is the MathML you'd want to generate for a renderer that implemented
MathML3 linebreaking.

Thus if this were going to be supported I think one should look to a
TeX syntax for the MathML attributes on an operator, something like

\attr[linebreak=auto]{=}

where \attr allows the setting of any MathML attribute on the operator,

\attr[linbreakstyle=duplicate,linebreak=goodbreak]{=}

Of course any given renderer might not support all the attributes but
as in XML such a markup gives a consistent markup for all the
attributes in a way that can easily be ignored by systems that do not
support the full set. Such syntax is easily supported in LaTeX with
the standard keyval package. (Supporting line breaking in display math
is a lot harder, but supporting and ignoring the syntax is easy:-)

David

Victor Ivrii

unread,
Mar 4, 2013, 8:03:23 PM3/4/13
to mathja...@googlegroups.com

On Mon, Mar 4, 2013 at 7:28 PM, David Carlisle <d.p.ca...@gmail.com> wrote:
In MathML the line breaking is attached to the = operator not to the
point after it

<mo linebreak="auto">=</mo>


Agree, = is a natural breaking point but if we have a really long sum then "top level" + or - or \times would be also natural breaking points. What I mean by "top level"? If sum has parenthesis like ( ), [ ]. \{ \} etc then signs outside of them. However things may get really complicated with this 

Actually MJ is already not completely compliant with LaTeX with \\ in both inline and display modes. I really don't like when MJ works (in math snippets) differently from LaTeX but some compromise is needed.

David Carlisle

unread,
Mar 4, 2013, 10:02:58 PM3/4/13
to mathja...@googlegroups.com
On 5 March 2013 01:03, Victor Ivrii <viv...@gmail.com> wrote:
>
> On Mon, Mar 4, 2013 at 7:28 PM, David Carlisle <d.p.ca...@gmail.com>
> wrote:
>>
>> In MathML the line breaking is attached to the = operator not to the
>> point after it
>>
>> <mo linebreak="auto">=</mo>
>
>
>
> Agree, = is a natural breaking point but if we have a really long sum then
> "top level" + or - or \times would be also natural breaking points.

Yes exactly and again the mml syntax would be <mo
linebreak="auto">+</mo> so I think the tex syntax ought to mirror that
concept of attributing the operator so \attr[linebreak=auto]{+}

David

Peter Krautzberger

unread,
Mar 4, 2013, 10:15:50 PM3/4/13
to mathja...@googlegroups.com
Just to point out what Fred had written: the problem isn't so much to indicate a break. It's to efficiently implement a reflow of MathJax typesetting.


--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.

Frédéric WANG

unread,
Mar 5, 2013, 4:10:17 AM3/5/13
to mathja...@googlegroups.com
I think a key point here is to notice that MathML (understand: math on
the Web) is different than LaTeX. In LaTeX you can "tweak" your formula
to be good-looking when you create your pdf or print it. With MathML you
can't assume that what you see on your screen with be the same on, say
mobile terminals or other systems with different math fonts. Thus the
linebreaking design explained by David Carlisle. Your proposal will work
to make one break optional but as you say in other screens one will need
to break elsewhere (like at + operators etc).

The MathML linebreaking (essentially, "breaking at operators") is
implemented in MathJax, but disabled by default. To enable it, add

"HTML-CSS": { linebreaks: { automatic: true } },
"SVG": { linebreaks: { automatic: true } }

to your configuration file. I think what you really want is an option to
recommend a "good break" in the MathML terminology. So when the the
space is narrow, MathJax will try to break at that point in priority. Of
course, if it is still not enough then it will break at other operators too.

I don't think MathJax as TeX command to specify a goodbreak but you can use

\mmlToken{mo}[linebreak="goodbreak"]{=}

to say that the = is a good break (of course, you can define a new macro
for that purpose). I attach screenshots showing how MathJax behaves with
and without this goodbreak.

Hope that helps.
default.png
goodbreak.png

David Carlisle

unread,
Mar 5, 2013, 5:11:57 AM3/5/13
to mathja...@googlegroups.com
On 5 March 2013 09:10, Frédéric WANG <fred...@free.fr> wrote:


> but you can use
>
> \mmlToken{mo}[linebreak="goodbreak"]{=}
>


ooh can you, I really must read the docs one of these days:-)
That is of course exactly what I was suggesting ought to be the syntax
(modulo cosmetics of the name of the command and order of the
arguments)
(Normally latex a=b arguments don't use "" delimiters so it would be
nice not to require those but that's a small issue)

David

Frédéric WANG

unread,
Mar 5, 2013, 5:19:14 AM3/5/13
to mathja...@googlegroups.com
On 05/03/2013 11:11, David Carlisle wrote:
> ooh can you, I really must read the docs one of these days:-) That is
> of course exactly what I was suggesting ought to be the syntax (modulo
> cosmetics of the name of the command and order of the arguments)
> (Normally latex a=b arguments don't use "" delimiters so it would be
> nice not to require those but that's a small issue)
Well, I'm not sure we have documentation on this (searching mmlToken in
the MathJax doc only returns the
http://docs.mathjax.org/en/latest/tex.html where it is just listed as
"non-standard". In general the "non-standard" TeX commands provide some
interesting features for the Web).

I think you can do a='b' and a=b too for that command.

Victor Ivrii

unread,
Mar 5, 2013, 5:30:15 AM3/5/13
to mathja...@googlegroups.com
I am a bit concerned about this 


F.e. in ansatz like
.... \sin(x)\bigr_{x=a}^{x=b} ....
would not it encourage line break at the very wrong place?

Let us look at LaTeX beamer package: by default it does not insert page breaks leaving it to the author as in presentations page breaks should be in the logical place rather than when page is full. So I believe that in math snippets line breaks should be also in the logical places.

Victor

Frédéric WANG

unread,
Mar 5, 2013, 5:36:49 AM3/5/13
to mathja...@googlegroups.com
Putting the breaks at the logical places is also what the MathML spec is
trying to achieve and we all agree about that. The question is: how do
we define the "logical" places? If you don't see what you want then it's
either an issue in the MathML spec or an issue about how it is
implemented in MathJax.

Victor Ivrii

unread,
Mar 5, 2013, 5:37:56 AM3/5/13
to mathja...@googlegroups.com
IMHO, the author should decide what is the logical place

Frédéric WANG

unread,
Mar 5, 2013, 5:46:55 AM3/5/13
to mathja...@googlegroups.com
On 05/03/2013 11:37, Victor Ivrii wrote:
> IMHO, the author should decide what is the logical place
That's where we disagree (see my comment about math on the web being
different than math on paper/pdf).
It would be possible to define all the operators as not logical break
("nobreak" or "badbreak") by default and let the author define the
logical places as "goodbreak". That would make the author happy but
other users with different screen configuration are likely to complain...

Victor Ivrii

unread,
Mar 5, 2013, 6:04:52 AM3/5/13
to mathja...@googlegroups.com


On Tue, Mar 5, 2013 at 5:46 AM, Frédéric WANG <fred...@free.fr> wrote:
On 05/03/2013 11:37, Victor Ivrii wrote:
IMHO, the author should decide what is the logical place
That's where we disagree (see my comment about math on the web being different than math on paper/pdf).
It would be possible to define all the operators as not logical break ("nobreak" or "badbreak") by default and let the author define the logical places as "goodbreak". That would make the author happy but other users with different screen configuration are likely to complain...


 
Not necessary. Let me repeat my example. For my screen configuration no break is needed

\begin{equation*}
\tilde{u}_{\xi}= -\frac{1}{4c^2}\int^\eta \tilde{f}(\xi,\eta' )\,d\eta'=
 -\frac{1}{4c^2}\int_\xi ^\eta \tilde{f}(\xi,\eta' )\,d\eta' + \phi'(\xi)
\end{equation*}


but I suspect that for narrow screen this would be too long and suggest that in this case the linebreak should be there

\begin{equation*}
\tilde{u}_{\xi}= -\frac{1}{4c^2}\int^\eta \tilde{f}(\xi,\eta' )\,d\eta'=\\[opt]
 -\frac{1}{4c^2}\int_\xi ^\eta \tilde{f}(\xi,\eta' )\,d\eta' + \phi'(\xi)
\end{equation*}


Similarly I may suggest optional additional line breaks in multiline or gather environment (align with & is much more problematic)

Frédéric WANG

unread,
Mar 5, 2013, 6:16:04 AM3/5/13
to mathja...@googlegroups.com
On 05/03/2013 12:04, Victor Ivrii wrote:


\begin{equation*}
\tilde{u}_{\xi}= -\frac{1}{4c^2}\int^\eta \tilde{f}(\xi,\eta' )\,d\eta'=
 -\frac{1}{4c^2}\int_\xi ^\eta \tilde{f}(\xi,\eta' )\,d\eta' + \phi'(\xi)
\end{equation*}


So this is exactly the \mmlToken solution I suggest:

1) with large screen: no break
2) with narrower screen: break at the "goodbreak" specified by the author with the mmlToken command (here the "=" sign)
3) with even narrower screen: try to break at more operators (+, etc)

You seem to consider only 1) and 2). Not sure how you want to handle 3), from what I understand your solution is that is is up to the author to specify all its preferred breaks.
-- 
Frédéric Wang
maths-informatique-jeux.com/blog/frederic

David Carlisle

unread,
Mar 5, 2013, 6:30:02 AM3/5/13
to mathja...@googlegroups.com
On 5 March 2013 10:30, Victor Ivrii <viv...@gmail.com> wrote:
> I am a bit concerned about this
>
>
> F.e. in ansatz like
> .... \sin(x)\bigr_{x=a}^{x=b} ....
> would not it encourage line break at the very wrong place?


If you mean would it encourage line breaking at the = in the
sub/superscript no the default would only be to look at operators in
the mrow that is being wrapped.

David

Victor Ivrii

unread,
Mar 5, 2013, 6:35:48 AM3/5/13
to mathja...@googlegroups.com

--



Then its OK here.

Now about breaking at + or -:

\begin{equation*}
.................. + \sum _{k=1}^\infty (a_k + b_k) + .....
\end{equation*}

The first and the last + are good places logically to break but the middle one (in a_k+b_k) is not. 




 

David Carlisle

unread,
Mar 5, 2013, 7:21:04 AM3/5/13
to mathja...@googlegroups.com
On 5 March 2013 11:35, Victor Ivrii <viv...@gmail.com> wrote:

>
>
> Then its OK here.
>
> Now about breaking at + or -:
>
> \begin{equation*}
> .................. + \sum _{k=1}^\infty (a_k + b_k) + .....
> \end{equation*}
>
> The first and the last + are good places logically to break but the middle
> one (in a_k+b_k) is not.
>

If the MathmL is correctly marked up then the middle + will not be in
the top level mrow it will be in an explicit mrow for the bracketed
term or in an mfenced which is an implicit mrow. If things get really
squeezed an algorithm might need to start breaking inner terms but not
before breaking at the top level operators.

Unlike TeX where you are looking at a fixed fonts and a fixed page
width so it makes sense to directly markup line breaks, in MathML (or
TeX aimed at generating mathml) you really want to avoid that as far
as possible. The nested mrow structure gives the engine a lot of hints
about the logical structure of the expression, that's why the MathML
spec encourages people to use good mrow structure even if it makes no
visible difference to the layout they see.

David


David




--
http://dpcarlisle.blogspot.com/

Davide P. Cervone

unread,
Mar 5, 2013, 7:47:02 AM3/5/13
to mathja...@googlegroups.com
> Now about breaking at + or -:
>
> \begin{equation*}
> .................. + \sum _{k=1}^\infty (a_k + b_k) + .....
> \end{equation*}
>
> The first and the last + are good places logically to break but the middle one (in a_k+b_k) is not.

The line breaking algorithm in MathJax takes a number of factors into account, including the nesting depth (and tries to determine nesting even if the mrow's are not explicit). So MathJax would be less likely to break at the nested + than at the other two.

You can add a level of nesting in your TeX by adding braces. So if MathJax breaks a line where you don't want it to, you can discourage that using braces, e.g.,

+ {sum_{k=1}^\infty (a_k + b_k)} +

would discourage breaks within the sum.

I gave some definitions for macros like \goodbreak in my response at

https://groups.google.com/d/msg/mathjax-users/Uaaht3cGJu8/X7aplu8UQncJ

so you can look there for some ideas about how to control the line breaking algorithm.

Davide

Reply all
Reply to author
Forward
0 new messages