Skip to content

PGF xelatex can't find fonts in special-character paths #17765

Closed
@QuLogic

Description

@QuLogic

Bug report

Bug summary

On Fedora, the latest guidelines put ~ in the version for release candidates. This translates to everything being in a directory with ~ in the name. This breaks the PGF tests using xelatex, but also can be reproduced by placing custom fonts in a similar path.

Code for reproduction

I used Josefin Slab from Google Fonts, as I didn't have it installed already, so I knew if it'd be working. I then placed those in a foo~bar directory, and ran the following.

import os

import matplotlib.pyplot as plt
import matplotlib.font_manager

matplotlib.font_manager.fontManager.addfont(
    os.path.abspath('foo~bar/JosefinSlab-Regular.ttf'))
plt.rcParams['font.sans-serif'] = ['Josefin Slab']
plt.rcParams['pgf.texsystem'] = 'xelatex'

fig, ax = plt.subplots()
fig.savefig('test.pdf', backend='pgf')

Actual outcome

kpathsea:make_tex: Invalid filename `[/home/elliott/code/matplotlib/foo', contains '['
Traceback (most recent call last):
  File "../mpl-tests/pgf-font-fail.py", line 12, in <module>
    fig.savefig('test.pdf', backend='pgf')
  File "/home/elliott/code/matplotlib/lib/matplotlib/figure.py", line 2309, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/home/elliott/code/matplotlib/lib/matplotlib/backends/backend_qt5agg.py", line 81, in print_figure
    super().print_figure(*args, **kwargs)
  File "/home/elliott/code/matplotlib/lib/matplotlib/backend_bases.py", line 2217, in print_figure
    **kwargs)
  File "/home/elliott/code/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 940, in print_pdf
    self._print_pdf_to_fh(file, *args, **kwargs)
  File "/home/elliott/code/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 901, in _print_pdf_to_fh
    self.print_pgf(fname_pgf, *args, **kwargs)
  File "/home/elliott/code/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 884, in print_pgf
    self._print_pgf_to_fh(file, *args, **kwargs)
  File "/home/elliott/code/matplotlib/lib/matplotlib/backend_bases.py", line 1639, in wrapper
    return func(*args, **kwargs)
  File "/home/elliott/code/matplotlib/lib/matplotlib/cbook/deprecation.py", line 410, in wrapper
    return func(*inner_args, **inner_kwargs)
  File "/home/elliott/code/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 864, in _print_pgf_to_fh
    RendererPgf(self.figure, fh),
  File "/home/elliott/code/matplotlib/lib/matplotlib/cbook/deprecation.py", line 410, in wrapper
    return func(*inner_args, **inner_kwargs)
  File "/home/elliott/code/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 429, in __init__
    self._latexManager = LatexManager._get_cached_or_new()  # deprecated
  File "/home/elliott/code/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 241, in _get_cached_or_new
    return cls._get_cached_or_new_impl(cls._build_latex_header())
  File "/home/elliott/code/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 246, in _get_cached_or_new_impl
    return cls()
  File "/home/elliott/code/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 308, in __init__
    "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.999991 (TeX Live 2019) (preloaded format=xelatex)
 restricted \write18 enabled.
**entering extended mode
LaTeX2e <2018-12-01>

*
*(/usr/share/texlive/texmf-dist/tex/latex/base/minimal.cls
Document Class: minimal 2001/05/25 Standard LaTeX minimal class
)
*(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/xetex.def)))
(Please type a command or say `\end')
*
*(/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec.sty
(/usr/share/texlive/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
(/usr/share/texlive/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/share/texlive/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-xdvipdfmx.def)))
(/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/tuenc.def))
(/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec.cfg)))
*
! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
<*> ...ath=/home/elliott/code/matplotlib/foo~bar/]
                                                  
No pages of output.
Transcript written on texput.log.

Expected outcome

PDF is produced, like it is in 3.2.2, using Josefin Slab font.

Matplotlib version

  • Operating system: Fedora 31
  • Matplotlib version: 4a143b9
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.6.10

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions