forked from openqasm/openqasm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert2pdf.py
executable file
·43 lines (32 loc) · 1.11 KB
/
convert2pdf.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import subprocess
CONVERT_COMMAND = 'texi2pdf'
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 have LaTeX installed and '
'the command is in the PATH.' % CONVERT_COMMAND, file=sys.stderr)
return -1
try:
subprocess.run(
[CONVERT_COMMAND, '-c', absolute_tex_filepath],
cwd=destination_directory)
except subprocess.CalledProcessError:
return -1
return 0
if __name__ == '__main__':
if len(sys.argv) != 2:
print('Usage: convert2pdf.py path/to/texfile.tex')
sys.exit(-1)
sys.exit(main(sys.argv[1]))