Skip to content

Instantly share code, notes, and snippets.

@danthedaniel
Created August 26, 2017 18:33
Show Gist options
  • Save danthedaniel/157bb1ee76ae236d43258e38f9e5764f to your computer and use it in GitHub Desktop.
Save danthedaniel/157bb1ee76ae236d43258e38f9e5764f to your computer and use it in GitHub Desktop.
Tiny automatic KaTeX rendering.
// Automatically render all elements of type pre.math as latex equations.
(function() {
var math_elements = document.querySelectorAll('pre.math');
math_elements.forEach(function(e) {
e.innerHTML = katex.renderToString(e.innerText);
});
})();
@danthedaniel
Copy link
Author

danthedaniel commented Aug 26, 2017

In my opinion, this is significantly better than using the massive auto-render.js that KaTeX provides. You don't get the convenience of automatically rending LaTeX inside of text blocks, but you save over 10KB and an extra HTTP request.

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