Skip to content

Commit 1e46cd5

Browse files
committed
adding crop function
1 parent e3e1802 commit 1e46cd5

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
An Inkscape extension: Latex/Tex editor for Inkscape, inspired by [textext](http://pav.iki.fi/software/textext/).
66

7-
This extension uses Inkscape build-in extension system, does not require TK or PyGtk as textext. Live preview feature is supported. You can obtain orginal TeX source from View Old Text tab.
7+
This extension uses Inkscape build-in extension system, does not require TK or PyGtk as textext. Live preview feature is supported. You can obtain original TeX source from View Original TeX tab.
88

99
## Installation
10-
Just drop `writetex.py` and `writetex.inx` to Inkscape extension folder, which is normally at `$inkscapeFolder$/share/extensions`. Make sure `XeLatex` and `PDF2SVG` or `PDFtoEDIT` are in you path.
10+
Just drop `writetex.py` and `writetex.inx` to Inkscape extension folder, which is normally at `$inkscapeFolder$/share/extensions`. Make sure one `LaTeX` command and one `PDFtoSVG` converter are in you path.
11+
12+
## More info
13+
Can be found in the [website](https://wanglongqi.github.io/WriteTeX/).
14+

writetex.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
An Latex equation editor for Inkscape.
66
77
:Author: WANG Longqi <[email protected]>
8-
:Date: 2015-06-14
9-
:Version: v0.4
8+
:Date: 2017-04-01
9+
:Version: v0.99
1010
1111
This file is a part of WriteTeX extension for Inkscape. For more information,
1212
please refer to http://wanglongqi.github.io/WriteTeX.
@@ -97,6 +97,7 @@ def effect(self):
9797
out_file = os.path.join(tmp_dir, "writetex.out")
9898
err_file = os.path.join(tmp_dir, "writetex.err")
9999
aux_file = os.path.join(tmp_dir, "writetex.aux")
100+
crop_file = os.path.join(tmp_dir, "writetex-crop.pdf")
100101

101102
if self.options.preline == "true":
102103
preamble = self.options.preamble
@@ -132,7 +133,15 @@ def effect(self):
132133
else:
133134
# Setting `latexcmd` to following string produces the same result as xelatex condition:
134135
# 'xelatex "-output-directory={tmp_dir}" -interaction=nonstopmode -halt-on-error "{tex_file}" > "{out_file}"'
135-
os.popen(self.options.latexcmd.format(tmp_dir=tmp_dir, tex_file=tex_file, out_file=out_file))
136+
os.popen(self.options.latexcmd.format(
137+
tmp_dir=tmp_dir, tex_file=tex_file, out_file=out_file))
138+
139+
try:
140+
os.popen('pdfcrop %s' % pdf_file)
141+
os.remove(pdf_file)
142+
os.rename(crop_file, pdf_file)
143+
except:
144+
pass
136145

137146
if not os.path.exists(pdf_file):
138147
print >>sys.stderr, "Latex error: check your latex file and preamble."
@@ -196,23 +205,23 @@ def svg_to_group(self, svgin):
196205
if replace:
197206
try:
198207
if self.options.rescale == 'true':
199-
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (800*self.options.scale, 800*self.options.scale,
200-
-200*self.options.scale, 100*self.options.scale)
208+
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
209+
800*self.options.scale, 800*self.options.scale, 0, 0)
201210
else:
202211
if 'transform' in node.attrib:
203212
newnode.attrib['transform'] = node.attrib['transform']
204213
else:
205-
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (800*self.options.scale, 800*self.options.scale,
206-
-200*self.options.scale, 100*self.options.scale)
214+
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
215+
800*self.options.scale, 800*self.options.scale, 0, 0)
207216
newnode.attrib['style'] = node.attrib['style']
208217
except:
209218
pass
210219
p = node.getparent()
211220
p.remove(node)
212221
p.append(newnode)
213222
else:
214-
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (800*self.options.scale, 800*self.options.scale,
215-
-200*self.options.scale, 100*self.options.scale)
223+
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
224+
800*self.options.scale, 800*self.options.scale, 0, 0)
216225
self.current_layer.append(newnode)
217226

218227
def merge_pdf2svg_svg(self, svg_file):
@@ -260,14 +269,14 @@ def svg_to_group(self, svgin):
260269
if replace:
261270
try:
262271
if self.options.rescale == 'true':
263-
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (self.options.scale, self.options.scale,
264-
-168*self.options.scale, -100*self.options.scale)
272+
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
273+
self.options.scale, self.options.scale, 0, 0)
265274
else:
266275
if 'transform' in node.attrib:
267276
newnode.attrib['transform'] = node.attrib['transform']
268277
else:
269-
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (self.options.scale, self.options.scale,
270-
-168*self.options.scale, -100*self.options.scale)
278+
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
279+
self.options.scale, self.options.scale, 0, 0)
271280
newnode.attrib['style'] = node.attrib['style']
272281
except:
273282
pass
@@ -276,8 +285,8 @@ def svg_to_group(self, svgin):
276285
p.append(newnode)
277286
else:
278287
self.current_layer.append(newnode)
279-
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (self.options.scale, self.options.scale,
280-
-168*self.options.scale, -100*self.options.scale)
288+
newnode.attrib['transform'] = 'matrix(%f,0,0,%f,%f,%f)' % (
289+
self.options.scale, self.options.scale, 0, 0)
281290

282291

283292
if __name__ == '__main__':

0 commit comments

Comments
 (0)