-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile
More file actions
executable file
·43 lines (32 loc) · 944 Bytes
/
compile
File metadata and controls
executable file
·43 lines (32 loc) · 944 Bytes
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
import shutil
from pathlib import Path
from subprocess import check_output, run
base_dir = Path(__file__).absolute().parent
excluded_dirs = []
out_dir = base_dir / "out"
out_dir.mkdir(exist_ok=True)
tex_files = []
for d in base_dir.iterdir():
if not d.is_dir():
continue
if d.name in excluded_dirs:
continue
tex_file = d / "main.tex"
if not tex_file.exists():
continue
tex_files.append((tex_file, d.with_suffix(".pdf").name))
for tex_file, out_name in tex_files:
print(f"Compiling {tex_file}")
contents = tex_file.read_text()
try:
tex_file.write_text(contents)
run(
["latexmk", "-halt-on-error", "-pdf", tex_file.name],
cwd=tex_file.parent,
check=True,
)
pdf = tex_file.with_suffix(".pdf")
shutil.copy(pdf, out_dir / out_name)
finally:
tex_file.write_text(contents)