From 60976d4e5504006f8d6f48574b19e845afb2b5bd Mon Sep 17 00:00:00 2001 From: WANG Longqi Date: Thu, 30 Mar 2017 16:43:19 +0800 Subject: [PATCH 1/2] hot fix on the fail of pdfcrop --- writetex.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/writetex.py b/writetex.py index 29982ae..2e7da72 100644 --- a/writetex.py +++ b/writetex.py @@ -5,8 +5,8 @@ An Latex equation editor for Inkscape. :Author: WANG Longqi -:Date: 2017-03-27 -:Version: v1.5 +:Date: 2017-03-30 +:Version: v1.5.1 This file is a part of WriteTeX extension for Inkscape. For more information, please refer to http://wanglongqi.github.io/WriteTeX. @@ -163,15 +163,17 @@ def effect(self): tmp_dir=tmp_dir, tex_file=tex_file, out_file=out_file)) try: - os.popen('pdfcrop %s' % pdf_file) - os.remove(pdf_file) - os.rename(crop_file, pdf_file) + os.popen('pdfcrop "%s"' % pdf_file) + if os.path.exists(crop_file): + os.remove(pdf_file) + os.rename(crop_file, pdf_file) except: pass if not os.path.exists(pdf_file): print >>sys.stderr, "Latex error: check your latex file and preamble." print >>sys.stderr, open(log_file).read() + return else: if self.options.pdftosvg == '1': os.popen('pdf2svg %s %s' % (pdf_file, svg_file)) From fdccf03b2864bb46553726ed97f69e20b1a37a17 Mon Sep 17 00:00:00 2001 From: WANG Longqi Date: Fri, 31 Mar 2017 10:44:40 +0800 Subject: [PATCH 2/2] return error message for further inspection --- writetex.py | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/writetex.py b/writetex.py index 2e7da72..64e66e9 100644 --- a/writetex.py +++ b/writetex.py @@ -5,8 +5,8 @@ An Latex equation editor for Inkscape. :Author: WANG Longqi -:Date: 2017-03-30 -:Version: v1.5.1 +:Date: 2017-03-31 +:Version: v1.5.2 This file is a part of WriteTeX extension for Inkscape. For more information, please refer to http://wanglongqi.github.io/WriteTeX. @@ -17,6 +17,7 @@ import tempfile import sys import copy +import subprocess WriteTexNS = u'http://wanglongqi.github.io/WriteTeX' # from textext SVG_NS = u"http://www.w3.org/2000/svg" @@ -151,19 +152,32 @@ def effect(self): tex.close() if self.options.latexcmd.lower() == "xelatex": - os.popen('xelatex "-output-directory=%s" -interaction=nonstopmode -halt-on-error "%s" > "%s"' - % (tmp_dir, tex_file, out_file)) + subprocess.call('xelatex "-output-directory=%s" -interaction=nonstopmode -halt-on-error "%s" > "%s"' + % (tmp_dir, tex_file, out_file), shell=True) elif self.options.latexcmd.lower() == "pdflatex": - os.popen('pdflatex "-output-directory=%s" -interaction=nonstopmode -halt-on-error "%s" > "%s"' - % (tmp_dir, tex_file, out_file)) + subprocess.call('pdflatex "-output-directory=%s" -interaction=nonstopmode -halt-on-error "%s" > "%s"' + % (tmp_dir, tex_file, out_file), shell=True) else: # Setting `latexcmd` to following string produces the same result as xelatex condition: # 'xelatex "-output-directory={tmp_dir}" -interaction=nonstopmode -halt-on-error "{tex_file}" > "{out_file}"' - os.popen(self.options.latexcmd.format( - tmp_dir=tmp_dir, tex_file=tex_file, out_file=out_file)) + subprocess.call(self.options.latexcmd.format( + tmp_dir=tmp_dir, tex_file=tex_file, out_file=out_file), shell=True) try: - os.popen('pdfcrop "%s"' % pdf_file) + # Here is a bug in pdfcrop, no idea how to fix. + crop_cmd = 'pdfcrop "%s"' % pdf_file + crop = subprocess.Popen(crop_cmd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + shell=True) + out = crop.communicate() + if len(out[1]) > 0: + inkex.errormsg("Error in pdfcrop:\n") + inkex.errormsg(" CMD executed: %s\n" % crop_cmd) + for msg in out: + inkex.errormsg(msg) + inkex.errormsg("Process will continue without crop") + if os.path.exists(crop_file): os.remove(pdf_file) os.rename(crop_file, pdf_file) @@ -176,11 +190,12 @@ def effect(self): return else: if self.options.pdftosvg == '1': - os.popen('pdf2svg %s %s' % (pdf_file, svg_file)) + subprocess.call('pdf2svg %s %s' % + (pdf_file, svg_file), shell=True) self.merge_pdf2svg_svg(svg_file) else: - os.popen('pstoedit -f plot-svg "%s" "%s" -dt -ssp -psarg -r9600x9600 > "%s" 2> "%s"' - % (pdf_file, svg_file, out_file, err_file)) + subprocess.call('pstoedit -f plot-svg "%s" "%s" -dt -ssp -psarg -r9600x9600 > "%s" 2> "%s"' + % (pdf_file, svg_file, out_file, err_file), shell=True) self.merge_pstoedit_svg(svg_file) os.remove(tex_file)