Set links on custom bibtex-keys with bibtex OR biblatex

Long time ago, while working on my thesis I fumbled with bibtex (do NOT do this) that creates bibliographies from *.bib files using a horrible stack-based scripting language for the styling. I wanted to have references directly linked to the matching articles in the web as many scientific journals do, see e.g. Nature Materials (hyperlink in blue):

nmat-citation

Citation style of Nature Materials

You can do that either by using the URL directly or resolve the digital object identifier (DOI) via dx.doi.org. DOIs are very useful, if you can get them. See e.g. this article.

So my task was to implement that using bibtex (biblatex was not very common at that time). I succeeded, by introducing some linker function, named link_it, which was able to set an appropriate link on some sequence of bibtex-keys that were processed with bibtex. For technical details look at the custom style file unsrtnat_abbrv_link_it.bst on pastebin.com and search for that linker-function. Also see this article. However, here is how it looks like (hyperlink in green):

citation-bibtex-natbib

BibTeX reference using the style file unsrtnat_abbrv_link_it.bst found at http://pastebin.com/ux6eMuMq

and here is how you use it:

...
\usepackage[numbers,sort&compress]{natbib}
\bibliographystyle{unsrtnat_abbrv_link_it}
...
\begin{document}
...
\small{\bibliography{bibtex}}
\end{document}

Quite simple, apart from the difficulties altering the style file. However, every slight change involves stack-based horrors again, so better use the new approach with the biblatex package. For later works I used that with great success, so this is what I wanted to share with you today.

The result with the near-default style with the linker-function in it looks somewhat different from the one of natbib (hyperlink again in green):

Reference style created by the biblatex package

A bit longer is the piece of code that you have to add to your Header.tex file. But note, that you only need LaTeX-code here. Customization does not involve bibtex-style files! Okay, some of you might say that LaTeX code is also horrible to write at some deeper level. That’s true. But if you take this as an argument towards old-style bibtex, I would just say, you know nothing [John Snow].

...
\usepackage[
backend=bibtex8,
style=numeric-comp,
sorting=none,
hyperref=true,
natbib=true,
doi=false,url=false,isbn=true,
backref=false,
maxnames=4,maxcitenames=1
]{biblatex}
% bibliography file
\addbibresource{biblatex.bib}
% clear some fields
\AtEveryBibitem{
\clearfield{day}\clearfield{month}
\clearfield{issn}
\clearlist{language}
}
% define a link format for arbitrary bibtex keys
\newbibmacro{link_it}[1]{%
\ifhyperref{
% if hyperref is used, set doi/url links
\iffieldundef{doi}{
% if not url and not doi, print without link
\iffieldundef{url}{#1}
% use url only if doi is NOT present
{\href{\thefield{url}}{#1}}
}
% if doi is present, set a link on the key
{\href{http://dx.doi.org/\thefield{doi}}{#1}}
}
% if no hyperref, do not link
{#1}
}
% format settings
\DeclareFieldFormat[book,incollection]{isbn}{% set url link on ISBN
\mkbibacro{ISBN}\addcolon\space \usebibmacro{link_it}{#1}}
\DeclareFieldFormat[misc]{note}{\usebibmacro{link_it}{#1}}
\DeclareFieldFormat[article]{volume}{#1}
\DeclareFieldFormat[article]{number}{\mkbibparens{#1}} % number in brackets
\DeclareFieldFormat[article]{pages}{#1} % do not add anything to pages
\renewbibmacro{in:}{} % suppress "in:"
% define a "volume(number):pages" key
\newbibmacro*{volume+number+eid}{%
\usebibmacro{link_it}{
\printfield{volume}
\printfield{number}
\setunit{\addcolon}
\printfield{pages}
}
\clearfield{pages} % pages used, where not intended, clear field
}
% use "et al."
\DefineBibliographyStrings{ngerman}{
andothers={et\addabbrvspace al\adddot}}
....
\begin{document}
...
{\small\printbibliography}
\end{document}

I’m very hapy with this now. Another pro for biblatex is, that you only have to compile once, not twice, to update your bibliography. You may also have multiple bibtex-ressource files.

Feel free to comment or to use the code above. As always: everything CC BY-NC-SA🙂

About

Peter Pan. Kann fliegen mit Feenstaub.

Tagged with: , , , ,
Posted in Technik

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Posts by topic…
…by month
Have a look at…


%d bloggers like this: