49
49
doc_sizeW = max(doc_width,doc_height)
51
51
def clone_and_rewrite(self, node_in):
52
if node_in.tag != 'svg':
53
node_out = inkex.etree.Element(inkex.addNS(node_in.tag,'svg'))
52
in_tag = node_in.tag.rsplit('}',1)[-1]
54
node_out = inkex.etree.Element(inkex.addNS(in_tag,'svg'))
54
55
for name in node_in.attrib:
55
56
node_out.set(name, node_in.attrib[name])
57
58
node_out = inkex.etree.Element(inkex.addNS('g','svg'))
58
59
for c in node_in.iterchildren():
59
if c.tag in ('g', 'path', 'polyline', 'polygon'):
60
c_tag = c.tag.rsplit('}',1)[-1]
61
if c_tag in ('g', 'path', 'polyline', 'polygon'):
60
62
child = clone_and_rewrite(self, c)
62
64
child.set('transform','matrix('+str(doc_sizeH/700.)+',0,0,'+str(-doc_sizeH/700.)+','+str(-doc_sizeH*0.25)+','+str(doc_sizeW*0.75)+')')
63
65
node_out.append(child)
86
88
dvi_file = os.path.join(base_dir, "eq.dvi")
87
89
svg_file = os.path.join(base_dir, "eq.svg")
88
90
out_file = os.path.join(base_dir, "eq.out")
91
err_file = os.path.join(base_dir, "eq.err")
91
94
os.remove(latex_file)
95
98
os.remove(dvi_file)
96
99
os.remove(svg_file)
97
100
os.remove(out_file)
101
if os.path.exists(err_file):
98
103
os.rmdir(base_dir)
100
105
create_equation_tex(latex_file, self.options.formula)
101
#os.system('cd ' + base_dir)
102
os.system('latex -output-directory=' + base_dir + ' -halt-on-error ' + latex_file + ' > ' + out_file)
106
print >>sys.stderr, "invalid LaTeX input:"
106
os.system('latex "-output-directory=%s" -halt-on-error "%s" > "%s"' \
107
% (base_dir, latex_file, out_file))
111
print >>sys.stderr, "invalid LaTeX input:"
107
112
print >>sys.stderr, self.options.formula
108
113
print >>sys.stderr, "temporary files were left in:", base_dir
111
os.system('dvips -q -f -E -D 600 -y 5000 -o ' + ps_file + ' ' + dvi_file)
112
#os.system('cd ' + base_dir)
113
os.system('pstoedit -f plot-svg -dt -ssp ' + ps_file + ' ' + svg_file + '> ' + out_file)
116
os.system('dvips -q -f -E -D 600 -y 5000 -o "%s" "%s"' % (ps_file, dvi_file))
117
# cd to base_dir is necessary, because pstoedit writes
118
# temporary files to cwd and needs write permissions
122
os.system('cd "%s" %s pstoedit -f plot-svg -dt -ssp "%s" "%s" > "%s" 2> "%s"' \
123
% (base_dir, separator, ps_file, svg_file, out_file, err_file))
125
# forward errors to stderr but skip pstoedit header
126
if os.path.exists(err_file):
127
err_stream = open(err_file, 'r')
128
for line in err_stream:
129
if not line.startswith('pstoedit: version'):
130
sys.stderr.write(line + '\n')
114
133
svg_open(self, svg_file)
137
if __name__ == '__main__':
142
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99