8000 comment on http://matplotlib.org/users/pgf.html#pgf-tutorial - minor issue with xits font · Issue #1500 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
comment on http://matplotlib.org/users/pgf.html#pgf-tutorial - minor issue with xits font #1500
Closed
@fmitha

Description

@fmitha

I have a comment on http://matplotlib.org/users/pgf.html#pgf-tutorial,
which has a minor issue with fonts. Specifically, the example below does
not work with my machine - Debian squeeze, Tex Live 2012 backported from
unstable, matplotlib 1.2 backported from unstable.

  1. The documentation says

Rc parameters that control the behavior of the pgf backend:
[...]
pgf.texsystem Either “xelatex”, “lualatex” or “pdflatex”

It is worth mentioning the default is (it seems) "xelatex".

  1. It seems the default is "xelatex", but the specification
\setmathfont{XITS Math}

does not work with xelatex, at least for me, and possibly not for anyone
using Tex Live. See for example

http://tex.stackexchange.com/questions/50381/xelatex-and-unicode-math-problems
and
http://tex.stackexchange.com/questions/82113/subscript-is-set-too-low-in-math-mode-with-xits-math

It seems xelatex expects something like

\setmathfont{xits-math.otf}   

I'm not sure why. In any case, I had to make a change to make this example
work. First, I have the original example, and then my changed version.

HERE IS THE ORIGINAL EXAMPLE. SUGGESTED CHANGES FOLLOW.

# -*- coding: utf-8 -*-

import matplotlib as mpl
mpl.use("pgf")
pgf_with_custom_preamble = {
       "font.family": "serif", # use serif/main font for text elements
       "text.usetex": True,    # use inline math for ticks
       "pgf.rcfonts": False,   # don't setup fonts from rc parameters
       "pgf.preamble": [
              r"\usepackage{units}",        # load additional packages
              r"\usepackage{metalogo}",        # load additional packages
              r"\usepackage{unicode-math}", # unicode math setup
              r"\setmathfont{XITS Math}",
              r"\setmainfont{DejaVu Serif}", # font setup via preamble
              ]
}
mpl.rcParams.update(pgf_with_custom_preamble)

import matplotlib.pyplot as plt
plt.figure(figsize=(4.5,2.5))
plt.plot(range(5))
plt.xlabel(u"unicode text: я, ψ, €, ü, \\unitfrac[10]{°}{µm}")
plt.ylabel(u"\\XeLaTeX")
plt.legend([u"unicode math: $λ=∑_i^∞ μ_i^2$"])
plt.tight_layout(.5)

Option 1:

Add the line

"pgf.texsystem": "lualatex"

to the pgf_with_custom_preamble dict. I.e. switch to lualatex. Or

Option 2:

Replace

r"\setmainfont{XITS}",
r"\setmathfont{XITS Math}",

with

r"\setmainfont{xits-math.otf}",

           Regards, Faheem

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0