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:
bib.bib
@Article{tversky83,
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}}
CLI
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.
Best Answer
Disclaimer: I'm not sure if this is the
droidtool 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
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:Credits to Joseph Wright for this awesome script.
The usual call to
fred
would be:Consider the following
.bib
file:Now let's simply call
fred
on myreferences.bib
file: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 sampleconfig.yaml
file:type
is related to, well, the type of the BibTeX entry (article, book, technical report, and so forth), whileformat
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 theauthor
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
is available in its own GitHub repository, under the Downloads section. Note thatfred
requires the Java Virtual Machine, at least from version 1.5 on. The shellscript file is also provided, make sure to include bothfred
andfred.jar
files at the same folder, and add it to the system path.Hope you guys like this humble tool.
:)
fred
was formely known ashorned owl
(blame percusse).:)
An exercise for the reader: find out whatfred
means. Hint: ask Andrew Stacey.:)