First i got a js script to update a preview div from Pagedown textarea/Pagedown widget from Django-pagedown, with the code below:
MathJax.Hub.Config({
tex2jax: { inlineMath: [['$', '$'], ["\\(", "\\)"]] }
});
var timeout;
$(function () {
function makePreview() {
input = $('#id_content').val().replace(/</g, "<").replace(/>/g, ">");
$('#id_content_wmd_preview').html(input);
MathJax.Hub.Queue(["Typeset", MathJax.Hub, "preview"]);
}
$('body').keyup(function () {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
timeout = setTimeout(makePreview, 400);
});
$('body').bind('updated', function () { makePreview() });
});
But the problem is that when this script updates the preview div, it also updates and removes the markdown? If i constantly type then the markdown shows correctly, but not mathjax. If I stop typing the markdown don't show, but mathjax shows correctly?
I know the answer is here https://gist.github.com/gdalgas/a652bce3a173ddc59f66 but i don't know how to do it. Looks like i have to remove and store the math, and then put it back in later.