I have a function I am consuming that returns a string of latex code. I need to generate an image from this. Most of the methods I have seen for doing so suggest calling an external application via say the subprocess module which will generate the image for me.
However, management is not keen on this as it will require external users to install additional software in addition to our own which, with our user base, is not something we can assume to be a simple task.
So are there any python libraries that will accomplish the task of taking latex into a format (such as an image file) which is displayable in a GUI?
Maybe you could use an online service such as this one: http://www.codecogs.com/components/equationeditor/equationeditor.php.
Following Joel A. Christophel's suggestion, here's a working similar website: http://arachnoid.com/latex/
SymPy has a builtin preview function that does this.
generates
There are lots of options to
preview
to change the format of the output (for instance, if you don't like the Euler font you can seteuler=False
).preview
also accepts a LaTeX string instead of a SymPy expression if you have thatTake a look at mathtex.
this answer might not have been available at the time when the question was asked, but i will add it for those seeking a solution as of 2015.
you can use
matplotlib.pyplot
to render an equation in a graph with axes, and then remove the axes manually. you can also generate the latex withsympy
:tested with sympy
0.7.6
and matplotlib1.4.3
This is a bit ugly solution I often use, but I found it easiest to use in many cases.
Keep in mind, it requires pillow and matplotlib.
You're going to need to use LaTeX to process to string. The process of rendering LaTex/TeX is very involved (it generally takes a 100+MB package to do the work), you're just not going to be able toss in a little python module to get the work done.