forked from vongostev/202-Advanced-Python-3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversionV1.py
More file actions
33 lines (27 loc) · 903 Bytes
/
versionV1.py
File metadata and controls
33 lines (27 loc) · 903 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
import sympy.abc
import re
def parsing():
with open('example.tex') as f:
data = f.read()
formulas = list()
data = data.replace('$$', '$')
formulas.append(re.findall(r'\\begin{equation}([\s\S]*?)\\end{equation}', data))
formulas.append(re.findall(r'\$([^$]+)\$', data))
i = 0
while i < len(formulas):
if len(formulas[i]) == 0:
formulas.pop(i)
i -= 1
i += 1
for i in range(len(formulas)):
for j in range(len(formulas[i])):
temp = formulas[i][j].replace('\\', '')
formulas[i][j] = temp
print(formulas)
return formulas
if __name__ == '__main__':
data = parsing()
for i in range(len(data)):
for j in range(len(data[i])):
expr = sympy.Eq(*map(sympy.sympify, (data[i][j].split("="))))
print(expr)