Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+5 votes
in Q2A Core by
I'm looking to implement q2a as a way to slowly move new students into asking questions more readily.  A q&a solution that removes the embarrassment some students have(especially freshmen) to asking a question.  However, a lot of these are math related, and I find that writing... for example: a^2 + b^2 = c^2 ... is a bit daunting and not as clear as it could be.

Is there a way then, to integrate mathtex/latex with q2a?

2 Answers

+4 votes
Best answer
On the output/rendering side, you could do this with a TeX to HTML translator such as:


The appropriate place to do this is after the following line in qa_post_html_fields(...) in qa-app-format.php:

$fields['content']=qa_html($post['content'], true);

After installing the Tex to HTML tool on your web server as an executable, the PHP code should:

a) Detect TeX code within $post['content'] (to make this easier, perhaps ask your students to start and finish with a special character sequence).

b) Pass the detected TeX code through to the translator executable using one of PHP's program execution functions (the most appropriate one will depend on exactly how the tool does input and output):


c) Substitute what you get back from the executable into $post['content'].
Thanks for the detailed comment gidgreen!  I started experimenting with jsmath a few hours after answering this question as well, however I think the tex to html tool will be much more efficient!
I am very new in programming. I have install the q2a in my website where the school student can ask there question. I am trying to include the Math formula just like writing math equation. I have told my website hosting service provider to install the Tet to HTML and they have install it also. I have include the line $fields['content']=qa_html($post['content'], true); as per your guideline. but still unable to include the Math formula.
I believe there is a Javascript you can include that will do the Mathjax stuff for you. Check out http://math.stackexchange.com/ and see what they use.
+4 votes

Thanks DisgruntledGoat for your suggestion and I got the answer with your help.

I want to share the code to those who love to have math formula with the question2answer.

In the admin panel click on the "custom HTML in <HEAD> section of every page" and paste the following code -

<script type="text/javascript"

And download the markdown editor plugin from the -


and install it to you question2answer webpage and make it default editor from admin panel -> Posting tab.

Now your website is ready for LaTeX, MathML, and AsciiMath notation. For the supported command refer to


This works brilliantly. Thanks bishu! Only problem is: my LaTeX code only displays when I post the question and view the question - not when I'm writing the equation (in the preview section.)

I'm wondering if there is any way to apply LaTeX (Mathjax) formatting to preview comments?