Skip to content

Commit fdccf03

Browse files
committed
return error message for further inspection
1 parent 60976d4 commit fdccf03

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

writetex.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
An Latex equation editor for Inkscape.
66
77
:Author: WANG Longqi <[email protected]>
8-
:Date: 2017-03-30
9-
:Version: v1.5.1
8+
:Date: 2017-03-31
9+
:Version: v1.5.2
1010
1111
This file is a part of WriteTeX extension for Inkscape. For more information,
1212
please refer to http://wanglongqi.github.io/WriteTeX.
@@ -17,6 +17,7 @@
1717
import tempfile
1818
import sys
1919
import copy
20+
import subprocess
2021
WriteTexNS = u'http://wanglongqi.github.io/WriteTeX'
2122
# from textext
2223
SVG_NS = u"http://www.w3.org/2000/svg"
@@ -151,19 +152,32 @@ def effect(self):
151152
tex.close()
152153

153154
if self.options.latexcmd.lower() == "xelatex":
154-
os.popen('xelatex "-output-directory=%s" -interaction=nonstopmode -halt-on-error "%s" > "%s"'
155-
% (tmp_dir, tex_file, out_file))
155+
subprocess.call('xelatex "-output-directory=%s" -interaction=nonstopmode -halt-on-error "%s" > "%s"'
156+
% (tmp_dir, tex_file, out_file), shell=True)
156157
elif self.options.latexcmd.lower() == "pdflatex":
157-
os.popen('pdflatex "-output-directory=%s" -interaction=nonstopmode -halt-on-error "%s" > "%s"'
158-
% (tmp_dir, tex_file, out_file))
158+
subprocess.call('pdflatex "-output-directory=%s" -interaction=nonstopmode -halt-on-error "%s" > "%s"'
159+
% (tmp_dir, tex_file, out_file), shell=True)
159160
else:
160161
# Setting `latexcmd` to following string produces the same result as xelatex condition:
161162
# 'xelatex "-output-directory={tmp_dir}" -interaction=nonstopmode -halt-on-error "{tex_file}" > "{out_file}"'
162-
os.popen(self.options.latexcmd.format(
163-
tmp_dir=tmp_dir, tex_file=tex_file, out_file=out_file))
163+
subprocess.call(self.options.latexcmd.format(
164+
tmp_dir=tmp_dir, tex_file=tex_file, out_file=out_file), shell=True)
164165

165166
try:
166-
os.popen('pdfcrop "%s"' % pdf_file)
167+
# Here is a bug in pdfcrop, no idea how to fix.
168+
crop_cmd = 'pdfcrop "%s"' % pdf_file
169+
crop = subprocess.Popen(crop_cmd,
170+
stdout=subprocess.PIPE,
171+
stderr=subprocess.PIPE,
172+
shell=True)
173+
out = crop.communicate()
174+
if len(out[1]) > 0:
175+
inkex.errormsg("Error in pdfcrop:\n")
176+
inkex.errormsg(" CMD executed: %s\n" % crop_cmd)
177+
for msg in out:
178+
inkex.errormsg(msg)
179+
inkex.errormsg("Process will continue without crop")
180+
167181
if os.path.exists(crop_file):
168182
os.remove(pdf_file)
169183
os.rename(crop_file, pdf_file)
@@ -176,11 +190,12 @@ def effect(self):
176190
return
177191
else:
178192
if self.options.pdftosvg == '1':
179-
os.popen('pdf2svg %s %s' % (pdf_file, svg_file))
193+
subprocess.call('pdf2svg %s %s' %
194+
(pdf_file, svg_file), shell=True)
180195
self.merge_pdf2svg_svg(svg_file)
181196
else:
182-
os.popen('pstoedit -f plot-svg "%s" "%s" -dt -ssp -psarg -r9600x9600 > "%s" 2> "%s"'
183-
% (pdf_file, svg_file, out_file, err_file))
197+
subprocess.call('pstoedit -f plot-svg "%s" "%s" -dt -ssp -psarg -r9600x9600 > "%s" 2> "%s"'
198+
% (pdf_file, svg_file, out_file, err_file), shell=True)
184199
self.merge_pstoedit_svg(svg_file)
185200

186201
os.remove(tex_file)

0 commit comments

Comments
 (0)