# Mathematical formulas can't be translated in comments.

+1 vote
1.3k views
in Q2A Core

I have added the following Mathjax code to the <head> of all pages.

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX","output/HTML-CSS"],
tex2jax: {inlineMath: [["$","$"],["\$","\$"]]},
TeX: { extensions: ["AMSmath.js","AMSsymbols.js"]}
});
</script>

So all mathematical formulas between  could be translated.(for example see mathoverflow.com)

My problem is when I write a mathematical formula in comments and add comment browser doesn't translate it until I refresh the page.

I have the same problem when I click on previous comments.

But I don't have this problem when I edit a comment. because after editing a comment the page will refresh.

This is a big problem because my website is about mathematic. :(

by
edited by

You need to call Mathjax again after the ajax post.

But this is not easily done with q2a 1.6.3 - since everything is coded in pure Javascript.

Check qa-question.js there should be something like:

var answTxt = lines.slice(3).join("\n");
if(answTxt.indexOf('^')!=-1 && answTxt.indexOf('$$')==-1 && answTxt.indexOf('\\(')==-1) { e.innerHTML = answTxt; } else { e.innerHTML = answTxt; if(answTxt.indexOf('$$')!=-1 || answTxt.indexOf('\(')!=-1 ) {
// insert mathjax-config for linebreak option
$('head').append('<script type="text/x-mathjax-config"> MathJax.Hub.Config({ "HTML-CSS": { scale:100, linebreaks: { automatic: true } }, SVG: { linebreaks: { automatic: true } }, displayAlign: "left" }); </script>'); var mjaxURL = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML&locale=de'; // ,Safe.js // as soon mathjax is loaded$.getScript(mjaxURL, function() {
// mathjax loaded, call it on the comment which is e
MathJax.Hub.Queue(['Typeset', MathJax.Hub, e]);
});
}
}

Hope this helps.

PS: This approach is used in my German math forum: http://www.gute-mathe-fragen.de/

by
Kai: Thanks. But in qa-page.js I just have these:
qa_ajax_post('vote', {postid:postid, vote:vote, code:code},
qa_ajax_post('notice', {noticeid:ens[1], code:code},
qa_ajax_post('favorite', {entitytype:ens[1], entityid:ens[2], favorite:parseInt(ens[3]), code:code},
function qa_ajax_post(operation, params, callback)