You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need a way to compile code without MathJax remembering the commands that I defined in previous compilations.
asyncfunctionprintRenderedText(text: string){constrender=awaitwindow.MathJax.tex2chtmlPromise(text,{display: true});console.log(`For the code '${text}' the rendered HTML is: \n${render.outerHTML}\n\n`)}awaitprintRenderedText("\\command")// Displays \command in red lettersawaitprintRenderedText("\\newcommand{\\command}{x+z} \\command ")// Displays x+zawaitprintRenderedText("\\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:
Macros, once defined (either by hand, or by loading an extension, including by using \require) are permanent, and can't be removed from the TeX input jax. You would need to create a new instance of the TeX input jax in order to get one without the previous definitions (and labels, etc.). The easiest way to do that is probably just to call MathJax.startup.getComponents() which will re-instantiate all the components (input and output jax, DOM adapter, and MathDocument). Its a bit of overkill, but should be the easiest to do. Note, however, that you will lose the CHTML character cache, so the CSS generated will be just for the next expression processed, so won't include the CSS for the previous expressions. But that may be what you want (it is not clear from your example). If you need to keep the CSS for the previous expressions, then you would need to re-instantiate only the TeX input jax and hook it into the existing MathDocument. That takes a little more work, but can be done if necessary.
I need a way to compile code without MathJax remembering the commands that I defined in previous compilations.
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:
and many other things.
Additional context
The output produced by the aforementioned code is
Help would be appreciated. Thanks!!
The text was updated successfully, but these errors were encountered: