Michael Droettboom <md...@stsci.edu> writes:

> Jörgen Stenarson wrote:
>> I tried to use usetex to generate my pdf figures but I got a crash 
>> when saving the figure, log attached. I traced the crash to 
>> find_tex_file(), apparently ' can not be used to quote filenames in 
>> the windows shell it has to be ". In my patch I just changed it to 
>> always use " I don't know if that works on other systems.
> Someone who knows about usetex should review and apply this patch.

In Unix shells ' is the better quoting character because all sorts of
things have special meaning within " characters... but I changed it to
use subprocess.Popen instead, so we shouldn't need to worry about shell
quoting at all.

Jörgen: Thanks for your report, which I think is the first one from a
Windows user using usetex with the pdf backend. Can you check that the
latest version on the trunk works (either by updating from svn or by
applying the attached patch)? Have you run into any other problems? What
TeX distribution are you using?

-- 
Jouni K. Seppänen
http://www.iki.fi/jks

Index: lib/matplotlib/dviread.py
===================================================================
--- lib/matplotlib/dviread.py	(revision 6564)
+++ lib/matplotlib/dviread.py	(revision 6565)
@@ -21,8 +21,8 @@
 import matplotlib
 import matplotlib.cbook as mpl_cbook
 import numpy as np
-import os
 import struct
+import subprocess
 
 _dvistate = mpl_cbook.Bunch(pre=0, outer=1, inpage=2, post_post=3, finale=4)
 
@@ -742,25 +742,15 @@
     doesn't use kpathsea, so what do we do? (TODO)
     """
 
-    cmd = 'kpsewhich '
+    cmd = ['kpsewhich']
     if format is not None:
-        assert "'" not in format
-        cmd += "--format='" + format + "' "
-    assert "'" not in filename
-    cmd += "'" + filename + "'"
-
+        cmd += ['--format=' + format]
+    cmd += [filename]
+    
     matplotlib.verbose.report('find_tex_file(%s): %s' \
                                   % (filename,cmd), 'debug')
-    pipe = os.popen(cmd, 'r')
-    result = ""
-    while True:
-        data = _read_nointr(pipe)
-        if data == "":
-            break
-        result += data
-    pipe.close()
-    result = result.rstrip()
-
+    pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+    result = pipe.communicate()[0].rstrip()
     matplotlib.verbose.report('find_tex_file result: %s' % result,
                               'debug')
     return result
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to