--- /usr/share/inkscape/extensions/eqtexsvg.inx 2014-09-08 17:44:49.000000000 +0100 +++ /tmp/eqtexsvg.inx 2014-09-17 20:46:07.971143772 +0100 @@ -4,8 +4,7 @@ org.inkscape.effect.eqtexsvg eqtexsvg.py inkex.py - latex - dvips + pdflatex pstoedit \(\displaystyle\frac{\pi^2}{6}=\lim_{n \to \infty}\sum_{k=1}^n \frac{1}{k^2}\) --- /usr/share/inkscape/extensions/eqtexsvg.py 2014-09-08 17:45:11.000000000 +0100 +++ /tmp/eqtexsvg.py 2014-09-17 20:04:53.615300944 +0100 @@ -1,17 +1,21 @@ #! /usr/bin/python -# -*- coding: cp1252 -*- + """ eqtexsvg.py functions for converting LaTeX equation string into SVG path -This extension need, to work properly: +This extension needs, to work properly: - a TeX/LaTeX distribution (MiKTeX ...) - pstoedit software: Copyright (C) 2006 Julien Vitard 2010-04-04: Added support for custom packages Christoph Schmidt-Hieber +2014-09-17: Modified to use pdflatex to produce a PDF file to process + directly with pstoedit + Julian Gilbey + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -28,6 +33,7 @@ """ +from __future__ import print_function import inkex, os, tempfile, sys, xml.dom.minidom def parse_pkgs(pkgstring): @@ -44,7 +50,6 @@ \\documentclass{article} \\usepackage{amsmath} \\usepackage{amssymb} -\\usepackage{amsfonts} """) tex.write(add_header) tex.write("""\\thispagestyle{empty} @@ -70,7 +75,7 @@ node_out = inkex.etree.Element(inkex.addNS('g','svg')) for c in node_in.iterchildren(): c_tag = c.tag.rsplit('}',1)[-1] - if c_tag in ('g', 'path', 'polyline', 'polygon'): + if c_tag in ('g', 'line', 'path', 'polyline', 'polygon'): child = clone_and_rewrite(self, c) if c_tag == 'g': child.set('transform','matrix('+str(doc_sizeH/700.)+',0,0,'+str(-doc_sizeH/700.)+','+str(-doc_sizeH*0.25)+','+str(doc_sizeW*0.75)+')') @@ -97,47 +102,61 @@ def effect(self): base_dir = tempfile.mkdtemp("", "inkscape-"); - latex_file = os.path.join(base_dir, "eq.tex") - aux_file = os.path.join(base_dir, "eq.aux") - log_file = os.path.join(base_dir, "eq.log") - ps_file = os.path.join(base_dir, "eq.ps") - dvi_file = os.path.join(base_dir, "eq.dvi") - svg_file = os.path.join(base_dir, "eq.svg") - out_file = os.path.join(base_dir, "eq.out") - err_file = os.path.join(base_dir, "eq.err") - - def clean(): - os.remove(latex_file) - os.remove(aux_file) - os.remove(log_file) - os.remove(ps_file) - os.remove(dvi_file) - os.remove(svg_file) - os.remove(out_file) - if os.path.exists(err_file): - os.remove(err_file) - os.rmdir(base_dir) + + latex_base = "eq.tex" + aux_base = "eq.aux" + log_base = "eq.log" + pdf_base = "eq.pdf" + svg_base = "eq.svg" + out_base = "eq.out" + err_base = "eq.err" + + latex_file = os.path.join(base_dir, latex_base) + aux_file = os.path.join(base_dir, aux_base) + log_file = os.path.join(base_dir, log_base) + pdf_file = os.path.join(base_dir, pdf_base) + svg_file = os.path.join(base_dir, svg_base) + out_file = os.path.join(base_dir, out_base) + err_file = os.path.join(base_dir, err_base) + + def clean(): + try: + os.remove(latex_file) + os.remove(aux_file) + os.remove(log_file) + os.remove(pdf_file) + os.remove(svg_file) + os.remove(out_file) + if os.path.exists(err_file): + os.remove(err_file) + os.rmdir(base_dir) + except: + print("Could not delete temporary directory %s" % base_dir, + file=sys.stderr) + + # cd to base_dir is necessary, because pstoedit writes + # temporary files to cwd and needs write permissions. + # We also don't rely on latex's -output-directory option, because + # it may have difficulty opening the full filename if the pathname + # has spaces in it. + separator = ';' + if os.name == 'nt': + separator = '&&' add_header = parse_pkgs(self.options.packages) create_equation_tex(latex_file, self.options.formula, add_header) - os.system('latex "-output-directory=%s" -halt-on-error "%s" > "%s"' \ - % (base_dir, latex_file, out_file)) + os.system('cd "%s" %s pdflatex -interaction=batchmode -halt-on-error "%s" > "%s"' \ + % (base_dir, separator, latex_base, out_base)) try: - os.stat(dvi_file) + os.stat(pdf_file) except OSError: - print >>sys.stderr, "invalid LaTeX input:" - print >>sys.stderr, self.options.formula - print >>sys.stderr, "temporary files were left in:", base_dir + print("invalid LaTeX input or other error:", file=sys.stderr) + print(self.options.formula, file=sys.stderr) + print("temporary files were left in:", base_dir, file=sys.stderr) sys.exit(1) - os.system('dvips -q -f -E -D 600 -y 5000 -o "%s" "%s"' % (ps_file, dvi_file)) - # cd to base_dir is necessary, because pstoedit writes - # temporary files to cwd and needs write permissions - separator = ';' - if os.name == 'nt': - separator = '&&' os.system('cd "%s" %s pstoedit -f plot-svg -dt -ssp "%s" "%s" > "%s" 2> "%s"' \ - % (base_dir, separator, ps_file, svg_file, out_file, err_file)) + % (base_dir, separator, pdf_base, svg_base, out_base, err_base)) # forward errors to stderr but skip pstoedit header if os.path.exists(err_file): --- /usr/share/inkscape/extensions/inkex.py 2014-09-08 17:45:11.000000000 +0100 +++ /tmp/inkex.py 2014-09-17 19:47:54.904000783 +0100 @@ -42,7 +42,7 @@ 'km':3543307.0866, 'pc':15.0, 'yd':3240 , 'ft':1080} def unittouu(string): '''Returns userunits given a string representation of units in another system''' - unit = re.compile('(%s)$' % '|'.join(uuconv.keys())) + unit = re.compile('(%s)$' % '|'.join(list(uuconv.keys()))) param = re.compile(r'(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)') p = param.match(string) @@ -84,7 +84,10 @@ ... inkex.errormsg(_("This extension requires two selected paths.")) """ - sys.stderr.write((unicode(msg) + "\n").encode("UTF-8")) + if sys.version_info[0] < 3: + sys.stderr.write((unicode(msg) + "\n").encode("UTF-8")) + else: + sys.stderr.write((str(msg) + "\n").encode("UTF-8")) def check_inkbool(option, opt, value): if str(value).capitalize() == 'True': @@ -96,8 +99,12 @@ def addNS(tag, ns=None): val = tag - if ns!=None and len(ns)>0 and NSS.has_key(ns) and len(tag)>0 and tag[0]!='{': - val = "{%s}%s" % (NSS[ns], tag) + if sys.version_info[0] < 3: + if ns!=None and len(ns)>0 and NSS.has_key(ns) and len(tag)>0 and tag[0]!='{': + val = "{%s}%s" % (NSS[ns], tag) + else: + if ns!=None and len(ns)>0 and ns in NSS and len(tag)>0 and tag[0]!='{': + val = "{%s}%s" % (NSS[ns], tag) return val class InkOption(optparse.Option):