From 6779a4836f7e5a3f28120d5258c0bb59657b980b Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 26 Sep 2022 11:02:08 +0200 Subject: [PATCH] In usetex, remove vertical space inserted by TeX after displaymath. --- lib/matplotlib/tests/test_usetex.py | 8 ++++++++ lib/matplotlib/texmanager.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_usetex.py b/lib/matplotlib/tests/test_usetex.py index 22309afdaf97..d5888eb1bd00 100644 --- a/lib/matplotlib/tests/test_usetex.py +++ b/lib/matplotlib/tests/test_usetex.py @@ -8,6 +8,7 @@ from matplotlib.testing import _has_tex_package from matplotlib.testing.decorators import check_figures_equal, image_comparison from matplotlib.testing._markers import needs_usetex +from matplotlib.texmanager import TexManager import matplotlib.pyplot as plt @@ -138,3 +139,10 @@ def test_missing_psfont(fmt, monkeypatch): ax.text(0.5, 0.5, 'hello') with TemporaryFile() as tmpfile, pytest.raises(ValueError): fig.savefig(tmpfile, format=fmt) + + +def test_ends_with_displaymath(): + # Check that we do not include extra vspace after displaymath. + text = r'\begin{eqnarray*} foo \\ bar \end{eqnarray*}' + w, h, d = TexManager().get_text_width_height_descent(text, 12) + assert d == 0 # no extra descent on the last line. diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index c0d37edbc3d8..80fe287f28c9 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -231,7 +231,7 @@ def _get_tex_source(cls, tex, fontsize): rf"\fontsize{{{fontsize}}}{{{baselineskip}}}%", r"\ifdefined\psfrag\else\hbox{}\fi%", rf"{{\obeylines{fontcmd} {tex}}}%", - r"\special{matplotlibbaselinemarker}%", + r"\vskip-\lastskip\special{matplotlibbaselinemarker}%", r"\end{document}", ])