Giter VIP home page Giter VIP logo

Comments (6)

drlippman avatar drlippman commented on May 22, 2024

While we're at it, in checkMathML, we might want to update the detection in checkMathML(). Here is a super-nasty version that also includes basic font detection to make sure FireFox has adequate fonts to display radicals and other stretchy symbols:

var isGecko = 0;
function init(){
    var msg, warnings = new Array();
    if (document.getElementById==null){
        alert("This webpage requires a recent browser such as Mozilla Firefox");
        return null;
    }
    if (checkForMathML && (msg = checkMathML())) warnings.push(msg);
    if (checkForMathML && isGecko>0 && (msg = AMcheckTeX())) warnings.push(msg);
    if (warnings.length>0) displayWarnings(warnings);
    if (!noMathML) initSymbols();
    return true;
}

function checkMathML(){
   if (navigator.product && navigator.product=='Gecko' && !navigator.userAgent.toLowerCase().match(/webkit/)) {
       var rv = navigator.userAgent.toLowerCase().match(/rv:\s*([\d\.]+)/);
       if (rv!=null) {
        rv = rv[1].split('.');
        if (rv.length<3) { rv[2] = 0;}
        if (rv.length<2) { rv[1] = 0;}
       }
       if (rv!=null && 10000*rv[0]+100*rv[1]+1*rv[2]>=10100) {
           isGecko = 10000*rv[0]+100*rv[1]+1*rv[2];
           noMathML = null;
       } else {
           noMathML = true;
       }
    }
    else if (navigator.appName.slice(0,9)=="Microsoft") {
        version = parseFloat(navigator.appVersion.split("MSIE")[1]);
        if (version >= 10) {
                noMathML = true;
        } else {
          try {
        var ActiveX = new ActiveXObject("MathPlayer.Factory.1");
        noMathML = null;
          } catch (e) {
        noMathML = true;
          }
        }
    } else noMathML = true;
    if (noMathML && notifyIfNoMathML) {
            var msg = "To view the ASCIIMathML notation use Internet Explorer + MathPlayer or Mozilla Firefox 2.0 or later.";
            if (alertIfNoMathML)
                    alert(msg);
            else return msg;
    }
}
function AMBBoxFor(s) {
    document.getElementById("hidden").innerHTML = 
      '<nobr><span class="typeset"><span class="scale">'+s+'</span></span></nobr>';
      var bbox = {w: document.getElementById("hidden").offsetWidth, h: document.getElementById("hidden").offsetHeight};
      document.getElementById("hidden").innerHTML = '';
      return bbox;
}
//check for TeX font based on approach from jsMath
function AMcheckTeX() {
    hiddendiv = document.createElement("div");
    hiddendiv.style.visibility = "hidden";
    hiddendiv.id = "hidden";
    document.body.appendChild(hiddendiv);
    if (isGecko<10900) { //Mozilla 1.8 could use cmex fonts; Mozilla 1.9 only works well with STIX
        wh = AMBBoxFor('<span style="font-family: STIXgeneral, cmex10, serif">&#xEFE8;</span>');
    } else {
        wh = AMBBoxFor('<span style="font-family: STIXgeneral, serif">&#xEFE8;</span>');
    }
    wh2 = AMBBoxFor('<span style="font-family: serif">&#xEFE8;</span>');
    nofonts = (wh.w==wh2.w && wh.h==wh2.h);
    if (nofonts) {
        noMathML = true;
    } else {
        noMathML = false;
    }
    if (noMathML && notifyIfNoMathML) {
            var msg = "To view the ASCIIMathML notation, install STIX fonts, available at stixfonts.org";
            if (alertIfNoMathML)
                    alert(msg);
            else return msg;
        }
}

from asciimathml.

dpvc avatar dpvc commented on May 22, 2024

Note that Firefox can use fonts other than STIXGeneral and cmex10 for stretchy characters, so you might be limiting your users unnecessarily.

Also, you might want to use an ID for your hidden element that includes something unique to AsciiMath, so that it doesn't conflict with other potential ID's in the page. For example "AM_hidden" or "AsciiMath_hidden". Just "hidden" is too generic, and the page might already include an element with that ID.

from asciimathml.

drlippman avatar drlippman commented on May 22, 2024

Will make the ID change.  

Do you have a suggestion for the font issue?  The main goal was to avoid issues where the square roots weren't extending over expressions properly due to font issues.  In my case, where I fall back to mimetex images, some false negatives on the MathML check isn't a huge deal.  Clearly the better solution is to use MathJax, but if anyone is going to use AsciiMath standalone, I'd like it work correctly.  

from asciimathml.

dpvc avatar dpvc commented on May 22, 2024

You might be able to check whether a stretchy element has actually stretched. For example, you might be able to use

<math>
  <mo stretchy="true" id="AM_test_paren">(</mo>
  <mpadded height="200%" id="AM_test_padded">
    <mo stretchy="false">(</mo>
  </mpadded>
</math>

has the AM_test_paren element of height greater than that of AM_test_padded. I'm not sure if this works or not, but it might be worth a try, as it makes no assumptions about the fonts used by Firefox (which have changed over time).

from asciimathml.

dpvc avatar dpvc commented on May 22, 2024

OK, it looks like Firefox doesn't stretch to fit the <mpadded> element as it should. So you can compare the scrollHeights of AM_test_paren1 and AM_test_paren2 to see if the first is larger than the second in

<math displaystyle="true">
  <mo stretchy="true" id="AM_test_paren1">(</mo>
  <mfrac><mo id="AM_test_paren2">(</mo><mo>)</mo></mfrac>
</math>

See if that works.

from asciimathml.

drlippman avatar drlippman commented on May 22, 2024

I'll give it a try.  In the meantime, since stix and the tex fonts have been the official recommended fonts for MathML by Firefox, I don't feel too bad limiting the check to those two.

-------- Original message --------
From: "Davide P. Cervone" [email protected]
Date:03/17/2014 1:43 PM (GMT-08:00)
To: mathjax/asciimathml [email protected]
Cc: David [email protected]
Subject: Re: [asciimathml] IE9 (#1)

OK, it looks like Firefox doesn't stretch to fit the element as it should. So you can compare the scrollHeights of AM_test_paren1 and AM_test_paren2 to see if the first is larger than the second in

( ()

See if that works.


Reply to this email directly or view it on GitHub.

from asciimathml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.