[Matplotlib-users] Set text.latex.preamble in style sheet

Dear matplotlib developers,

Suppose I define a style sheet ‘foo.mplstyle’ as

text.usetex : True
font.family : serif

and setting the LaTeX preamble in the following MWE:

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams[“text.latex.preamble”] = r"\usepackage{newpxtext} \usepackage{eulervm}"

plt.style.use(‘foo’)

x = np.linspace(0.0,1.0,50)
y = x

plt.plot(x,y)
plt.show()

This works fine with matplotlib 3.3.0.

But the MWE fails when I try to set the LaTeX preamble directly in the style sheet. What’s the correct syntax for ‘text.latex.preamble’? I tried

text.latex.preamble : r"\usepackage{newpxtext} \usepackage{eulervm}"

text.latex.preamble : “\usepackage{newpxtext}, \usepackage{eulervm}”

text.latex.preamble : \usepackage{newpxtext},\usepackage{eulervm}

without success, despite seeing the API change notice about the parameter.

System info:

Ubuntu 20.10 Linux 5.8.0-29-generic x86_64
matplotlib 3.3.0 installed with apt
ghostscript 9.52
texlive 2020

Thanks for the support,

Thibaut

Hi Thibaut,

Dear matplotlib developers,

Suppose I define a style sheet 'foo.mplstyle' as

text.usetex : True
font.family : serif

and setting the LaTeX preamble in the following MWE:

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["text.latex.preamble"] = r"\usepackage{newpxtext} \usepackage{eulervm}"

plt.style.use('foo')

x = np.linspace(0.0,1.0,50)
y = x

plt.plot(x,y)
plt.show()

This works fine with matplotlib 3.3.0.

But the MWE fails when I try to set the LaTeX preamble directly in the style sheet. What's the correct syntax for 'text.latex.preamble'? I tried

text.latex.preamble : r"\usepackage{newpxtext} \usepackage{eulervm}"

text.latex.preamble : "\usepackage{newpxtext}, \usepackage{eulervm}"

text.latex.preamble : \usepackage{newpxtext},\usepackage{eulervm}

without success, despite seeing the API change notice <https://matplotlib.org/3.3.3/api/prev_api_changes/api_changes_3.3.0.html&gt; about the parameter.

The API change is about setting the variable at runtime, not in a configuration file. The correct format for those is:

text.latex.preamble : \usepackage{newpxtext}\usepackage{eulervm}

The difference with your solution is the absence of comma (those are allowed for separating options of packages only).

For instance, mine:

text.latex.preamble: \usepackage{mathtools}\usepackage{xfrac}\usepackage{siunitx}\usepackage[lining,proportional]{ebgaramond}\usepackage{ebgaramond-maths}

Regards,
Bruno

···

Le 22/11/2020 à 04:18, Thibaut Appel a écrit :