-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile
executable file
·47 lines (36 loc) · 1.14 KB
/
compile
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
#!/usr/bin/env python3
import shutil
from pathlib import Path
from subprocess import check_output, run
base_dir = Path(__file__).absolute().parent
tex_files = [
(Path("barvagt/main.tex"), "barvagt.pdf"),
]
out_dir = base_dir / "out"
out_dir.mkdir(exist_ok=True)
for d in base_dir.iterdir():
if not d.is_dir():
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}")
change_date = check_output(
["git", "log", "-1", "--pretty=format:%ad", "--date=short", tex_file],
encoding="utf-8",
).strip()
contents = tex_file.read_text()
new_contents = contents.replace("\\date{\\today}", "\\date{" + change_date + "}")
try:
tex_file.write_text(new_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)