Permalink
Browse files

Another major update, still needs test.

  • Loading branch information...
wanglongqi committed Mar 27, 2017
1 parent d02042d commit e29781da2425ffc30e257de9db6270e7d94512b2
Showing with 43 additions and 10 deletions.
  1. +1 −0 writetex.inx
  2. +42 −10 writetex.py
@@ -16,6 +16,7 @@
</page>
<page name="viewold" _gui-text="View Original TeX">
<_param name="old" type="description">Choose this tab if you would like to obtain the original TeX string.</_param>
<param name="tosvg" type="boolean" _gui-text="Write output to Figure"></param>
</page>
<page name="help" _gui-text="Help">
<_param name="help" type="description">You need at least one LaTeX command and one PDFtoSVG command to execute this plugin correctly. Please visit http://writetex.tk for more information. If you have any suggestion, feel free to open an issue in the repository.</_param>
@@ -5,8 +5,8 @@
An Latex equation editor for Inkscape.
:Author: WANG Longqi <iqgnol@gmail.com>
:Date: 2017-03-23
:Version: v1.1
:Date: 2017-03-27
:Version: v1.5
This file is a part of WriteTeX extension for Inkscape. For more information,
please refer to http://wanglongqi.github.io/WriteTeX.
@@ -62,8 +62,23 @@ def __init__(self):
action="store", type="string",
dest="latexcmd", default="xelatex",
help="Latex command used to compile")
self.OptionParser.add_option("-t", "--tosvg",
action="store", type="string",
dest="tosvg", default="false",
help="Write output directly to a new node in svg file")

def effect(self):
self.zoom = float(self.document.xpath(
'//sodipodi:namedview/@inkscape:zoom', namespaces=inkex.NSS)[0])
self.width = 1/self.zoom * \
float(self.document.xpath(
'//sodipodi:namedview/@inkscape:window-width', namespaces=inkex.NSS)[0])
self.height = 1/self.zoom * \
float(self.document.xpath(
'//sodipodi:namedview/@inkscape:window-height', namespaces=inkex.NSS)[0])
self.width = self.unittouu(str(self.width)+'px')
self.height = self.unittouu(str(self.height)+'px')

self.options.scale = float(self.options.scale)
action = self.options.action.strip("\"")
if action == "viewold":
@@ -72,8 +87,19 @@ def effect(self):
if node.tag != '{%s}g' % SVG_NS:
continue
if '{%s}text' % WriteTexNS in node.attrib:
print >>sys.stderr, node.attrib.get(
'{%s}text' % WriteTexNS, '').decode('string-escape')
if self.options.tosvg == "true":
doc = inkex.etree.fromstring(
'<text x="%g" y="%g">%s</text>' % (
self.view_center[0]-self.width/6,
self.view_center[1]-self.height/6,
node.attrib.get(
'{%s}text' % WriteTexNS, '').decode('string-escape')))
p = node.getparent()
# p.remove(node)
p.append(doc)
else:
print >>sys.stderr, node.attrib.get(
'{%s}text' % WriteTexNS, '').decode('string-escape')
return
print >>sys.stderr, "No text find."
return
@@ -207,14 +233,16 @@ def svg_to_group(self, svgin):
if self.options.rescale == 'true':
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
800*self.options.scale, 800*self.options.scale,
self.view_center[0], self.view_center[1])
self.view_center[0]-self.width/6,
self.view_center[1]-self.height/6)
else:
if 'transform' in node.attrib:
newnode.attrib['transform'] = node.attrib['transform']
else:
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
800*self.options.scale, 800*self.options.scale,
self.view_center[0], self.view_center[1])
self.view_center[0]-self.width/6,
self.view_center[1]-self.height/6)
newnode.attrib['style'] = node.attrib['style']
except:
pass
@@ -224,7 +252,8 @@ def svg_to_group(self, svgin):
else:
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
800*self.options.scale, 800*self.options.scale,
self.view_center[0], self.view_center[1])
self.view_center[0]-self.width/6,
self.view_center[1]-self.height/6)
self.current_layer.append(newnode)

def merge_pdf2svg_svg(self, svg_file):
@@ -274,14 +303,16 @@ def svg_to_group(self, svgin):
if self.options.rescale == 'true':
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
self.options.scale, self.options.scale,
self.view_center[0], self.view_center[1])
self.view_center[0]-self.width/6,
self.view_center[1]-self.height/6)
else:
if 'transform' in node.attrib:
newnode.attrib['transform'] = node.attrib['transform']
else:
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
self.options.scale, self.options.scale,
self.view_center[0], self.view_center[1])
self.view_center[0]-self.width/6,
self.view_center[1]-self.height/6)
newnode.attrib['style'] = node.attrib['style']
except:
pass
@@ -292,7 +323,8 @@ def svg_to_group(self, svgin):
self.current_layer.append(newnode)
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
self.options.scale, self.options.scale,
self.view_center[0], self.view_center[1])
self.view_center[0]-self.width/6,
self.view_center[1]-self.height/6)


if __name__ == '__main__':

0 comments on commit e29781d

Please sign in to comment.