2 # -*- coding: utf-8 -*-
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
9 # author Martin Vermeer
11 # This script converts an SVG image to something that latex can process
12 # into high quality PostScript.
14 # Full author contact details are available in file CREDITS
17 # python svg2pstex.py ${base}.fig ${base}.pstex
18 # This command generates
19 # ${base}.eps the converted eps file
20 # ${base}.pstex a tex file that can be included in your latex document
21 # using '\input{${output}}'.
24 # Do not use this command as
25 # python svg2pstex.py file.fig file.eps
26 # the real eps file will be overwritten by a tex file named file.eps.
33 run a command, quit if fails
35 if os.system(cmd) != 0:
36 print "Command '%s' fails." % cmd
39 # We expect two args, the names of the input and output files.
40 if len(sys.argv) != 3:
43 input, output = sys.argv[1:]
45 # Fail silently if the file doesn't exist
46 if not os.path.isfile(input):
49 # Strip the extension from ${output}
50 outbase = os.path.splitext(output)[0]
52 # Inkscape 0.48 can output the image as a EPS file ${base}.pdf and place the text
53 # in a LaTeX file ${base}.eps_tex, which is renamed to ${output}, for typesetting
55 runCommand('inkscape --file=%s --export-eps=%s.eps --export-latex' % (input, outbase))
56 os.rename('%s.eps_tex' % outbase, output)