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 # Full author contact details are available in file CREDITS
13 # This script converts an SVG image to something that pdflatex can process
14 # into high quality PDF.
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}'
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.
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 PDF file ${base}.pdf and place the text
53 # in a LaTeX file ${base}.pdf_tex, which is renamed to ${output}, for typesetting
55 runCommand('inkscape --file=%s --export-pdf=%s.pdf --export-latex' % (input, outbase))
57 os.rename('%s.pdf_tex' % outbase, output)