2 # This file is part of LyX, the document processor.
3 # Licence details can be found in the file COPYING.
5 # authors Richard Heck and [SchAirport]
7 # Full author contact details are available in file CREDITS
12 def __init__(self, start = -1, end = -1):
16 class BibError(Exception):
17 def __init__(self, msg):
24 def InsertBib(fil, out):
25 ''' Inserts the contents of the .bbl file instead of the bibliography in a new .tex file '''
27 texlist = open(fil, 'r').readlines()
29 # multiple bibliographies
33 for i, line in enumerate(texlist):
34 if "\\bibliographystyle" in line:
36 elif "\\bibliography" in line:
38 elif "\\begin{btSect}" in line:
39 raise BibError("Cannot export sectioned bibliographies")
41 filenew = fil[:-4] + "-bibinc.tex" #The new .tex file
44 raise BibError("Cannot export multiple bibliographies.")
46 raise BibError("No biliography found!")
49 newlist = texlist[0:bibpos]
50 bblfile = fil[:-4] + ".bbl"
51 bbllist = open(bblfile, 'r').readlines()
53 newlist += texlist[bibpos + 1:]
55 outfile = open(out, 'w')
56 outfile.write("".join(newlist))
61 if __name__ == "__main__":
62 newfile = InsertBib(sys.argv[1], sys.argv[2])
63 print "Wrote " + newfile