cruft
·
2009-07-09
splitup.py
1#! /usr/bin/env python3
2
3import optparse
4import re
5
6badchars = re.compile(r'[^A-Za-z0-9]')
7
8p = optparse.OptionParser()
9opts, args = p.parse_args()
10
11chapter = None
12for fn in args:
13 for line in open(fn):
14 if line.startswith('%%%%%%%%%'):
15 continue
16 if line.startswith('\\chapter'):
17 chapter = line[9:-2]
18 chapter_line = line
19 continue
20 if line.startswith('\\by{'):
21 by = line[4:-2]
22 by = badchars.sub('_', by)
23
24 chapter_ = badchars.sub('_', chapter)
25 chapter_ = chapter_[:10]
26
27 ofn = 'stories/%s.%s' % (by, chapter_)
28 print('\\include{%s}' % ofn)
29 of = open(ofn + '.tex', 'w')
30 of.write(chapter_line)
31 of.write(line)