2 # -*- coding: utf-8 -*-
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
8 # authors Richard Heck and [SchAirport]
10 # Full author contact details are available in file CREDITS
15 def __init__(self, start = -1, end = -1):
19 class BibError(Exception):
20 def __init__(self, msg):
27 def InsertBib(fil, out):
28 ''' Inserts the contents of the .bbl file instead of the bibliography in a new .tex file '''
30 texlist = open(fil, 'r').readlines()
32 # multiple bibliographies
36 for i, line in enumerate(texlist):
37 if "\\bibliographystyle" in line:
39 elif "\\bibliography" in line:
41 elif "\\begin{btSect}" in line:
42 raise BibError("Cannot export sectioned bibliographies")
44 filenew = fil[:-4] + "-bibinc.tex" #The new .tex file
47 raise BibError("Cannot export multiple bibliographies.")
49 raise BibError("No biliography found!")
52 newlist = texlist[0:bibpos]
53 bblfile = fil[:-4] + ".bbl"
54 bbllist = open(bblfile, 'r').readlines()
56 newlist += texlist[bibpos + 1:]
58 outfile = open(out, 'w')
59 outfile.write("".join(newlist))
64 if __name__ == "__main__":
65 newfile = InsertBib(sys.argv[1], sys.argv[2])
66 print "Wrote " + newfile