Python: Unable to Render Tex in Matplotlib
Asked Answered
B

6

77

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.

Bifurcate answered 5/7, 2012 at 23:58 Comment(1)
this fixed for me sudo apt-get install dvipngBotelho
C
58

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

Comitia answered 6/7, 2012 at 7:32 Comment(8)
Still applicable on my Ubuntu 13.10 machine. I also needed the dvipng package.Minier
On ubuntu 14.04.1 I needed to install both texlive-latex-extra and texlive-fonts-recommendedNecrophobia
Same on ubuntu 15.10 ... However, matplotlib continued using cached versions of plots generated before installing these packages. Before installing these packages, matplotlib would generate plots with no text at all. It took me a little bit to realize the cached versions were being used, but removing the dvi's and pdfs in ~/.cache/matplotlib/tex.cache/ did the trick.Intelligentsia
On Ubuntu 16.04, texlive-latex-extra texlive-fonts-recommended and dvipng were needed.Teishateixeira
Any idea what to add on a windows machine? tried to add type1cm and it says package not found on miktex. thanksShayne
The miktex.org search does find a type1cm package: miktex.org/packages/type1cmInternalcombustion
Under Arch/Manjaro it's called texlive-latexextra.Sketch
...a couple of years later macport has it in texlive-lang-otherMaltz
H
100

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
Hastings answered 13/5, 2016 at 20:33 Comment(6)
Works on Ubuntu16.04 as well.Reconsider
Also works on Ubuntu 16.04.1 in the Windows Subsystem for Linux.Cyruscyst
I can generate plots, but they have serif fonts.Marrilee
Update 09/2021: This works on Ubuntu 21.04 as well.Caressive
Similar issue on windows (behind a firewall). Adding cm-super solved it.Dynode
Also works for 22.04 =)Littles
C
58

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

Comitia answered 6/7, 2012 at 7:32 Comment(8)
Still applicable on my Ubuntu 13.10 machine. I also needed the dvipng package.Minier
On ubuntu 14.04.1 I needed to install both texlive-latex-extra and texlive-fonts-recommendedNecrophobia
Same on ubuntu 15.10 ... However, matplotlib continued using cached versions of plots generated before installing these packages. Before installing these packages, matplotlib would generate plots with no text at all. It took me a little bit to realize the cached versions were being used, but removing the dvi's and pdfs in ~/.cache/matplotlib/tex.cache/ did the trick.Intelligentsia
On Ubuntu 16.04, texlive-latex-extra texlive-fonts-recommended and dvipng were needed.Teishateixeira
Any idea what to add on a windows machine? tried to add type1cm and it says package not found on miktex. thanksShayne
The miktex.org search does find a type1cm package: miktex.org/packages/type1cmInternalcombustion
Under Arch/Manjaro it's called texlive-latexextra.Sketch
...a couple of years later macport has it in texlive-lang-otherMaltz
C
45

I had to install the cm-super package in a ubuntu derivate (jupyter/minimal-notebook which derives from Ubuntu 18.04) $ sudo apt-get install cm-super

Copycat answered 27/3, 2020 at 16:13 Comment(5)
Indeed, cm-super was needed on Ubuntu 18.04 along with dvipng texlive-latex-extra texlive-fonts-recommended.Mackinaw
I also needed cm-super on (LM) Ubuntu 18.04Leonteen
Also did the trick for me. I had previously sudo apt install texlive (which includes texlive-fonts-recommended). Had to install also: cm-super and texlive-latex-extra (with apt-get, for whatever reasons it didn't work with apt).Inoculate
Installation of cm-super also did the trick for me in Ubuntu 19.10, but with two caveats: (i) now the plot takes way too longer to be rendered, (ii) my font styles has been affected (which I don't want it to happen)Condescend
@Condescend I'm not sure on why it should take longer to render, but for the fonts I assume that it might make sense. Could you check what fonts are used to render the plot without latex (default, or rc('text', usetex=True)), and what fonts are used once you rc('text', usetex=True)?Copycat
S
3

Along with dvipng texlive-latex-extra texlive-fonts-recommended, cm-super was also need in Ubuntu 20.04.

Statue answered 28/6, 2022 at 4:47 Comment(0)
S
0

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.

State answered 31/1, 2023 at 11:54 Comment(0)
I
0

In Manjaro, you may also need texlive-fontrecommended.

Imbue answered 30/4 at 16:8 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Mirellamirelle

© 2022 - 2024 — McMap. All rights reserved.