|
5 | 5 | An Latex equation editor for Inkscape. |
6 | 6 |
|
7 | 7 | :Author: WANG Longqi <[email protected]> |
8 | | -:Date: 2017-03-27 |
9 | | -:Version: v1.5 |
| 8 | +:Date: 2017-03-31 |
| 9 | +:Version: v1.5.2 |
10 | 10 |
|
11 | 11 | This file is a part of WriteTeX extension for Inkscape. For more information, |
12 | 12 | please refer to http://wanglongqi.github.io/WriteTeX. |
|
17 | 17 | import tempfile |
18 | 18 | import sys |
19 | 19 | import copy |
| 20 | +import subprocess |
20 | 21 | WriteTexNS = u'http://wanglongqi.github.io/WriteTeX' |
21 | 22 | # from textext |
22 | 23 | SVG_NS = u"http://www.w3.org/2000/svg" |
@@ -151,34 +152,50 @@ def effect(self): |
151 | 152 | tex.close() |
152 | 153 |
|
153 | 154 | 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) |
156 | 157 | 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) |
159 | 160 | else: |
160 | 161 | # Setting `latexcmd` to following string produces the same result as xelatex condition: |
161 | 162 | # '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) |
164 | 165 |
|
165 | 166 | try: |
166 | | - os.popen('pdfcrop %s' % pdf_file) |
167 | | - os.remove(pdf_file) |
168 | | - os.rename(crop_file, 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 | + |
| 181 | + if os.path.exists(crop_file): |
| 182 | + os.remove(pdf_file) |
| 183 | + os.rename(crop_file, pdf_file) |
169 | 184 | except: |
170 | 185 | pass |
171 | 186 |
|
172 | 187 | if not os.path.exists(pdf_file): |
173 | 188 | print >>sys.stderr, "Latex error: check your latex file and preamble." |
174 | 189 | print >>sys.stderr, open(log_file).read() |
| 190 | + return |
175 | 191 | else: |
176 | 192 | if self.options.pdftosvg == '1': |
177 | | - os.popen('pdf2svg %s %s' % (pdf_file, svg_file)) |
| 193 | + subprocess.call('pdf2svg %s %s' % |
| 194 | + (pdf_file, svg_file), shell=True) |
178 | 195 | self.merge_pdf2svg_svg(svg_file) |
179 | 196 | else: |
180 | | - os.popen('pstoedit -f plot-svg "%s" "%s" -dt -ssp -psarg -r9600x9600 > "%s" 2> "%s"' |
181 | | - % (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) |
182 | 199 | self.merge_pstoedit_svg(svg_file) |
183 | 200 |
|
184 | 201 | os.remove(tex_file) |
|
0 commit comments