-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.py
27 lines (25 loc) · 962 Bytes
/
compile.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
import subprocess
import sys
import re
def watch_typst(font_path, filename):
command = f'typst compile {filename}.typ --font-path fonts'
try:
subprocess.run(command, shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: 'typst' command not found. Make sure it's installed and in your PATH.")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python3 compile.py <filename>")
else:
font_path = "fonts"
filename = sys.argv[1]
if not filename:
print("Error: Please provide a valid filename.")
else:
filename = re.sub(r"\.pdf$", "", filename)
filename = re.sub(r"\.typ$", "", filename)
filename = re.sub(r"\.$", "", filename)
watch_typst(font_path, filename)
print("Compiled " + filename)