]> git.llucax.com Git - z.facultad/75.00/informe.git/blob - bibsort.py
Mejorar resaltado de pseudocódigo
[z.facultad/75.00/informe.git] / bibsort.py
1 #!/usr/bin/env python
2
3 import re
4
5 fname = 'build/latex/tesis.tex'
6
7 bib_re = re.compile(r'(\\begin{thebibliography}{[^}]+})'
8                 r'(.*)'
9                 r'(\\end{thebibliography})',
10                 re.S)
11
12 text = file(fname).read()
13
14 head, body, foot = bib_re.findall(text)[0]
15
16 body = '\n'.join(
17                 sorted(
18                         body
19                                 .replace('\n', '')
20                                 .replace('\\bibitem', '\n\\bibitem')
21                                 .splitlines()
22                 )
23         )
24
25 text = bib_re.sub('\n'.join((head, body, foot)).replace('\\', '\\\\'), text)
26
27 #print text
28 file(fname, 'w').write(text)
29