Skip to content

Instantly share code, notes, and snippets.

@mauriciopoppe
Last active August 29, 2015 14:17
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 mauriciopoppe/2f40ceee20841ffe782f to your computer and use it in GitHub Desktop.
Save mauriciopoppe/2f40ceee20841ffe782f to your computer and use it in GitHub Desktop.
Live Mathjax preview on Ghost 0.5.10
{{! Load and configure mathjax }}
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
showProcessingMessages: false,
messageStyle: 'none',
tex2jax: {
inlineMath: [['$','$']],
displayMath: [['$$','$$']],
processEnvironments: false
},
'HTML-CSS': { imageFont: null }
});
</script>
{{! Re-render MathJax in live preview}}
<script>
(function () {
var timeout;
function mathjaxify() {
var entry = document.getElementsByClassName('entry-markdown')[0];
if (entry) {
var preview = document.getElementsByClassName('rendered-markdown')[0];
if (typeof(typeset) == "undefined" || typeset == true) {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, preview]); // renders mathjax if 'typeset' is true (or undefined)
typesetStubbornMath();
}
// Render the bits of math that have inexplicably still failed to render, while
// leaving the rest alone. (If you try to typeset the whole page, it will break
// other things)
function typesetStubbornMath() {
$(".MathJax_Preview").each(function () {
if ($(this).text() != "") {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, $(this).attr("id")]);
}
});
}
}
}
jQuery(document).keypress(function () {
clearTimeout(timeout);
timeout = setTimeout(mathjaxify, 500);
});
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment