-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathsplit.py
More file actions
30 lines (27 loc) · 764 Bytes
/
split.py
File metadata and controls
30 lines (27 loc) · 764 Bytes
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
"""Outputs the LaTeX source for a single chapter."""
import sys
def main(tex, num):
src = open(tex)
# copy the preamble
for line in src:
print line,
if line.startswith("\\begin{document}"):
print "\\setcounter{chapter}{" + str(num - 1) + "}\n"
break
# copy the chapter
i = -1
for line in src:
if line.startswith("\\backmatter"):
break
if line.startswith("\\chapter"):
i += 1
if i > num:
break
if i == num:
print line,
print "\\end{document}"
if __name__ == "__main__":
if len(sys.argv) == 3:
main(sys.argv[1], int(sys.argv[2]))
else:
print "Usage: python split.py MAIN.tex NUMBER"