2

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)
JohanC
  • 71,591
  • 8
  • 33
  • 66
Bextia C.
  • 21
  • 4
  • 1
    You probably need a raw string (with an `r` before the string) when your string contains backslashes and curly brackets. So, `expr=r"$$\frac{2}{3}$$"`. See e.g. [What exactly do “u” and “r” string flags do, and what are raw string literals?](https://stackoverflow.com/questions/2081640/what-exactly-do-u-and-r-string-flags-do-and-what-are-raw-string-literals) – JohanC Feb 24 '21 at 17:29
  • Thank you JohanC! placing a simple r before the string solved the problem. – Bextia C. Feb 24 '21 at 20:38

1 Answers1

0

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+"}$$"
Bextia C.
  • 21
  • 4