-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linebreaking support #127
Comments
We need to investigate a bit this, but I imaging we could introduce a math-wrap property (or rely on an existing CSS one) in the future, which would default to nowrap if we are concerned about backward-compatibility change. |
Gecko disables linebreaking in table cell: WebKit disables linebreaking in foreign content: I guess we could set white-space to nowrap by default on MathML elements to prevent any backward-compatibility issue. |
It would probably interesting to start experiment line breaking with the CSS Layout API ( https://drafts.css-houdini.org/css-layout-api/ ) maybe starting with basic tests and then trying write a mrow-like layout. In any case, I think #123 should be resolved first. |
Line breaks are more important in the mobile-screen world than they were years ago. I think this should get a high priority. The TeXbook, page 173 states that a "A formula will be broken only after a relation symbol like KaTeX does its best to emulate the TeXbook rule. For my own work, this issue the is single thing that will cause me to use use KaTeX HTML rather than MathML. |
The rules that TeX has for linebreaking only apply to inline math. TeX categorizes symbols into a small number of categories (to fit in four bits because efficiency was critical at the time of its design). This means that there are broad generalizations that work a lot of the time but not always. E.g., Generally, in linebreaking you want to look at the expression tree and break as close to the root as possible while still filling as much of the line as possible. Typically, relational operators will be at the root of a tree, then lower precedence operators like + and -, then higher precedence operators like ⋅, ⨯, and /. Well-structured MathML (which is unfortunately not very common) has mrows that align with the expression tree so knowing where is a good spot to break is easier with well structured MathML. MathML's operator dictionary gives priorities of operators that can be used for parsing and linebreaking, and serve as a guide for spacing also (higher priorities have less space around them in general). MathML 3 lists a potential linebreaking algorithm that takes time proportional to the number of token elements times the number of lines, so it is relatively quick and does a pretty good job. A more complicated version that looks at the whole expression vs a single line would mimic TeX's paragraph linebreaking rules. I would like to see the simpler algorithm become part of the core spec, but I understand we need to have priorities and this might add several weeks of implementation and spec time if cleanly doable at all with the current state of CSS. In response to earlier comments:
|
I think there are two important points in Neil's reply:
|
Agreed and acknowledged. The work being done is excellent.
Yes, MathML 3 contemplates an attribute of
If I understand that statement correctly, then one could apply an inline style of Do I understand that statement correctly? |
A similar approach would break the top level into multiple
This approach would create automatic line breaks in the TeXbook locations. It works, at some cost to the semantics. As suggested, KaTeX could implement this method. It is very similar to what is now done in HTML. If the method in the previous statement will not work, the method in this comment is probably what we will do. Let me know where we stand. |
This is the short term approach I was thinking about. You can use |
@fred-wang Thank you for the quick response. That clears up the picture considerably. |
@ronkok No problem. Additionally, note that you can use https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver to watch when the width of the container of the |
KaTeX avoids, so far, any reliance on the browser for runtime information. It generates code that works whether generated client-side or server-side. So I think we're stuck with the multiple |
consensus from 2020/06/23: postpone to a future version |
Since it is not in this issue and might prove useful to a future core implementation... I implemented a linebreaking polyfil back in 2020 (seems like a lifetime ago...). You can see it in action on github.io. Click on This transform makes use of one column Note: indentation is done using |
Since we have a prolonged gap period here, are there any current recommendations for pure CSS solutions for reflow? I took a stab at switching the display of a simple equation to Here is an example of that (with flex always on). The demo should be able to render 6 different arrangements as the screen shrinks: It would take some more fine-tuning to control the finer details of reflow, but this could already be a healthy upgrade for common equation markup. |
I can confirm that a flex-based solution works pretty well. You can see it already in action if you navigate to Temml.org and turn display mode off. In default mode, Temml writes MathML with
I don’t apply flex-wrap in Firefox. In Firefox, the separation by Temml has a rendering option which allows a website administrator to select breaks before In the comments above, I was one of those asking for line-breaking action in the MathML Core specification. At this time, I do not make that request. In Chromium and Firefox, I think line-breaking is largely a solved problem. Chromium and WebKit have much bigger rendering problems to solve. Sadly, flex-based line-breaking does not work in WebKit. Maybe someday. |
@ronkok This is great, thank you for the extra context. But I wouldn't go beyond calling this a "stopgap solution", since you've enumerated some serious problems. WebKit lacking support is one, another is ending up with two non-standard solutions for Chrome and Firefox. Not having a standard way to manually force (or softly suggest) a linebreak in the usual MathML markup is a third. Flexbox allows a variety of techniques to support what Neil referred to as In summary: <mrow> ...LHS... </mrow>
<mo>=</mo>
<mspace class="linebreak"></mspace>
<mrow> ...RHS... </mrow> mspace.linebreak {
flex-basis: 100%;
height: 0;
width: 0;
overflow: hidden;
} Update: In cases where we have a As an alternative (and maybe even worse) trick, one could rearrange the |
One of these is a typo, I suppose? The second one? |
To clarify: Temml's On the more general question, I have begun compiling a list of browser issues. Firefox is the best, by a large margin. Chromium has some serious issues, especially if system fonts are used. WebKit is the worst. It cannot even render an accent at the correct vertical alignment. I put a lot of work into the Temml library. It is my sincere hope that someday, MathML will get widespread use. But I think that day is not yet. I suspect most web site administrators will avoid MathML until browser rendering is more reliable. |
@ronkok: I'm a little late to the game, but I finally tried temml.org in Chrome and it is great to see flex-based solution works. But putting aside it currently only works in Chrome/Edge, I would add it is only half the solution. Not only does an expression need to wrap long lines, it needs to indent them appropriately. Is that something that can be done with flexbox? The polyfill I mentioned illustrates why that's important. But it is hacky in that it had to create an mtable. I hope core level 2 will have at least the hook mentioned. |
@NSoiffer I'd like to look at your polyfill in action, but I'm getting a 404 error when I click on that link. I'm still thinking about how to get an indent. I have a version working in a web app I call Hurmet.app. It renders math with Temml's version of MathML and I have it set to wrap before top-level To get that indent, I have appended the following CSS.
That's pretty hacky and I have applied it only to my own site, Hurmet, not to the library Temml. I'd like better control over the width of the indent. I'd like something less odd. But it will serve as a temporary line breaking solution. I agree with both you and @dginev that this is a temporary fix and would benefit from better support in MathML-Core someday. But there several other rendering issues that I think should get higher priority. |
On Thu, 3 Aug 2023 at 16:55, Ron Kok ***@***.***> wrote:
@NSoiffer <https://github.com/NSoiffer> I'd like to look at your polyfill
in action, but I'm getting a 404 error when I click on that link.
I'm still thinking about how to get an indent. I have a version working in
a web app I call Hurmet.app <https://hurmet.app/sample>. It renders math
with Temml's version of MathML and I have it set to wrap before top-level
= characters. Here is a screenshot of how that looks:
[image: Math wrap]
<https://user-images.githubusercontent.com/16403058/258165385-eb5e6b13-4268-49b1-acd8-8e2afb5cb063.png>
To get that indent, I have appended the following CSS.
/* Create a hanging indent on calculations that wrap to a second line. */
.hurmet-calc > math > mrow:not(:first-child) { margin-left: 2em }
.hurmet-calc > math > mrow:not(:last-child) { margin-right: -2em }
That's pretty hacky and I have applied it only to my own site, Hurmet, not
to the library Temml. I'd like better control over the width of the indent.
I'd like something less odd. But it will serve as a temporary line breaking
solution. I agree with both you and @dginev <https://github.com/dginev>
that this is a temporary fix and would benefit from better support in
MathML-Core someday.
But there several other rendering issues that I think should get higher
priority.
—
The polyfills moved from mathml-refresh to w3c github organisations
https://w3c.github.io/mathml-polyfills/
but the html linking seems broken in the move (all links off the above page
are 404) , I'll look...
Just github pages is broken, the source is
https://github.com/w3c/mathml-polyfills/blob/main/acid-test.html
Message ID: ***@***.***>
… |
Thank you for the link to the polyfill. It's nice work. Temml is written to run either client-side or server-side. It therefore does not have access to There is room in the world for both CSS solutions and JavaScript solutions. Hopefully, one day the browser will have a native solution and neither will be necessary. |
cc @bfgeek
The MathML core spec now defines all the min-content / max-content values, however these two are equal and linebreaking is supposed to never happens.
I believe linebreaking could potentially happen in:
Inline equations. However, I think defining CSS fragments will be a bit complicate.
mrow-like element from display equations. We have an experiment like this in chromium. Currently that depends on the parent's width however, we could do something similar if width is specified on the element (Generate new PNGs for examples in the core spec #45).
mtable (I guess that's already defined by CSS). Maybe we want to prevent it for now.
MathML 3 rules for linebreaking are quite complex, maybe we should have a simple version first and refine it later or get it improved by polyfills when the CSS Layout API is ready.
Just opening this so that it can be referenced from the spec.
The text was updated successfully, but these errors were encountered: