2013-02-25 87 views
1

现在我编写了Android程序。此应用程序必须使用MathJax库将Form FORM呈现给WebView。但我有问题......有时它不工作(形式不定期)... 现在来源:MathJax渲染Android

// This function calls everytime before output 

public static void clearWebView() 
{ 
    w.loadDataWithBaseURL("http://bar", "<!DOCTYPE html><html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no\"> <script type='text/x-mathjax-config'>" 
      +"MathJax.Hub.Config({ " 
       +"showMathMenu: false, " 
       +"jax: ['input/TeX','output/HTML-CSS'], " 
       +"extensions: ['tex2jax.js'], " 
       +"TeX: { extensions: ['AMSmath.js','AMSsymbols.js'," 
        +"'noErrors.js','noUndefined.js', 'MathZoom.js'" + 
       "] } " 
       +"});</script>" 
      +"<script type='text/javascript' " 
       +"src=\"file:///android_asset/MathJax/MathJax.js\"" 
       +"></script></head><body><span id='solve'></span></body></html>" ,"text/html","utf-8", ""); 
    } 

和两个渲染功能:

public static void RenderHTML(String html) 
{  
     w.loadUrl("javascript:document.getElementById('solve').innerHTML += '" + html + "';"); 

} 

public static void RenderMath(String tex) 
{ 
    RenderHTML("\\\\[" + doubleEscapeTeX(tex) + "\\\\]"); 

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

} 
+0

我为我的应用程序使用相同的代码并面临Android 4.4上的问题。它在Android 4.3及更低版本上为我工作。 – 2013-12-14 10:50:20

+0

这是我在4.4上遇到的问题,http://stackoverflow.com/questions/20582282/uncaught-referenceerror-while-loading-asset-file-on-android-4-4 – 2013-12-14 11:12:48

回答

0

这是完美的解决方案4.4:

wq.getSettings().setJavaScriptEnabled(true); 
      wq.getSettings().setBuiltInZoomControls(true); 
      wq.getSettings().setLoadWithOverviewMode(true); 
      wq.loadDataWithBaseURL("http://bar/", "<script type='text/x-mathjax-config'>" 
        +"MathJax.Hub.Config({ " 
        +"showMathMenu: false, " 
        +"jax: ['input/MathML','output/HTML-CSS'], " // output/SVG 
        +"extensions: ['mml2jax.js'], " 
        +"TeX: { extensions: ['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><span id='text'> </span> <span id='math'></span>", "text/html", "utf-8", ""); 





    if (android.os.Build.VERSION.SDK_INT < 19) 
      { 
       wq.loadUrl("javascript:document.getElementById('math').innerHTML='" 
        + "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">" 
        + "<mstyle displaystyle=\"true\">" 
        + doubleEscapeTeX(questn+ans) 
        + "</mstyle></math>';"); 
       wq.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);"); 
      } 
      else 
      { 
       wq.evaluateJavascript("javascript:document.getElementById('math').innerHTML='<font color=\"#000000\">`"+doubleEscapeTeX(questn+ans)+"`</font>';",null); 
       wq.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);"); 
      }