-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_nomencature2.py
executable file
·102 lines (93 loc) · 4.04 KB
/
create_nomencature2.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import os as os
import re as re
import sys
file = open('./customcommands.tex','r')
content=file.read().splitlines()
symbols={}
abbrevations={}
operators={}
################################################
# Read customcommands.tex file #
################################################
while len(content)>0:
curline=content.pop(0) #get a line
if curline.startswith("%%")==False: #just ignore it
if curline.find("SYMBOLS") > -1:
description=content.pop(0)[2:].strip()
print(description)
symbols[description]=[]
content.pop(0)
commandline=content.pop(0)
while commandline:
macro=commandline.split("%")[0].strip()
explanation=commandline.split("%")[1].strip()
commandline=content.pop(0)
symbols[description].append([explanation,macro])
print(" "+explanation+":::"+macro)
if curline.find("OPERATORS") > -1:
description=content.pop(0)[2:].strip()
operators[description]=[]
content.pop(0)
commandline=content.pop(0)
while commandline:
macro=commandline.split("%")[0].strip()
explanation=commandline.split("%")[1].strip()
commandline=content.pop(0)
operators[description].append([explanation,macro])
# print(symbols)
# sys.exit(-1)
print("------------------------------------------------------------------")
#################################################
# Write Nomenclature.tex file #
#################################################
with open("Nomenclature.tex","w") as outfile:
outfile.write("\\section*{Nomenclature}\\label{sec:nomenclature}\n\n")
#############################################
# Writing Operator commands #
#############################################
outfile.write("\\subsection*{Operators}\n\n")
# print(operators.keys())
for secname in operators.keys():
# print(secname)
outfile.write("\subsection*{"+secname+"}\n")
outfile.write("\\begin{tabular}{l l l}\n")
print(operators[secname])
for temp in operators[secname]:
print(temp)
# print("===="+str(temp)+"\n")
withexpr=re.search("with{.*}",temp[0]).group(0)
# print("::::eithexpr: "+withexpr)
explclean=temp[0].replace(withexpr,"").strip()
withexpr=withexpr.replace('with{','').replace('}','')
command=temp[1].split("{")[1].split("}")[0]
numarg=int(temp[1].split("{")[1].split("}")[1][1])
if numarg==1:
print(command+str(numarg))
outfile.write("$"+command+"{"+withexpr+"}$" +" & "+explclean+"& \\texttt{"+command[1:]+"}\\\\\n")
elif numarg==2:
print(command+str(numarg))
outfile.write("$"+command+"{"+withexpr.split('&')[0]+"}"+"{"+withexpr.split('&')[1]+"}$" +" & "+explclean+"& \\texttt{"+command[1:]+"}\\\\\n")
else:
print("\033[91mERROR Currently only operators with one argument are supported\033[00m")
sys.exit()
outfile.write("\end{tabular}\n\n")
# sys.exit(-1)
print("------------------------------------------------------------------")
###########################################
# Writing Symbol commands #
###########################################
outfile.write("\\subsection*{Symbols}\n\n")
for descr in symbols.keys():
print(descr)
outfile.write("\\subsubsection*{"+descr+"}\n")
outfile.write("\\begin{tabular}{l l l}\n")
for temp in symbols[descr]:
command=temp[1]
name=temp[0]
print(name)
print(command)
# sys.exit(-1)
# print(symbols[descr])
command=command.split("{")[1].split("}")[0]
outfile.write("$"+command+"$ & "+name+"& \\texttt{"+command[1:]+"}\\\\\n")
outfile.write("\end{tabular}\n\n")