-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfigure_table_numbers.py
38 lines (32 loc) · 1.01 KB
/
figure_table_numbers.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
#!/usr/bin/env python
import re
chapters = ['abstract',
'foreword',
'acknowledgements',
'preface',
'introduction',
'eom',
'extensions',
'physicalparameters',
'parameterstudy',
'delftbicycle',
'motioncapture',
'davisbicycle',
'control',
'systemidentification']
def old2new(matchobj):
oldNum, figNum, typ = matchobj.groups()
newNum = str(int(oldNum) - 2)
return '{}.{}<{}'.format(newNum, figNum, typ)
def new2old(matchobj):
newNum, figNum, typ = matchobj.groups()
oldNum = str(int(newNum) + 2)
return '{}.{}<{}'.format(oldNum, figNum, typ)
funcs = {'new2old': new2old, 'old2new': old2new}
def convert(to):
for chapter in chapters:
with open(chapter + '.rst') as f:
text = f.read()
newText = re.sub(r'(\d*)\.(\d*) *<(fig|tab)', funcs[to], text)
with open(chapter + '.rst', 'w') as f:
f.write(newText)