Skip to content

Commit dc9b721

Browse files
committed
Test that text is located correctly with xcolor.
1 parent d6f0783 commit dc9b721

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

lib/matplotlib/testing/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ def setup():
4444
# are not necessarily the default values as specified in rcsetup.py.
4545
set_font_settings_for_testing()
4646
set_reproducibility_for_testing()
47+
48+
49+
def _has_tex_package(package):
50+
return bool(mpl.dviread.find_tex_file(f"{package}.sty"))

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import matplotlib as mpl
1313
import matplotlib.pyplot as plt
14+
from matplotlib.testing import _has_tex_package
1415
from matplotlib.testing.compare import compare_images, ImageComparisonFailure
1516
from matplotlib.backends.backend_pgf import PdfPages, common_texification
1617
from matplotlib.testing.decorators import (_image_directories,
@@ -51,10 +52,6 @@ def check_for(texsystem):
5152
reason="This test needs a ghostscript installation")
5253

5354

54-
def _has_tex_package(package):
55-
return bool(mpl.dviread.find_tex_file(f"{package}.sty"))
56-
57-
5855
def compare_figure(fname, savefig_kwargs={}, tol=0):
5956
actual = os.path.join(result_dir, fname)
6057
plt.savefig(actual, **savefig_kwargs)

lib/matplotlib/tests/test_usetex.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33

44
import matplotlib as mpl
5+
from matplotlib.testing import _has_tex_package
56
from matplotlib.testing.decorators import check_figures_equal, image_comparison
67
import matplotlib.pyplot as plt
78

@@ -80,6 +81,23 @@ def test_minus_no_descent(fontsize):
8081
assert len({*heights.values()}) == 1
8182

8283

84+
@pytest.mark.skipif(not _has_tex_package('xcolor'),
85+
reason='xcolor is not available')
86+
def test_usetex_xcolor():
87+
mpl.rcParams['text.usetex'] = True
88+
89+
fig = plt.figure()
90+
t = fig.text(0.5, 0.5, "Some text 0123456789")
91+
fig.canvas.draw()
92+
pos = t.get_window_extent()
93+
94+
mpl.rcParams['text.latex.preamble'] = r'\usepackage[dvipsnames]{xcolor}'
95+
fig = plt.figure()
96+
t = fig.text(0.5, 0.5, "Some text 0123456789")
97+
fig.canvas.draw()
98+
np.testing.assert_array_equal(t.get_window_extent(), pos)
99+
100+
83101
def test_textcomp_full():
84102
plt.rcParams["text.latex.preamble"] = r"\usepackage[full]{textcomp}"
85103
fig = plt.figure()

0 commit comments

Comments
 (0)