Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+5 votes
1.8k views
in Q2A Core by

Hello

I asked this question about 3 years ago :) http://question2answer.org/qa/39275

based on Kai's answer it's enought to add MathJax.Hub.Queue(['Typeset', MathJax.Hub, e]);  to https://github.com/q2a/question2answer/blob/dev/qa-content/qa-question.js#L76

qa_ajax_post('answer', params,

there I have added

                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]); 
                        }); 
                    } 
                } 

This works fine but when you click on "comment" or "add comment" all the page will be reloaded and then rendered by mathjax. I want just the comment will be reloaded to show math.

Is there any way?

1 Answer

+2 votes
by
selected by
by
This works great. Thank you so much.
by
Hi Arjun
I upgraded to q2a 1.8 beta and it seems this doesn't work in new version? does it work for you?
by
Haven't migrated to 1.8 beta yet. Waiting for the full release.
by
Hello arjunsuresh
did you install new version?
by
Yes. I have.
by
Thank you. It works very well. but why do you use 'PrettyPrint' after mathjax call?(
MathJax.Hub.Queue(['Typeset', MathJax.Hub, e]);//arjun
                                prettyPrint();
)
 is it necessary? I think it causes some problems when adding comments.
by
If it causes problem, you may remove it. I added it to use prettyprint for code formatting.
by
I have created a plugin with basic MatjJax settings. It should render it on comment too.
you can check it at  https://github.com/varuninorbit/question2answer-mathjax-plugin
...