Skip to content

PGF backend (LaTeX) on macOS: font-not-found #10307

Closed
@laborleben

Description

@laborleben

With default parameters the script fails to write the pgf file to disk. Running the script triggers an exception (see code block and message below). Setting pgf.rcfonts to False fixes the issue for me, but the parameter is set to True by default.

Maybe related: #2097

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib as mpl

# remove or set to True (default) to trigger exception
rc_xelatex = {'pgf.rcfonts': False} 
mpl.rcParams.update(rc_xelatex)

plt.plot([1, 2, 3, 4], label="$test$")  # adding latex label
plt.legend(loc='right')  # add to plot
plt.show()  # works
plt.savefig("latex_pyplot.pdf")  # works
plt.savefig("latex_pyplot.pgf")  # exception if pgf.rcfonts is True

Terminal output

kpathsea:make_tex: Invalid fontname `Bitstream Vera Serif', contains ' '
Traceback (most recent call last):
  File "latex_pyplot.py", line 16, in <module>
    plt.savefig("latex_pyplot.pgf")  # exception if pgf.rcfonts is True
  File "/Users/jens/dev/matplotlib/lib/matplotlib/pyplot.py", line 710, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/Users/jens/dev/matplotlib/lib/matplotlib/figure.py", line 1883, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/Users/jens/dev/matplotlib/lib/matplotlib/backend_bases.py", line 2261, in print_figure
    **kwargs)
  File "/Users/jens/dev/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 834, in print_pgf
    self._print_pgf_to_fh(fh, *args, **kwargs)
  File "/Users/jens/dev/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 813, in _print_pgf_to_fh
    RendererPgf(self.figure, fh),
  File "/Users/jens/dev/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 417, in __init__
    self.latexManager = LatexManagerFactory.get_latex_manager()
  File "/Users/jens/dev/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 229, in get_latex_manager
    new_inst = LatexManager()
  File "/Users/jens/dev/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 313, in __init__
    raise LatexError("LaTeX returned an error, probably missing font or error in preamble:\n%s" % stdout)
matplotlib.backends.backend_pgf.LatexError: LaTeX returned an error, probably missing font or error in preamble:
This is XeTeX, Version 3.14159265-2.6-0.99998 (TeX Live 2017) (preloaded format=xelatex)
 restricted \write18 enabled.
**entering extended mode
LaTeX2e <2017-04-15>
Babel <3.16> and hyphenation patterns for 84 language(s) loaded.

*(/usr/local/texlive/2017/texmf-dist/tex/latex/base/minimal.cls
Document Class: minimal 2001/05/25 Standard LaTeX minimal class
)
(Please type a command or say `\end')
*
*(/usr/local/texlive/2017/texmf-dist/tex/latex/fontspec/fontspec.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/local/texlive/2017/texmf-dist/tex/latex/l3kernel/l3xdvipdfmx.def)))
(/usr/local/texlive/2017/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/fontenc.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/tuenc.def))
(/usr/local/texlive/2017/texmf-dist/tex/latex/fontspec/fontspec.cfg)))

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! fontspec error: "font-not-found"
! 
! The font "Bitstream Vera Serif" cannot be found.
! 
! See the fontspec documentation for further information.
! 
! For immediate help type H <return>.
!...............................................
                         
<*> \setmainfont{Bitstream Vera Serif}

No pages of output.
Transcript written on texput.log.

fc-list

...
/opt/X11/share/fonts/TTF/VeraMoBI.ttf: Bitstream Vera Sans Mono:style=Bold Oblique
/usr/X11R6/lib/X11/fonts/TTF/VeraIt.ttf: Bitstream Vera Sans:style=Oblique
/opt/X11/share/fonts/TTF/Vera.ttf: Bitstream Vera Sans:style=Roman
/usr/X11R6/lib/X11/fonts/TTF/VeraMoBd.ttf: Bitstream Vera Sans Mono:style=Bold
/opt/X11/share/fonts/TTF/VeraMoIt.ttf: Bitstream Vera Sans Mono:style=Oblique
/opt/X11/share/fonts/TTF/VeraSe.ttf: Bitstream Vera Serif:style=Roman
/opt/X11/share/fonts/TTF/VeraMono.ttf: Bitstream Vera Sans Mono:style=Roman
/usr/X11R6/lib/X11/fonts/TTF/VeraSe.ttf: Bitstream Vera Serif:style=Roman
/opt/X11/share/fonts/TTF/VeraIt.ttf: Bitstream Vera Sans:style=Oblique
/usr/X11R6/lib/X11/fonts/TTF/Vera.ttf: Bitstream Vera Sans:style=Roman
/usr/X11R6/lib/X11/fonts/TTF/VeraMoBI.ttf: Bitstream Vera Sans Mono:style=Bold Oblique
/usr/X11R6/lib/X11/fonts/TTF/VeraBI.ttf: Bitstream Vera Sans:style=Bold Oblique
/usr/X11R6/lib/X11/fonts/TTF/VeraMono.ttf: Bitstream Vera Sans Mono:style=Roman
/usr/X11R6/lib/X11/fonts/TTF/VeraBd.ttf: Bitstream Vera Sans:style=Bold
/usr/X11R6/lib/X11/fonts/TTF/VeraSeBd.ttf: Bitstream Vera Serif:style=Bold
/opt/X11/share/fonts/TTF/VeraBd.ttf: Bitstream Vera Sans:style=Bold
/opt/X11/share/fonts/TTF/VeraSeBd.ttf: Bitstream Vera Serif:style=Bold
/opt/X11/share/fonts/TTF/VeraMoBd.ttf: Bitstream Vera Sans Mono:style=Bold
/opt/X11/share/fonts/TTF/VeraBI.ttf: Bitstream Vera Sans:style=Bold Oblique
/usr/X11R6/lib/X11/fonts/TTF/VeraMoIt.ttf: Bitstream Vera Sans Mono:style=Oblique
...

Matplotlib version

  • Operating system: macOS 12.13 High Sierra
  • Matplotlib version: Matplotlib 2.1.1 (Anaconda default) and master branch bd75712
  • Matplotlib backend (print(matplotlib.get_backend())): MacOSX
  • Python version: 2.7.14 (Anaconda)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesbackend: pgf

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions