Skip to content

Instantly share code, notes, and snippets.

@pkra
Last active February 10, 2017 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkra/36f5873e5d57f11a87858fab6412ff87 to your computer and use it in GitHub Desktop.
Save pkra/36f5873e5d57f11a87858fab6412ff87 to your computer and use it in GitHub Desktop.
A snippet for wordpress's math PNGs
(function () {
var images = document.querySelectorAll('img.latex');
for (var i = 0; i < images.length; i++){
var image = images[i];
tex = image.getAttribute('alt');
var preview = document.createElement('span');
preview.setAttribute('class','MathJax_Preview');
image.parentNode.insertBefore(preview, image);
preview.appendChild(image);
var script = document.createElement('script');
script.type = 'math/tex';
script.text= tex; // strip dollars from TeX string
preview.parentNode.insertBefore(script, preview.nextSibling)
}
var mathjax = document.createElement('script');
mathjax.src= 'https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML-full';
document.head.appendChild(mathjax);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment