I have finally written a little Python script that does what I needed.
It takes a blablablah.lyx file as input, one that calls a .bib file, and
outputs blablablah-bibinc.tex, a .tex file that has the bibliography in
the form of /bibitems. This is the version I would submit to journals.
Anyway, just in case anyone else finds it helpful.
Cheers,
Manolo
Manolo Martínez escribió:
not sure, I understood your problem. If you don't want to share the
whole bib-file all.bib, but only the references cited in cited.bib,
and your document is doc.lyx you could e.g. use JabRef as a reference
manager and say on a command line
jabref --aux doc.aux,cited.bib all.bib
after having exported your doc.lyx to doc.tex by using file>export>latex
You would share cited.bib with your colleagues
This is already an improvement from what I was doing, thank you. It's
not a matter of sharing more or less files. Rather, as you surely
know, many scientific journal have pretty strict requirements on the
formatting of bibliography. So you come up with a .bst that suits your
needs but, then, if you are to submit a .tex paper, you just cannot
send it using your carefully arranged format. Or else you need to send
the .bst as well, and trust the LaTeX competence of your correspondent.
That's why I was saying that a way to resolve the references into the
.tex (or .lyx) document as already formatted /bibitems would be nice.
Anyway, thanks for your help. Cheers,
Manolo
import sys, os
def LyxtoTeX(n): #Exports .lyx files to .tex
argument = "lyx -e latex " + n
os.system(argument)
def CreateBbl(n): #Creates .aux and .bbl from .tex
argument = "latex " + n[:-4] #n[:-4] is the name of the file without extension
os.system(argument)
argument = "bibtex " + n[:-4]
os.system(argument)
def InsertBib(n): #Inserts the contents of the .bbl file instead of the bibliography in a new .tex file
fileold = n[:-4] + ".tex" #The .tex file we have created
tex = open(fileold, 'r')
texlist = tex.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
bblfile = n[:-4] + ".bbl" #the name of the .bbl file we have created
bbl = open(bblfile, 'r')
bbllist = bbl.readlines()
newtexlist = beginning + bbllist + end
filenew = n[:-4] + "-bibinc.tex" #The new .tex file
endfile = open (filenew, 'w')
for line in newtexlist:
endfile.write(line)
def CleanFiles(n): #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 n[:-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)
if __name__ == "__main__":
inputfile = str(sys.argv[1])
inputfile = inputfile.replace(' ', '\ ') #For a good parsing of spaces in file names
LyxtoTeX(inputfile)
CreateBbl(inputfile)
InsertBib(sys.argv[1])
CleanFiles(sys.argv[1])