Comment 10 for bug 167579

Revision history for this message
Roman Dubtsov (busa-ru) wrote :

I'm the one who reported the problem into debian bugzilla.

here's the diff for eqtexsvg.py, which
a) uses better (still silly) svg parsing technique
b) does better tmp file creation
c) uses plot-svg pstoedit driver to produce svgs
d) does not use -output-dir with latex, but the solution is
*nix only =(

diff -urNBb inkscape1.44.orig/share/extensions/eqtexsvg.py
inkscape-0.44/share/extensions/eqtexsvg.py
--- inkscape-0.44.orig/share/extensions/eqtexsvg.py
2006-07-06 23:11:01.000000000 +0700
+++ inkscape-0.44/share/extensions/eqtexsvg.py 2006-07-06
23:14:56.000000000 +0700
@@ -27,7 +27,7 @@

 """

-import inkex, os, tempfile
+import inkex, os, tempfile, xml.dom.minidom

 def create_equation_tex(filename, equation):
     tex = open(filename, 'w')
@@ -44,42 +44,28 @@
     tex.close()

 def svg_open(self,filename):
- # parsing of SVG file with the equation
- # real parsing XML to use!!!! it will be easier !!!
- svg = open(filename, 'r')
- svg_lines = svg.readlines()

-
- # trip top/bottom lines from svg file
- svg_lines.pop(0)
- svg_lines.pop(1)
- svg_lines.pop(len(svg_lines)-1)
+ def clone_and_rewrite(self, node_in):
+ if node_in.localName != 'svg':
+ node_out = self.document.createElement('svg:' +
node_in.localName)
+ for i in range(0, node_in.attributes.length):
+ name = node_in.attributes.item(i).name
+ value = node_in.attributes.item(i).value
+ node_out.setAttribute(name, value)
+ else:
+ node_out = self.document.createElement('svg:g')

- group = self.document.createElement('svg:g')
- self.current_layer.appendChild(group)
+ for c in node_in.childNodes:
+ if c.localName in ('g', 'path'):
+
node_out.appendChild(clone_and_rewrite(self, c))

- # deleting "<g... >" "</g>" "<path d=" and "/>" from
svg_lines
- nodegroup=''
- s_nodegroup_path=''
-
- for i in range(1,len(svg_lines)):
- if svg_lines[i].find("<g") != -1:
- nodegroup=svg_lines[i].split("<g")
- nodegroup=nodegroup[1].split(" >")
- nodegroup=nodegroup[0]+'\n'
- elif svg_lines[i].find("<path d=") != -1:
- s_nodegroup_path=svg_lines[i].split("<path d=")
- s_nodegroup_path=s_nodegroup_path[1]

- elif svg_lines[i].find("/>") != -1:
- s_nodegroup_path=s_nodegroup_path+'"\n'
- elif svg_lines[i].find("</g>") != -1:
- nodegroup_svg =
self.document.createElement('svg:g')
- nodegroup_svg.setAttribute('style',nodegroup)
- nodegroup_path =
self.document.createElement('svg:path')
- nodegroup_path.setAttribute('d',s_nodegroup_path)
- group.appendChild(nodegroup_svg)
- nodegroup_svg.appendChild(nodegroup_path)
- else:
- s_nodegroup_path=s_nodegroup_path+svg_lines[i]
+ return node_out
+
+ doc = xml.dom.minidom.parse(filename)
+ svg = doc.getElementsByTagName('svg')[0]
+
+ group = clone_and_rewrite(self, svg)
+ group.setAttribute('transform', 'scale(1000)')
+ self.current_layer.appendChild(group)

 class EQTEXSVG(inkex.Effect):
     def __init__(self):
@@ -89,19 +75,17 @@
                         dest="formule", default=10.0,
                         help="Formule LaTeX")
     def effect(self):
-
- base_file = os.path.join(tempfile.gettempdir(),
"inkscape-latex.tmp")
+ base_file = os.path.join(tempfile.gettempdir(),
"inkscape-latex.tmp." + str(os.getpid()))
         latex_file = base_file + ".tex"
         create_equation_tex(latex_file, self.options.formule)
-
- out_file = os.path.join(tempfile.gettempdir(),
"inkscape-latex.tmp.output")
- os.system('latex -output-directory=' +
tempfile.gettempdir() + ' ' + latex_file + '> ' + out_file)
+ out_file = base_file + ".output"
+ os.system('cd ' + tempfile.gettempdir() + '; latex
' + latex_file + ' > ' + out_file)

         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 svg -dt -ssp ' + ps_file + '
' + svg_file + '>> ' + out_file)
+ os.system('cd ' + tempfile.gettempdir() + ';
pstoedit -f plot-svg -dt -ssp ' + ps_file + ' ' + svg_file +
' &> ' + out_file)

         # ouvrir le svg et remplacer #7F7F7F par #000000
         svg_open(self, svg_file)