Last modified: 2014-10-11 16:37:38 UTC
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).
Is there a sample HTML page that detects MathPlayer via JavaScript?
Searching MathPlayer in the user agent string should be enough to detect MathPlayer: https://github.com/brucemiller/LaTeXML/blob/master/lib/LaTeXML/resources/javascript/LaTeXML-maybeMathjax.js#L12 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.
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.
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 https://gerrit.wikimedia.org/r/165997
Change 165997 merged by jenkins-bot: Display MathML when MathPlayer is installed https://gerrit.wikimedia.org/r/165997