# Description

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

Reference
bz71748

# Related ObjectsSearch...

### Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 3:51 AM
bzimport set Reference to bz71748.
bzimport added a subscriber: Unknown Object (MLST).
fredw created this task.Oct 7 2014, 4:56 PM

physik wrote:

Is there a sample HTML page that detects MathPlayer via JavaScript?

fredw added a comment.Oct 7 2014, 5:18 PM

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.

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?

fredw added a comment.Oct 7 2014, 5:28 PM

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"

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 = "$<mspace height='23px' width='77px'/>$";
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.

fredw added a comment.Oct 7 2014, 6:12 PM

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.

fredw added a comment.Oct 7 2014, 6:16 PM

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)