See the script posted here:
http://www.lyx.org/trac/ticket/4624
Note that there are problems when there is more than one bibliography.
There is a script included in LyX 2.1 beta 1. Look in lib/scripts/include_bib.py.
The general idea is that to produce a PDF file, LyX copies your .lyx file and .bib file to a temporary folder, generates the .tex and runs pdflatex (or other) on it and bibtex. Then LyX copies the pdf back to the destination. You need to tell LyX to also copy the bbl, which is in the temporary folder. The way to do this is to create a converter. See Help > Customization for more information.
A quick and dirty way is to view as PDF, then (without closing LyX), find LyX's temporary folder (see Tools > Preferences > Paths for the root location).
What do .bbl
files do?
.bbl
files are the intermediate data format used to make .bib
entries usable in a LaTeX file. Their format and exact use differs between biblatex
and BibTeX-based systems.
For BibTeX-based systems (e.g. natbib
) the .bbl
file contains a thebibliography
environment that can be typeset directly. Usually thebibliography
is a glorified enumerate
environment with a few extra \label
-like commands. The .bbl
file is (essentially) \input
by \bibliography{...}
and typeset as is. The format and contents of the .bbl
file are controlled by the .bst
you gave in \bibliographystyle
in your document. BibTeX's .bbl
files can be easily edited by hand, indeed the 'manual bibliography method' essentially consists of writing the contents of a .bbl
directly into the document (see for example https://www.tug.org/TUGboat/tb30-1/tb94mori.pdf).
For biblatex
the .bbl
file does not contain typesettable code, instead it contains the original data in a digested format usable for biblatex
. The .bbl
file is read at the beginning of the document so that all information about all entries is available while the document is processed. Since biblatex
allows you to separate your document into several refsection
s and supports getting data from different refcontext
s, the structure of the file can be slightly more complicated than a simple list of all entries with their data. Still ultimately, biblatex
's .bbl
files are a text-based list structure that can be edited manually if need be.
See also Difference between a .bib and .bbl file for Latex, How tell LaTeX to use existing bbl file without running bibtex?. I have touched on this in Customize citation with bibulous, Making the arXiv accept a BibTeX BBL (May 2018) and Can a LaTeX file include the BibTeX file? and you will probably find many more posts on this site that explain this or mention how .bbl
s work in passing or in more detail.
Difficulties in merging several .bbl
files
One important thing to keep in mind is that both the .bbl
files for BibTeX and biblatex
are sorted. That means that you must pay attention to the sort order when you merge two .bbl
files (by whatever means).
Furthermore .bbl
files may contain data not present in the .bib
that goes beyond sorting. For biblatex
that includes name uniqueness and disambiguation data. Some more advanced author-year BibTeX styles also create year disambiguation labels like the "a" and "b" in "Knuth 1986a, Knuth 1986b" on the fly. If new entries are added, these context-dependent features may not behave as expected any more. Another example of data that is not present in the .bib
file itself and calculated by the backend are the alphanumeric labels as produced by alpha.bst
or style=alphabetic
.
For BibTeX-based .bbl
files it would be good if the output of the two .bbl
files was compatible so that the output is consistent. This is a given if both .bbl
s were produced with the same .bst
, if that is not the case, manual interventions might be needed. Since biblatex
's .bbl
files contain only data, this is not a concern for biblatex
.
Pasting the contents of .bbl
file one into file two
The simple solution to merging .bbl
files is to just copy the contents of one .bbl
file into another.
Since .bbl
files are intended as an auxiliary and temporary bridge between the .bib
and the .tex
file they are supposed to be overwritten by each BibTeX or Biber run. That means that it is tedious, if very straightforward for BibTeX and fairly straightforward for biblatex
, to make manual changes to these files.
All in all I would say this approach is viable if you have only few entries to integrate into your .bbl
file and context-sensitive data and sorting play little or no role.
Loading several .bbl
files with LaTeX
It is no problem to load several .bbl
files with BibTeX, but if you do not manipulate the involved macros, both files will produce separate bibliographies with their own numbering
\begin{document}
\cite{sarfraz,kullback}
\cite{doody,wilde}
\input{bblone.bbl}
\input{bbltwo.bbl}
\end{document}
Depending on the desired output it might be possible to hack something together that would combine the two .bbl
files (more or less) (this is just a proof of concept and absolutely not recommended, it redefines low level commands in a very naive way)
\begin{document}
\cite{sarfraz,kullback}
\cite{doody,wilde}
\makeatletter
\begingroup
% usually \begin{...}\end{...} has an implicit group, we need to get rid of that
\def\begin#1{\csname #1\endcsname}
\def\end#1{\csname end#1\endcsname}
% save the real endthebibliography and disable the end for the first bbl
\let\orig@endthebibliography\endthebibliography
\let\endthebibliography\relax
\input{bblone.bbl}
% remove the beginning and restore the end
\let\thebibliography\@gobble
\let\endthebibliography\orig@endthebibliography
\input{bbltwo.bbl}
\endgroup
\makeatother
\end{document}
With biblatex
it is possible to obtain the data from different .bbl
files as well, see How to import / print a bibliography created from a separate / external document?. But it is more complicated to get things right due to the more complex structure.
So it is theoretically possible to combine .bbl
s on the the LaTeX side, but that might get very complicated quite quickly and does not solve the issues of sorting and context dependent information.
Converting the .bbl
to .bib
My preference would be to convert the contents of your second .bbl
back to a .bib
file. With that .bib
file you can then use BibTeX or Biber as usual.
The conversion does not have to be done by hand, you can use https://text2bib.economics.utoronto.ca/ as suggested in Convert from a textplain reference to bibtex. Of course you have to double check the result and should expect to have to apply some fixes to the result, but as a first approach such a tool can be helpful. The good thing is that you only have to do this once.
There is no issue with loading several .bib
files at once, see Bibliographies from multiple .bib files.
Best Answer
I don't see how you're going to get around a lot of hand-editing to recreate a .bib file from the .bbl file. A lot of essential meta information is embedded in bib files that's not contained in bbl files:
For each and every entry, somebody competent has to decide the appropriate entry type:
@article
,@book
, something else?You'll have to assign a key to each entry. If you have the full bbl file, the keys (aka labels) of the entries should be available as the argument to each
\bibitem
. If you still have the tex file, you could (should, really) use the arguments of the\cite
commands to come up with the keys.Within each
author
field, replace,
between authors (but not between surnames and first names...) with the reserved wordand
. Replace any and all&
symbols between authors withand
. Or, if the author is a "corporate" author, surround the entire name with an extra set of curly braces.Within each
title
field (for entries of type@article
,@techreport
,@unpublished
, and@misc
), find the words that need to stay capitalized even if so-called sentence style is in effect; surround these words with curly braces.Any remaining
&
symbols (probably in the entries' titles) will need to be escaped, i.e., written as\&
.Etc.
The ordering of the entries inside a bib file is of no relevance to BibTeX. Well,
crossref
-ed entries should be placed last, but you're not likely to construct entries withcrossref
fields, right?