Skip to content

Commit 6c1105b

Browse files
authored
Merge pull request #11381 from anntzer/text.latex.unicode
API: Deprecate text.latex.unicode.
2 parents 27493dc + 9a147a4 commit 6c1105b

File tree

13 files changed

+41
-22
lines changed

13 files changed

+41
-22
lines changed

doc/api/next_api_changes/2018-02-15-AL-deprecations.rst

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ The following classes, methods, functions, and attributes are deprecated:
4444
The following rcParams are deprecated:
4545
- ``examples.directory`` (use ``datapath`` instead),
4646
- ``pgf.debug`` (the pgf backend relies on logging),
47+
- ``text.latex.unicode``,
4748

4849
The following keyword arguments are deprecated:
4950
- passing ``verts`` to ``Axes.scatter`` (use ``marker`` instead),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Changes regarding the text.latex.unicode rcParam
2+
````````````````````````````````````````````````
3+
4+
The rcParam now defaults to True and is deprecated (i.e., in future versions
5+
of Maplotlib, unicode input will always be supported).
6+
7+
Moreover, the underlying implementation now uses ``\usepackage[utf8]{inputenc}``
8+
instead of ``\usepackage{ucs}\usepackage[utf8x]{inputenc}``.

examples/text_labels_and_annotations/tex_demo.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import numpy as np
1818
import matplotlib
1919
matplotlib.rcParams['text.usetex'] = True
20-
matplotlib.rcParams['text.latex.unicode'] = True
2120
import matplotlib.pyplot as plt
2221

2322

examples/text_labels_and_annotations/usetex_baseline_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from matplotlib import rcParams
1313
rcParams['text.usetex'] = True
14-
rcParams['text.latex.unicode'] = True
1514

1615

1716
class Axes(maxes.Axes):

lib/matplotlib/__init__.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,10 @@ def gen_candidates():
821821
'axes.hold': ('2.1',),
822822
'backend.qt4': ('2.2',),
823823
'backend.qt5': ('2.2',),
824+
'text.latex.unicode': ('3.0',),
824825
}
825826

827+
826828
_all_deprecated = {*_deprecated_map, *_deprecated_ignore_map}
827829

828830

