I'd like a tool that, when given a .bib file and a key from that file as inputs, outputs a plain text rendition of the full entry. For example:


  author =   {Amos Tversky and Daniel Kahneman},
  title =    {Extension versus intuitive reasoning: The conjunction fallacy in probability judgement},
  journal =      {Psychological Review},
  year =     1983,
  volume =   90,
  pages =    {293--315}}


me@computer > magictool bib.bib tversky83
> Tversky, Amos, and Daniel Kahneman. "Extensional versus intuitive reasoning: The conjunction fallacy in probability judgment." Psychological review 90 (1983): 293--315.

Does such a tool exist? If not, could you give me some pointers on how to build one? Presumably it would involve parsing the bib file in much the same way that bibtex does.

  • 1
    I guess you could generate a tex file that consisted only of the citation (with the appropriate formatting commands in preamble) and then compile it, and then use pdftotext to create a plain text version. But that seems a long way round. – Seamus Nov 8 '12 at 13:01
  • 2
    Gimme ten minutes, I'll try to write one. :) – Paulo Cereda Nov 8 '12 at 13:04
  • @PauloCereda That's the spirit! – Seamus Nov 8 '12 at 13:04
  • Just remembered that Pandoc can manage references, so it might be worth looking at how that does it. Although pandoc is written in Haskell, so that might be more trouble than it's worth! – Seamus Nov 8 '12 at 13:13
  • 2
    There are Perl libraries that can parse BibTeX syntax (see, for example, search.cpan.org/~ambs/Text-BibTeX-0.66/lib/Text/BibTeX.pm) – Loop Space Nov 8 '12 at 13:25

Disclaimer: I'm not sure if this is the droid tool you are looking for. :) I wrote it in my lunch time, so it might be very buggy. But we do love problematic software, don't we? :)

Introducing fred1:

Fred 1

The idea here is to behave exactly Seamus' idea: given a bibfile and a key, return the desired entry, if any. fred is written in Java, but here I created a shellscript file to call it for me:


while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd -P "$( dirname "$SOURCE" )" && pwd )"
java -jar "$DIR/fred.jar" $*

Credits to Joseph Wright for this awesome script.

The usual call to fred would be:

$ java -jar fred.jar <bibfile> <key>

Consider the following .bib file:

  author = {Bruce Perens and Eric Steven Raymond},
  title = {Open Source Initiative},
  year = {1998},
  note = {Nonprofit corporation with global scope formed to educate about and
    advocate for the benefits of open source and to build bridges among
    different constituencies in the open source community.},
  url = {http://www.opensource.org/}

  author =   {Amos Tversky and Daniel Kahneman},
  title =    {Extension versus intuitive reasoning: The conjunction fallacy
             in probability judgement},
  journal =  {Psychological Review},
  year =     1983,
  volume =   90,
  pages =    {293--315}

Now let's simply call fred on my references.bib file:

Fred 2

How did I set the output format? fred uses a local (not global) configuration file written in the YAML format which determines how the output should look like. Let's see my sample config.yaml file:


- type: MISC
  format: '$!{author}. $!{title}.'

- type: ARTICLE
  format: '$!{author}. "$!{title}". $!{journal} ${volume} (${year}): ${pages}.'

type is related to, well, the type of the BibTeX entry (article, book, technical report, and so forth), while format holds the template used to print the entry. The template is written using the Apache Velocity template engine. I could add some more complex verifications (e.g, if the field is empty, suppress the next punctuation symbol), but the template would become quite complex for a simple example. The only "advanced" part of this template is the use of the "silent" fallback for variables, that is, the ${author} variable will be resolved to the author field of the BibTeX entry, and stay as it is if the field is absent. If I use $!{author}, an empty variable is not displayed.

Let's now run fred again:


It's important to observe that the author field is treated as it is. I would have to include a static method for parsing each author and display their names accordingly. I'll try to write some helper methods for this feature in the near future, but for now, it's what I can offer - after all, I wrote it in my lunch time. :)

If we try to print an invalid key:

Fred 4

fred is available in its own GitHub repository, under the Downloads section. Note that fred requires the Java Virtual Machine, at least from version 1.5 on. The shellscript file is also provided, make sure to include both fred and fred.jar files at the same folder, and add it to the system path.

Hope you guys like this humble tool. :)

  1. fred was formely known as horned owl (blame percusse). :) An exercise for the reader: find out what fred means. Hint: ask Andrew Stacey. :)
  • I wish my lunch-times were this productive! – Seamus Nov 8 '12 at 15:27
  • 1
    Clearly you had the wrong date services.w3.org/… – David Carlisle Nov 8 '12 at 15:40
  • @DavidCarlisle: ♥ – Paulo Cereda Nov 8 '12 at 15:43
  • 1
    Another tool! Paulo's productivity ---> \infty :-) – user11232 Nov 8 '12 at 15:47

Here is a Perl program template that can be used to extract any parts of the entry based on the key:

#! /usr/bin/env perl

use warnings;
use strict;
use feature qw(say);
use Text::BibTeX;

die "Usage $0 <bibfile> <key>\n" if @ARGV != 2;
my $fn=shift;
my $key=shift;

my $bibfile = new Text::BibTeX::File($fn);

while (my $entry = new Text::BibTeX::Entry($bibfile)) {
  if (!$entry->parse_ok) {
    warn "error in input";
  my $ckey = $entry->key; 
  if (defined $ckey) {
    my $title="<no title found>";
    if ($ckey eq $key) {
      if ($entry->exists ('title')) {
        $title = $entry->get ('title');
      say "$key : '$title'";
say "Key '$key' was not found.";

We here extract the title of the entry with the given key as an example. (Note: You must have installed the libbtparse-dev package on Ubuntu... that is run: sudo apt-get install libbtparse-dev)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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