1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#!/usr/bin/env python3
#coding=utf8
from optparse import OptionParser
import shutil
import os
import subprocess
svg2eps = 'inkscape %s -C --export-filename=%s.eps --export-type=eps --export-latex'
svg2pdf = 'inkscape %s -C --export-filename=%s.pdf --export-type=pdf --export-latex'
def create_image(input_filename, output_filename, mode, ext):
subprocess.Popen(mode % (input_filename, output_filename),
stdout=subprocess.PIPE, shell=True).communicate()[0]
o_ext = output_filename + '.' + ext
o = output_filename
o_ext_tex = output_filename + '.' + ext + '_tex'
o_t = output_filename + '_t'
shutil.move(o_ext, o)
fin = open(o_ext_tex, 'r')
fout = open(o_t, 'w')
#\includegraphics[width=\unitlength,page=1]{logo.pdftex}
for line in fin:
# FIXME: be more conservative in the replacement
# (in case '{'+o_ext+'}' appeares somewhere else)
out = line.replace('{'+os.path.basename(o_ext)+'}', '{'+os.path.basename(o)+'}')
fout.write(out)
fin.close()
fout.close()
os.remove(o_ext_tex)
def main():
parser = OptionParser()
parser.add_option("-L", "--format", dest="outputFormat",
metavar="FORMAT", help="output format", default="spstex")
parser.add_option("-p", "--portrait", dest="portrait", help="dummy arg")
(options, args) = parser.parse_args()
if len(args) != 2: return
(input_filename, output_filename) = args
fmt = options.outputFormat
portrait = options.portrait
if fmt == 'eps':
create_image(input_filename, output_filename, svg2eps, 'eps')
elif fmt == 'spstex' or fmt == 'pstex':
create_image(input_filename, output_filename, svg2eps, 'eps')
elif fmt == 'spstex_t' or fmt == 'pstex_t':
pass
elif fmt == 'spdftex' or fmt == 'pdftex':
create_image(input_filename, output_filename, svg2pdf, 'pdf')
elif fmt == 'spdftex_t' or fmt == 'pdftex_t':
pass
if __name__ == "__main__":
main()
|