Skip to content

Commit 98f8534

Browse files
committed
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{}.
1 parent 7b6eb77 commit 98f8534

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/matplotlib/tests/test_usetex.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ def test_usetex():
3030
ax.set_yticks([])
3131

3232

33+
@check_figures_equal()
34+
def test_empty(fig_test, fig_ref):
35+
mpl.rcParams['text.usetex'] = True
36+
fig_test.text(.5, .5, "% a comment")
37+
38+
3339
@check_figures_equal()
3440
def test_unicode_minus(fig_test, fig_ref):
3541
mpl.rcParams['text.usetex'] = True

lib/matplotlib/texmanager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ def make_tex(self, tex, fontsize):
214214
\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
215215
\pagestyle{empty}
216216
\begin{document}
217-
\fontsize{%f}{%f}%s
217+
%% The empty hbox ensures that a page is printed even for empty inputs.
218+
\hbox{}\fontsize{%f}{%f}%s
218219
\end{document}
219220
""" % (self._get_preamble(), fontsize, fontsize * 1.25, fontcmd % tex),
220221
encoding='utf-8')

0 commit comments

Comments
 (0)