android - MathJax 无法正确呈现

标签 android mathjax tex

我目前在我的应用程序中使用这个库: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/

相关文章:

javascript - Mathjax:将文本放在代码旁边

c++ - 如何根据区域设置为文件中的所有单词添加软连字符?

python - 将 iPython notebook 转换为 tex 时如何为代码单元格获取正确的换行符?

java - 在 map 上移动时如何更改谷歌地图标记大小

java - 为什么 Android 回调方法的名称以 'on' 开头?

mathjax - 如何检测mathjax何时完全加载?

python - 在 matplotlib python 中使用带有 tex 分数表达式的格式

Android 小部件 - 使用带有远程 View 的 setOnClickPendingIntent 未收到 Intent

android - ListView中的checkbox 'Checked'滚动后恢复

javascript - 使用 .html() 更新渲染 MathJax