开发者

WebView and MathML

I have tried putting MathML code into a WebView and it doesn't render properly. Wha开发者_JS百科t am I doing incorrectly?

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class HelloWebView extends Activity {
WebView mWebView;
String mathml = "<html><body><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow><msup> <mi>x</mi> <mn>2</mn> </msup></mrow></math> END OF TEST</body></html>";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadData(mathml, "text/html", "utf-8");
   }
}


String mathml used MathML tags. WebView cannot render MathML tags. I tried using MathJax but it needs 16MB of files to render mathematical equations. I don't how MathJax can be used in Android given it's size.


You should look at MathJax (www.mathjax.org). Its a JavaScript engine for displaying MathML. In fact, it is used to display math in StackExchange.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