75

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.

1
  • 7
    this fixed for me sudo apt-get install dvipng Jul 6, 2016 at 23:41

5 Answers 5

95

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
6
  • 5
    Works on Ubuntu16.04 as well.
    – user
    Dec 27, 2016 at 20:06
  • 2
    Also works on Ubuntu 16.04.1 in the Windows Subsystem for Linux. Apr 8, 2017 at 1:45
  • 1
    I can generate plots, but they have serif fonts.
    – Soerendip
    Jun 20, 2018 at 16:12
  • 1
    Update 09/2021: This works on Ubuntu 21.04 as well.
    – Heath
    Sep 24, 2021 at 19:56
  • 1
    Also works for 22.04 =)
    – Rasmus
    Feb 21 at 12:39
57

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

8
  • 3
    Still applicable on my Ubuntu 13.10 machine. I also needed the dvipng package.
    – travc
    Feb 12, 2014 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, 2015 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. Feb 7, 2016 at 14:21
  • 9
    On Ubuntu 16.04, texlive-latex-extra texlive-fonts-recommended and dvipng were needed.
    – galath
    May 17, 2016 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, 2016 at 21:23
44

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

5
  • 6
    Indeed, cm-super was needed on Ubuntu 18.04 along with dvipng texlive-latex-extra texlive-fonts-recommended.
    – Donshel
    Apr 18, 2020 at 16:33
  • 1
    I also needed cm-super on (LM) Ubuntu 18.04 Apr 22, 2020 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, 2020 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, 2020 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 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 2, 2020 at 4:56
2

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.