8000 Fix support for empty usetex strings. · matplotlib/matplotlib@3ee33f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ee33f4

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 0cdd0e8 commit 3ee33f4

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

lib/matplotlib/dviread.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ def _output(self):
275275
maxy = max(maxy, y + e)
276276
maxy_pure = max(maxy_pure, y)
277277

278+
if not self.text and not self.boxes: # Avoid infs/nans from inf+/-inf.
279+
return Page(text=[], boxes=[], width=0, height=0, descent=0)
280+
278281
if self.dpi is None:
279282
# special case for ease of debugging: output raw dvi coordinates
280283
return Page(text=self.text, boxes=self.boxes,

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
@@ -207,7 +207,8 @@ def make_tex(self, tex, fontsize):
207207
\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
208208
\pagestyle{empty}
209209
\begin{document}
210-
\fontsize{%f}{%f}%s
210+
%% The empty hbox ensures that a page is printed even for empty inputs.
211+
\fontsize{%f}{%f}\hbox{}%s
211212
\end{document}
212213
""" % (self._get_preamble(), fontsize, fontsize * 1.25, fontcmd % tex),
213214
encoding='utf-8')

0 commit comments

Comments
 (0)
0