MathJax无法正确渲染

时间:2018-01-06 09:56:15

标签: android mathjax tex

我目前在我的应用中使用此库:https://github.com/kexanie/MathView 它用于将文本转换为数学,它使用TeX / MathJax。

这是按预期工作的:

#include <iostream>
#include <string>
#include<conio.h>

using namespace std;

int main() {

    string username, password, User="usman", Pass="12345";

    //username variable is used to take input from the user
    //password variable is used to take input from the user 
    //User variable has the hardcode value of username 'usman' which is used to compare in if condition
    //Pass variable has the hardcode value of password '12345' which is used to compare in if condition


    //taking username from user through keyboard in 'username' variable
    std::cout << "enter username: " << std::endl;
    std::cin >> username;


    //taking password from user through keyboard in 'password' variable
    std::cout << "enter password: " << std::endl;
    std::cin >> password;


    //Now compare the 'username' & 'password' variable value with the hardcode values of 'User' & 'Pass'
    if (username != User && password != Pass)
    {
        std::cout << "error";
    }
    if (username == User && password != Pass)
    {
        std::cout << "error";
    }
    if (username != User && password == Pass)
    {
        std::cout << "error";
    }
    if (username == User && password == Pass)
    {
        std::cout << "success";
    }

    _getch();
    return 0;

}

其中&#34; id&#34;指向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\"" +
                "});"
        );
        mv.setText(context.getString(id));

从文件中接收文本,但与strings.xml中的早期文本相同,我记录了该文件进行验证。

但现在输出被打破了。它没有正确识别文本 &#34; \压裂{A} {B}&#34;以前曾经是&#34; a / b&#34;现在它是&#34; fracab&#34;

这是库问题吗?

1 个答案:

答案 0 :(得分:1)

我在angular4项目中使用过MathJax。它也可以帮助你完成项目。

使用cdnjs链接进行mathjax库:

 <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>