The pstoedit version (3.42) installed in Suse 10.0 doesn't accept the command line options passed to it from the eqtexsvg.py extension file. I really love and need this feature, but to be truth I'm not an expert at using LaTeX and satellite command line utilities, so the more I could do was to write a workaround, see it at the bottom. Still remains a problem, present in the original eqtexsvg.py and the adjoint one: when the formula doesn't parses correctly, the script hangs, possibly because LaTeX doesn't leave, but remains in interactive mode; turning Inkscape irresponsive. Any idea of how to avoid that?
=============== eqtexsvg.py==============================================
import inkex, os, tempfile import xml.dom.minidom import sys import xml_utils
def create_equation_tex(filename, equation): tex = open(filename, 'w') tex.write("""%% processed with EqTeXSVG.py \documentclass{article}
\thispagestyle{empty} \begin{document} """) tex.write("$$\n") tex.write(equation) tex.write("\n$$\n") tex.write("\end{document}\n") tex.close()
def svg_xml_open(self, filename): document = xml.dom.minidom.parse(filename) #We have two groups, with a few attributes an some other extravagances #The second group is the interesting one current_node = document.documentElement.firstChild # Move until you find a group node while current_node.nodeName != 'g': current_node = current_node.nextSibling if current_node == None : break
copier = xml_utils.XmlCopier( document, self.document) append_this = copier.deepCopyElement(current_node) self.document.documentElement.appendChild(append_this)
class EQTEXSVG(inkex.Effect): def __init__(self): inkex.Effect.__init__(self) self.OptionParser.add_option("-f", "--formule", action="store", type="string", dest="formule", default=10.0, help="Formule LaTeX") def effect(self):
base_file = os.path.join(tempfile.gettempdir(), "inkscape-latex.tmp ") latex_file = base_file + ".tex" create_equation_tex(latex_file, self.options.formule)
out_file = os.path.join(tempfile.gettempdir(), " inkscape-latex.tmp.output") exit_status = os.system('latex -output-directory=' + tempfile.gettempdir() + ' ' + latex_file + '> ' + out_file) if exit_status != 0: sys.exit(exit_status)
ps_file = base_file + ".ps" dvi_file = base_file + ".dvi" svg_file = base_file + ".svg" os.system('dvips -q -f -E -D 600 -y 5000 -o ' + ps_file + ' ' + dvi_file) os.system('pstoedit -f plot-svg -dt -ssp ' + ps_file + ' ' + svg_file + '>> ' + out_file)
# ouvrir le svg et remplacer #7F7F7F par #000000 svg_xml_open(self, svg_file)
# clean up aux_file = base_file + ".aux" log_file = base_file + ".log" os.remove(latex_file) os.remove(aux_file) os.remove(log_file) os.remove(dvi_file) os.remove(ps_file) os.remove(svg_file) os.remove(out_file)
e = EQTEXSVG() e.affect()
=============== xml_utils.py ==============================================
class XmlCopier:
def __init__(self, source_document, target_document): self.s_doc = source_document self.t_doc = target_document
def deepCopyElement(self, source_element): """ Copies attributes and contents from source_node to target_node """ name = str(source_element.nodeName) target_element = self.t_doc.createElement(name) #Start with the attributes attrs = source_element.attributes for attr_name in attrs.keys(): target_element.setAttribute(str(attr_name), source_element.getAttribute(attr_name)) #Next go with the childs for c in source_element.childNodes: if c.nodeType == 3: new_node = self.copyText(c) else: #Node is assumed to be another element new_node = self.deepCopyElement(c) target_element.appendChild(new_node) return target_element
def copyText(self, text_node): the_text = str(text_node.nodeValue) result = self.t_doc.createTextNode(the_text) return result