Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

PGF uses the minimal document class #18271

Copy link
Copy link
Closed
@krabo0om

Description

@krabo0om
Issue body actions

Bug report

Bug summary

The pgf backend uses the minimal document class. It is incompatible with many packages, e.g., enumitem (uses font scaling) and thus does not create any output. Using this document class should apparently be avoided.

Code for reproduction

import matplotlib
import matplotlib.pyplot as plt

params = {
    'pgf.texsystem': 'pdflatex',
    'pgf.preamble': r'\usepackage{enumitem}',
}
matplotlib.rcParams.update(params)

print(matplotlib.get_backend())

plt.savefig('example.pgf')

Actual outcome

(added line breaks to improve readability)

Traceback (most recent call last):
  File "crashes.py", line 10, in <module>
    plt.savefig('example.pgf')
  File "...../matplotlib/pyplot.py", line 722, in savefig
    res = fig.savefig(*args, **kwargs)
  File "...../matplotlib/figure.py", line 2180, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "...../matplotlib/backend_bases.py", line 2082, in print_figure
    result = print_method(
  File "...../matplotlib/backends/backend_pgf.py", line 848, in print_pgf
    self._print_pgf_to_fh(file, *args, **kwargs)
  File "...../matplotlib/backends/backend_pgf.py", line 828, in _print_pgf_to_fh
    RendererPgf(self.figure, fh),
  File "...../matplotlib/backends/backend_pgf.py", line 397, in __init__
    self.latexManager = LatexManager._get_cached_or_new()
  File "...../matplotlib/backends/backend_pgf.py", line 233, in _get_cached_or_new
    return cls._get_cached_or_new_impl(cls._build_latex_header())
  File "...../matplotlib/backends/backend_pgf.py", line 238, in _get_cached_or_new_impl
    return cls()
  File "...../matplotlib/backends/backend_pgf.py", line 293, in __init__
    raise LatexError("LaTeX returned an error, probably missing font "
matplotlib.backends.backend_pgf.LatexError: LaTeX returned an error, probably missing font or error in preamble:
b'This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/Arch Linux) (preloaded format=pdflatex)\n 
restricted \\write18 enabled.\n
**entering extended mode\n
LaTeX2e <2020-02-02> patch level 5\n
L3 programming layer <2020-06-03>\n
*\n
*(/usr/share/texmf-dist/tex/latex/base/minimal.cls\n
Document Class: minimal 2001/05/25 Standard LaTeX minimal class\n
)\n
*(/usr/share/texmf-dist/tex/latex/enumitem/enumitem.sty\n
! Undefined control sequence.\n
<argument> \\scriptsize \n
                       \n
                       l.1084 \\SetEnumitemSize{script}\\scriptsize
                       \n                                          \n
                       !  ==> Fatal error occurred, no output PDF file produced!\n
                       Transcript written on texput.log.\n'

Expected outcome

I expect this example to not crash. Changing the document class to article does not produce this error.

Suggestion

Make the document class an rcParam so that the user can decide and even use their own classes.

Matplotlib version

  • Operating system: Manjaro Linux
  • Matplotlib version: 3.1.2 (document class has not changed in the latest version)
  • Matplotlib backend: TkAgg (but actually uses pgf)
  • Python version: 3.8.3

Installed via pip in a venv.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.