Textvc PHP Alternative

Overview
Mediawiki uses an additional program, Texvc, to render math into nice images for page display. Unfortunately texvc needs to be compiled and is written in OCamel which can pose a problem on most public hosts even if all the other requirements are met (ghostscript, latex, etc). This work around replaces the Math rendering code with an in suite PHP version, performing all the image manipulations, renderings, etc that Texvc would normally do.

Limitations
This "hack" is not a workaround to get out of using "latex", "dvips", and "convert" (these three image processing unix commands are required) but it does workaround having to get access to installing ocamel and compiling texvc. While this hack does retain image caching, most of the other features available to math rendering have been lost and some slight differences do occur between the final output image. One notable difference is that only images are produced, the MyMCAT project didn't care for MathML or text outputs of formulas, thus these options were cut.

How it works
Basically, in Math.php, the rendering function has been striped of its calls to texvc and instead PHP makes all the calls to the necessary functions directly.

How to install it
Below is a copy of the source from Math.php. You will need to ensure you have a working directory and the shell commands work correctly for this to work.

Note: The render function still passes arguments, but they are no longer read. If anyone wants to update this script with some more fancy features, please email me, I would love to hear about it.

Known Bugs
Beyond the fact that parameters can't be passed to this renderer and the output sometimes looks slightly different than other latex renderings there are some other minor issues: - Sometimes PHP warnings get posted to the page when you render some math. I believe I am getting this because I do my file handling in /usr/temp which isn't the best place. This warning never shows up again the next time you go to the page and the image is still rendered just fine. - If you manually delete all the images in the cache folder you get warnings the first time Math.php needs to rerender them but again it renders fine and the warnings never show up again.

Working Example
This work was done for MyMCAT. You can specifically see an example of the math rendered at The Railgun Passage.

Acknowledgments
This hack was based off of the linux journal article http://www.linuxjournal.com/article/7870 by Titus Barik.