2 # -*- coding: utf-8 -*-
6 # This script converts an SVG image to something that latex can process
7 # into high quality PostScript.
10 # python svg2pstex.py ${base}.fig ${base}.pstex
11 # This command generates
12 # ${base}.eps the converted eps file
13 # ${base}.pstex a tex file that can be included in your latex document
14 # using '\input{${output}}'.
17 # Do not use this command as
18 # python svg2pstex.py file.fig file.eps
19 # the real eps file will be overwritten by a tex file named file.eps.
26 run a command, quit if fails
28 if os.system(cmd) != 0:
29 print "Command '%s' fails." % cmd
32 # We expect two args, the names of the input and output files.
33 if len(sys.argv) != 3:
36 input, output = sys.argv[1:]
38 # Fail silently if the file doesn't exist
39 if not os.path.isfile(input):
42 # Strip the extension from ${output}
43 outbase = os.path.splitext(output)[0]
45 # Inkscape 0.48 can output the image as a EPS file ${base}.pdf and place the text
46 # in a LaTeX file ${base}.eps_tex, which is renamed to ${output}, for typesetting
48 runCommand('inkscape --file=%s --export-eps=%s.eps --export-latex' % (input, outbase))
49 os.rename('%s.eps_tex' % outbase, output)