Attaching patch with suggested modifications. The file include_bib.py is a modified version of IncludeBib.py first created by Manolo Martínez (user SchAirport) and posted on trac as part of ticket #4624 (http://www.lyx.org/trac/ticket/4624) and this has been approved by the author for modification and release under GPL v2 in a previous email.
I hereby grant permission to license my contributions to LyX under the Gnu General Public Licence, version 2 or later. @Vincent: > >+ if len(sys.argv) >= 3: > >+ outputfile = str(sys.argv[2]) > > Shouldn't this be 2 then ? IIUC, should be >2 or >=3. This creates the outputfile name if one is not supplied. My python isn't very good but argv[0] should be the script name itself unless the python shell has been invoked. Then argv[1] == inputfile Thanks, Manoj On Tuesday 02 March 2010 11:16:46 am Vincent van Ravesteijn - TNW wrote: > >+ > >+# author user SchAirport on trac > > I'm not sure what to do with this. > > >+def make_bbl(name): #Creates .bbl from .tex > >+ arg = "bibtex " + name[:-4] #name[:-4] is the name of the file > > without extension > > >+ os.system(arg) > >+ > > This is not necessary (and wrong). The bbl file is generated anyway, and > we might have specified a custom bibtex command. > > >+ > >+def insert_bib(name,outputfilename): #Inserts the contents of the > > .bbl file instead of the bibliography in a new .tex file > > >+ fileold = name[:-4] + ".tex" #The old .tex file > >+ texfile = open(fileold, 'r') > > The filename is supplied as the first parameter to the script right, so > there is no need to do this. > > >+def make_clean(name): #Cleans files created in the process > >+ extensions = ['aux', 'bbl', 'blg', 'dvi', 'log', 'spl'] > >+ files = [f for f in os.listdir(os.getcwd()) if os.path.isfile(f)] > > #puts every filename in the current directory in a list > > >+ filesinteresting = [f for f in files if name[:-4] in f] #Every > > file with the same name as the original file > > >+ for f in filesinteresting: > >+ overall = sum([(f[-3:]==ext) for ext in extensions]) #Is 1 if > > f has any of the extensions, 0 otherwise > > >+ if overall: > >+ os.remove(f) > > This is not necessary, we're working in the temp directory anyway. > > >+ if len(sys.argv) >= 3: > >+ outputfile = str(sys.argv[2]) > > Shouldn't this be 2 then ? > > >+\Format ltxbib tex "LaTeX (plain,embed bib)" "" "" "%%" > > "document" > > > \Format pdflatex tex "LaTeX (pdflatex)" "" "" "%%" > > "document" > > >+\Format pdfltxbib tex "LaTeX (pdflatex,embed bib)" "" "" > > "%%" "document" > > Why, maybe again, do we need a pdflatex version ? > > >- scripts/tex_copy.py > >+ scripts/tex_copy.py \ > >+ scripts/inline_bib.py > > A little glitch. I guess we keep this file sorted alphabetically, but > don't hold me to that. > > Vincent
Index: scripts/inline_bib.py =================================================================== --- scripts/inline_bib.py (revision 0) +++ scripts/inline_bib.py (revision 0) @@ -0,0 +1,49 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# file inline_bib.py +# This file is part of LyX, the document processor. +# Licence details can be found in the file COPYING. + +# author Manolo Martínez +# author Manoj Rajagopalan (modifications) + +# Full author contact details are available in file CREDITS + +import sys, os, shutil + +def insert_bib(inputfilename,outputfilename): #Inserts the contents of the .bbl file instead of the bibliography in a new .tex file + #fileold = name[:-4] + ".tex" #The old .tex file + texfile = open(inputfilename, 'r') + texlist = texfile.readlines() + for i,line in enumerate(texlist): + if "\\bibliography" in line: + break + else: + beginning = texlist[0:(i+1)] #This will be the part of the file before the bibliography + end = texlist[(len(beginning)+2):] #Ditto for the part after the bibliography + bblfilename = inputfilename[:-4] + ".bbl" #the name of the .bbl file we have created + bblfile = open(bblfilename, 'r') + bbllist = bblfile.readlines() + newtexlist = beginning + bbllist + end + # outputfile may be same as inputfile so write to temp + tempfilename = inputfilename[:-4] + "-bibinc.tex" #The new .tex file + tempfile = open (tempfilename, 'w') + for line in newtexlist: + tempfile.write(line) + texfile.close() + tempfile.close() + bblfile.close() + shutil.move(tempfilename, outputfilename) + + +if __name__ == "__main__": + inputfile = str(sys.argv[1]) + inputfile = inputfile.replace(' ', '\ ') #For a good parsing of spaces in file names + if len(sys.argv) >= 3: + outputfile = str(sys.argv[2]) + outputfile = outputfile.replace(' ', '\ ') #For a good parsing of spaces in file names + else: + outputfile = inputfile + insert_bib(inputfile,outputfile) + Index: doc/UserGuide.lyx =================================================================== --- doc/UserGuide.lyx (revision 33608) +++ doc/UserGuide.lyx (working copy) @@ -34841,6 +34841,52 @@ \begin_inset space ~ \end_inset +(pdflatex,embed +\begin_inset space ~ +\end_inset + +bib) +\family default +Like +\family sans +LaT +\begin_inset ERT +status collapsed + +\begin_layout Plain Layout + +{} +\end_layout + +\end_inset + +eX +\begin_inset space ~ +\end_inset + +(pdflatex) +\family default +but with bibliography items embedded into the LaTeX source code. +\end_layout + +\begin_layout Description + +\family sans +LaT +\begin_inset ERT +status collapsed + +\begin_layout Plain Layout + +{} +\end_layout + +\end_inset + +eX +\begin_inset space ~ +\end_inset + (plain) \family default text file with the LaTeX source code, additionally all images used in the @@ -34853,6 +34899,52 @@ \end_layout \begin_layout Description + +\family sans +LaT +\begin_inset ERT +status collapsed + +\begin_layout Plain Layout + +{} +\end_layout + +\end_inset + +eX +\begin_inset space ~ +\end_inset + +(plain,embed +\begin_inset space ~ +\end_inset + +bib) +\family default +Like +\family sans +LaT +\begin_inset ERT +status collapsed + +\begin_layout Plain Layout + +{} +\end_layout + +\end_inset + +eX +\begin_inset space ~ +\end_inset + +(plain) +\family default +but with bibliography items embedded into the LaTeX source code. +\end_layout + +\begin_layout Description LyX \begin_inset space ~ \end_inset Index: configure.py =================================================================== --- configure.py (revision 33608) +++ configure.py (working copy) @@ -507,7 +507,9 @@ \Format sweave Rnw "Sweave" S "" "%%" "document" \Format lilypond ly "LilyPond music" "" "" "%%" "vector" \Format latex tex "LaTeX (plain)" L "" "%%" "document" +\Format ltxbib tex "LaTeX (plain,embed bib)" "" "" "%%" "document" \Format pdflatex tex "LaTeX (pdflatex)" "" "" "%%" "document" +\Format pdfltxbib tex "LaTeX (pdflatex,embed bib)" "" "" "%%" "document" \Format xetex tex "LaTeX (XeTeX)" "" "" "%%" "document" \Format text txt "Plain text" a "" "%%" "document" \Format text2 txt "Plain text (pstotext)" "" "" "%%" "document" @@ -817,6 +819,8 @@ \converter clyx lyx "python -tt $$s/lyx2lyx/lyx2lyx -c big5 $$i > $$o" "" \converter jlyx lyx "python -tt $$s/lyx2lyx/lyx2lyx -c euc_jp $$i > $$o" "" \converter klyx lyx "python -tt $$s/lyx2lyx/lyx2lyx -c euc_kr $$i > $$o" "" +\converter latex ltxbib "python -tt $$s/scripts/inline_bib.py $$i $$o" "needaux" +\converter pdflatex pdfltxbib "python -tt $$s/scripts/inline_bib.py $$i $$o" "needaux" ''') Index: Makefile.am =================================================================== --- Makefile.am (revision 33608) +++ Makefile.am (working copy) @@ -1187,6 +1187,7 @@ scripts/fig2pdftex.py \ scripts/fig2pstex.py \ scripts/fig_copy.py \ + scripts/inline_bib.py \ scripts/layout2layout.py \ scripts/legacy_lyxpreview2ppm.py \ scripts/listerrors \