2

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.

4
  • What should be done if the doi field is non-empty?
    – Mico
    Oct 2, 2015 at 17:12
  • DOIs have precedence over URLs, so if DOI field is not empty, then it should be displayed and URL should not.
    – Gaijin
    Oct 2, 2015 at 17:13
  • Are you OK with the way the doi field is printed (in case it's non-empty, of course)?
    – Mico
    Oct 2, 2015 at 17:23
  • I've managed to modify "doi:" with code in the tex file itself like this: \newcommand{\DOIprefix}{http://dx.doi.org/} % Text before DOI number. \newcommand{\doi}[1]{\textrm{#1}} % Changes the font of DOIs. It think will do if it is left as it is in the bst file... But if you know a better way to do this, let me know!
    – Gaijin
    Oct 2, 2015 at 17:24

1 Answer 1

2

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}
13
  • Thank you Mico for your effort... I followed the instructions carefully, but unfortunately didn’t work this time...
    – Gaijin
    Oct 2, 2015 at 18:15
  • @Gaijin - "didn't work" isn't very specific. Do you get errors? Do you get undesired behavior?
    – Mico
    Oct 2, 2015 at 18:29
  • It it correctly strips down the URL when DOI is present, but it doesn’t print URL when DOI is absent... Also, there are no errors after typesetting.
    – Gaijin
    Oct 2, 2015 at 18:30
  • @Gaijin - I've posted an addendum to show the output produced by my modified bst file. Please let me know if the output is not what you're expecting -- and, if so, what you are expecting.
    – Mico
    Oct 2, 2015 at 18:46
  • The output is correct for the DOI example, but the URL in the second example has to be without the "URL" term and without the period at the end of the address (e.g., Retrieved from address.com) http:// included.
    – Gaijin
    Oct 2, 2015 at 19:10

You must log in to answer this question.

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