From 5325aff4e1964e10233430a2dbea74ae87d20ec0 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 11 Oct 2010 21:37:59 -0300 Subject: [PATCH] =?utf8?q?Ordenar=20alfab=C3=A9ticamente=20las=20referenci?= =?utf8?q?as?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Makefile | 1 + bibsort.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100755 bibsort.py diff --git a/Makefile b/Makefile index 5613fcb..5912026 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ latex: @sed -i 's/, \\py@release//' build/latex/sphinx.sty @sed -i '/-makeindex/d' build/latex/Makefile @cp manual.cls build/latex/ + @./bibsort.py @echo @echo "Build finished; the LaTeX files are in build/latex." @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \ diff --git a/bibsort.py b/bibsort.py new file mode 100755 index 0000000..547a0b1 --- /dev/null +++ b/bibsort.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +import re + +fname = 'build/latex/tesis.tex' + +bib_re = re.compile(r'(\\begin{thebibliography}{[^}]+})' + r'(.*)' + r'(\\end{thebibliography})', + re.S) + +text = file(fname).read() + +head, body, foot = bib_re.findall(text)[0] + +body = '\n'.join( + sorted( + body + .replace('\n', '') + .replace('\\bibitem', '\n\\bibitem') + .splitlines() + ) + ) + +text = bib_re.sub('\n'.join((head, body, foot)).replace('\\', '\\\\'), text) + +#print text +file(fname, 'w').write(text) + -- 2.43.0