8

I am using natbib (+ BibTeX). Some entries in my bibliography file (.bib) have the field doi, some have url and some have both. I would like to edit the bibliography style file (.bst) so that, if doi is available, url is suppressed.

At the moment, the .bst file has the functions:

FUNCTION {format.doi}
{ doi empty$
    { "" }
    {
      new.block
      "\doi{" doi * "}" *
    }
  if$
}

FUNCTION {format.url}
{
  url
  duplicate$ empty$
    { pop$ "" }
    { "\urlprefix\url{" swap$ * "}" * }
  if$
}

[I was looking for a solution to this problem and found some similar questions and answers. However, they didn't address this specific case. After searching and trying, I could solve it. I present the solution as a reply for my own question to document it.]

0

1 Answer 1

6

You can achieve it by testing if doi is empty inside the function format.url. Replace your format.url by the following:

FUNCTION {format.url}
{
  doi empty$
    {    
      url
      duplicate$ empty$
        { pop$ "" }
        { "\urlprefix\url{" swap$ * "}" * }
      if$
    }
    { "" }
  if$
}
3
  • Would you mind editing the answer and pointing to the .bst file? Where is it usually? Can it be a custom add-on file, integrated while compiling the .tex and .bib source files? Jul 18, 2018 at 9:31
  • @NikosAlexandris, I don't mind, but I don't think this edition is needed in order to answer the question. The question is about a achieving a specific goal, not about how to use a .bst file.
    – toliveira
    Jul 19, 2018 at 6:40
  • It does not work for me. The error message reads: [9] (somefilename.bbl [10] ! Undefined control sequence. l.122 \urlprefix \url{http://www.globtemperature.info/}. The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., \hobx'), type I' and the correct spelling (e.g., I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.` Any hints? Jul 20, 2018 at 16:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .