-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatexlib.py
More file actions
61 lines (60 loc) · 2.12 KB
/
atexlib.py
File metadata and controls
61 lines (60 loc) · 2.12 KB
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
def parseSeq(infile, outfile, charOpen, charClose, parenOpen, parenClosed, control):
oldPos=0
passVar=False
math=False
paren=False
thmline=infile.readline()
while(thmline[0]== " "):
thmline=remLeadWhite(thmline)
for i in range(0, len(thmline)):
if passVar:
passVar=False
if thmline[i]==control:
outfile.write("\\")
else:
outfile.write(thmline[i])
elif(not thmline[i]== charOpen) and (not thmline[i]==charClose) and (not thmline[i]==control) and (not thmline[i]==parenOpen) and (not thmline[i]==parenClosed):
outfile.write(thmline[i])
elif thmline[i]==control:
outfile.write("\\")
passVar=True
elif thmline[i]==charOpen or thmline[i]==charClose or thmline[i]==parenOpen or thmline[i]==parenClosed:
if math and paren:
outfile.write("}")
paren=False
elif math and (not paren) and (thmline[i]==parenOpen):
outfile.write("{")
paren=True
elif math and (not paren):
outfile.write("$")
math=False
elif (not math):
outfile.write("$")
math=True
oldPos=infile.tell()
thmline=infile.readline()
infile.seek(oldPos)
def parseTex(infile, outfile):
oldPos=0
thmline=infile.readline()
while(thmline[0]==" "):
thmline=remLeadWhite(thmline)
outfile.write(thmline)
oldPos=infile.tell()
thmline=infile.readline()
infile.seek(oldPos)
def parseCmd(outfile, fields):
if(len(fields)==3):
outfile.write("\\newcommand{\\"+fields[1]+"}{\\"+fields[2]+"}\n")
else:
outfile.write("\\newcommand{\\"+fields[1]+"}["+fields[2]+"]{\\"+fields[3]+"}")
def remLeadWhite(word):
count=0
for i in range(0,len(word)):
if(word[i]==" "):
count+=1
else:
break;
return word[count:]
def fileExt(f):
return f[:-4]+".tex"