/
fix.py
53 lines (43 loc) · 1.08 KB
/
fix.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
"""Fixing my really bad LaTeX codes and formatting when I started this project."""
f = open("main.tex")
main = f.read()
f.close()
dirs = []
while 1:
start = main.find("\\input{") + len("\\input{")
if start < len("\\input{"):
break
main = main[start:]
end = main.find("}")
path = main[:end]
if path.find(".tex") < 0:
path += ".tex"
dirs.append(path)
for path in dirs:
is_begin = True
f = open(path)
latex = f.read()
f.close()
print("OLd\n")
print(latex)
fixed = ""
while 1:
loc = latex.find("$$")
if loc < 0:
fixed += latex
break
if is_begin:
fixed += latex[:loc] + "\\begin{equation}\n\t"
is_begin = False
else:
fixed += latex[:loc] + "\n\\end{equation}"
is_begin = True
latex = latex[loc+2:]
print("New\n")
print(fixed)
i = input("Do you want to overwrite [y/N]")
if i == "y":
f = open(path, "w")
f.write(fixed)
print("Write succesful")
print(dirs)