1

I have a PHP-script that outputs: ((5^2x^2)^2+3)/(sqrt(sqrt(81)))

I want it to be formatted properly like you would write it.

Where can I find a ASCII to MathML converter like this: http://www.equationsheet.com/asciitomathml.php That is OpenSource in PHP or JavaScript so that I can use it on my webpage to format the mathematical fraction? (Because this is done in PHP closed source, but I need something that I can implement on my own server.)

My scripts outputs the math as that, and I need it to be displayed properly

I really appriciate that you spend your time helping me! :)

VividD
  • 10,456
  • 6
  • 64
  • 111
Friend of Kim
  • 850
  • 9
  • 24

2 Answers2

4

I recommend you to use MathJax.

  • It is used by many forums and also by StackExchange Mathematics!

  • It supports all modern browsers (even Internet Explorer 6!)

  • Very simple, just upload MathJax to your server and include 2 CSS/JS files! Some weeks ago, I installed it on a MediaWiki installation and it was easy as installing XAMPP ;)

ComFreek
  • 29,044
  • 18
  • 104
  • 156
  • Thanks for your reply! :) Can I use this to convert sqrt(2x^2)/(5x+2) into mathematical formatting? Or do I have to make my script convert it to a different format? I couldn't find any place to test it on [MathJax](http://www.mathjax.org/). – Friend of Kim Nov 19 '11 at 14:36
  • You have to convert it to: `\frac{ \sqrt{2x^2} }{ 5x+2 }`. But I think that's pretty simple :) – ComFreek Nov 19 '11 at 14:44
  • I found this: [Chapman's ASCIIMathML](http://mathcs.chapman.edu/~jipsen/mathml/asciimathdownload.html) That's probably what I was looking for. Have been looking for several hours now.. What do you think is the best solution, when it comes to the fact that the script is probably going to be extended sometime? – Friend of Kim Nov 19 '11 at 14:55
  • Okay, but this converter only translates your formula into a `` tag. MathJax can also display images (browser compatibility!). And the last SVN commit of Chapman's ASCIIMathML was on 16. July 2009! – ComFreek Nov 19 '11 at 15:10
  • Ok. But the problem is that my script should process the formula, so I don't know what to do. :( Do you know about any place I can see the whole syntax of the MathJax? So that I maybe can implement that in my script? – Friend of Kim Nov 19 '11 at 15:13
  • Could you write eigther: `\frac{ \sqrt{2x^2} }{ 5x+2 }` or `&frac{ sqrt{2x^2} }{ 5x+2 }&` – Friend of Kim Nov 19 '11 at 15:27
  • Oh, is it a good idea to use Chapman's ASCIIMathML to convert to MathML and use MathJax to display the MathML? You see I'm making a script to process some of the formulas. I'm a 16 years old boy from Norway, so I don't know to much about those formulas and so on.. That's the reason why I need something simple. – Friend of Kim Nov 19 '11 at 16:11
  • The MathJax syntax is like the normal LaTeX syntax, just search for `latex math` ([example site](http://web.ift.uib.no/Teori/KURS/WRK/TeX/symALL.html)). – ComFreek Nov 20 '11 at 12:44
  • Yes, you could also use MathML as the input for MathJax (see [here](http://www.mathjax.org/docs/1.1/start.html#mathml-input)). – ComFreek Nov 20 '11 at 12:50
  • MathJax v2.0 now accepts AsciiMath format as one of its input formats, so you can use MathJax to go directly from your format to MathML. – Davide Cervone Apr 07 '12 at 16:18
2

You might also look at my jqMath JavaScript library at http://mathscribe.com/author/jqmath.html - it's like MathJax, but simpler, smaller, and much faster. Unlike ASCIIMathML, jqMath will work in any browser back to IE6, and is also open source. If you know LaTeX and want its full power for very advanced mathematics, and don't mind if pages load slowly, then use MathJax. But for examples like yours, jqMath will be faster, and use a simpler syntax based directly on MathML and Unicode. In your example, you would need to input {(5^2x^2)^2+3}/√√81 to jqMath. You can try this out at the page I linked to above.

Dave Barton
  • 1,429
  • 13
  • 12
  • Thanks, but my problem is that my script processes the formula, and I don't want to write 400 lines of code just to output the result of the script. – Friend of Kim Nov 19 '11 at 18:53
  • Your php page should include/produce an html – Dave Barton Nov 19 '11 at 19:58
  • Thanks. But, the user inputs a formula, my script changes it and outputs it. So you mean that I have to write the script to work with the syntax of jqMath? – Friend of Kim Nov 19 '11 at 20:34
  • Yes, your script output must match the input syntax of whatever you are feeding it to, jqmath or mathjax or mathml or whatever you choose. The problem with mathml is that most browsers don't support it yet, plus it's very verbose, so it's better to produce a concise string that jqmath or mathjax can convert to either mathml or html+css, depending on the user's browser. – Dave Barton Nov 19 '11 at 23:54
  • Thanks. But, you say that jqMath and MathJax can convert from a string to HTML+CSS or MathML. Can it be formatted like I did in the example? You see I have a script on 500 lines, but I don't want to write another 500 lines just to output my script's result... – Friend of Kim Nov 20 '11 at 09:20
  • It isn't 500 lines. You just have to output √ instead of "sqrt". – Dave Barton Nov 20 '11 at 17:01
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5175/discussion-between-dave-barton-and-50ndr33) – Dave Barton Nov 20 '11 at 18:52