From 76ffbd136ae935861e8b98a9e47b3ad0957924be Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Mon, 1 Nov 2010 20:21:02 +0000 Subject: [PATCH] Add script that writes the bbl file in place of the bibliography. Part of #4624. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35971 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/scripts/include_bib.py | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 lib/scripts/include_bib.py diff --git a/lib/scripts/include_bib.py b/lib/scripts/include_bib.py new file mode 100644 index 0000000000..6c92ad449e --- /dev/null +++ b/lib/scripts/include_bib.py @@ -0,0 +1,63 @@ +# file include_bib.py +# This file is part of LyX, the document processor. +# Licence details can be found in the file COPYING. + +# authors Richard Heck and [SchAirport] + +# Full author contact details are available in file CREDITS + +import sys, os + +class secbib: + def __init__(self, start = -1, end = -1): + self.start = start + self.end = end + +class BibError(Exception): + def __init__(self, msg): + self.msg = msg + + def __str__(self): + return self.msg + + +def InsertBib(fil, out): + ''' Inserts the contents of the .bbl file instead of the bibliography in a new .tex file ''' + + texlist = open(fil, 'r').readlines() + + # multiple bibliographies + biblist = [] + stylist = [] + + for i, line in enumerate(texlist): + if "\\bibliographystyle" in line: + stylist.append(i) + elif "\\bibliography" in line: + biblist.append(i) + elif "\\begin{btSect}" in line: + raise BibError("Cannot export sectioned bibliographies") + + filenew = fil[:-4] + "-bibinc.tex" #The new .tex file + + if len(biblist) > 1: + raise BibError("Cannot export multiple bibliographies.") + if not biblist: + raise BibError("No biliography found!") + + bibpos = biblist[0] + newlist = texlist[0:bibpos] + bblfile = fil[:-4] + ".bbl" + bbllist = open(bblfile, 'r').readlines() + newlist += bbllist + newlist += texlist[bibpos + 1:] + + outfile = open(out, 'w') + outfile.write("".join(newlist)) + outfile.close() + return filenew + + +if __name__ == "__main__": + newfile = InsertBib(sys.argv[1], sys.argv[2]) + print "Wrote " + newfile