2

我尝试将 MathML 代码放入 WebView 中,但无法正确呈现。我做错了什么?

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");
   }
}
4

3 回答 3

2

字符串 mathml 使用了 MathML 标签。WebView 无法呈现 MathML 标记。我尝试使用 MathJax,但它需要 16MB 的文件来渲染数学方程。考虑到它的大小,我不知道如何在 Android 中使用 MathJax。

于 2011-09-07T08:34:52.197 回答
1

你应该看看 MathJax (www.mathjax.org)。它是一个用于显示 MathML 的 JavaScript 引擎。实际上,它用于在 StackExchange 中显示数学。

于 2011-04-20T02:23:30.603 回答
0
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]);");
于 2017-03-31T11:43:04.900 回答