-
Notifications
You must be signed in to change notification settings - Fork 218
/
Copy pathbuild.py
51 lines (43 loc) · 1.41 KB
/
build.py
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
import os
import fileinput
from subprocess import call
os.makedirs('built', exist_ok=True)
call_pdflatex_l = ['pdflatex', '-synctex=1',
'-interaction=nonstopmode', 'main.tex']
def clear_tex_binaries():
# clean misc files
for file in os.listdir('.'):
if file.startswith('main'):
if not file.endswith(('.tex', '.pdf')):
os.remove(file)
# build main pdf
clear_tex_binaries()
with fileinput.input('main.tex', inplace=True) as f:
for line in f:
if 'includeonly{' in line:
# comment out includeonly flag
print(f'%{line}', end='')
else:
print(line, end='')
call(call_pdflatex_l)
call(call_pdflatex_l)
os.replace('main.pdf', os.path.join('built', 'main.pdf'))
# build single chapters
chap_list = [os.path.splitext(p)[0] for p in os.listdir('tex')
if p.endswith('.tex')]
for tex_file in chap_list:
clear_tex_binaries()
with fileinput.input('main.tex', inplace=True) as f:
for line in f:
if 'includeonly{' in line:
# specify chapter to render
print(f'\\includeonly{{tex/{tex_file}}}')
else:
print(line, end='')
call(call_pdflatex_l)
call(call_pdflatex_l)
call(call_pdflatex_l)
os.replace('main.pdf', os.path.join('built', tex_file + '.pdf'))
print('Done processing:')
for p in chap_list:
print(' ', p)