My colleague asked me to write a page for a paper he writes. I wrote the page in LyX, compiled it to LaTeX, and sent him the TeX files. Then he reminded me that I forgot to send the .bib file with all the references.

But, my .bib file is huge - it contains over 1000 references (I have a global BiBTeX file for all my papers). The page I wrote uses only about 20 of them.

Is there an automatic way to extract from the bib file, only the records relevant to the current paper?

  • You could send him the .bbl file (provided that you haven't used the \nocite{*} command, or else you'll get ALL your bibliography file). – Mario S. E. Oct 7 '13 at 17:01
  • 2
    JabRef can for example create a new .bib-file based on a .aux file, see tex.stackexchange.com/questions/98370/… See also tex.stackexchange.com/questions/41821/… – Torbjørn T. Oct 7 '13 at 17:02
  • @MarioS.E. I don't see any bbl file; – Erel Segal-Halevi Oct 7 '13 at 18:15
  • @TorbjørnT. I don't see any .aux file... I only have .bib and .tex . – Erel Segal-Halevi Oct 7 '13 at 18:16
  • 1
    Ah, sorry (on two counts). The .aux file is generated when you run pdflatex on the .tex file. Also, do you use biblatex as the tag suggests? In that case you probably have to add backend=bibtex as an option to the biblatex package before you compile. – Torbjørn T. Oct 7 '13 at 18:33

One solution would be to use bibtool. It only works with BibTeX though, not Biblatex.

Use the following command to extract relevant entries:

bibtool -x myfile.aux > myfile.bib
  • I see that it can extract entries from an aux file, but I don't have any aux file... LyX export creates only .tex . – Erel Segal-Halevi Oct 7 '13 at 18:17
  • 1
    Presumably you can just run e.g. latexmk on your .tex file and that will generate an .aux file. – twsh Oct 7 '13 at 21:24
  • 1
    Thanks! This is what I did: "pdflatex myfile.tex" "bibtool -x myfile.aux > myfile.bib". Probably I have BibTeX and not Biblatex (I used LyX export so I don't know). – Erel Segal-Halevi Oct 7 '13 at 21:30
  • To ensure that the keys are not converted to lowercase, I use: echo "preserve.key.case=on" > /tmp/b; bibtool -r /tmp/b -x myfile.aux > myfile.bib – Erel Segal-Halevi Jun 23 '17 at 5:55

If you want to give a bib file away only including entrys which are cited in a document use package bibexport. If you have a main TeX file mwe.tex and want to create a short bib file short.bib use:

bibexport.sh -o short.bib mwe.aux

You get an resulting bib file short.bib containing only cited/crossreferenced entrys from your main bib file.

  • 2
    I found it easier to use than bibtool, since it does not convert the keys to lowercase by default. – Erel Segal-Halevi Oct 9 '15 at 11:35

Through the compilation a file .bbl is created. There are the relevant references of your manuscript.

You could insert the content of this file directly on the .tex in the place of the bibliography (erasing the command \bibliography{....bib} of your original text).

  • 1
    +1. This is far and away the simplest solution, especially if you just use \input{foo.bbl}. – Stephan Kolassa Mar 20 '18 at 12:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.