Created
March 7, 2017 09:37
-
-
Save adiog/ea421005241945828d84f589507f8b22 to your computer and use it in GitHub Desktop.
MathJax toggle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MathJax.Hub.Config({ | |
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} | |
}); | |
function hideTypeset() | |
{ | |
var HTML = MathJax.HTML; | |
var jax = MathJax.Hub.getAllJax(); | |
for (var i = 0, m = jax.length; i < m; i++) | |
{ | |
var script = jax[i].SourceElement(); | |
var 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); | |
mathJaxNode = script.parentNode; | |
script.parentNode.removeChild(script); | |
mathJaxNode.innerHTML = mathJaxNode.innerHTML.replace('<span class="MathJax_Preview">', '').replace('</span>', ''); | |
} | |
} | |
function showTypeset(show) | |
{ | |
MathJax.Hub.Queue(["Typeset",MathJax.Hub]); | |
} | |
function toggleTypeset(show) | |
{ | |
if (show) | |
{ | |
showTypeset(); | |
} | |
else | |
{ | |
hideTypeset(); | |
} | |
} | |
function MathJaxToggle() | |
{ | |
toggleWrapper = document.createElement('div'); | |
toggleWrapper.className = 'ui checkbox'; | |
toggleWrapper.style = 'position: absolute; right: 10px; top: 10px;'; | |
toggle = document.createElement('input'); | |
toggle.type = 'checkbox'; | |
toggle.checked = true; | |
toggle.addEventListener('change', function (ev) { | |
toggleTypeset(toggle.checked); | |
}); | |
toggleWrapper.appendChild(toggle); | |
toggleLabel = document.createElement('label'); | |
toggleLabel.innerHTML = 'TeX'; | |
toggleWrapper.appendChild(toggleLabel); | |
document.body.appendChild(toggleWrapper); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment