LaTeX can't find file for text in plot
Apologies in advance if I've missed something obvious. I'm trying to add LaTeX text to a plot, e.g.
from matplotlib import rc
rc('text', usetex=True)
plot(x^2, legend_label=r'This is $x^2$')
and each time, I get an error message like this:
/opt/sagemath-9.3/local/lib/python3.7/site-packages/sage/repl/rich_output/display_manager.py:596: RichReprWarning: Exception in _rich_repr_ while displaying object: latex was not able to process the following string:
b'lp'
Here is the full report generated by latex:
This is pdfTeX, Version 3.141592653-2.6-1.40.23 (MiKTeX 21.10)
entering extended mode
! I can't find file `/home/sage/.sage/matplotlib-1.5.1/tex.cache/1acea6f6c115d0
ec7a634ed0529287b9.tex'.
<*> ....cache/1acea6f6c115d0ec7a634ed0529287b9.tex
Please type another input file name
! Emergency stop.
<*> ....cache/1acea6f6c115d0ec7a634ed0529287b9.tex
No pages of output.
Transcript written on texput.log.
RichReprWarning,
The file in question (1acea6f6c115d0ec7a634ed0529287b9.tex) does exist, but the path is
`/home/.sage/matplotlib-1.5.1/tex.cache/1acea6f6c115d0
ec7a634ed0529287b9.tex'
not
`/home/sage/.sage/matplotlib-1.5.1/tex.cache/1acea6f6c115d0
ec7a634ed0529287b9.tex'
For whatever it's worth, my home directory is C:\Users\davis\
and if I copy the relevant file into the folder that LaTeX says it's looking for, and then run the same code, I get the same error message.
I'm on Windows 10 running Sage 9.3 (fresh installation this morning).
FWIW, your code works with SageMath 9.4 running on Ubuntu 20.04. The first two lines are even not necessary to get the LaTeX output. So maybe it is an issue specific to Windows' version of Sage...
see the post:some-latex-code-no-longer-works-in-9.3
The 3 codes lines generate an error also in 9.4 W10 WSL2 UBUNTU 20.04 for me , but as @eric_g remarked not the last one only, maybe something fishy here ?
@xdav : What the use of two first lines ? (just by curiosity)
the two files contents and their location for my system
@ortollj The first two lines are because I wanted to have some non-mathematical text in a nicer font; I've edited the sample code to reflect this. The relevant tex file isn't hard to find, and it compiles ok on my system - it just gives a blank page. I did see the post you mentioned (some-latex-code-no-longer-works-in-9.3) but was reluctant to try the WSL solution because that code gives syntax errors, not file-not-found errors on my system.