-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathexciseLines.py
More file actions
43 lines (39 loc) · 1.15 KB
/
Copy pathexciseLines.py
File metadata and controls
43 lines (39 loc) · 1.15 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
import os
import sys
from render import render
def excise(content):
blocks = exciseTikZ(content)
lines = []
for b in blocks:
lines += [ l+";" for l in b.split(";") if l ]
return set(lines)
def exciseTikZ(content):
blocks = []
TikZ = False
for line in content.splitlines():
if "begin{tikzpicture}" in line:
TikZ = True
blocks.append("")
elif "end{tikzpicture}" in line:
TikZ = False
elif TikZ:
blocks[-1] += "\n"+line
return blocks
def getLinesFromDirectory(directory):
lines = set([])
for f in os.listdir(directory):
if f.endswith(".tex"):
with open(directory+"/"+f) as h:
lines |= excise(h.read())
return lines
if __name__ == "__main__":
lines = getLinesFromDirectory("TikZCrawl/data")
j = 0
for l in lines:
render(l,"TikZCrawl/lines/%d.png"% j, None) # no canvas
with open("TikZCrawl/lines/%d.tex"%j, 'w') as handle:
handle.write(l + "\n")
j += 1
# every one percent
if j%int(len(lines)/100.0) == 0:
print "%d/%d" % (j,len(lines))