如何在android,离线中使用Mathjax

时间:2014-05-27 11:46:52

标签: java android html mathjax

我看过这篇文章

http://cs.jsu.edu/wordpress/?p=498

我尝试在离线

中使用mathjax

我只想将此代码包含在我的html中

w.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","");

我尝试了很多次但没有工作。

我试过这个html

<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];

                          mml=math.root.toMathMLquote(getLiteralMML()); return mml;}
                          </script>
                          <span id='math'></span><pre><span id='mmlout'></span></pre>

我不擅长HTML帮助我

2 个答案:

答案 0 :(得分:0)

在设置文本之前等待页面加载。

webview.setWebViewClient(new WebViewClient() {
            public void onPageFinished(WebView view, String url) {

                   // do your stuff here
                   question_webview.loadUrl("javascript:document.getElementById('mmlout').innerHTML='';");
                   question_webview.loadUrl("javascript:document.getElementById('math').innerHTML='\\\\["
                   +text.getText()+"\\\\]';");
                   question_webview.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");
                   //question_webview.loadUrl("javascript:document.getElementById('mmlout').style.fontSize='200%'");
                   //question_webview.loadUrl("javascript:document.getElementById('math').style.fontSize='200%'");
            }
        });

答案 1 :(得分:0)

 webview.setWebViewClient(new WebViewClient(){
        public void onPageFinished(WebView view, String url) {
           webview.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");
        }
    });

webview.loadDataWithBaseURL("http://bar",
            "<html><head>" +
                    " <meta name=\"viewport\" content=\"width=device-width, user-scalable=yes\" />" +
                    "</head>" +
                    "" +
                    "<body style=\"font-size:18px\" >" +
                    message+
                    "</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", "");