TURN MATHJAX OFF

465 views
Skip to first unread message

everymoment missingu

unread,
Aug 16, 2011, 3:50:39 PM8/16/11
to MathJax Users
May be I have overlooked some topics, I have a simple question is to
turn the mathjax off or on by clicking a button on a web page. Any
script or function could do this? Thank you.

Phillip Lord

unread,
Aug 17, 2011, 5:41:51 AM8/17/11
to mathja...@googlegroups.com

Easiest solution is to switch javascript off. This will do other things
as well of course.

Phil

--
Phillip Lord, Phone: +44 (0) 191 222 7827
Lecturer in Bioinformatics, Email: philli...@newcastle.ac.uk
School of Computing Science, http://homepages.cs.ncl.ac.uk/phillip.lord
Room 914 Claremont Tower, skype: russet_apples
Newcastle University, msn: m...@russet.org.uk
NE1 7RU twitter: phillord

Davide P. Cervone

unread,
Aug 18, 2011, 9:47:36 AM8/18/11
to mathja...@googlegroups.com
> Easiest solution is to switch javascript off. This will do other
> things
> as well of course.

I think what the questioner had in mind was to give a toggle on the
page that would either show the original TeX code or the typeset code,
so that you could switch between the two, rather than simply turning
off MathJax entirely. But that is just a guess.

If that is what was requested, there is no direct way to do that, but
it could be done with some javascript code. For instance, adding

<script>
function removeTypeset() {
var HTML = MathJax.HTML, jax = MathJax.Hub.getAllJax();
for (var i = 0, m = jax.length; i < m; i++) {
var script = jax[i].SourceElement(), tex = jax[i].originalText;
if (script.type.match(/display/)) {tex = "\\["+tex+"\\]"} else
{tex = "\\("+tex+"\\)"}
jax[i].Remove();
var preview = script.previousSibling;
if (preview && preview.className === "MathJax_Preview") {
preview.parentNode.removeChild(preview);
}
preview = HTML.Element("span",{className:"MathJax_Preview"},[tex]);
script.parentNode.insertBefore(preview,script);
}
}

function showTypeset(show) {
MathJax.Hub.Queue(show ? ["Reprocess",MathJax.Hub] : removeTypeset);
}
</script>

<style>
.MathJax_Preview {color:black ! important}
</style>

to the <head> section of your page, and

<label>
<input type="checkbox" onchange="showTypeset(this.value)"
checked="checked" />
Show Typeset Mathematics
</label>

to the body of the page will add a checkbox that lets you turn on and
off the typeset mathematics. When turned off, the mathematics will
show as its original TeX code (with delimiters), and when on as the
typeset code.

Hope that does what you need.

Davide

Phillip Lord

unread,
Aug 18, 2011, 11:14:26 AM8/18/11
to mathja...@googlegroups.com


"Davide P. Cervone" <dp...@union.edu> writes:

>> Easiest solution is to switch javascript off. This will do other things
>> as well of course.
>
> I think what the questioner had in mind was to give a toggle on the page that
> would either show the original TeX code or the typeset code, so that you
> could switch between the two, rather than simply turning off MathJax
> entirely. But that is just a guess.


You can get to the underlying TeX with a right click, cannot you not?

Never worked out whether this was the real underlying code or generated.
But it's close enough.

Phil

Davide P. Cervone

unread,
Aug 19, 2011, 11:56:07 AM8/19/11
to mathja...@googlegroups.com
> You can get to the underlying TeX with a right click, cannot you not?

Yes, but there may be other reasons to not have the math be typeset
(copy and paste of whole paragraphs at a time, for example).

> Never worked out whether this was the real underlying code or
> generated.

It is the original.

Davide

goharrypotte...@gmail.com

unread,
Aug 24, 2012, 6:53:43 PM8/24/12
to mathja...@googlegroups.com, missingue...@gmail.com
Read my answer in stackoverflow.
Reply all
Reply to author
Forward
0 new messages