简体   繁体   English

如果不支持svg,则退回到html-css

[英]Fallback to html-css if svg not supported

I'm using MathJax to render mathml markup in the browser. 我正在使用MathJax在浏览器中呈现mathml标记。 I have it working fine in Chrome using the TeX-AMS-MML_SVG config, but this doesn't work in IE8. 我使用TeX-AMS-MML_SVG配置在Chrome中正常工作,但是在IE8中不起作用。

If I switch to TeX-AMS-MML_HTMLorMML it works fine in all browsers. 如果我切换到TeX-AMS-MML_HTMLorMML,则在所有浏览器中都可以正常工作。 However the SVG rendering looks much better, so where possible i'd like that to be preferred. 但是,SVG渲染看起来要好得多,因此在可能的情况下,我希望将其作为首选。

Does MathJax have anything built in to support this? MathJax是否内置任何支持此功能的内容? It seems it can fallback from MML to HTML but not SVG to HTML. 看来它可以从MML转换为HTML,但不能从SVG转换为HTML。 I could check for SVG support via javascript, but i'm hoping there's something already in the MathJax config i'm missing. 我可以通过javascript检查SVG支持,但是我希望MathJax配置中已经缺少了一些东西。

Here's the documentation on common configurations . 这是有关常见配置的文档。 I'm looking for something like a MML_SVGorHTML config. 我正在寻找类似MML_SVGorHTML的配置。

See the discussion on the MathJax User's Forum that describes a way to do it. 请参阅MathJax用户论坛上的讨论,该讨论描述了一种实现方法。 Basically, 基本上,

    <script type="text/x-mathjax-config">
    if (MathJax.Hub.Browser.isMSIE && (document.documentMode||0) < 9) {
      MathJax.Hub.Register.StartupHook("End Config",function () {
        var settings = MathJax.Hub.config.menuSettings;
        if (!settings.renderer) {settings.renderer = "HTML-CSS"}
      });
    }
    </script>

takes care of older versions of IE, which are about the only browsers that don't do SVG any at this point. 负责IE的较旧版本,这是目前唯一不使用SVG的浏览器。

I'm currently in the process of testing this method, which is manually checking for svg support: 我目前正在测试此方法,正在手动检查svg支持:

function supportsSvg() {
    return !!document.createElementNS && 
        !!document.createElementNS('http://www.w3.org/2000/svg', "svg").createSVGRect;
}

var mathjaxConfig = (supportsSvg()) ? 'TeX-AMS-MML_SVG' : 'MML_HTMLorMML';

Then you can insert the mathjaxConfig as normal into the url: 然后,您可以像往常一样将mathjaxConfig插入url中:

"../MathJax.js?config=" + mathjaxConfig

You can use Walter Zorn's drawing library . 您可以使用Walter Zorn的图形库 It renders everything as DIVs. 它将所有内容呈现为DIV。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM