Skip to content

Commit

Permalink
Merge pull request matplotlib#14567 from anntzer/texminus
Browse files Browse the repository at this point in the history
Fix unicode_minus + usetex.
  • Loading branch information
timhoffm authored Jun 19, 2019
2 parents f0290cc + a973b75 commit 63d96d2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/matplotlib/dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ def _parse_enc(path):
with open(path, encoding="ascii") as file:
no_comments = "\n".join(line.split("%")[0].rstrip() for line in file)
array = re.search(r"(?s)\[(.*)\]", no_comments).group(1)
lines = [line for line in array.split("\n") if line]
lines = [line for line in array.split() if line]
if all(line.startswith("/") for line in lines):
return [line[1:] for line in lines]
else:
Expand Down
24 changes: 13 additions & 11 deletions lib/matplotlib/tests/test_usetex.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import warnings

import pytest

import matplotlib
from matplotlib.testing.decorators import image_comparison
import matplotlib as mpl
from matplotlib.testing.decorators import check_figures_equal, image_comparison
import matplotlib.pyplot as plt
from matplotlib.ticker import EngFormatter


with warnings.catch_warnings():
warnings.simplefilter('ignore')
needs_usetex = pytest.mark.skipif(
not matplotlib.checkdep_usetex(True),
reason='Missing TeX of Ghostscript or dvipng')
@pytest.fixture(autouse=True) # All tests in this module use usetex.
def usetex():
if not mpl.checkdep_usetex(True):
pytest.skip('Missing TeX of Ghostscript or dvipng')
mpl.rcParams['text.usetex'] = True


@needs_usetex
@image_comparison(baseline_images=['test_usetex'],
extensions=['pdf', 'png'],
tol=0.3)
def test_usetex():
matplotlib.rcParams['text.usetex'] = True
fig = plt.figure()
ax = fig.add_subplot(111)
ax.text(0.1, 0.2,
Expand All @@ -32,3 +28,9 @@ def test_usetex():
fontsize=24)
ax.set_xticks([])
ax.set_yticks([])


@check_figures_equal()
def test_unicode_minus(fig_test, fig_ref):
fig_test.text(.5, .5, "$-$")
fig_ref.text(.5, .5, "\N{MINUS SIGN}")
18 changes: 8 additions & 10 deletions lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,10 @@ def make_tex(self, tex, fontsize):
r'{\rmfamily %s}')
tex = fontcmd % tex

if rcParams['text.latex.unicode']:
unicode_preamble = r"""
\usepackage[utf8]{inputenc}"""
else:
unicode_preamble = ''
unicode_preamble = "\n".join([
r"\usepackage[utf8]{inputenc}",
r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}",
]) if rcParams["text.latex.unicode"] else ""

s = r"""
\documentclass{article}
Expand Down Expand Up @@ -257,11 +256,10 @@ def make_tex_preview(self, tex, fontsize):
r'{\rmfamily %s}')
tex = fontcmd % tex

if rcParams['text.latex.unicode']:
unicode_preamble = r"""
\usepackage[utf8]{inputenc}"""
else:
unicode_preamble = ''
unicode_preamble = "\n".join([
r"\usepackage[utf8]{inputenc}",
r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}",
]) if rcParams["text.latex.unicode"] else ""

# newbox, setbox, immediate, etc. are used to find the box
# extent of the rendered text.
Expand Down

0 comments on commit 63d96d2

Please sign in to comment.