Linking to Google Scholar via BibTeX and hyperref

Published on 2009-02-13 00:00:00

Clickable links in the bibliography [of scientific writings] are tons of fun, especially in the age of Digital Object Identifiers when nearly every article in any journal can be linked to. Having a pointer to the article you wanted to see pop up just by clicking on a link avoids the annoying hassle of entering volume and page numbers in various WWW forms. But where do you point your hyperlink to if (a) you are too lazy to keep track of DOIs, or (b) the paper is so obscure that it doesn’t have a DOI, [1] or (c) the reference is a book?

Google’s Scholar search is not a bad place to link to: it has a large citation database and can point you to the publisher’s online service; it knows what to do with books, too. Then comes the technical question: since you’re efficient, i.e., lazy, you already have your citations in a BibTeX file and would like to automate generating the links in a LaTeX document. How to do this?


A combination of BibTex style files (see [BTXHAK] for the gory details) and hyperref does it. You’ll need a custom BibTeX style file (.bst) with something like the following in it:

% Note the lovely stack push-pop syntax, see btxhak

INTEGERS { nameptr namesleft numnames }

FUNCTION {format.googlelinknames}
{ 's :=
  "" 't :=
  s num.names$ 'numnames :=
  #0 'nameptr :=
    { nameptr numnames < }
    { nameptr #1 + 'nameptr :=
      t quote$ * s nameptr "{ll}" format.name$ * quote$ * " "  * 't :=
    }
  while$
  t
}

FUNCTION {format.googlelink}
{ "http://scholar.google.com/scholar"
  title empty$
    { "?q=" * }
    { "?as_epq=" * quote$ * title * quote$ * "&as_occt=title" * }
  if$
  author empty$
    { }
    { "&as_sauthors=" * author format.googlelinknames * }
  if$
  journal empty$
    { }
    { "&as_publication=" * journal *
      year empty$
        { }
        { "&as_ylo=" * year * "&as_yhi=" * year * }
      if$
    }
  if$
}

FUNCTION {format.hyperlink}
{ doi empty$
     { url empty$
          { "\bibUrlHref{" format.googlelink * "}{" * }
          { "\bibUrlHref{" url * "}{" * }
       if$
     }
     { "\bibUrlHref{http://dx.doi.org/" doi * "}{" * }
  if$
}

FUNCTION {fin.hyperlink}
{ doi empty$
    { url empty$ { "}" } { "}" } if$ }
    { "}" }
  if$
}

...

FUNCTION {fin.entry}
{ add.period$
  write$
  fin.hyperlink write$
  newline$
}

...

FUNCTION {output.bibitem}
{ newline$
  "\bibitem{" write$
  cite$ write$
  "}" write$
  newline$
  format.hyperlink write$
  ""
  before.all 'output.state :=
}

...

FUNCTION {begin.bib}
{ preamble$ empty$
    'skip$
    { preamble$ write$ newline$ }
  if$
  "\begin{thebibliography}{"  longest.label  * "}" *
  write$ newline$
  "\newcommand{\enquote}[1]{``#1''}"
  write$ newline$
  "\providecommand{\bibUrlHref}[2]{\href{#1}{#2}}"
  write$ newline$
}

Above, the fin.entry, output.bibitem, and begin.bib are standard parts of makebst produced BST files.

A complete example:

However, it isn’t perfect: Google doesn’t recognize many of the various abbreviations of journal names. (Not even Phys. Rev. Lett.!) But in any case, it should be trivial to rewrite the above to use another citation database, if needed.

[1]Say, certain Soviet journals.
[BTXHAK]O. Patashnik, “Designing BibTeX Styles”. http://www.ctan.org/tex-archive/biblio/bibtex/contrib/doc/

Comments

blog comments powered by Disqus