-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlatex.py
66 lines (60 loc) · 1.7 KB
/
latex.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
class LatexDocument:
def __init__(self):
self.content=[]
def append(self,element):
self.content.append(element)
return element
def __unicode__(self):
r=""
for e in self.content:
r += unicode(e)+"\n"
return r
class LatexElement:
def __init__(self,name,*parameters):
self.content=[]
self.name=name
self.parameters=parameters
def append(self,child):
self.content.append(child)
return child
def __unicode__(self):
r="\\"+self.name
for param in self.parameters:
r+="{"+unicode(param)+"}"
return r
class LatexBlock:
def __init__(self,name,*parameters):
self.content=[]
self.name=name
self.parameters=parameters
def append(self,child):
self.content.append(child)
return child
def __unicode__(self):
r="\\begin{"+self.name+"}"
for param in self.paraleters:
r+="{%s}" % (param,)
r+="\n"
for e in self.content:
r+=unicode(e)+"\n"
r+="\\end{"+self.name+"}"
return r
if __name__ == "__main__":
t=LatexDocument();
t.append(LatexElement("documentclass",["no.oao.girofaktura"]))
doc=t.append(LatexBlock("document"))
doc.append(LatexElement("input",["config.tex"]))
doc.append(LatexElement("ToCompany",["Foo Inc\\\\infinite loop"]))
doc.append(LatexElement("CustNo",[343]))
doc.append(LatexElement("YourRef",[""]))
doc.append(LatexElement("InvoiceNo",[4]))
doc.append(LatexElement("InvoiceDate",["11.03.2012"]))
doc.append(LatexElement("LastDate",["31.03.2012"]))
doc.append(LatexElement("SumTot",["500,00"]))
doc.append(LatexElement("InvoiceTop"))
art=doc.append(LatexBlock("Articles"))
art.append(LatexElement("Article",["Bedriftsmedlemskap"," 500,00"]))
art.append(LatexElement("Divider"))
art.append(LatexElement("Sum"))
doc.append("InvoiceBottom")
print t