From ac6cc5076e0c9649c4e0454daa4f52ba8a8769da Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 5 Feb 2020 01:05:04 +0100 Subject: [PATCH] Fix support for empty usetex strings. Currently, `figtext(.5, .5, "%foo", usetex=True)` results in an obscure exception (`FileNotFoundError: No such file or directory: blah.dvi`). Fix that by forcing tex to always generate a page, by inserting at least an empty \hbox{}. --- lib/matplotlib/tests/test_usetex.py | 6 ++++++ lib/matplotlib/texmanager.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_usetex.py b/lib/matplotlib/tests/test_usetex.py index 6cd328244c97..f9e2f062005f 100644 --- a/lib/matplotlib/tests/test_usetex.py +++ b/lib/matplotlib/tests/test_usetex.py @@ -30,6 +30,12 @@ def test_usetex(): ax.set_yticks([]) +@check_figures_equal() +def test_empty(fig_test, fig_ref): + mpl.rcParams['text.usetex'] = True + fig_test.text(.5, .5, "% a comment") + + @check_figures_equal() def test_unicode_minus(fig_test, fig_ref): mpl.rcParams['text.usetex'] = True diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index fb23212febf8..91aac1f6cf3e 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -214,7 +214,8 @@ def make_tex(self, tex, fontsize): \usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry} \pagestyle{empty} \begin{document} -\fontsize{%f}{%f}%s +%% The empty hbox ensures that a page is printed even for empty inputs. +\fontsize{%f}{%f}\hbox{}%s \end{document} """ % (self._get_preamble(), fontsize, fontsize * 1.25, fontcmd % tex), encoding='utf-8')