Bibtex DOI – Adding Retrieved from URL When DOI is Absent in Model5-names.bst

bibliographiesbibtexdoi

I would like to add "Retrieved from URL address" when DOI is missing for online articles in the bibliography of model5-names.bst (elsarticle.cls). This is in accordance with the APA 6th style.

For example:

Kanizsa, G. (1976). Subjective contours. Scientific American, 234(4), 48–52. Retrieved from http://www.address.edu (when doi is missing)

rather than:

Kanizsa, G. (1976). Subjective contours. Scientific American, 234(4), 48–52.

Thank you.

Best Answer

To get the desired output, you need to change the \URLprefix macro (to change the prefix before the URL string), the print.url function (to suppress printing if a non-empty doi string is present), and the fin.entry function (to suppress the . at end of the formatted entry.

  • Change the instruction (ca. line 1686)

    "\providecommand{\URLprefix}{URL: }"
    

    to

    "\providecommand{\URLprefix}{Retrieved from }"
    
  • Change the print.url function (starts ca. line 995) from

    FUNCTION {print.url}
     {url duplicate$ empty$
       { pop$ "" }
       { new.sentence
         urlprefix "\url{" * swap$  * "}" *
       }
       if$
     }
    

    to

    FUNCTION {print.url}
     {url duplicate$ empty$
       { pop$ "" }
       { doi empty$
         { new.sentence
           urlprefix "\url{" * swap$  * "}" * }
         { pop$ "" }
         if$
       }
       if$
     }
    

    The new code chunk checks if the doi field is empty; only if that's the case, the formatted contents of the url field are printed.

  • Change the fin.entry function so that it looks like this (this will suppress printing a . if either a doi or a url field is non-empty, incorporating your earlier query):

    FUNCTION {fin.entry}
    { doi empty$
        { url empty$
          { add.period$ }
          { }
          if$ 
        }
        { }
      if$
      write$
      newline$
    }
    

Addendum: Here's an MWE (minimum working example) that has two bib entries: one with both url and doi fields, and one with only a url field. If both fields are present, only the doi is printed; if only a url field is present, it's printed out, prefixed by "Retrieved from URL address ". (A separate comment: the modified bst file incorporates your earlier two requests as well: (i) showing the number field, in parentheses, and (ii) no period at end of entry if doi field is printed.)

enter image description here

\RequirePackage{filecontents}
\begin{filecontents}{mybib.bib}
@article{abc,
   author  = "Anne Author",
   title   = "An entry with both doi and url fields",
   journal = "Thoughts",
   year    = 3001,
   volume  = 1,
   number  = 2,
   pages   = "3-4",
   url     = "http://xyz.com",
   doi     = 12345678,
}

@article{def,
   author  = "Annie Author",
   title   = "An entry with only a url field",
   journal = "Thoughts",
   year    = 3002,
   volume  = 5,
   number  = 6,
   pages   = "7-8",
   url     = "http://xyz.com",
}
\end{filecontents}

\documentclass{article}
\bibliographystyle{mymodel5}
\usepackage{url,natbib}
\begin{document}
\nocite{*}
\bibliography{mybib}
\end{document}
Related Question