]> git.lyx.org Git - features.git/blob - lib/scripts/svg2pdftex.py
Add proper author info and license header to the inkscape.xtemplate related files
[features.git] / lib / scripts / svg2pdftex.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # file svg2pdftex.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 # Full author contact details are available in file CREDITS
12
13 # This script converts an SVG image to something that pdflatex can process
14 # into high quality PDF.
15
16 # Usage:
17 #   python svg2pdftex.py ${base}.svg ${base}.pdft
18 # This command generates
19 #   ${base}.pdf  the converted pdf file
20 #   ${base}.pdft a tex file that can be included in your latex document
21 #       using '\input{${base}.pdft}'
22 #
23 # Note:
24 #   Do not use this command as
25 #     python svg2pdftex.py file.svg file.pdf
26 #   the real pdf file will be overwritten by a tex file named file.pdf.
27 #
28
29 import os, sys, re
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 PDF file ${base}.pdf and place the text 
53 # in a LaTeX file ${base}.pdf_tex, which is renamed to ${output}, for typesetting 
54 # by pdflatex itself. 
55 runCommand('inkscape --file=%s --export-pdf=%s.pdf --export-latex' % (input, outbase))
56
57 os.rename('%s.pdf_tex' % outbase, output)
58