Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
5.5k views
in Q2A Core by
I have installed MathJax using the following scripts:

- Custom HTML in <head> section of every page

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

- Custom HTML at top of every page

<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>

This works fine for one question. However, if answers and comments are displayed on the same page, MathJax compiles inline math using the delimiter $ only after reloading the page manually in the browser.

Is there a way to trigger MathJax to compile on first time loading of the page?
Q2A version: 1.6.2
by
Do you mean you want MathJax to compile after user enters data / answer and hit the Add Comment or Add Answer button?
by
No. If I click on a question title in the list of questions, a new page is displayed with the whole thread of answers and comments. However, MathJax does not compile yet. Reloading the page in the browser (for instance by pressing ctrl reload in Firefox) loads the page again, but this time correctly compiled.
by
yes, implemented at GMF, see example http://www.gute-mathe-fragen.de/46171/neu-tex-eingaben-ab-sofort-moglich

I only load the mathjax library when Latex code is detected. That saves a lot of loading time, and makes the site more performant for my users.

Greetings, Kai

2 Answers

+1 vote
by
selected by
 
Best answer
Yes this is possible - I am saying from my experience with MathJax. You have to use the MathJax.Hub.Typeset() method in order to re-parse the page and this should be done using a queue, for example - MathJax.Hub.Queue(["Typeset",MathJax.Hub])

You should take  alook at the source code of the following example - http://mathjax.org/mathjax/test/sample-dynamic.html

and modify Q2A answer, comment forms to add the functions on the onclick listeners of the Answer & COmment buttons. You can use jQuery & the onclick listener with the classes - .qa-form-tall-button-answer & .qa-form-tall-button-comment
by
Would that mean that the Typeset method has to be implemented on the onclick event triggered by pressing on a question in the list (see my comment to my question above)?
by
Got it. Just put the queue in document.ready and see. It will solve your problem :-)
by
Thank you! It will take a while until I have found the appropriate positions in the core code of Q2A. I will report my experience.
by
MathJax.Hub.Queue(["Typeset",MathJax.Hub]) triggered at jQuery's function $(window)load() did the job perfectly! Thanks a lot!
by
Great. You're welcome.
0 votes
by

it depends of the preload of the mathjax library. If it is already loaded , the onload function will not work.

Any case, if you need mathjax, you must have it loaded in all the pages.

Therefore , inserting in qa-question.js , after qa_conceal() , a general MathJax.Hub.Queue will work. If 'e', the div object , is specified in this function , it doesn't work as expected

                qa_reveal(c, 'answer');
                qa_conceal(a, 'form');

/****************** insert ***********************/
            if (typeof MathJax != "undefined" && typeof MathJax.Hub != "undefined")
                    MathJax.Hub.Queue(['Typeset', MathJax.Hub]);
/****************** /insert ***********************/

 

...