Embedding a Bibtex publication list in a website with PHP

Posted .

Now that I have a more professional website, I wanted to include on it a list of publications. It took me a while to figure out a “good” way to do this, and many things I tried didn’t work, so here’s the solution I eventually settled on.

Maybe it can help you too!

My list of publications, though not huge yet, is stored in Bibtex format. I wanted a way to embed that nicely on a website. Since the same bibtex files feed other documents, I didn’t really want to retype them in HTML markup. Instead I wanted something which would take the data directly out of the Bibtex files and put it in a format where I could use CSS to style it myself.

Some options I found after searching for a while:

Eventually I found:

For the PHP-semi-literate (such as myself), you use it like this:

  1. Upload the files somewhere visible from the PHP page in which you want your publication list.
  2. At the top of your PHP page, add
<?php include 'bibtexParse/PARSEENTRIES.php' ?>
<?php include 'bibtexParse/PARSECREATORS.php' ?>

Where the paths indicate where you uploaded the files.
3. ParseEntries() will take a .bib file and convert it into a PHP array. It is invoked like this:

<?php
$parse = NEW PARSEENTRIES();
$parse->expandMacro = FALSE;
$parse->removeDelimit = TRUE;
$parse->fieldExtract = TRUE;
$parse->openBib("publications.bib");
$parse->extractEntries();
$parse->closeBib();
list($preamble, $strings, $entries, $undefinedStrings) = $parse->returnArrays();
?>

Where the meaning of the various parameters can be found in the documentation.
4. Then, $entries is a PHP array of bib entries which can be listed in the following way:

<?php foreach ( $entries as $entry ) { ?>
  <li class="publication">
    <?php $title = $entry["title"]; ?>
    <span class="publication-title"><?php print($title); ?></span>
  </li>
<?php } ?>

etc.
5. ParseCreators() also allows the conversion of the and-delimited list of authors in a Bibtex entry into a PHP array of author names:

<?php
$creator = new PARSECREATORS();
foreach ( $entries as $entry ) { ?>
<span class="publication-authors">
  <?php
  $authors = $creator->parse($entry["author"]);
  $author_full_names = array();
  foreach ($authors as $author) {
    $author_full_name = implode(' ', $author);
    $author_full_names[] = $author_full_name;
  }
  $author_full_names = array_map('trim', $author_full_names);
  $author_list = implode(', ', $author_full_names);
  print($author_list); ?>
<span>
<?php } ?>
  1. Since the markup is user-written, the style of the publication can be chosen at will, and can be formatted using CSS.
  2. ParseEntries() looks like it will do a bunch of Bibtex-supported things like macros and strings (which I don’t use), and also has the benefit that it can parse arbitrary “unsupported” fields. So I used a pdf = {path/to/file.pdf} field in my bibliography to include a link to a file, and a doi = {doi} field to automatically produce a link to the publication’s DOI.

Because it’s live-rendered in PHP, it would be straightforward enough to have it automatically render me a CV if I wanted. Problem solved.

I’m currently using it to generate a couple of pages on my site.

Comments

Amit

Posted at .

Thank you! I was searching for bibbase website. I used it before, but just could not remember its name!

Thank you again!

Cai Wingfield

Posted at .

Glad it was helpful! :)

To add your own comment, or reply to an existing one, email me and be clear what your comment is, what name you'd like it posted under, and if you'd like a link included (like a homepage). I may edit comments for length or clarity. If you'd like to delete an old comment or change your name, let me know.