73

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.

kmario23
  • 57,311
  • 13
  • 161
  • 150
cosmosis
  • 6,047
  • 3
  • 32
  • 28

5 Answers5

90

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
Praveen
  • 6,872
  • 3
  • 43
  • 62
Matthijs Noordzij
  • 923
  • 1
  • 7
  • 8
57

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

Jouni K. Seppänen
  • 43,139
  • 5
  • 71
  • 100
  • 3
    Still applicable on my Ubuntu 13.10 machine. I also needed the dvipng package. – travc Feb 12 '14 at 19:53
  • 3
    On ubuntu 14.04.1 I needed to install both `texlive-latex-extra` and `texlive-fonts-recommended` – eldad-a Jan 11 '15 at 12:00
  • 1
    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. – Matt Hancock Feb 07 '16 at 14:21
  • 9
    On Ubuntu 16.04, `texlive-latex-extra` `texlive-fonts-recommended` and `dvipng` were needed. – galath May 17 '16 at 13:27
  • 2
    Any idea what to add on a windows machine? tried to add type1cm and it says package not found on miktex. thanks – Wade Bratz Aug 11 '16 at 21:23
  • The miktex.org search does find a type1cm package: http://www.miktex.org/packages/type1cm – Jouni K. Seppänen Aug 13 '16 at 14:29
  • Under Arch/Manjaro it's called `texlive-latexextra`. – Jabba Oct 24 '16 at 20:24
  • ...a couple of years later macport has it in `texlive-lang-other` – bibi Mar 14 '19 at 21:00
43

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

Community
  • 1
  • 1
FZeiser
  • 947
  • 7
  • 9
  • 6
    Indeed, `cm-super` was needed on Ubuntu 18.04 along with `dvipng` `texlive-latex-extra` `texlive-fonts-recommended`. – Donshel Apr 18 '20 at 16:33
  • 1
    I also needed `cm-super` on (LM) Ubuntu 18.04 – diatomicDisaster Apr 22 '20 at 17:25
  • 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). – nabla May 10 '20 at 16:04
  • 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) – kmario23 May 30 '20 at 20:47
  • @kmario23 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](https://stackoverflow.com/questions/27817912/find-out-which-font-matplotlib-uses) to render the plot without latex (default, or `rc('text', usetex=True)`), and what fonts are used once you `rc('text', usetex=True)`? – FZeiser Jun 02 '20 at 04:56
1

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

JialeDu
  • 6,021
  • 2
  • 5
  • 24
Amar Aryan
  • 21
  • 2
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.

Abe Brandsma
  • 139
  • 1
  • 1
  • 7