Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0651abb

Browse filesBrowse 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 b7c9d85 commit 0651abb
Copy full SHA for 0651abb

File tree

Expand file treeCollapse file tree

3 files changed

+11
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+11
-1
lines changed

‎lib/matplotlib/dviread.py

Copy file name to clipboardExpand all lines: lib/matplotlib/dviread.py
+3Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_usetex.py
+6Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/texmanager.py
+2-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.