-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathordercitations.py
More file actions
38 lines (30 loc) · 969 Bytes
/
Copy pathordercitations.py
File metadata and controls
38 lines (30 loc) · 969 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
31
32
33
34
35
36
37
38
"""
Reads in a tex file with bibitems. Prints out a ordered list of bibitems
according to their occurence in the tex file.
"""
import sys
import re
if len(sys.argv) < 2:
print "Usage: python ordercitations.py filename.tex"
else:
file = sys.argv[1]
started = False
items = {}
for line in open(file,"r"):
if line.startswith('\\end{thebibliography}'):
started = False
if started:
if line.startswith('\\bibitem'):
name = re.findall( 'bibitem{(.*?)\}', line )[0].strip(' \t\n\r')
items[name] = line
print name
if not started and line.startswith('\\begin{thebibliography}'):
started = True
cites = []
for line in open(file,"r"):
for m in re.findall( 'cite{(.*?)\}', line ):
for cite in m.split(","):
if not cite.strip(' \t\n\r') in cites:
cites.append(cite.strip(' \t\n\r'))
for c in cites:
print items[c]