Processing BibTeX Files with BibTool

BibTeX can be considered the standard bibliography format for scientific wordprocessing with LaTeX. BibTeX and LaTeX form a very powerful team, but the idiosyncrasies of the BibTeX format (macros, LaTeX syntax, cross-references, and special purpose characters) render automated processing of BibTeX files rather difficult.

BibTool is an excellent tool for processing BibTeX files. BibTool can be used to normalize the citation keys, to add, modify and remove fields, to search and extract certain BibTeX entries and much more. I will show a couple of examples of my uses of BibTool in this article.

Reformatting (Pretty Printing) BibTeX files

BibTool normalizes the format of BibTeX entries, for example by neatly aligning the field names and contents in columns. You can reformat the bibliography with the following command:

bibtool bib/plessl2007a.bib -o bib/plessl2007a_pretty.bib

There are a number of parameters (e.g. print.indent=n which indents entries to column n) that allow for customizing the pretty printed output.

Extracting a single BibTeX entry by key

For extracting the BibTeX entry with key "plessl2007a" from bib/plessl.bib the following bibtool command is used:

bibtool -X plessl2007a bib/plessl.bib

BibTeX allows you to define "macros", i.e., textual replacements, with the @String command, e.g., @STRING{s-procspie={Proceedings of SPIE} }. By default BibTool does not expand macros when extracting entries from the bibliography, but copies the used macros to the output too.

Macro expansion is enabled by passing the option expand.macros = ON to BibTool as in the following example:

bibtool -X plessl2007a bib/plessl.bib -- 'expand.macros = ON'

Extracting BibTeX entries used in a specific document

BibTool can be used to generate a "minimal" BibTeX file for a given document that contains the BibTeX entries of all references used in a document. To this end, BibTool interprets the .aux file created by LaTeX which contains all information about which BibTeX files and references are used for building this document.

With the following command, you can create a custom BibTeX file containing all BibTeX entries for the document plessl2007a.tex:

bibtool -x plessl2007a.aux -o plessl2007a.bib -- 'expand.macros = ON'

This function can be useful if you would like to archive only the relevant portions of your bibliography after the final version of a publication has been completed.

Summary

BibTool is a very powerful tool and my examples only scratched the surface of what BibTool can do. I hope you have enjoyed this brief tour of BibTool and I would be interested to learn about your uses of BibTool in the comments to this article.

Written January 16th, 2007