Skip to content

Instantly share code, notes, and snippets.

@tillahoffmann
Last active November 8, 2016 13:12
Show Gist options
  • Save tillahoffmann/e03a7a9cf4059e92774b to your computer and use it in GitHub Desktop.
Save tillahoffmann/e03a7a9cf4059e92774b to your computer and use it in GitHub Desktop.
JavaScript to add MathJax support to Simplenote web app.
if (window.MathJax === undefined) {
//Add the MathJax script
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML";
var config = 'MathJax.Hub.Config({' + 'extensions: ["tex2jax.js"],' + 'tex2jax: { inlineMath: [["$","$"],["\\\\\\\\\\\\(","\\\\\\\\\\\\)"]], displayMath: [["$","$"],["\\\\[","\\\\]"]], processEscapes: true },' + 'jax: ["input/TeX","output/HTML-CSS"]' + '});';
if (window.opera) {
script.innerHTML = config
} else {
script.text = config
}
document.getElementsByTagName("head")[0].appendChild(script);
//Add the reload tag
script = document.createElement("script");
script.text = 'document.getElementById("view_mode_markdown").onclick = ' + 'function() {MathJax.Hub.Queue(["Typeset", MathJax.Hub, "static_content"]);};';
document.getElementsByTagName("head")[0].appendChild(script);
} else {
//Render the content
MathJax.Hub.Queue(["Typeset", MathJax.Hub, "static_content"]);
}
@Palaing
Copy link

Palaing commented Jul 17, 2016

It looks great but I could not get it to work. Can you help please?

@snakeneedy
Copy link

I use the console in the developer tools (Firefox) to work it.

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