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