我曾尝试将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");
}
}发布于 2011-09-07 16:34:52
String mathml使用了MathML标签。WebView无法呈现MathML标记。我尝试使用MathJax,但它需要16MB的文件来呈现数学公式。考虑到MathJax的大小,我不知道如何在安卓系统中使用它。
发布于 2011-04-20 10:23:31
你应该看看MathJax (www.mathjax.org)。它是一个用于显示MathML的JavaScript引擎。实际上,它被用来在StackExchange中显示数学。
发布于 2017-03-31 19:43:05
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]);");https://stackoverflow.com/questions/5721823
复制相似问题