As researchers, we sometimes write manuscripts collectively and remotely in
LaTeX (or in a lightweight markup languages
that is converted into LaTeX at some point). In such case, it is quite
useful to let co-authors edit their own bib file in order to store the references included in the part of the manuscript they are editing. One way to deal with several bib files is to merge them into one bib file before compiling the final document to pdf. In this note, I exemplify how to do so.
Let’s assume that there are two bib files within the manuscript folder:
kevcaz.bib file, my own list of references;author.bib, my colleague’s references list.
I added these two files below:
click to display kevcaz.bib
Click here to download it.
| |
click to display coauthor.bib
Click here to download it.
| |
Then, what I want is to merge them into one single file biblio_sorted.bib (the
one to be used as reference data base for the manuscript) and I also want to
remove all duplicates before the merge. How to do so? Well, that is the king of
situation where bibtool comes in handy.
This command line tool allows several manipulations of .bib files and here I
use it to merge two bib file, sort the entries in alphabetical order and
remove all duplicates with single line of command:
| |
Where :
- option
-ssorts entries in alphabetical order; - option
-dcomments out duplicates - option
-oindicate the name of the output files.
Below is the final file with two comments of my own:
click to display biblio_sorted.bib
Click here to download it.
| |
Pretty neat, isn’t it? Plus, if you are familiar with
Makefiles,
it is easy to add this to your compilation process so that each time your bib
file is edited, the manuscript database will be edited will be updated 😃!
I find this way quite convenient as it allows co-author to edit the list of
reference without worrying about potential conflicts in this list.
Three final remarks to conclude this post:
have a look at
man bibtool, there are several options to explore, for instance-Sto sort entries in reverse order;the approach described above will work seamlessly if all the authors edit the keys of the entries in the same way (as above), otherwise another step is required to standardize these keys;
there are alternative ways to deal with several
bibfiles directly in the LaTex file. For instance, the macro\addbibresourceof thebiblatexpackage, see this answer on .