How to Extract Used Entries From BibTeX Files

From korrekt.org

Jump to: navigation, search
Apr 21 2012

 

When using BibTeX to create bibliographies with LaTeX, it is convenient to work with one large bib file that defines all relevant references, and that is re-used again and again in new LaTeX projects. Sometimes, however, such a large file is unwieldy, and you want to create a smaller file that contains only the entries that you have actually used in a document. I am hereby releasing a powerful software suite for solving this problem: BibDigest.

This is a one-page shell script bibdigest.sh that digests a bibfile and spits out the entries that are used in a particular latex document. Using it is very simple:

bibdigest.sh bibfile.bib file.aux > newbib.bib

If you need more detailed instructions, you will find them below. You must compile the LaTeX document before doing this (or you won't have an aux file). The digested bibliography will then end up in newbib.bib (which will be overwritten mercilessly when running the above). Any comments and declarations before the first entry will be preserved, the rest may be eaten. The input files are not touched. If you use crossrefs, you should run bibtex with parameter -min-crossrefs=1 first and run latex again thereafter; otherwise crossrefs are not preserved and must be added manually after digesting.

Related Works

You may also want to have a look at the very useful latexpand script, which allows you to combine multiple source files into one, possibly adding used bibliography entries into the tex file. It can even strip comments from LaTeX.

Detailed Instructions

In detail, here is what you need to do:

  • Download and store the file bibdigest.sh
  • This is a script; you can read it in any text editor – or you can trust me blindly.
  • Open a terminal (you will need bash, sed and grep; most operating systems come with this pre-installed; however, Windows users may need to install this manually).
  • Navigate to the directory of your LaTeX project by typing:
cd /path/to/your/latex/files
  • Now run:
bash /path/to/your/downloaded/bibdigest.sh bibfile.bib file.aux > newbib.bib
where bibfile.bib is your biliography file and file.aux is the aux file of your LaTeX project (thus called file.tex).


That is all. If you do this a lot, you could also install the script (under Linux) as usual:

  • Make it executable:
chmod 755 /path/to/your/downloaded/bibdigest.sh
  • Copy it to a location where your system will look for it:
sudo cp /path/to/your/downloaded/bibdigest.sh /usr/loca/bin/
  • From now on, you can just type:
bibdigest.sh bibfile.bib file.aux > newbib.bib

Disclaimer and Contact

This is free software. Use at your own risk. If you have any improvements (crossref support? better preservation of comments?), I am happy to update the script.

Comments and feedback for this article can be sent to me via email: markus at this domain.

enNote:How to Extract Used Entries From BibTeX Files


Personal tools