Skip to content

LaTeX and PGF preambles do not allow commas #4371

@EdwinChan

Description

@EdwinChan

I understand latex.preamble and pgf.preamble are not officially-supported features, but I believe the fact that commas cannot be used in them is enough of a showstopper to warrant a bug report.

Let me demonstrate by the following contrived example:

>>> import matplotlib
>>> matplotlib.rcParams['pgf.preamble'] = r'\macro[option1,option2]{arg}'
>>> matplotlib.rcParams['pgf.preamble']
['\\macro[option1', 'option2]{arg}']

As you can see, the command is incorrectly split up into two. Someone might want to supply their list of packages as \usepackage{bm},\usepackage{euler}, but I see no advantage to that as LaTeX is perfectly happy with \usepackage{bm}\usepackage{euler}, sans comma. The bigger problem is that matplotlib splitting the preamble at commas makes it impossible to choose a font in PGF/XeTeX, since one is often required to identify font variants in a comma-separated list if XeTeX cannot locate them:

\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{texgyretermes}[
  Extension      = .otf,
  UprightFont    = *-regular,
  BoldFont       = *-bold,
  ItalicFont     = *-italic,
  BoldItalicFont = *-bolditalic]
\usepackage{amsmath,unicode-math}
\setmathfont[Extension=.otf]{texgyretermes-math}

At this moment I'm not aware of a method to separate \setmainfont into multiple commands. In a pinch, I can write

dict.__setitem__(matplotlib.rcParams, 'pgf.preamble', r'\macro[option1,option2]{arg}')

but this is certainly undesirable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions