在Android应用程序中脱机MathML rendring支持

时间:2016-02-20 08:06:33

标签: android mathjax mathml

我想在Android应用中将MathML渲染为离线状态。我正在使用leathrum的APK使用MathJax。以下是设置mathjax离线配置(http://cs.jsu.edu/~leathrum/mjapp-src/full/MainActivity.java)的代码:

webview.loadDataWithBaseURL("http://bar/", "<script type='text/x-mathjax-config'>"
                              +"MathJax.Hub.Config({ " 
                                +"showMathMenu: false, "
                                +"jax: ['input/TeX','output/HTML-CSS'], " // output/SVG
                                +"extensions: ['tex2jax.js','toMathML.js'], " 
                                +"TeX: { extensions: ['AMSmath.js','AMSsymbols.js',"
                                  +"'noErrors.js','noUndefined.js'] }, "
                              //+"'SVG' : { blacker: 30, "
                              // +"styles: { path: { 'shape-rendering': 'crispEdges' } } } "
                              +"});</script>"
                              +"<script type='text/javascript' "
                              +"src='file:///android_asset/MathJax/MathJax.js'"
                              +"></script>"
                              +"<script type='text/javascript'>getLiteralMML = function() {"
                              +"math=MathJax.Hub.getAllJax('math')[0];"
                              // below, toMathML() rerurns literal MathML string
                              +"mml=math.root.toMathML(''); return mml;"
                              +"}; getEscapedMML = function() {"
                              +"math=MathJax.Hub.getAllJax('math')[0];"
                              // below, toMathMLquote() applies &-escaping to MathML string input
                              +"mml=math.root.toMathMLquote(getLiteralMML()); return mml;}"
                              +"</script>"
                              +"<span id='math'></span><pre><span id='mmlout'></span></pre>","text/html","utf-8","");

本地Mathjax属于assets.It正确呈现Tex Input但我无法将其配置为将MathML作为输入并显示结果离线。

1 个答案:

答案 0 :(得分:1)

要使mathml脱机,您需要将MathJax库添加到资源文件夹并使用Web视图配置库

loadDataWithBaseURL("http://bar",
    "<html><head>" +
    " <meta name=\"viewport\" content=\"width=device-width, user-scalable=yes\" />" +
    "</head>" +
    "" +
    "<body style=\"font-size:18px\" >" +
    "<b>Put here your equation</b> </br> " +
    "<script type=\"text/x-mathjax-config\">" +
    "  MathJax.Hub.Config({\n" +
    "  CommonHTML: { linebreaks: { automatic: true },EqnChunk:(MathJax.Hub.Browser.isMobile?10:50) },displayAlign: \"left\",\n" +
    "  \"HTML-CSS\": { linebreaks: { automatic: true } ," +
    "\n" +
    "    preferredFont: \"STIX\"}," +
    "extensions: [\"tex2jax.js\"],messageStyle:\"none\"," +
    "jax: [\"input/TeX\", \"input/MathML\",\"output/HTML-CSS\"]," +
    "tex2jax: {inlineMath: [['$','$'],['\\\\(','\\\\)']]}" +
    "});" +
    "</script>" +
    "<script type=\"text/javascript\" async src=\"file:///android_asset/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"></script>" +
    "" +
    "</body>" +
    "</html>", "text/html", "utf-8", "");

loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");