Skip to content

Instantly share code, notes, and snippets.

@mhucka
Created September 6, 2021 15:21
Show Gist options
  • Save mhucka/567e1030c3b1de8c3b98c7d82778a957 to your computer and use it in GitHub Desktop.
Save mhucka/567e1030c3b1de8c3b98c7d82778a957 to your computer and use it in GitHub Desktop.
Code shown in the "Default – MathJax 3" tab of the section on "Loading MathJax" at https://facelessuser.github.io/pymdown-extensions/extensions/arithmatex/#loading-mathjax
window.MathJax = {
options: {
ignoreHtmlClass: 'tex2jax_ignore',
processHtmlClass: 'tex2jax_process',
renderActions: {
find: [10, function (doc) {
for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
const display = !!node.type.match(/; *mode=display/);
const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
const text = document.createTextNode('');
const sibling = node.previousElementSibling;
node.parentNode.replaceChild(text, node);
math.start = {node: text, delim: '', n: 0};
math.end = {node: text, delim: '', n: 0};
doc.math.push(math);
if (sibling && sibling.matches('.MathJax_Preview')) {
sibling.parentNode.removeChild(sibling);
}
}
}, '']
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment