Is there a workaround for Firefox's printing bug?

153 views
Skip to first unread message

Duane Nykamp

unread,
Mar 23, 2012, 10:59:07 AM3/23/12
to mathja...@googlegroups.com
Since Firefox currently doesn't download the webfonts when printing, Firefox users who don't have the mathjax or stix fonts installed will get messed up looking math when printing if they are using the HTML-CSS output jax.  Printing with the SVG output jax looks fine.  I'm wondering if one can create a workaround for this bug.

The best case scenario would be for mathjax to automatically capture the print command and reformat with SVG before printing.  Is this feasible?  I doubt it (or worth the effort if it is technically feasible but quite involved).  Assuming not, is it possible at least to alert users of Firefox without the fonts installed when they print?  Then, they could be directed to a page that instructs them to install the fonts or change to the SVG jax.  Or are there other workarounds?

Thanks,
Duane

Davide P. Cervone

unread,
Mar 26, 2012, 2:57:34 PM3/26/12
to mathja...@googlegroups.com
> The best case scenario would be for mathjax to automatically capture
> the print command and reformat with SVG before printing. Is this
> feasible? I doubt it (or worth the effort if it is technically
> feasible but quite involved).

Well, Firefox 6 and above have beforeprint and afterprint handlers, so
I suppose it would be possible to use those to switch to SVG, but
since the processing of math is asynchronous, I'm not sure it would
work (the handlers would return before the math was redisplayed).

> Assuming not, is it possible at least to alert users of Firefox
> without the fonts installed when they print? Then, they could be
> directed to a page that instructs them to install the fonts or
> change to the SVG jax. Or are there other workarounds?

You could use the "@media print" CSS to control the display of a
message that suggests switching to SVG output for printing. For
example:

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
styles: {
"#MJ_PrintWarning": {display: "none"},
"@media print": {
"#MJ_PrintWarning": {
display: "block",
border: "2px solid #800",
color: "#800",
padding: "1em", margin: ".5em 2em 1em 2em",
"text-align": "center",
"font-size": "small"
}
}
}
});
if (MathJax.Hub.Browser.isFirefox) {
MathJax.Hub.Register.StartupHook("onLoad",function () {
var message = MathJax.HTML.Element("div",{
id:"MJ_PrintWarning", style: {display:"none"}
},["Select the SVG renderer in the MathJax contextual menu " +
"for better printing results"]);
document.body.insertBefore(message,document.body.firstChild);
});
MathJax.Hub.Register.MessageHook("Renderer Selected",function
(message) {
var warning = document.getElementById("MJ_PrintWarning");
warning.style.display = (message[1] === "SVG" ? "none" : "");
});
MathJax.Hub.Queue(function () {
if (MathJax.Hub.config.menuSettings.renderer !== "SVG") {
document.getElementById("MJ_PrintWarning").style.display = "";
}
});
}
</script>

(placed BEFORE the script that loads MathJax.js) would insert a
message at the top of the document that would appear only in print for
Firefox except when the SVG output render is selected.

Perhaps that is what you are looking for.

Davide

Duane Nykamp

unread,
Mar 26, 2012, 11:01:37 PM3/26/12
to mathja...@googlegroups.com
Thanks, Davide.

I think that workaround is as good as any.  I hope Firefox will eventually get this fixed so that it won't be necessary for too long.

Duane
Reply all
Reply to author
Forward
0 new messages