@@ -882,7 +884,7 @@ def __setitem__(self, key, val):
882884
val = alt_val(val)
883885
elif key in _deprecated_remain_as_none and val is not None:
884886
version, = _deprecated_remain_as_none[key]
885-
addendum = None
887+
addendum = ''
886888
if key.startswith('backend'):
887889
addendum = (
888890
"In order to force the use of a specific Qt binding, "
@@ -1242,21 +1244,33 @@ def rcdefaults():
12421244
Use a specific style file. Call ``style.use('default')`` to restore
12431245
the default style.
12441246
"""
1245-
rcParams.clear()
1246-
rcParams.update(rcParamsDefault)
1247+
# Deprecation warnings were already handled when creating rcParamsDefault,
1248+
# no need to reemit them here.
1249+
with warnings.catch_warnings():
1250+
warnings.simplefilter("ignore", mplDeprecation)
1251+
rcParams.clear()
1252+
rcParams.update(rcParamsDefault)
12471253

12481254

12491255
def rc_file_defaults():
12501256
"""Restore the rc params from the original rc file loaded by Matplotlib.
12511257
"""
1252-
rcParams.update(rcParamsOrig)
1258+
# Deprecation warnings were already handled when creating rcParamsOrig, no
1259+
# need to reemit them here.
1260+
with warnings.catch_warnings():
1261+
warnings.simplefilter("ignore", mplDeprecation)
1262+
rcParams.update(rcParamsOrig)
12531263

12541264

12551265
def rc_file(fname):
12561266
"""
12571267
Update rc params from file.
12581268
"""
1259-
rcParams.update(rc_params_from_file(fname))
1269+
# Deprecation warnings were already handled in rc_params_from_file, no need
1270+
# to reemit them here.
1271+
with warnings.catch_warnings():
1272+
warnings.simplefilter("ignore", mplDeprecation)
1273+
rcParams.update(rc_params_from_file(fname))
12601274

12611275

12621276
class rc_context:

lib/matplotlib/mpl-data/stylelib/_classic_test.mplstyle

-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ text.usetex : False # use latex for all text handling. The following fo
109109
# If another font is desired which can loaded using the
110110
# LaTeX \usepackage command, please inquire at the
111111
# matplotlib mailing list
112-
text.latex.unicode : False # use "ucs" and "inputenc" LaTeX packages for handling
113-
# unicode strings.
114112
text.latex.preamble : # IMPROPER USE OF THIS FEATURE WILL LEAD TO LATEX FAILURES
115113
# AND IS THEREFORE UNSUPPORTED. PLEASE DO NOT ASK FOR HELP
116114
# IF THIS FEATURE DOES NOT DO WHAT YOU EXPECT IT TO.

lib/matplotlib/mpl-data/stylelib/classic.mplstyle

-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ text.usetex : False # use latex for all text handling. The following fo
111111
# If another font is desired which can loaded using the
112112
# LaTeX \usepackage command, please inquire at the
113113
# matplotlib mailing list
114-
text.latex.unicode : False # use "ucs" and "inputenc" LaTeX packages for handling
115-
# unicode strings.
116114
text.latex.preamble : # IMPROPER USE OF THIS FEATURE WILL LEAD TO LATEX FAILURES
117115
# AND IS THEREFORE UNSUPPORTED. PLEASE DO NOT ASK FOR HELP
118116
# IF THIS FEATURE DOES NOT DO WHAT YOU EXPECT IT TO.

lib/matplotlib/rcsetup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ def _validate_linestyle(ls):
11001100
# text props
11011101
'text.color': ['black', validate_color],
11021102
'text.usetex': [False, validate_bool],
1103-
'text.latex.unicode': [False, validate_bool],
1103+
'text.latex.unicode': [True, validate_bool],
11041104
'text.latex.preamble': [[''], validate_stringlist],
11051105
'text.latex.preview': [False, validate_bool],
11061106
'text.dvipnghack': [None, validate_bool_maybe_none],

lib/matplotlib/style/core.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import matplotlib as mpl
2020
from matplotlib import rc_params_from_file, rcParamsDefault
21+
from matplotlib.cbook import MatplotlibDeprecationWarning
2122

2223

2324
__all__ = ['use', 'context', 'available', 'library', 'reload_library']
@@ -98,7 +99,11 @@ def use(style):
9899
if not isinstance(style, str):
99100
_apply_style(style)
100101
elif style == 'default':
101-
_apply_style(rcParamsDefault, warn=False)
102+
# Deprecation warnings were already handled when creating
103+
# rcParamsDefault, no need to reemit them here.
104+
with warnings.catch_warnings():
105+
warnings.simplefilter("ignore", MatplotlibDeprecationWarning)
106+
_apply_style(rcParamsDefault, warn=False)
102107
elif style in library:
103108
_apply_style(library[style])
104109
else:

lib/matplotlib/tests/test_backend_ps.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
needs_ghostscript(
3333
('ps', False, {'ps.usedistiller': 'ghostscript'})),
3434
needs_usetex(needs_ghostscript(
35-
('ps', False, {'text.latex.unicode': True, 'text.usetex': True}))),
35+
('ps', False, {'text.usetex': True}))),
3636
('eps', False, {}),
3737
('eps', True, {'ps.useafm': True}),
3838
needs_usetex(needs_ghostscript(
39-
('eps', False, {'text.latex.unicode': True, 'text.usetex': True}))),
39+
('eps', False, {'text.usetex': True}))),
4040
], ids=[
4141
'ps',
4242
'ps with distiller',

lib/matplotlib/tests/test_rcparams.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ def test_if_rctemplate_is_up_to_date():
463463
continue
464464
if k in deprecated:
465465
continue
466-
if k.startswith(("verbose.", "examples.directory")):
466+
if k.startswith(
467+
("verbose.", "examples.directory", "text.latex.unicode")):
467468
continue
468469
found = False
469470
for line in rclines:

lib/matplotlib/texmanager.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ def make_tex(self, tex, fontsize):
203203

204204
if rcParams['text.latex.unicode']:
205205
unicode_preamble = r"""
206-
\usepackage{ucs}
207-
\usepackage[utf8x]{inputenc}"""
206+
\usepackage[utf8]{inputenc}"""
208207
else:
209208
unicode_preamble = ''
210209

@@ -255,8 +254,7 @@ def make_tex_preview(self, tex, fontsize):
255254

256255
if rcParams['text.latex.unicode']:
257256
unicode_preamble = r"""
258-
\usepackage{ucs}
259-
\usepackage[utf8x]{inputenc}"""
257+
\usepackage[utf8]{inputenc}"""
260258
else:
261259
unicode_preamble = ''
262260

matplotlibrc.template

-2
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ backend : $TEMPLATE_BACKEND
225225
## If another font is desired which can loaded using the
226226
## LaTeX \usepackage command, please inquire at the
227227
## matplotlib mailing list
228-
#text.latex.unicode : False ## use "ucs" and "inputenc" LaTeX packages for handling
229-
## unicode strings.
230228
#text.latex.preamble : ## IMPROPER USE OF THIS FEATURE WILL LEAD TO LATEX FAILURES
231229
## AND IS THEREFORE UNSUPPORTED. PLEASE DO NOT ASK FOR HELP
232230
## IF THIS FEATURE DOES NOT DO WHAT YOU EXPECT IT TO.

0 commit comments

Comments
 (0)