-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathlatex_pdf.py
114 lines (78 loc) · 3.11 KB
/
latex_pdf.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
101
102
103
104
105
106
107
108
109
110
111
import os
import sys
import subprocess
import shlex
from machine import *
class pdfCreator():
# declare and define all variables in the constructor
def __init__(self,dn,fn,inv):
self.invention = inv
self.file = self.create_TeX_file(dn,fn)
self.title = self.create_title()
self.abstract = self.create_abstract()
self.illustrations = self.create_illustrations()
self.description = self.create_description()
self.claims = self.create_claims()
self.file_contents = self.create_LaTeX()
# used to open a new folder and open appropriate file
def create_TeX_file(self,dname,fname):
if not os.path.exists(dname):
os.makedirs(dname)
return open(dname + "/" + fname + ".tex","a+")
# assemble the full LaTeX text
def create_LaTeX(self):
text = "\\documentclass[english]{uspatent}\n\\begin{document}"
text += self.title
text += self.abstract
text += self.illustrations
text += self.description
text += self.claims
text += "\n\\end{document}"
return text
# assemble the title featuers
def create_title(self):
title = "\n\\title{" + self.invention.title + "}"
title += "\n\\date{\\today}"
title += "\n\\inventor{First Named Inventor}"
title += "\n\\maketitle"
return title
# put the abstract together
def create_abstract(self):
abs = "\n\\patentSection{Abstract}"
abs += "\n\\patentParagraph " + self.invention.abstract
return abs
# collect image descriptions
def create_illustrations(self):
ill = "\n\\patentSection{Brief Description of the Drawings}"
for i in self.invention.illustrations:
# seperate paragraph for each, maybe not necessary
ill += "\n\\patentParagraph " + i
return ill
# put description together
def create_description(self):
desc = "\n\\patentSection{Detailed Description of the Preferred Embodiments}"
desc += "\n\\patentParagraph " + self.invention.description
return desc
# assemble the claims together
def create_claims(self):
cla = "\n\\patentClaimsStart"
for i,claim in enumerate(self.invention.claims):
cla += "\n\\beginClaim{Claim" + str(i) + "}" + claim[2:]
cla += "\n\\patentClaimsEnd"
return cla
# write the entire text to the file
def write_LaTeX_to_file(self):
# to fix paragraph formatting
self.file.write(self.file_contents.replace("\n\n","\n\\patentParagraph "))
# function to compile the LaTeX formatting, not working yet
#def compile_LaTeX(self):
#process = subprocess.call("pdflatex test/test.tex", shell=True)
if __name__ == '__main__':
import sys
text = open(sys.argv[1],"r").read().decode('ascii', errors='replace')
dir_name = sys.argv[2]
file_name = sys.argv[3]
invention = Invention(text)
pdf = pdfCreator(dir_name,file_name,invention)
pdf.write_LaTeX_to_file()
#pdf.compile_LaTeX()