forked from theory-cs/theory-cs.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivity_newtex.py
66 lines (46 loc) · 1.6 KB
/
activity_newtex.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
61
62
63
64
65
66
from string import Template
import os
import linecache
from user_functions import *
#TODO: use header file ...
with open('resources/lesson-head.tex') as f:
lines = f.readlines()
with open('resources/discrete-math-packages.tex') as f:
package = f.read()
for line in lines:
if("\input" in line):
idx = lines.index(line)
lines.pop(idx)
lines.insert(idx, package)
opening = ""
for line in lines:
opening += line
bigPDF = opening
directoryFolder = "notes/activity-snippets"
definition_array = []
for filename in os.listdir(directoryFolder):
# print(filename)
if("definition" in filename):
# print(filename)
definition_array.append(filename)
definition_array = sorted(definition_array)
websiteData = json.loads(open("website-settings.json").read())
full_definition = websiteData['Compiled Activity Snippets']
if(full_definition == "True"):
for filename in definition_array:
weekly = open (directoryFolder+"/"+filename, "r")
lines = weekly.readlines()
strNew = ""
for line in reversed(lines):
if(line.startswith("%!") or line.startswith("\n")):
lines.remove(line)
strNew += opening
for line in lines:
strNew += line
bigPDF += line
bigPDF += "\n"
strNew += "\n\end{document}"
# print(strNew)
write_if_different("generated/notes/activity-snippets-flat/" + filename, strNew)
bigPDF += "\n\end{document}"
write_if_different("generated/notes/activity-snippets-flat/full-definition.tex", bigPDF)