Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

illustrations for RH book

Views: 1857
1
def doc():
2
os.system('detex ../rh.tex > rh.txt')
3
return open('rh.txt').read()
4
5
def not_dumb(x):
6
for a in ['yet', 'you', 'width', 'approx']:
7
if x.startswith(a): return False
8
for a in ['ly', 'ing']:
9
if x.endswith(a): return False
10
for a in ['prove', 'propo', 'psi', '_', 'theorem', 'exercise', 'equation']:
11
if a in x.lower(): return False
12
return True
13
14
def words(exclude=True):
15
d = doc()
16
for a in '.?,:][)($0123456789!#/*+&=;\'`"':
17
d = d.replace(a,'')
18
if exclude:
19
v = list(sorted(set(d.split())))
20
v = [x for x in v if len(x) > 3 and not '-' in x]
21
w = set([x.lower() for x in open('omit.txt').read().split()])
22
v = [x for x in v if len(x) > 3 and x.lower() not in w]
23
v = [x for x in v if '\336' not in x and '\325' not in x]
24
v = [x for x in v if not_dumb(x)]
25
else:
26
v = d.split()
27
return v
28
29
def write_list():
30
v = words()
31
open('list.txt','w').write('\n'.join(v))
32
33
def count():
34
w = words(exclude=False)
35
print "Words: ", len(w)
36
r = open('../rh.tex').read()
37
n = len(r.split('\\ill'))-1
38
n += len(r.split('\\includegraphics'))-3
39
print "Illustrations: ", n
40
41