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 =(
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]
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/extension s/eqtexsvg. py 0.44/share/ extensions/ eqtexsvg. py 0.44.orig/ share/extension s/eqtexsvg. py 0.44/share/ extensions/ eqtexsvg. py 2006-07-06
inkscape-
--- inkscape-
2006-07-06 23:11:01.000000000 +0700
+++ inkscape-
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()
- pop(len( svg_lines) -1) rewrite( self, node_in): createElement( 'svg:' + attributes. length) : attributes. item(i) .name attributes. item(i) .value setAttribute( name, value) createElement( 'svg:g' )
- # trip top/bottom lines from svg file
- svg_lines.pop(0)
- svg_lines.pop(1)
- svg_lines.
+ def clone_and_
+ if node_in.localName != 'svg':
+ node_out = self.document.
node_in.localName)
+ for i in range(0, node_in.
+ name = node_in.
+ value = node_in.
+ node_out.
+ else:
+ node_out = self.document.
- group = self.document. createElement( 'svg:g' ) layer.appendChi ld(group) appendChild( clone_and_ rewrite( self, c))
- self.current_
+ for c in node_in.childNodes:
+ if c.localName in ('g', 'path'):
+
node_out.
- # deleting "<g... >" "</g>" "<path d=" and "/>" from len(svg_ lines)) : i].find( "<g") != -1: svg_lines[ i].split( "<g") nodegroup[ 1].split( " >") nodegroup[ 0]+'\n' i].find( "<path d=") != -1: path=svg_ lines[i] .split( "<path d=") path=s_ nodegroup_ path[1]
svg_lines
- nodegroup=''
- s_nodegroup_path=''
-
- for i in range(1,
- if svg_lines[
- nodegroup=
- nodegroup=
- nodegroup=
- elif svg_lines[
- s_nodegroup_
- s_nodegroup_
- elif svg_lines[ i].find( "/>") != -1: path=s_ nodegroup_ path+'" \n' i].find( "</g>") != -1: createElement( 'svg:g' ) svg.setAttribut e('style' ,nodegroup) createElement( 'svg:path' ) path.setAttribu te('d', s_nodegroup_ path) ld(nodegroup_ svg) svg.appendChild (nodegroup_ path) path=s_ nodegroup_ path+svg_ lines[i] minidom. parse(filename) ByTagName( 'svg')[ 0] rewrite( self, svg) ute('transform' , 'scale(1000)') layer.appendChi ld(group)
- s_nodegroup_
- elif svg_lines[
- nodegroup_svg =
self.document.
- nodegroup_
- nodegroup_path =
self.document.
- nodegroup_
- group.appendChi
- nodegroup_
- else:
- s_nodegroup_
+ return node_out
+
+ doc = xml.dom.
+ svg = doc.getElements
+
+ group = clone_and_
+ group.setAttrib
+ self.current_
class EQTEXSVG( inkex.Effect) :
dest= "formule" , default=10.0,
help= "Formule LaTeX") join(tempfile. gettempdir( ), latex.tmp" ) join(tempfile. gettempdir( ), latex.tmp. " + str(os.getpid()))
create_ equation_ tex(latex_ file, self.options. formule) join(tempfile. gettempdir( ), latex.tmp. output" ) gettempdir( ) + ' ' + latex_file + '> ' + out_file) gettempdir( ) + '; latex
def __init__(self):
@@ -89,19 +75,17 @@
def effect(self):
-
- base_file = os.path.
"inkscape-
+ base_file = os.path.
"inkscape-
latex_file = base_file + ".tex"
-
- out_file = os.path.
"inkscape-
- os.system('latex -output-directory=' +
tempfile.
+ out_file = base_file + ".output"
+ os.system('cd ' + tempfile.
' + latex_file + ' > ' + out_file)
ps_file = base_file + ".ps"
os.system( 'dvips -q -f -E -D 600 -y 5000 -o ' + gettempdir( ) + ';
dvi_file = base_file + ".dvi"
svg_file = base_file + ".svg"
ps_file + ' ' + dvi_file)
- os.system('pstoedit -f svg -dt -ssp ' + ps_file + '
' + svg_file + '>> ' + out_file)
+ os.system('cd ' + tempfile.
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)