Set text.latex.preamble in style sheet

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Set text.latex.preamble in style sheet

Thibaut Appel

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



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Set text.latex.preamble in style sheet

Bruno Pagani
Hi Thibaut,

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

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.

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


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users