开发离线MathJax Android移动应用程序
Develop a offline MathJax Android Mobile App
我一直在开发移动应用程序,为数学应用程序打字,但我遇到了一个问题。根据规则,代码是可以的,但表达式不会更改。没有进行排版。
这是我的MainActivity代码,请告诉我漏洞在哪里:
public class MainActivity extends Activity implements View.OnClickListener
{
private String doubleEscapeTeX(String s) {
String t="";
for (int i=0; i < s.length(); i++) {
if (s.charAt(i) == '''') t += '''';
if (s.charAt(i) != ''n') t += s.charAt(i);
if (s.charAt(i) == '''') t += "''";
}
return t;
}
public void onClick(View v) {
if (v == findViewById(R.id.button2)) {
WebView w = (WebView) findViewById(R.id.webview);
EditText e = (EditText) findViewById(R.id.edit);
w.loadUrl("javascript:document.getElementById('math').innerHTML='''''["
+doubleEscapeTeX(e.getText().toString())+"'''']';");
w.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");
}
else if (v == findViewById(R.id.button3)) {
WebView w = (WebView) findViewById(R.id.webview);
EditText e = (EditText) findViewById(R.id.edit);
e.setText("");
w.loadUrl("javascript:document.getElementById('math').innerHTML='';");
w.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView w = (WebView) findViewById(R.id.webview);
w.getSettings().setJavaScriptEnabled(true);
w.getSettings().setBuiltInZoomControls(true);
w.loadDataWithBaseURL("http://bar", "<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'] } "
+"});</script>"
+"<script type='text/javascript' "
+"src='file:///android_asset/MathJax/MathJax.js'"
+"></script><span id='math'></span>","text/html","utf-8","");
EditText e = (EditText) findViewById(R.id.edit);
e.setBackgroundColor(Color.LTGRAY);
e.setTextColor(Color.BLACK);
e.setText("");
Button b = (Button) findViewById(R.id.button2);
b.setOnClickListener(this);
b = (Button) findViewById(R.id.button3);
b.setOnClickListener(this);
}
}
抱歉自我推销。但也许你可以试试MathView
。它是一个基于Android WebView
的自定义视图库,使用MathJax
显示数学公式。
MathView
的用法和TextView
一样,但它会自动呈现TeX代码。
<io.github.kexanie.library.MathView
android:id="@+id/formula_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
auto:text="When ''(a ''ne 0''), there are two solutions to ''(ax^2 + bx + c = 0'') and they are $$x = {-b ''pm ''sqrt{b^2-4ac} ''over 2a}.$$"
>
</io.github.kexanie.library.MathView>
希望这能有所帮助!
使用此代码
w.loadDataWithBaseURL("http://bar",
"<html><head>" +
" <meta name='"viewport'" content='"width=device-width, user-scalable=yes'" />" +
"</head>" +
"" +
"<body style='"font-size:18px'" >" +
"<b>Put here your equation</b> </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", "");
相关文章:
- Meteor移动应用程序-嵌入式数据库
- 如何在telerik剑道移动应用程序中按下刷新数据源的按钮
- jquery移动应用程序无法使用jquryMobile框架JS和css文件的相对路径
- 离子框架移动应用程序性能问题
- 我想在混合移动应用程序中使用Sqlite插件(Cordova)创建一个示例项目
- 在移动应用程序上滚动iframe会在某个时刻跳到页面顶部
- 在加载移动应用程序页面时调用Javascript函数
- Facebook在跨平台移动应用程序中的集成
- 如何在点击链接后从用户取消对话框中获得回调以选择移动应用程序
- 在Trigger.io移动应用程序中启用缩放
- 在HTML5、CSS、JavaScript中添加选项选择器,类似于移动应用程序中的选项设置
- 如果从我的网站在浏览器中安装了其他程序,如何在移动应用程序中打开共享对话框
- 链接到移动应用程序中的本地文件夹
- 使用HTML5的跨平台移动应用程序
- 开发离线MathJax Android移动应用程序
- 我们如何在javascript移动应用程序中记录骨干历史堆栈列表
- 当未读邮件通过Office 365应用程序(离子移动应用程序)时通知
- 限制应用商店中的移动应用程序
- 从使用 Trigger.io 构建的移动应用程序发送帖子请求
- 传单地图需要刷新页面才能显示在 Jquery 移动应用程序中