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
Web-Font TeX/Main/Italic fails to load in QTWebKit #302
Comments
We have seen this problem with QtWebKit before. See this user forum post for example. As I mention in that thread, the font-detection code is one of the touchiest bits of MathJax, and the WebKit handling is particularly delicate, and it doesn't seem to work properly for QtWebKit. My suggestion in that discussion was to try SVG output if that is acceptable to you, as it avoids the font issues entirely. That might work better for you. |
SVG output may be acceptable for me, but it's definitely not acceptable for all ReText users :) I've noticed a strange thing: if I use the version from CDN, second try succeeds; if I use a local copy (from v2.0-latest Git branch), it never succeeds. Is that possible to fall back to the font used for the rest of the characters? Or fall back to SVG, that's still better than PNG. |
(Citing your post in the linked thread)
If you are looking for easy-installable QtWebKit-based browsers for testing, take a look at Arora and QtWeb, both are open-source and have Mac OS X builds available (I've used neither of them, though). |
Thanks for the links to the other browsers. Both of these work fine for me, both on your example and on my own. So I'm wondering what the difference is with your editor. Do you get to specify the default font? If so, can you change it to something else and see if that helps? |
I set default font to 'Sans'. Not setting it at all or setting to a different value (using embedded CSS, I didn't try QWebSettings) doesn't help. |
Here's a minimal Python script (PyQt needed) that demonstrates the issue. I can provide a C++ version if you prefer. |
About SVG: I wasn't suggesting using SVG for the saved output, only for the preview display (which I thought was where the problem was, since that is the viewer using QtWebKit, right?). The italic font is the first font MathJax is looking for, and I suspect the same problem will occur for any of the other MathJax fonts. So there is no other font to fall back on. MathJax can't use the page font because MathJax needs to know a lot about the font in order to use it (like the bounding boxes of all the characters), and anyway, most fonts don't include the math characters that it needs. So it has to use its own fonts, and since it is not able to access them, it falls back to images. Although MathJax doesn't provide a means of falling back to SVG from HTML-CSS, I suppose you could listen for the signal that HTML-CSS produces when it falls back and force a switch yourself. But I think the processing would still be done with images first, and then the switch would occur, so it would not be very efficient. |
Thanks for the code. I will give it a try. As for the font, I don't think CSS change will help; it is the default font for the browser instance that needs to be changed. I don't know how to do that, but your QWebSettings sounds like the right place. |
I get this error only with special characters like Other things (for example Jα(x) formula from mathjax.org front page) work fine. |
The formula from mathjax.org should definitely have cause the italic font to load (it has to use the characters from that font to display the equation). Can you send a screen shot of the output of the Jα(x) formula? Also, could you add <script type="text/x-mathjax-config">
MathJax.Hub.Queue(function () {alert(MathJax.Message.Log())});
</script> to the page just before the script that loads MathJax.js and let me know what the alert produces? Thanks. |
OK, I misread the font name: I see it is Main/italic not Math/italic, which is what is used for the other letters. Ignore my request for a screen shot. |
The alert produces:
|
MathJax "pre-requests" the most used fonts (Math/Italic, Main/Regular, Size1/Regular). These are probably already loaded and ready by the time MathJax gets around to using them. But the other fonts (Main/Bold, Main/Italic) etc. are requested when needed, and so they will not be ready when needed, meaning MathJax will have to wait for them, and detect their presence when they arrive. That is apparently where the problem lies. One solution might be to preload more of the fonts. Since you are running locally, that should not be much of a performance issue. To do that, try adding <script type="text/x-mathjax-config">
MathJax.Hub.Config({
"HTML-CSS": {
preloadWebFonts: ["MathJax_Main-italic","MathJax_Main-bold","MathJax_AMS",
"MathJax_Size2","MathJax_Size3","MathJax_Size4","MathJax_Caligraphic"]
}
});
</script> and see if that helps. We can add more to the list if it does. |
No, that doesn't help… |
I tried to play with QWebSettings, but had no success:
|
Thanks for trying the QWebSettings (and for the documentation link). Can you tell me the setFontFamily that you tried? |
In terms of the preload fonts, just to be sure, you put that script before the one that loads MathJax.js, right? Here's something else to try (sort of the reverse). Try adding <script type="text/x-mathjax-config">
MathJax.Hub.Config({
"HTML-CSS": {
Augment: {
PreloadWebFonts: function () {alert("Preload prevented")}
}
}
});
</script> before the script that loads MathJax.js. This should prevent any preloading of fonts. Try this with an equation like the one from mathjax.org, and see if that now causes failures (since the fonts aren't preloaded). |
I put it after, but putting it before doesn't help either. Inserting the preload-preventing code, I get the "Preload prevented" message (as expected) and the math is not rendered at all: http://ubuntuone.com/0GzZt3YhlZFnBoYljK56xE. |
Just retried again. The font is changed but MathJax still fails to load TeX/Main/Italic.
I tried "Liberation Sans", "Cantarell" (GNOME's default font) and a few others. |
Can you also try setting the serif and sans-serif fonts? I seem to recall WebKit-based browsers using those as the default for web fonts before they arrive. As for the failure, can you put <script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {noErrors: {disabled: true}}
});
</script> before loading MathJax.js, to show TeX error that is being suppressed. It looks from the TeX code that a bunch of characters have been lost. Like the |
(Sorry for the delay).
Sure, it was needed. I fixed that, and now the Jα(x) formula is rendered correctly, even if fonts preloading is disabled.
Done, doesn't help unfortunately... |
Are you using a full installation of MathJax, or have you trimmed it down? Do you have access to any DOM debugging tools, and if so, can you tell if the MathJax_Main-Italic font is actually being loaded (e.g., does it appear in the resources list)? |
In the test app, I'm just using the version from cdn.mathjax.org, so it's full. I don't know how to access the Web Inspector in QtWebKit app, but I can insert some |
Unfortunately, you can't get the information from javascript (otherwise it would be a LOT easier to tell when a font has arrived). At this point I'm kind of out of suggestions. I guess I'll have to try out the minimal python script that you provided myself and see what I can come up with. But I suspect I'm not going to be able to get to that for a while. |
I've installed QupZilla browser (which has web inspector), and I'm able to reproduce this bug there. With which configuration should I test the font loading? With |
With |
Here's the list of loaded fonts from Resources:
|
OK, so it appears to be a detection problem (which we suspected anyway). Do you have any timing information about how long the files have taken to get to you? Here is something to try. It disables the detection and just waits 200 milliseconds and says the font is there. This might let you get the math OK, but you might need to adjust the 200 to suit your needs. <script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Startup",function () {
var HTMLCSS = MathJax.OutputJax["HTML-CSS"];
HTMLCSS.Font.checkWebFont = function (check,font,callback) {
if (check.time(callback)) return;
if (check.total === 0) {
HTMLCSS.Font.testFont(font);
setTimeout(check,200);
} else {callback(check.STATUS.OK)}
}
});
</script> Not a permanent solution, but it could tell us if the fonts are able to be rendered properly. |
OOPS, I forgot to change the delay, but have edited the comment above to include it, so use that rather than the emailed one. |
No. I've had to slow down a bit because I started teaching the fall term last week. Things will move at a slower rate for a while, I'm afraid. The first priority is getting out a bug-fix release in the next few weeks. |
I think I remember that Fred Wang spotted some issues with accessing the STIX fonts from Linux. That might be the issue here. But note that is is again an italic versus upright issue, so perhaps there is an issue with some italic fonts in Linux? What flavor of Linux are you using?
Yes, you could set |
I can reproduce this issue on Debian and Ubuntu, with fonts-stix 1.1.0. This bug occurs only with Chrome for me, not with Firefox, ReText or Epiphany (which uses Gtk+ WebKit). FWIW, when I open the wrongly displayed characters in the Web Inspector, it displays this:
|
Interesting. Can you use the inspector to change that to
and see if that looks right? Also, can you type
into the console and see if it is |
Also, if you open the MathJax About dialog, does it list you properly as using Chrome? |
That helps. Also, changing the font for characters like ∀ and ∈ from
It is
Yes, it lists me as using Chrome. |
OK, thanks, that helps. I found the bug. The changes to the font name were to overcome a bug with STIX fonts in Mac OS X Lion (10.7), and it looks like I forgot to restrict to just Mac OS for the changes when Chrome is in use (ARGH!) so the change was also made for you in Linux. It is an easy fix, and I will put that into the v2.1 branch. For now, you can add
to your document somewhere before the script that loads MathJax.js itseld. This will undo the changes that were made for OS X Lion when you are not actually on OS X. (I haven't actually tested the code, so let me know if something goes wrong). |
Note: this should fix the STIX font issue, but does not help the web font problem. I still don't know what is going on there. |
@mitya57 this should be fixed in 2.1-beta now. Could you give it a try? |
Peter means the STIX font issue should be fixed, not the original web-font problem. |
Ah, sorry! My fault -- this thread has been around a bit ;) |
Yes, it's fixed now (the STIX font issue). Thanks! |
Some new investigations:
|
@pkra @dpvc : BTW, I asked @mitya57 to modify the way MathJax is packaged in Debian so that the open type fonts are in a separate package and are installed as "local fonts". That may help for Firefox's native MathML and also speed up MathJax's rendering on Debian-based Linux distributions. |
I was struggling all this afternoon trying to have wkhtmltopdf working with MathJax on Amazon EC2 (CentOS or Ubuntu): STIX local font not detected, TeX font not loading ("Can't load web font TeX/Main/Regular"), rendering image font after a while... The workaround posted by @dpvc on Aug 30, 2012 did fix the TeX font loading issue, thx! (not the STIX detection though) Note: the problem appears on latest version of wkhtmltopdf 0.12.x, it used to work fine with previous version 0.11 (using MathJax 2.4). |
I'm wondering if we should take another look at the qtwebkit problem. |
@benweet, there are several different packagings of the STIX fonts, and MathJax can only use one of them. If you have STIXGeneral.otf, STIXSizeOneSym.otf, and a total of about 28 different STIX fonts, then you have the right set. If you have five fonts (STIX in regular, italic, bold, and bold-italic, plus a STIX math font), then you have the version MathJax can't use, and it will not be detected by MathJax. I suspect that may be the issue for you. |
@dpvc I was using this package on Ubuntu: It contains the font you describe and worked fine with MathJax using wkhtmltopdf 0.11. |
OK, looks like font detection continues to be an issue in wkhtmltopdf. Thanks for the additional information. |
The fix for the Main-Italic web font not being detected (and causing a delay) is already made as the fix for #845, so the only remaining issue should be the detection of local STIX fonts. |
I'm going to move this out of this milestone since the QtWebKit part is all that is left. |
Closing this as abandoned. |
Hi!
I'm trying to add MathJax support to my text editor (ReText), which uses Qt version of WebKit engine. When the page has
\imath
symbol, it prints:(this takes a few seconds) and then prints
and I get an ugly PNG image as a result.
I can't reproduce this problem with Gtk-based WebKit browsers and Firefox.
P.S: example of page I try to load:
The text was updated successfully, but these errors were encountered: