【发布时间】:2017-03-04 04:24:48
【问题描述】:
我想在 android 中显示数学方程,我发现这个 https://github.com/kexanie/MathView 工作得非常好,但是在这段代码中,我可以从哪里得到一个方程的字符串 tex。我尝试使用 word 16 将公式转换为乳胶格式,但是当我将转换后的乳胶字符串替换为原始字符串(MainActivity 中的字符串 tex)时,乳胶字符串不会显示出来,而是按原样显示。
第一个 MainActivity 代码完美地显示了方程式
public class MainActivity extends AppCompatActivity {
MathView formula_two;
String tex = "This come from string. You can insert inline formula:" +
" \\(ax^2 + bx + c = 0\\) " +
"or displayed formula: $$\\sum_{i=0}^n i^2 = \\frac{(n^2+n)(2n+1)}{6}$$";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onResume() {
super.onResume();
formula_two = (MathView) findViewById(R.id.formula_two);
formula_two.setText(tex);
}
}
这是 MainActivity,我用我的字符串替换了 tex 字符串
public class MainActivity extends AppCompatActivity {
MathView formula_two;
String tex = "\\begin{document}\n" +
"\n" +
"%\\selectlanguage{english} %%% remove comment delimiter ('%') and select language if required\n" +
"\n" +
"\n" +
"\\noindent ${\\left(x+a\\right)}^n=\\int^n_{k=0}{\\left(\\genfrac{}{}{0pt}{}{n}{k}\\right)x^ka^{n-k}}$ this is a test to check latex format ${\\left(1+x\\right)}^n=1+\\frac{nx}{1!}+\\frac{n\\left(n-1\\right)x^2}{2!}+\\dots $\n" +
"\n" +
"\\noindent \n" +
"\n" +
"\n" +
"\\end{document}";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onResume() {
super.onResume();
formula_two = (MathView) findViewById(R.id.formula_two);
formula_two.setText(tex);
}
}
当然我在转换数学时做错了 方程转换成 tex 格式。我试过如何完美转换它 寻找一个好的教程,但找不到任何。任何帮助都是 赞赏
【问题讨论】:
标签: java android latex mathjax tex