BibTeX, biblatex and biberAdd DOI support to .bst file

Information and discussion about BiBTeX - the bibliography tool for LaTeX documents.
Post Reply
php1ic
Posts: 192
Joined: Wed Jan 28, 2009 8:17 pm

Add DOI support to .bst file

Post by php1ic »

Is it possible/not too complicated to add doi support to an already existing bibtex style file? I must be googling the wrong keywords as I can't seem to find much about it. I'm currently using this style
http://waugh.cchem.berkeley.edu/thesis/prsty.bst

Which styles natively support doi links? Perhaps one has a similar look and I won't need to write any low level TeX.

Thanks

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Add DOI support to .bst file

Post by localghost »

Not a solution, only a hint. Some styles of the natbib package offer a »DOI« field. Perhaps you can dig in the code and incorporate the relevant parts into the concerned style.

Alternatively you could try to mimic the style by means of the biblatex package. I'm not very familiar with that but its said to allow customizations in many ways.


Best regards
Thorsten
php1ic
Posts: 192
Joined: Wed Jan 28, 2009 8:17 pm

Add DOI support to .bst file

Post by php1ic »

This is by no means a general solution as I have only done it for articles, but I have modified the original bibtex style file so that the volume and page are a link to the address of the doi number given. My modifications require the use of the hyperref package.

I'll outline what I have done so hopefully others can modify their own bst files.

Firstly, at the top of the bst file there is

Code: Select all

ENTRY
  { address
    ...
    volume
    year
  }
  {}
  { label }
The option of a doi field needs to be added here. I think it can go anywhere, but I put it last

Code: Select all

ENTRY
  { address
    ...
    volume
    year
    doi
  }
  {}
  { label }
Next we need to tell bibtex/latex what to do with the information in this field. As mentioned I have only altered it for the articles. Here is the original code, starting on L614, with the lines I will change highlighted

Code: Select all

FUNCTION {article}
{ output.bibitem
  "author" format.authors #1 push.string.check
  "journal" journal #0 add.string.check " " *
  output
%%%%%%%%%%
  format.vol.page #0 push.string
%%%%%%%%%%
  " " *
  "date" format.date paren #0 add.string.check
  note empty$
    'skip$
    { ", " * note lc.first.letter * }
  if$
  fin.entry
  crossref empty$
    'skip$
    { "See Ref.\ \cite{" crossref "}." * * write$ newline$ }
  if$
}
Here is what I have changed it to

Code: Select all

FUNCTION {article}
{ output.bibitem
  "author" format.authors #1 push.string.check
  "journal" journal #0 add.string.check " " *
  output
%%%%%%%%%%%
  doi empty$
  {format.vol.page #0 push.string}
  {"\href{http://dx.doi.org/" doi "}{" format.vol.page "}" #0 push.string * * * *}
  if$
%%%%%%%%%%%
  " " *
  "date" format.date paren #0 add.string.check
  note empty$
    'skip$
    { ", " * note lc.first.letter * }
  if$
  fin.entry
  crossref empty$
    'skip$
    { "See Ref.\ \cite{" crossref "}." * * write$ newline$ }
  if$
}
The doi field is checked, and if it is empty the volume and page are display in the original way, if it has information in it then the \href{address}{link name} command is used with the volume and page displayed as before, but they now act as a link to the doi.

I don't understand the bibtex language well enough to fully explain, but the asterisks(*) at the end of the line concatenate the literal strings and variables. I had to use trial and error to get the correct number.

That's it, simple! ;)
Last edited by php1ic on Sun Sep 19, 2010 2:58 pm, edited 1 time in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Add DOI support to .bst file

Post by localghost »

Now that the problem seems to be solved, please be so kind and mark the topic accordingly as clearly written in the Board Rules. Otherwise tell us what is missing You are not new to the forum so by now you should know that.
Post Reply