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
Incorrect widths of math elements in Gecko #558
Comments
Thanks, Fred! |
Peter's original test case was test/sample-mml but it's somewhat difficult to reproduce. Here are some test cases related to this bug:
|
So I've committed a patch that restores the width correction of the math in Gecko's native MathML but removes the incorrect fix of issue #386 in that case (I guess the latter is less likely to happen than the former). However, the width may still be wrong for mtable cells so we definitely need to fix bug 415413 upstream. I suspect that in general, each time we measure some width in native MathML (not only Gecko), this width is likely to change after Web fonts are loaded. So in particular we'd rather implement mlabeledtr upstream and remove the workaround introduced in #356 in the future (or we'll have to do ugly measure verifications on each math, which will be a performance loss for the native MathML). Having #301 to ensure correct stretching of operators is more important to me and anyway people will always be able to use Web fonts themselves. |
Sorry, I forgot to switch to MathML output (D'oh!) |
They were local fonts. The result may well be system-dependent. For example I didn't see Peter's original bug without trying with a larger zoom. That may depend on default font preference of Firefox (font-family and font-size). Probably that worked on your system and so didn't see the issue when fixing the bug. |
OK :-) |
Here's what I've found out about the problem. It used to be that the The following code shows the issue:
The output for me is the following: Note that the true width of the math is 76 pixels, while the width of the containing element ( MathJax tries to compensate for the first error by transferring the Fred correctly points out that this correction was lost in the change for the |
The only widths that are being measured (currently) is the size of the
I'm not sure I understand the linkage between the The only solution I can think if is the one I suggested in #301 and that you suggest above: looping through the math periodically to see if the width has changed and updating it. It is ugly, but it is not that inefficient (it is merely checking if the top-level Certinaly fixing the measurement errors in Gecko is a better solution, but we have to work with the Firefox browser as it currently stands (and will still have to support some older versions even once it is fixed, at least for a while). |
There are two distinct Gecko bugs here:
|
Why do we have to put each math element in an inline-block span?
I think I remember that in mlabeledtr we take the width of the parent table at some point but didn't check in details. Anyway, my point is that we should ideally not measure anything in the NativeMML code since that's a performance loss and interfere with the user's CSS. So things like #564 must be fixed now. Of course if there are bugs, we have no other choice than to workaround them and to temporarily measure sizes. Another bug in Gecko affecting height: |
Note that we don't use any of clientWidth, clientHeight, offsetLeft, or offsetTop from MathML elements in MathJax. Never have. I certainly don't know anything about how Gecko works internally, but it doesn't to me that this problem is about the widths of token elements. Those all seem to have the correct widths. Even the math element has the correct width. It is that that width doesn't seem to be recognize by the parent element. Unless what you are saying is that the parent element asks the math element for its width, and the math element asks the mrow, and the mrow asks the token elements, and they report something wrong, and the mrow adds up the wrong values and reports it back to the math element, and it reports back the wrong sum to the parent. In that case, I don't see how the scrollWidth and the bounding rect size can be right. But, as I said, I don't know anything about the internals of Gecko; it just seems weird. |
There is a check to see if there is an explicit width that is a percentage, as the work around is different in that case, but no actual measuring of elements is performed. |
I just copied the bug report name, but the comment holds for all the offset_, scroll_ and client* metrics I think. I remember that in the Zoom code we use one on the math.
The intrinsic widths of these tokens are incorrect, not the final ones that are returned by Javascript. That means it will affect the width of elements like table cells that require these intrinsic widths to decide their layout. So finally, the final widths of the cells get wrong, but that's because of the incorrect intrinsic widths of tokens. |
Personally, I think the current behavior is correct. It's like a span with a large image in it, it's height is still that of a standard line. But that may be a matter of viewpoint. |
OK, I didn't check in details. |
OK, that was just to point it out. But I don't think it affect MathJax. |
Comment 14 on that bug report indicates |
Yes, I'll look into it and see if I can figure out what is wrong. The px width will certainly work (other than the print problem when the media scaling is different from the screen scaling), but I'd like to figure out why the ex width is off. |
…ing the width from the child mrow (works around FF bug that gets these widths wrong). Resolves issue mathjax#558.
I found the problem with the widths when given in ex's: the span being styled was inside the one that had the I've also added a work-around for the problem with the I still have to add the option to disable automatic scaling, and to do the loop that checks if web fonts have changed the sizes of the math. I'll post again when I have that taken care of. |
I'm not sure the loop that checks if the surrounding font size has changed is necessary for MathML, since I expect the incorrect width to be fixed in future versions of Gecko and the workaround to be removed in the next version when we deprecate old browsers. However, this will still be necessary for the HTML-CSS / SVG output, if that's what you mean. |
My |
…ath or the surrounding font. Resolves issue mathjax#558.
…he paramters that control it in NativeMML (so both have the same names). Add a global matchWebFonts option to control whether to do the loop to check for web fonts (off by default). Resolves more of issue mathjax#558.
OK, these last two commits (to the There is a global parameter One pass through the loop is pretty fast (60 equations used about 15 to 20 milliseconds for me), and it doesn't seem to interfere with scrolling and other user interaction. For the HTML-CSS output, if a change is detected, the output is re-rendered. This is because the output is sensitive to The SVG output doesn't need such a loop since it scales automatically (its size is given in units of ex, so a change to the surrounding font changes it automatically). Technically, we should re-render it on a font change as well, since the absolute units would need to be adjusted. But it probably isn't worth it, so I didn't add the loop. If you think it should be added for completeness, I can do that. Perhaps being able to disable the loop in individual output jax would be useful as well. |
The loop actually serves two purposes: detecting web font's within the MathML itself (and fixing the width values when that occurs), and detecting detecting font changes either within or without the MathML so that the math font can be scaled to match the surrounding text. While the first of these may be fixed in the next Firefox release, I suspect the second will not be resolved for some time, so if the MathML uses web fonts (as you have planned to do), or if the page does, then I still think there is a need for this feature. Of course, the page author can disable it (it is opt-in rather than opt-out anyway at the moment). I also added |
Here are the changes for the |
It is used for various event handlers for things like zoom click or hover events, and for the "discoverability" interface (which is not on by default, but is still there). For example, the border of this span can be made to "fade in" when the mouse is over the math, and a menu icon can appear at the upper right corner to give access to the contextual menu. This was designed to make the mobile interface easier, but the decisions about how to proceed with it where grounded when Robert went into the hospital. |
I hope the first to be fixed in Gecko Nightly soon. As for the second, this could just be modifying the CSS stylesheet not to change the font-family on the element, so that the font for the math matches the font of the surrounding text by default. However, a mechanism to automatically rescale the font size of the math will probably never be implemented. If a user decides to set the font-family or font-size on the math, then the native rendering engine must use that. While it could be considered a "feature" for a Javascript library as MathJax, it is just a CSS bug for a native rendering engine.
This is a very bad idea if linebreaking is implemented correctly in native MathML in the future and we'll have to reconsider this choice if we don't want to have yet another CSS compatibility issue. Consider for example
or equivalently, with pure HTML:
and here how they render in Gecko: while an inline frame splits into several lines and behaves well with respect to the surrounding text, an inline-block frame does not split and the linebreaking of the MathML happens inside that inline-block itself, without interaction with the surrounding text. To say it simple, it's just like if we were putting all the equations inside a HTML table with a single cell, preventing any interaction with the surrounding text... |
Great to hear that the FF nightly might fix this. How much does the NativeMML output differentiate between browser versions? Weighing accessibility (zoom, discoverability) against line breaking is a tough call. Perhaps we can solve some of these problems by using page-wide tools, e.g. zoom libraries. |
It is probably worth making this a separate issue for future consideration. Changing the |
Perhaps since the web-font-testing loop is off by default, that code should be made into an extension rather than be included in the core? (If so, however, that would also mean that the future use of web fonts for NativeMML output would also have to be an extension, since it would rely on this one.) |
|
Sorry about the debug message. I thought I had caught them all. OK, I'll turn the loops into an extension. About SVG, remember that the font height matching is automatic in that case, so the only advantage to doing this will be to adjust the size of dimensions given in absolute units within the math. Since those are seldom used, and it requires re-rendering the math to do it, I'm not sure it is worth it. But I can certainly add it. |
Yes, I got that. To be honest, I don't really have a preference but that seemed weird to not have the option for SVG. In that case, perhaps use one config option per rendering mode so that people can e.g. enable it for HTML but not SVG. And people who really need it for SVG could enable it too. |
OK, sounds good. |
I've moved the code to an extension, and made it possible to configure the renderers separately. This is the => Ready for Review |
I have not checked in details, but I'm OK with the changes in general so let's merge them to start the testing. => Ready For Release |
Improve width computation for MathML elements (issue #558)
=> Merged |
There seem to be a couple of failures do to spacing changes. I wonder if this is caused by #558 |
Follow-up of Peter's report on the dev list, there are issues with width of math elements in Gecko. MML.math has the following block:
As I read it, this will not be executed if there is not any mtable. I think we disabled the correction when we added the mlabeldtr workaround in 0891402#L5L621 (issue #356). The condition should probably be:
But then this gives too large widths. It seems to be due to the conversion to ex which was introduced in debc240#L3L618 (issue #386)
The text was updated successfully, but these errors were encountered: