to do LaTeX codes, you will need LaTeX and ImageMagick (the latter requires Ghostscript) installed on your server.
the code from: http://www.mayer.dial.pipex.com/tex.htm
should be readily adaptable to the purpose. I have had the script referenced above running on my phpBB board for a while with no problems at all.
please post up any code you get working, I will most likely want to set this up on MODx eventually too.