Currently, we use CSS hacks to choose between MathML or SVG/PNG. We will need to load an additional Javascript file after page load to show the MathML when MathPlayer is detected (using the user agent string).
Version: master
Severity: normal
Currently, we use CSS hacks to choose between MathML or SVG/PNG. We will need to load an additional Javascript file after page load to show the MathML when MathPlayer is detected (using the user agent string).
Version: master
Severity: normal
Status | Subtype | Assigned | Task | ||
---|---|---|---|---|---|
Resolved | None | T67341 Release Math 2.0 | |||
Resolved | None | T73929 SVG images should not be loaded when MathML is used | |||
Resolved | fredw | T73912 Some code cleanup is needed after the removal of the PNG fallback | |||
Resolved | None | T73748 Display MathML when MathPlayer is installed |
Searching MathPlayer in the user agent string should be enough to detect MathPlayer:
There are also other hacks to force MathPlayer to load (see the MathJax source). Since we are immediately putting MathML in the page source, that should not be necessary, I guess.
physik wrote:
A great. Maybe we should provide a standalone JavaScript function hasMathML support that can be used by different projects... What do you think?
Unfortunately, this kind of things is not always reliable (for example recent version of IE claims to be "Gecko" and Opera dropped MathML and switched from "Presto" to "Blink"). Moreover this depends on what you mean by "MathML is supported"
See https://developer.mozilla.org/en-US/docs/Web/MathML/Authoring#Fallback_for_Browsers_without_MathML_support for some suggestions.
However, if "MathPlayer" is in the user agent string then there is a strong probability that MathPlayer is installed and so that the user wants MathML to be displayed. So that sounds fine to just check the user agent string in that particular case.
physik wrote:
What do you think is the problem with this approach:
function hasMathMLSupport() { var div = document.createElement("div"), box; div.innerHTML = "<math><mspace height='23px' width='77px'/></math>"; document.body.appendChild(div); box = div.firstChild.firstChild.getBoundingClientRect(); document.body.removeChild(div); return Math.abs(box.height - 23) <= 1 && Math.abs(box.width - 77) <= 1; }
Independent of the actual implementation of hasMathMLSupport() I think we should create such a function that can be updated depending on the latests changes in the browser jungle.
Strictly speaking, this only detects whether the height/width attributes of <mspace/> are supported (which does not necessarily mean that the support is "good enough", whatever it means). I'm not sure it works with MathPlayer, but we can always do the UA sniffing in the MathPlayer case.
Also this requires a DOM to be used and might be affected by the surrounding context, might be too strict (only 1px error is tolerated) or not enough (there is not 100% guarantee that a browser will not give the right size. For example I notice that IE boxes for unknown elements sometimes have non-zero size)
Change 165997 had a related patch set uploaded by Frédéric Wang:
Display MathML when MathPlayer is installed