]> git.lyx.org Git - lyx.git/blob - lib/scripts/svg2pstex.py
Add proper author info and license header to the inkscape.xtemplate related files
[lyx.git] / lib / scripts / svg2pstex.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # file svg2pstex.py
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
7
8 # author Daniel Gloger
9 # author Martin Vermeer
10
11 # This script converts an SVG image to something that latex can process
12 # into high quality PostScript.
13
14 # Full author contact details are available in file CREDITS
15
16 # Usage:
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}}'.
22 #
23 # Note:
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.
27 #
28
29 import os, sys
30
31 def runCommand(cmd):
32     ''' Utility function:
33         run a command, quit if fails
34     '''
35     if os.system(cmd) != 0:
36         print "Command '%s' fails." % cmd
37         sys.exit(1)
38
39 # We expect two args, the names of the input and output files.
40 if len(sys.argv) != 3:
41     sys.exit(1)
42
43 input, output = sys.argv[1:]
44
45 # Fail silently if the file doesn't exist
46 if not os.path.isfile(input):
47     sys.exit(0)
48
49 # Strip the extension from ${output}
50 outbase = os.path.splitext(output)[0]
51
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 
54 # by latex itself. 
55 runCommand('inkscape --file=%s --export-eps=%s.eps --export-latex' % (input, outbase))
56 os.rename('%s.eps_tex' % outbase, output)