-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Using fonts from MathJax's CDN for Native MathML #301
Comments
I haven't test the fix yet. (this time I combined and repacked MathJax, although I don't know if that's convenient for merging branch) |
There were extra single quotes in the CSS rules, that I have fixed in my latest commit. I tested this with Firefox Beta 15 and the Web fonts are correctly used: http://devel.mathjax.org/testing/mathjax/tests/MozillaTortureTest/texvsmml.html However, MathJax does not seem to scale correctly the math with respect to the surrounding text. I guess this is because it does not have access to the font metrics until the fonts are downloaded... |
Yes, I think you have touched on the issue. The way MathJax tries to match the size is to use a box of a particular height and width in ex's and measure the size of that box. I guess that the web fonts aren't loaded by that action, and even if they were, they might not have arrived yet, so MathJax gets the wrong size. I suppose I could have MathJax insert a dummy |
Do you think that scaling the math with respect to the surrounding text is the only place where MathJax needs the fonts to be available? I'm wondering if it's really worth addressing this issue now (it is less serious than the bad rendering when users do not have the fonts installed). Another solution would be to insert the math elements to let Firefox display them, wait a certain delay and render the math elements again. Note sure that would be better, though. |
I think you are probably right, it is not something to worry about at the moment, so I'm marking it ADDRESS LATER so we remember to come back to it for the release after this one. |
I meant, we can take the fix at it is now (allowing the user to get a decent rendering without fonts installed) even if the scale is not applied correctly. |
Sorry, I'm working on too many things at once, and was getting confused about the plain FF usage of the fonts versus the MathJax NativeMML usage. Yes, we should be able to go ahead with the changes. It would also be possible, I suppose, to use a tester like the HTML-CSS output does to find out if the fonts are ready. The problem is, MathJax doesn't know what fonts the native MathML renderer will actually be using, so that probably doesn't help. I also noticed that the width of the math can grow when the fonts arrive, so the space reserved for the math may be too small in the end. That is potentially a worse situation. I suppose MathJax could go back afterward and adjust the sizes after it is finished. |
I think we should add options similar to the HTML-CSS / SVG outputs to force the choice of a font. We can add font-family rules to change the font of the text and the other -moz-* rules for the stretchy symbols.
Yes, I also noticed that too, although I was not sure it was the same problem or not. IIRC this was to fix a bug when the math is zoom. Anyway, I think your are right that we should handle this for after the next release. |
There is a font menu (hidden by default) that controls the HTML-CSS font usage. We could probably do a similar one for NativeMML output. |
I was thinking to the configuration options, but probably a font menu would be a good idea too. |
OK, good point. Yes, font options in the configuration for NativeMML would be appropriate. |
I've updated my branch to make the NativeMML font configurable. For the moment, I didn't do font detection or take the menu choice into account. It seems that the font detection and verification is not so simple. Would it be best to move it to a separate file that would be shared between the HTML-CSS & NativeMML output? I guess just force a reflow after some arbitrary time to avoid the problem mentioned above, but that won't help to detect which local fonts is installed. |
I wanted to put the FONTTEST variable in a specific extension that would be loaded by the HTML-CSS & NativeMML outputs but then I realized that it uses the HTMLCSS variable and specifically the HTMLCSS.FONTDATA. Is there a simple and reliable way to detect when the Web fonts arrive, that could be put in the NativeMML jax instead? It's a shame that browsers don't have an API to do that... |
The font testing is one of the most fragile components of MathJax, so "simple and reliable" is not really what I would call it. If you are wanting to deal only with the MathJax fonts, then the code could probably be simplified, and the section of HTMLCSS.FONTDATA that is needed (not much as I recall) could be included. But doing the detection in general is quite hard. It might be worth looking at the google webfont code to see if they have developed anything better. |
I've updated my branch again to recompute the scale and width after three seconds. Some things I'm not sure:
Other remarks:
|
I've updated the detection of changes to the default sizes as mentioned in my previous comment. I also added items for NativeMML in the font preference menu. In general, I tried to have configuration options consistent with the HTML-CSS ones, although of course the behavior may be slightly different depending on font support, native MathML support etc => Ready for review |
I haven't had the chance to look carefully at the changes, but you are right that changing the three loops to one destroys the "one reflow", and you now have a reflow for each math expression on the page. That was the reason for the three loops originally. I will look more closely at the rest of it when I can. |
IIUC, the reflow happens when the browser has to measure the offsetWidth. So that's not a problem if I keep a separate determineScalingFactor function, just that I need to keep the three loops. |
Right. It is not the separate function but the combining of the insertion of elements, measuring, removal all in one loop. The reason for three loops is to do all the insertion first, then all the measuring, then all the removal. That means the measuring only causes one reflow. |
So as discussed with Peter on IRC, the plan would be to check all the issues "Ready for review" and merge them, so that we can run the tests today and tomorrow. The issue301 branch allows the users to choose a font via the menu but I think this is not fundamental (the most important feature here is supporting Web fonts in native MathML here). Hence I think the modification to the menu can be removed before the merge, so that it won't be a problem with the localization. The Open Type font branch will certainly be merged after the beta and also modifies the menu. Hence that will be a good time to modify the menu for this issue301 branch too, and update the localization strings. dpvc: can you review the changes to unpacked/jax/output/NativeMML/config.js and merge them if they look ok? |
I'm removing the "Ready For Review" flag for now. I'll update the branch against the latest version (especially with localization change) and add woff versions of Asana/STIX for native MathML as specified in |
OK, I've created a new branch issue301-bis. This adds support for Asana, STIX and MathJax Web fonts for the native MathML (in browsers). This also fixes the issue with the horizontal braces in MathJax fonts, since Gecko can pick the glyphs needed from other fonts (while still using MathJax glyphs for the other constructions). This also works in Webkit, although it is not possible to decide which font to use for largeop/stretchy operators (probably a ::-math-stretchy CSS rule should be defined). Anyway, Webkit largeop/stretchy support is currently very limited. => Ready For Review |
https://github.com/fred-wang/MathJax/compare/mathjax:develop...issue301-bis I'm updating the title since it's not specific to Firefox |
I've been looking at this branch for a couple of days, and I think there are some issues to be addressed.
I suppose it would be possible to run through all the math elements to see if their widths have changed in order to update the width that was set on the containing span, and it probably wouldn't take all that long to do it, but it does seem rather drastic. I can't think of another reliable way to do it, and even then, it is not clear when you should stop looking. One approach is to use a short initial time (so you respond quickly to fonts arriving), but then make the delay longer and lager as you try again, until it gets long enough to give up trying. (That is how the timeouts work for HTML-CSS polling for fonts, for example). In any case, I'm a rather uncomfortable with the current approach that really doesn't give any reasonable guarantee of detecting the width changes. I know that is a lot of items, but I think there are some important issues that need to be resolved before this can be merged. |
Just to chime in.
|
I'm OK with not exposing the font menu, and having authors specify the fonts (as the do now for HTML-CSS output). I'm not sure what you mean by defaulting to the MathJax fonts, though. The pop-up tells what font is selected for HTML-CSS, so I figured if there is a choice for MathML, it should tell that, too (so we can get information about it when users report problems). The reason there is a difference between HTML-CSS and NativeMML is that the HTML-CSS fonts distinguish between local and network versions (there are four choices: local STIX fonts, local TEX fonts, web TeX fonts, and image fonts), while NativeMML doesn't. That is, the choices for the two output modes aren't the same. So you can't use the same value for both, since the choices for one don't correspond to the choices for the other. In terms of the using new web fonts, I'm not sure if that will work or not (which is why I was asking Fred about it). It may be that the current browser CSS rules preclude that (because of the naming or the math tables or something like that). As for the conflict between NativeMML and HTML-CSS, the way the Finally, about font detection, the NativeMML output jax sets the size of its output SPAN tag explicitly, at least for Firefox, because Firefox doesn't always get the size of the The problem is that his code doesn't actually detect the incoming fonts (it is not measuring anything that depends on them), so the sizes won't be fixed. And even if it did, since more than one font might be needed, MathJax might need to detect several incoming fonts, and recalculate as each arrives. But MathJax doesn't know what fonts are actually being used by the MathML (unlike when HTML-CSS is used, where the font used for each character is painstakingly determined), so can't tell what fonts to wait for, or which equations might need resizing. So the whole process is a bit fragile. My only suggestion would be to loop through all the math and update the sizes based on the sizes of the inner Hope that clears up the issues. |
=> One consequence of this is that the NativeMML can not (and must not) use our custom Web fonts. Also, for Gecko the Web font name should currently be exactly the same as the local font. Because Gecko uses the MathJax/STIX family that have several small fonts, we have to specify all these rules in the CSS which is a bit tedious. So I've written a script to generate these rules for my MathML-fonts add-on that just uses the list of files even if they are not all used in Gecko or WebKit ; and I've just used a macro to convert these rules to the MathJax format. This will be much more simpler when only a single font is necessary as it's the case for Asana. I would have guessed that browsers are clever enough not to download the uncessary fonts but I admit that I didn't checked.
|
I've created a simplified branch based on the one of issue 564 (that removes automatic resizing of text). Now I'm only using @font-face CSS rules to load MathJax Web fonts (and Asana to draw horizontal braces). I've removed all the config and menu features. So the only remaining issue is to rename the @font-face rule of the HTML-CSS output. What should I modify exactly for that? |
Differences with issue #564 : |
At the moment, I'm leaning toward giving up this for MathJax 2.3. Hopefully in the release that comes after, the Gecko width bug and the lack of good support for stretchy operators in WebKit will be fixed ; so we can do that properly. |
Your call, Fred. If this needs more work on the browser side, I'm sure we can figure that out. |
This discussion is out of date given the developments in Gecko (Opentype Math tables etc). Not sure if we should open a new issue to reflect the changed requirements. |
Marking this |
Firefox 15 is going to be release today and could now use MathJax fonts for the MathML operators.
See https://groups.google.com/forum/?fromgroups=#!topic/mathjax-dev/9EyiDt_0ess
=> assigned to myself.
The text was updated successfully, but these errors were encountered: