mathjax / MathJax-src

MathJax source code for version 3 and beyond

Home Page:https://www.mathjax.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overlapping output when using serveral expressions on the same page

stnor opened this issue · comments

I'm getting overlapping output in all expressions but the last when rendering multiple expressions on the same page:

    "mathjax-fira-font": "1.0.0-alpha.1",
    "mathjax-full": "4.0.0-alpha.1",

Screenshot 2022-11-06 at 14 07 05

I'm using this method of rendering:

    async doInitMathJax() {
        const {mathjax} = await import("mathjax-full/js/mathjax");
        const {MathML} = await import("mathjax-full/js/input/mathml");
        const {CHTML} = await import("mathjax-full/js/output/chtml");
        const {MathJaxFiraFont} = await import("mathjax-fira-font/js/output/fonts/mathjax-fira/chtml");
        const {browserAdaptor} = await import("mathjax-full/js/adaptors/browserAdaptor");
        const handler = await import("mathjax-full/js/handlers/html.js");
        handler.RegisterHTMLHandler(browserAdaptor());
        const font = new MathJaxFiraFont({fontURL: '/assets/mathjax-fonts'});
        return {MathJax: mathjax, MathML: MathML, CHTML: CHTML, font: font}
    }

    ngOnInit(): void {
        this.doInitMathJax().then(result => {
            const {MathJax, MathML, CHTML, font} = result;

                this.elementRef.nativeElement.innerHTML = mathml(asciimath);

                this.HTML = MathJax.document(window.document, {
                    InputJax: new MathML(),
                    OutputJax: new CHTML({font: font})
                });

                this.HTML.findMath({elements: [this.elementRef.nativeElement]})
                    .compile()
                    .typeset()
                    .updateDocument()
                    .clear();
            });
        });
    }

Worked fine in MathJax3 (beta2).

Every expression has its own Angular component that runs the code above. this.elementRef is a ref to the component local element. Any ideas?

Another example:
Screenshot 2022-11-06 at 14 17 16

I solved the issue by moving the creation of the MathDocument into a singleton and cached it there.

This component now reuses that instance and calls findMath for each expression.