]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/include_bib.py
Extend fix for #7404 to allow any inset collapsible to be edited
[lyx.git] / lib / scripts / include_bib.py
index cf3d453548747d4495f5b8d51504fbb58b056217..7e14d13579472dfe239d88066ab9e11d38e4ea91 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
 # file include_bib.py
 # -*- coding: utf-8 -*-
 
 # file include_bib.py
@@ -9,22 +8,26 @@
 
 # Full author contact details are available in file CREDITS
 
 
 # Full author contact details are available in file CREDITS
 
-# This script is intended to include a BibTeX-generated biblography 
+# This script is intended to include a BibTeX-generated biblography
 # in a LaTeX file, as publishers often want. It can be run manually
 # on an exported LaTeX file, though it needs to be compiled first,
 # so the bbl file will exist.
 #
 # It should also be possible to create a LyX converter to run this
 # in a LaTeX file, as publishers often want. It can be run manually
 # on an exported LaTeX file, though it needs to be compiled first,
 # so the bbl file will exist.
 #
 # It should also be possible to create a LyX converter to run this
-# automatically. To set it up, create a format "ltxbbl"; make sure to 
-# check it as a document format. Then create a LaTeX-->ltxbbl converter, 
+# automatically. To set it up, create a format "ltxbbl"; make sure to
+# check it as a document format. Then create a LaTeX-->ltxbbl converter,
 # with the command:
 # with the command:
-#   python -tt $$s/scripts/include_bib.py $$i $$0
-# and give it the "needaux" flag. You'll then have it in the export menu.
+#   python -tt $$s/scripts/include_bib.py $$i $$o
+# and give it the flags:
+#   needaux,nice
+# You'll then have it in the export menu.
+#
 # We do not activate this converter by default, because there are problems
 # when one tries to use multiple bibliographies.
 #
 # Please report any problems on the devel list.
 
 # We do not activate this converter by default, because there are problems
 # when one tries to use multiple bibliographies.
 #
 # Please report any problems on the devel list.
 
+from __future__ import print_function
 import sys, os
 
 class secbib:
 import sys, os
 
 class secbib:
@@ -40,7 +43,7 @@ class BibError(Exception):
     return self.msg
 
 
     return self.msg
 
 
-def InsertBib(fil, out):   
+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()
   ''' Inserts the contents of the .bbl file instead of the bibliography in a new .tex file '''
 
   texlist = open(fil, 'r').readlines()
@@ -48,7 +51,7 @@ def InsertBib(fil, out):
   # multiple bibliographies
   biblist = []
   stylist = []
   # multiple bibliographies
   biblist = []
   stylist = []
-  
+
   for i, line in enumerate(texlist):
     if "\\bibliographystyle" in line:
       stylist.append(i)
   for i, line in enumerate(texlist):
     if "\\bibliographystyle" in line:
       stylist.append(i)
@@ -56,7 +59,7 @@ def InsertBib(fil, out):
       biblist.append(i)
     elif "\\begin{btSect}" in line:
       raise BibError("Cannot export sectioned bibliographies")
       biblist.append(i)
     elif "\\begin{btSect}" in line:
       raise BibError("Cannot export sectioned bibliographies")
-  
+
   if len(biblist) > 1:
     raise BibError("Cannot export multiple bibliographies.")
   if not biblist:
   if len(biblist) > 1:
     raise BibError("Cannot export multiple bibliographies.")
   if not biblist:
@@ -68,21 +71,21 @@ def InsertBib(fil, out):
   bbllist = open(bblfile, 'r').readlines()
   newlist += bbllist
   newlist += texlist[bibpos + 1:]
   bbllist = open(bblfile, 'r').readlines()
   newlist += bbllist
   newlist += texlist[bibpos + 1:]
-    
+
   outfile = open(out, 'w')
   outfile.write("".join(newlist))
   outfile.close()
   return out
   outfile = open(out, 'w')
   outfile.write("".join(newlist))
   outfile.close()
   return out
-    
+
 
 def usage():
 
 def usage():
-  print r'''
+  print (r'''
 Usage: python include_bib.py file.tex [outfile.tex]
   Includes the contents of file.bbl, which must exist in the
   same directory as file.tex, in place of the \bibliography
   command, and creates the new file outfile.tex. If no name
   for that file is given, we create: file-bbl.tex.
 Usage: python include_bib.py file.tex [outfile.tex]
   Includes the contents of file.bbl, which must exist in the
   same directory as file.tex, in place of the \bibliography
   command, and creates the new file outfile.tex. If no name
   for that file is given, we create: file-bbl.tex.
-'''  
+''')
 
 if __name__ == "__main__":
   args = len(sys.argv)
 
 if __name__ == "__main__":
   args = len(sys.argv)
@@ -93,7 +96,7 @@ if __name__ == "__main__":
   # we might should make sure this is a tex file....
   infile = sys.argv[1]
   if infile[-4:] != ".tex":
   # we might should make sure this is a tex file....
   infile = sys.argv[1]
   if infile[-4:] != ".tex":
-    print "Error: " + infile + " is not a TeX file"
+    print ("Error: " + infile + " is not a TeX file")
     usage()
     sys.exit(1)
 
     usage()
     sys.exit(1)
 
@@ -103,4 +106,4 @@ if __name__ == "__main__":
     outfile = infile[:-4] + "-bbl.tex"
 
   newfile = InsertBib(infile, outfile)
     outfile = infile[:-4] + "-bbl.tex"
 
   newfile = InsertBib(infile, outfile)
-  print "Wrote " + outfile
+  print ("Wrote " + outfile)