LaTeX2MathML is a free LaTeX to Presentation MathML converter written in PHP5.
Features :
Features :
- Produce a valid MathML 3.0 output
- Some amsmath features are supported
- Fast and optimized conversion process
- Newcommand support
- And a lot more!
Demo
Feel free to test LaTeX2MathML here: LaTeX2MathML Demo.Brief presentation
LaTeX2MathML is a php5 written program that allows you convert LaTeX math formulas to MathML.About MathML
Do you know that your web-browser can display math formulas as if they were hand-written ? Although it works better with firefox (2, 3,...) or opera (9.5+, 10...), it's also possible to display mathml with internet explorer, you just have to download mathplayer, here. Thus, to read this article, which contains mathml, you will need one of the previously mentioned browser.Downloading LaTeX2MathML
The project is hosted by sourceforge.net, you can download the latest release at http://sourceforge.net/projects/latex2mathml/.First example
Examples of this page are converted from LaTeX by LaTeX2MathML.This formula :
\begin{pmatrix} \int_{-\infty}^{+\infty} \frac{1}{1+x^2} d x & \sum_{n=0}^{+\infty} \frac{1}{x_n+1} & E = mc^2 \\ e = -n \frac{d\phi}{dt} & a & b \\ u=Ri & E=Ri^2 & \dots \\ 0 & \frac{\pi^2}{6} = \sum_{n=0}^{+\infty}\text{qqchose} & 0 \end{pmatrix}
is converted and rendered (by your browser) as: How to use LaTeX2MathML
Installing the script
The script is pretty easy to use, and some examples are given in the provided package. However, you can find here some instructions.Simple example
Here's a very simple example :// These files are required to get the script fully functional.
require('config.class.php');
require('commands.class.php');
require('config.php');
require('latex2xml.class.php');
// Instantiation of the class.
$l2xml = LaTeX2Xml::getInstance();
// Parse a simple formula.
$l2xml->parseMath("\\frac{\pi}{2}");
// Display the MathML of the previous formula.
echo $l2xml->parse();
With this script, you can only display one formula, here :
Remove the xml prolog
The output given by LaTeX2MathML contains the xml prolog. If you want to include MathML in your XHTML pages, you will need to remove this part. The last line echo $l2xml->parse();
has to be replaced by :
echo preg_replace('/<\?xml(?:.+)\?>(.+)/s', '$1', $l2xml->parse());
Display formulas in XHTML documents
Now imagine that you want to display some formulas on your website. You can use html5 or xhtml 1.1. In that cas, your website has to be valid when it's checked by w3c's validator : http://validator.w3.org/. You should use the following DTD:
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
Also, prefer utf-8 charset, which is really better than iso for rendering mathml, and required for LaTeX2MathML. The document should be served as "application/xhtml+xml", which could be a problem with some browsers. A good solution for implementing that properly is:
if(stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")
|| stristr($_SERVER["HTTP_USER_AGENT"],"MathPlayer"))
header("Content-type: application/xhtml+xml; charset=utf-8");
else
header("Content-type:text/html; charset=utf-8");
Obviously, for a browser that doesn't support mathml, the document will be served as text/html and, thus, will not display mathml.