简体   繁体   中英

Python: Unable to Render Tex in Matplotlib

I recently upgraded my laptop to Snow Leopard, updated TeX to Version 3.1415926 (TeX Live 2011/MacPorts 2011_5), and installed Python 2.7.3. After all these installs, I ran macport selfupdate and macport upgrade outdated. However, now when I try to use TeX in matplotlib, I receive the following:

LaTeX was not able to process the following string:'lp'
Here is the full report generated by LaTeX: 

This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011/MacPorts 2011_5)
 restricted \write18 enabled.  
entering extended mode (./64a53cc27244d5ee10969789771e33fa.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, dumylang, nohyphenation, cz
ech, slovak, dutch, ukenglish, usenglishmax, basque, french, german-x-2009-06-1
9, ngerman-x-2009-06-19, german, ngerman, swissgerman, italian, polish, portugu
ese, spanish, catalan, galician, ukenglish, loaded.
(/opt/local/share/texmf-texlive-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/opt/local/share/texmf-texlive-dist/tex/latex/base/size10.clo))

! LaTeX Error: File `type1cm.sty' not found.

Type X to quit or <RETURN> to proceed, or enter new name. (Default extension: sty)


l.3 \renewcommand
             {\rmdefault}{pnc}^^M
No pages of output.

Similar to this previous question , I tried setting the path in my python code via:

os.environ['PATH'] = os.environ['PATH'] + ':/opt/local/bin/latex'

since which latex yielded /opt/local/bin/latex . However, that didn't work, with the same error message. I also tried the path to tex, as well as the example from the previous question. No change.

I then tried to force possibly missing packages via:

matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]

however, that also did not work.

The only way I can get my plots to work is to say rc('text', usetex=False) , which is not ideal. Any help would be much appreciated.

On an Ubunutu 14.04 machine the combination of answers from above worked. I sudo apt-get install the dvipng , texlive-latex-extra , and texlive-fonts-recommended packages and that did the trick:

$ sudo apt-get install dvipng texlive-latex-extra texlive-fonts-recommended 

Edit: As of Matplotlib 3.2.1, you now also need the package cm-super (see https://github.com/matplotlib/matplotlib/issues/16911 )

$ sudo apt-get install dvipng texlive-latex-extra texlive-fonts-recommended cm-super

The error message says you're missing the type1cm package. It seems that MacPorts includes it as part of texlive-latex-extra .

我必须将cm-super包安装在 ubuntu 衍生版本(从 Ubuntu 18.04 派生的jupyter/minimal-notebook$ sudo apt-get install cm-super

I recently upgraded my laptop to Snow Leopard, updated TeX to Version 3.1415926 (TeX Live 2011/MacPorts 2011_5), and installed Python 2.7.3. After all these installs, I ran macport selfupdate and macport upgrade outdated. However, now when I try to use TeX in matplotlib, I receive the following:

LaTeX was not able to process the following string:'lp'
Here is the full report generated by LaTeX: 

This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011/MacPorts 2011_5)
 restricted \write18 enabled.  
entering extended mode (./64a53cc27244d5ee10969789771e33fa.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, dumylang, nohyphenation, cz
ech, slovak, dutch, ukenglish, usenglishmax, basque, french, german-x-2009-06-1
9, ngerman-x-2009-06-19, german, ngerman, swissgerman, italian, polish, portugu
ese, spanish, catalan, galician, ukenglish, loaded.
(/opt/local/share/texmf-texlive-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/opt/local/share/texmf-texlive-dist/tex/latex/base/size10.clo))

! LaTeX Error: File `type1cm.sty' not found.

Type X to quit or <RETURN> to proceed, or enter new name. (Default extension: sty)


l.3 \renewcommand
             {\rmdefault}{pnc}^^M
No pages of output.

Similar to this previous question , I tried setting the path in my python code via:

os.environ['PATH'] = os.environ['PATH'] + ':/opt/local/bin/latex'

since which latex yielded /opt/local/bin/latex . However, that didn't work, with the same error message. I also tried the path to tex, as well as the example from the previous question. No change.

I then tried to force possibly missing packages via:

matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]

however, that also did not work.

The only way I can get my plots to work is to say rc('text', usetex=False) , which is not ideal. Any help would be much appreciated.

除了dvipng texlive-latex-extra texlive-fonts-recommendedUbuntu 20.04还需要cm-super

On Manjaro (Arch), I only needed to install texlive-latexextra , which contains the type1cm.sty file.

pacman -S texlive-latexextra

The packages texlive-bin and texlive-core were already installed on my computer and would likely also be required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM