-
Notifications
You must be signed in to change notification settings - Fork 1
/
Variables.py
76 lines (65 loc) · 2.32 KB
/
Variables.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
import unicodedata
class Variables:
def __init__(self, doctitle="", docauthor="", supervisor="",
institution="", faculty="", department="",
location="", papertype="", subject="", keywords=""):
self.vars = {
"title": ("pdftitle", doctitle),
"author": ("pdfauthor", docauthor),
"supervisor": ("", supervisor),
"institution": ("pdfproducer", institution),
"faculty": ("", faculty),
"department": ("", department),
"location": ("", location),
"papertype": ("", papertype),
"subject": ("pdfsubject", subject),
"keywords": ("pdfkeywords", keywords)
}
self.get_metadata_list()
def __convert(self, data):
data = unicodedata.normalize('NFKD', data)
output = ''
for c in data:
if not unicodedata.combining(c):
output += c
return output
def get_metadata_list(self):
list = []
for i in self.vars:
if self.vars[i][0] != "":
list.append((self.vars[i][0], self.__convert(self.vars[i][1])))
return list
def get_metadata_string(self):
ret = ""
list=self.get_metadata_list()
ret += "\hypersetup{\n"
for i in list:
ret += "\t" + i[0] + "={" + i[1] + "},\n"
ret += "\tpdfcreator = {\LaTeX\ with\ Bib\LaTeX},\n"
ret += "\tcolorlinks = false,\n"
ret += "\thidelinks\n}\n"
return ret
def get_commands_list(self):
list = []
for i in self.vars:
list.append((i, self.vars[i][1]))
return list
def get_commands_string(self):
ret = ""
for i in self.get_commands_list():
ret+= "\\set" + i[0] + "{" + i[1] + "}\n"
return ret
def process_line(self, line):
command = "\set"
auxfrs = line.find(command)
if auxfrs == -1:
return
auxsec = line[auxfrs:].find("{")
commandname = line[auxfrs+len(command):auxsec]
if commandname not in self.vars:
return
auxfrs = auxsec
auxsec = line[auxfrs:].find("}")
auxsec += auxfrs
commandvalue = line[auxfrs+1:auxsec]
self.vars[commandname] = (self.vars[commandname][0], commandvalue)