SIDEBAR
»
S
I
D
E
B
A
R
«
If you don’t know, I’m not going to tell you
July 17th, 2006 by teragram

If you don’t know what a PERL script is, or what bibtex is, you should probably stop reading now 🙂

I’ve written a little script that converts a bibtex file into HTML. You can copy and paste entries from the HTML, but you can also link to a specific entry using an anchor. So, for example, my evoting bibliography page contains the following entry, about half way down:

@ARTICLE{ Lillington02,
author = {Karlin Lillington},
title = {Electronic vote poses big security risk},
journal = {The Irish Times},
note = {Fri, Oct 18, 02},
}

If you click on this link:
http://www.cs.nuim.ie/~mmcgaley/bibliography.bib.html#Lillington02, it’ll take you straight there.

The script assumes that the bibtex file is well formed. For that purpose, I can’t recommend JabRef highly enough. A graphical interface for editing bibtex files. Genius!

Anyway here’s my script. Feel free to copy/modify/correct it.

#! /cygdrive/c/Perl/bin/perl
#
# A PERL script that takes a bibtex file as input and creates a file called
# .bib.html which should be a html file that can be copied and
# pasted into a bib file.
#
# Written by Margaret McGaley (mmcgaley@cs.nuim.ie) in an afternoon.
# No guarantees or even promises.
#
# WARNING: If the file
.bib.html already exists, this will overwrite
# it
#
# Feel free to copy and/or modify.

# Take the first argument to be the filename we want to htmlise
$filename = $ARGV[0];

# If it's not called .bib, exit with an error
if (!($filename =~ /\w+\.bib/)) {
die "Please specify a bibtex file.";
}

# Try to open the file
open $infile, $filename or die "Can't find file $filename. Quitting ...";

open $outfile, ">$filename.html" or die "Failed to open output file. Quitting.";

print "Printing html to $filename.html";

print $outfile "< !DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
print $outfile "$filename.html\n";
print $outfile "\n";
print $outfile "\n";
print $outfile "\n\n";
print $outfile "

This HTML was created from $filename using htmliser.pl Each bibentry can be linked with #key.

";

while (< $infile>) {
# This is attempting to match
# @ { ,
if (/(\s*@\w+\{)([\w:]+),/) {
print $outfile "

$1 $2,\n";
}
# This should match
# =
elsif (/\s*\w+\s*=\s*[\w{}]\s*,?\s*/) {
print $outfile "
    ", $_;
}
# Closing brace
elsif (/\s*}\s*/) {
print $outfile "
$_

\n";
}
else {
print $outfile "

", $_, "

\n";
}
}

print $outfile "\n\n";


One Response  
Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

»  Substance:WordPress   »  Style:Ahren Ahimsa