UPDATE: This is not a duplicate of Align TeX equations in matplotlib.
- The sample code shown in this question does not produce the output I would have expected or wanted given the specified input LaTeX string. When I ran the code shown in this question, there were no errors, but the output was simply the same as the original input string (i.e., it had not been rendered to nice math type).
ORIGINAL QUESTION
I am attempting to use the python package, "matplotlib", to convert LaTeX markup into an image. Per the instructions, I have completed the following:
1) Have a working LaTeX installation on my machine (I'm using TexLive).
2) Have properly set my matplotlib.rcParams such that:
- text.usetex = True
- text.latex.preamble = r"\usepackage{amsmath}"
The exact code I'm using to set the params is:
params = {
"text.usetex": True,
"text.latex.preamble": [r"\usepackage{amsmath}"], (have tried this part both as a string and as a list as shown here)
"verbose.level": "debug-annoying"
}
matplotlib.rcParams.update(params)
3) Have verified that my LaTeX snippet is written correctly by running it through the pdflatex tool independently. The sample code is:
$\begin{eqnarray} 3=3 \end{eqnarray}$
and the equivalent string I'm using in Python is:
r"$\begin{eqnarray} 3=3 \end{eqnarray}$"
The problem is that when I try to run the LaTeX fragment above through matplotlib's "to_png" or "math_to_image" functions, I consistently get a Value Error message stating that "\begin" is an unknown symbol. It doesn't seem to matter what's inside the curly braces; matplotlib seems to get hung up on the "\begin" piece in particular.
I'm at a loss for what could be wrong with my configuration given that I have followed all of the matplotlib instructions for using LaTeX as well as other stackoverflow posts reporting similar sounding issues (in most cases, adding \usepackage{amsmath} seems to fix the problem for everyone else).
Hoping to find some leads here. Cheers!