在 android 中显示数学方程式
Displaying Maths equation in android
我想在 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);
}
}
For sure i am doing something wrong in converting a mathematical
equation into tex format. how can convert it perfectly i tried
searching for a good tutorial but couldnt find any. Any help would be
appreciated
MathJax 不处理完整的 LaTeX 文档,只处理数学表达式。因此,您将无法呈现您定义的 tex
变量。特别是,MathJax 认为 \begin{...}
和 \end{...}
之间的任何内容都是数学表达式,因此 \begin{document}...\end{document}
将被视为数学表达式。 \noindent
宏将无法识别(仅实现数学模式宏),额外的美元符号将呈现为文字美元符号。
另外,请注意 MathJax 的默认配置中未启用单个美元符号分隔符,因此如果您希望它们充当数学分隔符,则需要明确启用它们。有关详细信息,请参阅 MathJax Documentation。
我想在 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);
}
}
For sure i am doing something wrong in converting a mathematical equation into tex format. how can convert it perfectly i tried searching for a good tutorial but couldnt find any. Any help would be appreciated
MathJax 不处理完整的 LaTeX 文档,只处理数学表达式。因此,您将无法呈现您定义的 tex
变量。特别是,MathJax 认为 \begin{...}
和 \end{...}
之间的任何内容都是数学表达式,因此 \begin{document}...\end{document}
将被视为数学表达式。 \noindent
宏将无法识别(仅实现数学模式宏),额外的美元符号将呈现为文字美元符号。
另外,请注意 MathJax 的默认配置中未启用单个美元符号分隔符,因此如果您希望它们充当数学分隔符,则需要明确启用它们。有关详细信息,请参阅 MathJax Documentation。