Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3aa72b1

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 a1cd024 commit 3aa72b1

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
@@ -32,6 +32,12 @@ def test_usetex():
3232
ax.set_yticks([])
3333

3434

35+
@check_figures_equal()
36+
def test_empty(fig_test, fig_ref):
37+
mpl.rcParams['text.usetex'] = True
38+
fig_test.text(.5, .5, "% a comment")
39+
40+
3541
@check_figures_equal()
3642
def test_unicode_minus(fig_test, fig_ref):
3743
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+
\fontsize{%f}{%f}\hbox{}%s
218219
\end{document}
219220
""" % (self._get_preamble(), fontsize, fontsize * 1.25, fontcmd % tex),
220221
encoding='utf-8')

0 commit comments

Comments
 (0)