Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix unicode_minus + usetex. #14567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the previous version was buggy: on an encoding file like http://tug.ctan.org/info/fontname/8r.enc, you can see there are multiple entries per line (/.notdef /dotaccent /...) and lines are starting with a space, so the previous parser would fail immediately below when asserting that all lines start with a /, and even without the assertion, would misparse the file.

if all(line.startswith("/") for line in lines):
return [line[1:] for line in lines]
else:
Expand Down
24 changes: 13 additions & 11 deletions 24 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 18 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.