From 96d7d0556d5bae762ebfc3c80a00bb9cc514e0b1 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 16 Apr 2020 16:06:32 +0200 Subject: [PATCH] Deprecate text.latex.preview rcParam. It is now unneeded; see changelog note. --- doc/api/api_changes_3.3/deprecations.rst | 6 ++++++ .../text_labels_and_annotations/usetex_baseline_test.py | 5 +++++ lib/matplotlib/__init__.py | 1 + lib/matplotlib/backends/backend_ps.py | 2 +- lib/matplotlib/dviread.py | 2 +- lib/matplotlib/mpl-data/stylelib/classic.mplstyle | 1 - lib/matplotlib/texmanager.py | 6 ++++-- matplotlibrc.template | 1 - 8 files changed, 18 insertions(+), 6 deletions(-) diff --git a/doc/api/api_changes_3.3/deprecations.rst b/doc/api/api_changes_3.3/deprecations.rst index 54fb8fe63ee4..697bafc90e80 100644 --- a/doc/api/api_changes_3.3/deprecations.rst +++ b/doc/api/api_changes_3.3/deprecations.rst @@ -388,6 +388,12 @@ instead. The unused ``animation.html_args`` rcParam and ``animation.HTMLWriter.args_key`` attribute are deprecated. +``text.latex.preview`` rcParam +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +This rcParam, which controlled the use of the preview.sty LaTeX package to +align TeX string baselines, is deprecated, as Matplotlib's own dvi parser now +computes baselines just as well as preview.sty. + ``SubplotSpec.get_rows_columns`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This method is deprecated. Use the ``GridSpec.nrows``, ``GridSpec.ncols``, diff --git a/examples/text_labels_and_annotations/usetex_baseline_test.py b/examples/text_labels_and_annotations/usetex_baseline_test.py index 84db23ebd1b9..b56af44a4ca2 100644 --- a/examples/text_labels_and_annotations/usetex_baseline_test.py +++ b/examples/text_labels_and_annotations/usetex_baseline_test.py @@ -3,6 +3,11 @@ Usetex Baseline Test ==================== +A test for :rc:`text.latex.preview`, a deprecated feature which relied +on the preview.sty LaTeX package to properly align TeX baselines. This +feature has been deprecated as Matplotlib's dvi parser now computes baselines +just as well as preview.sty; this example will be removed together with +:rc:`text.latex.preview` after the deprecation elapses. """ import matplotlib.pyplot as plt diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 02179b8809cb..bcdf19f2ef48 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -624,6 +624,7 @@ def gen_candidates(): 'mathtext.fallback_to_cm': ('3.3',), 'keymap.all_axes': ('3.3',), 'savefig.jpeg_quality': ('3.3',), + 'text.latex.preview': ('3.3',), } diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 03693c859440..44ad5a00361a 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -477,7 +477,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None): tex = r'\color[rgb]{%s} %s' % (color, s) corr = 0 # w/2*(fontsize-10)/10 - if mpl.rcParams['text.latex.preview']: + if dict.__getitem__(mpl.rcParams, 'text.latex.preview'): # use baseline alignment! pos = _nums_to_str(x-corr, y) self.psfrag.append( diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index 47cc8109ff63..4fc0d75f2e0c 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -214,7 +214,7 @@ def __init__(self, filename, dpi): self.baseline = self._get_baseline(filename) def _get_baseline(self, filename): - if rcParams['text.latex.preview']: + if dict.__getitem__(rcParams, 'text.latex.preview'): baseline = Path(filename).with_suffix(".baseline") if baseline.exists(): height, depth, width = baseline.read_bytes().split() diff --git a/lib/matplotlib/mpl-data/stylelib/classic.mplstyle b/lib/matplotlib/mpl-data/stylelib/classic.mplstyle index 91e3ed29f28e..e46f5bbb0c8b 100644 --- a/lib/matplotlib/mpl-data/stylelib/classic.mplstyle +++ b/lib/matplotlib/mpl-data/stylelib/classic.mplstyle @@ -122,7 +122,6 @@ text.latex.preamble : # IMPROPER USE OF THIS FEATURE WILL LEAD TO LATEX FAILURE # beware of package collisions: color, geometry, graphicx, # type1cm, textcomp. Adobe Postscript (PSSNFS) font packages # may also be loaded, depending on your font settings -text.latex.preview : False text.hinting : auto # May be one of the following: # 'none': Perform no hinting diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index 3badbbc21117..89ef92ec3b31 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -219,6 +219,7 @@ def make_tex(self, tex, fontsize): _re_vbox = re.compile( r"MatplotlibBox:\(([\d.]+)pt\+([\d.]+)pt\)x([\d.]+)pt") + @cbook.deprecated("3.3") def make_tex_preview(self, tex, fontsize): """ Generate a tex file to render the tex string at a specific font size. @@ -286,7 +287,7 @@ def make_dvi(self, tex, fontsize): Return the file name. """ - if rcParams['text.latex.preview']: + if dict.__getitem__(rcParams, 'text.latex.preview'): return self.make_dvi_preview(tex, fontsize) basefile = self.get_basefile(tex, fontsize) @@ -306,6 +307,7 @@ def make_dvi(self, tex, fontsize): return dvifile + @cbook.deprecated("3.3") def make_dvi_preview(self, tex, fontsize): """ Generate a dvi file containing latex's layout of tex string. @@ -397,7 +399,7 @@ def get_text_width_height_descent(self, tex, fontsize, renderer=None): dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1 - if rcParams['text.latex.preview']: + if dict.__getitem__(rcParams, 'text.latex.preview'): # use preview.sty basefile = self.get_basefile(tex, fontsize) baselinefile = '%s.baseline' % basefile diff --git a/matplotlibrc.template b/matplotlibrc.template index 04b87c9a932b..297e8644b829 100644 --- a/matplotlibrc.template +++ b/matplotlibrc.template @@ -291,7 +291,6 @@ # type1cm, textcomp. # Adobe Postscript (PSSNFS) font packages may also be # loaded, depending on your font settings. -#text.latex.preview: False #text.hinting: auto # May be one of the following: # - none: Perform no hinting