forked from openqasm/openqasm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert2svg.py
executable file
·44 lines (33 loc) · 1.17 KB
/
convert2svg.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import subprocess
CONVERT_COMMAND = 'pdftocairo'
def main(relative_tex_filepath):
if not os.path.exists(relative_tex_filepath):
print(
'File %s does not exist.' % relative_tex_filepath, file=sys.stderr)
return -1
absolute_tex_filepath = os.path.abspath(relative_tex_filepath)
destination_directory = os.path.dirname(absolute_tex_filepath)
try:
subprocess.run(
['command', '-v', CONVERT_COMMAND]).check_returncode()
except subprocess.CalledProcessError:
print('Cannot find `%s`. Ensure you it installed and the command is '
'in the PATH.' % CONVERT_COMMAND, file=sys.stderr)
return -1
try:
subprocess.run(
[CONVERT_COMMAND, '-svg', absolute_tex_filepath],
cwd=destination_directory)
except subprocess.CalledProcessError:
return -1
return 0
if __name__ == '__main__':
if len(sys.argv) != 2:
print('Usage: convert2svg.py path/to/pdffile.pdf')
print('For converting to PDF, use convert2pdf.py first.')
sys.exit(-1)
sys.exit(main(sys.argv[1]))