Generating an image of a fraction with python using SymPy

Viewed 97

I'm following asmeurer's solution on this thread (Converting latex code to Images (or other displayble format) with Python and everything worked fine will I tried to display a simple fraction like \frac{2}{3}.

Why am I getting a LaTex abnormally exit error if the LaTex code for the equation is right? It works fine as long as the LaTex code has a single line (I mean, everything is written side by side, once it has to be something written above something else... crashes)

This code works:

expr="r'$$\int_0^1 e^x\,dx$$"
preview(expr, viewer='file', filename='test.png', euler=False)

and produces this image:

generated PNG

But this code doesn't:

expr="$$\frac{2}{3}$$"
preview(expr, viewer='file', filename='test.png', euler=False)
1 Answers

As JohanC pointed in his reply to my post: the solution was to place an r before the string. Now the code works like this.

expr=r"$$\frac{2}{3}$$"
preview(expr, viewer='file', filename='output.png', euler=False)

But... when I try to replace some parts of the expr with a variable... doesn't. But that's another problem.

expr=r"$$\frac{+"foo+"}{+"morefoo+"}$$"
Related