我目前在我的应用程序中使用这个库:https://github.com/kexanie/MathView 用于将文本转换为数学,它使用 TeX/MathJax。
这按预期工作:
MathView mv = new MathView(context, null);
mv.setEngine(MathView.Engine.MATHJAX);
mv.config("MathJax.Hub.Config({\n" +
"jax: [\"input/TeX\",\"output/HTML-CSS\"],\n" +
"displayAlign: \"left\"" +
"});"
);
mv.setText(context.getString(id));
其中“id”指向 strings.xml 文件中的资源。
现在,我将其更改为包含在一个文件中,并从那里获取它。
MathView mv = new MathView(context, null);
mv.setEngine(MathView.Engine.MATHJAX);
mv.config("MathJax.Hub.Config({\n" +
"jax: [\"input/TeX\",\"output/HTML-CSS\"],\n" +
"displayAlign: \"left\"" +
"});"
);
String a= text;
mv.setText(a);
从文件中接收到文本,但与之前在 strings.xml 中的文本相同,我将其记录下来以进行验证。
但是现在输出坏了。它无法正确识别文本 "\frac{a}{b}"以前是"a/b",现在是"fracab"
是图书馆的问题吗?
最佳答案
我在 angular4 项目中使用了 MathJax。它也可能对您的项目有所帮助。
为 mathjax 库使用 cdnjs 链接:
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?
config=TeX-MML-AM_CHTML"></script>
创建 mathjax 指令:
import {Directive, ElementRef, Input, OnChanges} from'@angular/core';
declare var MathJax:any;
@Directive({
selector : '[mathText]',
})
export class MathTextDirective implements OnChanges {
constructor(public elementRef: ElementRef) {
this.hostEl = elementRef.nativeElement; //capture the HTML
element host
}
//Used to bind data: eg: <div [mathText]="raw string">
@Input('mathText') inputString:string;
// host element
private hostEl:HTMLElement;
//have MathJax parse the host element and render the math
render(){MathJax.Hub.Queue(['Typeset', MathJax.Hub, this.hostEl])}
// called when the inputString changes.
ngOnChanges(){
//make the input string into the innerText of the host element
this.hostEl.innerText = this.inputString;
this.render();
}
}
在 app.module.ts 中注册这个指令 并在 html 中使用此指令,例如:
<div [mathText]="\frac{a}{b}"></div>
关于android - MathJax 无法正确呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48126200/