Skip to content

Clear the state #3275

Open
Open
@fachu000

Description

@fachu000

I need a way to compile code without MathJax remembering the commands that I defined in previous compilations.

    async function printRenderedText(text: string) {
        const render = await window.MathJax.tex2chtmlPromise(text, { display: true });
        console.log(`For the code '${text}' the rendered HTML is: \n${render.outerHTML}\n\n`)
    }
    await printRenderedText("\\command")// Displays \command in red letters
    await printRenderedText("\\newcommand{\\command}{x+z} \\command ") // Displays x+z
    await printRenderedText("\\command")// I want it to display \command in red letters, but it displays x+z

Describe the solution you'd like
Something like window.MathJax.clear() so that MathJax forgets what I compiled before.

Describe alternatives you've considered
I tried enclosing the code in braces { } so that the command definition is local, I tried clearing the variables that I found that contained the new command:

window.MathJax.startup.document.menu.options.jax.CHTML.math.math = ""
window.MathJax.startup.document.menu.options.jax.CHTML.math.inputJax.latex = ""

and many other things.

Additional context
The output produced by the aforementioned code is

For the code '{\command}' the rendered HTML is: 
<mjx-container class="MathJax CtxtMenu_Attached_0" jax="CHTML" display="true" tabindex="0" ctxtmenu_counter="0" style="position: relative;"><mjx-math display="true" class="MJX-TEX" aria-hidden="true" style="margin-left: 0px; margin-right: 0px;"><mjx-texatom texclass="ORD"><mjx-mtext class="mjx-n" style="color: red;"><mjx-c class="mjx-c5C"></mjx-c><mjx-c class="mjx-c63"></mjx-c><mjx-c class="mjx-c6F"></mjx-c><mjx-c class="mjx-c6D"></mjx-c><mjx-c class="mjx-c6D"></mjx-c><mjx-c class="mjx-c61"></mjx-c><mjx-c class="mjx-c6E"></mjx-c><mjx-c class="mjx-c64"></mjx-c></mjx-mtext></mjx-texatom></mjx-math><mjx-assistive-mml unselectable="on" display="block"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow data-mjx-texclass="ORD"><mtext mathcolor="red">\command</mtext></mrow></math></mjx-assistive-mml></mjx-container>

For the code '{\newcommand{\command}{x+z} \command } ' the rendered HTML is: 
<mjx-container class="MathJax CtxtMenu_Attached_0" jax="CHTML" display="true" tabindex="0" ctxtmenu_counter="1" style="position: relative;"><mjx-math display="true" class="MJX-TEX" aria-hidden="true" style="margin-left: 0px; margin-right: 0px;"><mjx-texatom texclass="ORD"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D465 TEX-I"></mjx-c></mjx-mi><mjx-mo class="mjx-n" space="3"><mjx-c class="mjx-c2B"></mjx-c></mjx-mo><mjx-mi class="mjx-i" space="3"><mjx-c class="mjx-c1D467 TEX-I"></mjx-c></mjx-mi></mjx-texatom></mjx-math><mjx-assistive-mml unselectable="on" display="block"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow data-mjx-texclass="ORD"><mi>x</mi><mo>+</mo><mi>z</mi></mrow></math></mjx-assistive-mml></mjx-container>

For the code '{\command}' the rendered HTML is: 
<mjx-container class="MathJax CtxtMenu_Attached_0" jax="CHTML" display="true" tabindex="0" ctxtmenu_counter="2" style="position: relative;"><mjx-math display="true" class="MJX-TEX" aria-hidden="true" style="margin-left: 0px; margin-right: 0px;"><mjx-texatom texclass="ORD"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D465 TEX-I"></mjx-c></mjx-mi><mjx-mo class="mjx-n" space="3"><mjx-c class="mjx-c2B"></mjx-c></mjx-mo><mjx-mi class="mjx-i" space="3"><mjx-c class="mjx-c1D467 TEX-I"></mjx-c></mjx-mi></mjx-texatom></mjx-math><mjx-assistive-mml unselectable="on" display="block"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow data-mjx-texclass="ORD"><mi>x</mi><mo>+</mo><mi>z</mi></mrow></math></mjx-assistive-mml></mjx-container>

Help would be appreciated. Thanks!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Code ExampleContains an illustrative code example, solution, or work-aroundQuestionv3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions