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.

Gaijin
  • 179
  • What should be done if the doi field is non-empty? – Mico Oct 02 '15 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 02 '15 at 17:13
  • Are you OK with the way the doi field is printed (in case it's non-empty, of course)? – Mico Oct 02 '15 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 02 '15 at 17:24

1 Answers1

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}
Mico
  • 506,678
  • Thank you Mico for your effort... I followed the instructions carefully, but unfortunately didn’t work this time... – Gaijin Oct 02 '15 at 18:15
  • @Gaijin - "didn't work" isn't very specific. Do you get errors? Do you get undesired behavior? – Mico Oct 02 '15 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 02 '15 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 02 '15 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 http://www.address.com) http:// included. – Gaijin Oct 02 '15 at 19:10
  • @Gaijin - I guess I had copied the instruction string from your posting... You didn't mention the thing about no period after the URL field earlier, did you? – Mico Oct 02 '15 at 19:15
  • Sorry I didn’t mention about the period, thought you'll spot it in the example of my original post... – Gaijin Oct 02 '15 at 19:16
  • @Gaijin - I'm the worst mind-reader in the world. If you want a mind-reader, don't count on me... – Mico Oct 02 '15 at 19:18
  • Yes, my bad. I had to mention it explicitly. Lesson learned. – Gaijin Oct 02 '15 at 19:25
  • @Gaijin - I've updated my answer. – Mico Oct 02 '15 at 19:34
  • Thank you for your time and effort. I really appreciate it! However, the update you gave me for the fin.entry function still does not print the URL when there is no record for doi = {} in the bib file... :( This version removes the dot after the page numbers, but does not print the URL. DOIs print OK. – Gaijin Oct 02 '15 at 19:48
  • @gaijin - Please refer to the second entry in my MWE: it has a URL field and no doi field, and the URL shows up in the formatted output. Isn't that what you want? – Mico Oct 02 '15 at 19:54
  • It worked! You are amazing! The problems was in the spacing of the code... Got it right. Thank you immensely! – Gaijin Oct 02 '15 at 19:56