Mathjax: How to enable/disable mathjax from javascript with a button?

Created on 23 Nov 2016  路  7Comments  路  Source: mathjax/MathJax

How to disable MathJax display (then the text will be displayed as $$f(x)=x^2$$ instead of the math rendering) from Javascript ?

$('#enablemathjax').click(function() {   // working
   MathJax.Hub.queue.pending = 0;
   MathJax.Hub.Queue(["Typeset", MathJax.Hub, "wmd-preview"]);
});
$('#disablemathjax').click(function() {    // non-working
   MathJax.Hub.queue.pending = 0;
   // here something is missing:
   // how to force rerendering of the page, and remove all the existing mathjax?
});

Sidequestion: how to start MathJax, with rendering off by default?

i.e. the user would have to press #enablemathjax first before having math displayed.

Question

All 7 comments

how to force rerendering of the page, and remove all the existing mathjax?

There's no routine for "removing all existing mathjax" but it depends a lot on what you mean by that. You could switch to the PlainSource output to get the original input as output.

how to start MathJax, with rendering off by default?

Please read the documentation for skipStartupTypeset.

Thanks for your answer.

There's no routine for "removing all existing mathjax" but it depends a lot on what you mean by that. You could switch to the PlainSource output to get the original input as output.

I'm looking at http://docs.mathjax.org/en/latest/options/PlainSource.html, but I don't find how to do it.

For example, how would you remove all math rendering when clicking on a button on this page:
https://cdn.mathjax.org/mathjax/latest/test/sample-tex.html
and display text only?
Would you have a short example?

I'm looking at http://docs.mathjax.org/en/latest/options/PlainSource.html, but I don't find how to do it.

That's the documentation for the output itself; you'd need the core APIs, e.g., http://docs.mathjax.org/en/latest/api/hub.html#setRenderer.

Would you have a short example?

General questions are best posted to the MathJax User Group where the wider community can help you. A quick search immediately gives this discussion.

I tried with PlainSource, and I see what you mean now, but it's not what I'm looking for.

I would like to purely be able to disable MathJax when clicking on a button. The output of
https://cdn.mathjax.org/mathjax/latest/test/sample-tex.html should be this text only, not rendered at all:

When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and
they are$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$

Then, when clicking on Enable button again, it should rerender again as math.

General questions are best posted to the MathJax User Group https://groups.google.com/forum/#%21forum/mathjax-users where the wider community can help you.

Ok I'll do this.

A quick search https://groups.google.com/forum/#%21searchin/mathjax-users/switch$20renderer%7Csort:relevance immediately gives this discussion https://groups.google.com/d/msg/mathjax-users/X6IfrP2B6ro/egVYY6iMCZUJ.

I tried, this doesn't disable MathJax completely, it only changes the renderer.

PS: maybe a solution would be to change MathJax delimiters on the fly , and remove $ $$ detection. Is this possible on the fly?

The output [...] should be this text only, not rendered at all:

Again, there is no routine for this. It's still not clear how clean you expect the DOM to be when you "disable" MathJax.

Ok I'll do this.

Thanks. You might want to describe in more detail what problem you are trying to solve.

As suggested by @pkra, discussion moved to https://groups.google.com/forum/#!topic/mathjax-users/x6XVkwp8i0o

Thanks!

Was this page helpful?
0 / 5 - 0 ratings