Skip to content

Instantly share code, notes, and snippets.

@juanmalunatic
Created August 10, 2020 16:56
Show Gist options
  • Save juanmalunatic/0e592515641458fd5ea2c493b16af090 to your computer and use it in GitHub Desktop.
Save juanmalunatic/0e592515641458fd5ea2c493b16af090 to your computer and use it in GitHub Desktop.
Toggle MathJax to copy EdX equations to Anki
// Based on https://github.com/mathjax/mathjax-docs/wiki/Obtaining-the-original-TeX-from-a-rendered-page
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);
}
function on() {
showTypeset(true);
}
function off() {
showTypeset(false);
}
@juanmalunatic
Copy link
Author

juanmalunatic commented Aug 10, 2020

Should paste the code in the console and then run "off()" or "on()" as needed.

Would be cool to create a hotkey using Greasemonkey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment