-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
60 lines (49 loc) · 1.66 KB
/
build.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pathlib
import sys
import json
input_dir = pathlib.Path("tex")
output_dir = pathlib.Path("statements")
if len(sys.argv) < 2:
print("Usage: build.py [template]")
exit(1)
template = pathlib.Path("templates") / sys.argv[1]
for directory in input_dir.glob("*"):
if not directory.is_dir():
continue
lang = directory.name
print("Processing", directory, file=sys.stderr)
template_file = (template / lang).with_suffix(".tex")
if not template_file.exists():
print("Could not find template {template_file}.", file=sys.stderr)
exit(1)
template_real = template_file.readlink().with_suffix("").name
for problem in directory.glob("*"):
if not problem.is_dir():
continue
for part in ("answer", "solution", "statement"):
input_file = problem / f"{part}.tex"
output_file = output_dir / problem.relative_to(input_dir) / f"{part}.html"
output_file.parent.mkdir(parents=True, exist_ok=True)
pandoc_cmd = [
"/usr/bin/pandoc",
"-t",
"html",
"-s",
'--webtex="eqn://"',
str(input_file),
]
webtex_cmd = [
"./wr",
"-engine",
"tectonic",
"-template",
str(template_file),
"-innerhtml",
"-eqdir",
f"assets/eqs_{template_real}",
"-outurl",
f"eqs_{template_real}",
"-output",
str(output_file),
]
print(" ".join(pandoc_cmd) + " | " + " ".join(webtex_cmd))