6

Trying to add urldate to my bst-file.

I have the entry as:

ENTRY
  { address
    ...
    url
    urldate
    ...
    year
  }

With the two functions defining url and urldate:

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

FUNCTION {format.urldate}
{ urldate duplicate$ empty$
    { pop$ "" }
    { "~(Accessed: " * urldate * ")" * }
  if$
}

And last, the function misc:

FUNCTION {misc}
{ output.bibitem
  format.authors output
  author format.key output
  format.date "year" output.check
  date.block
  format.title output
  new.block
  howpublished "howpublished" bibinfo.check output
  format.doi output
  new.block
  format.annote output
  format.eprint output
  format.url output
  format.urldate output
  fin.entry
}

And a MWE:

\documentclass{article}
\usepackage[main=UKenglish,danish]{babel}
\usepackage{natbib}
\usepackage{filecontents,url}
\begin{filecontents*}{\jobname.bib}
@misc{DenTool2015,
author = {{The Engineering ToolBox}},
title = {{Density and Specific Weight of Air at Standard Atmospheric Pressure -- SI Units}},
url = {http://www.engineeringtoolbox.com/air-density-specific-weight-d_600.html},
urldate = {2015-03-30},
year = {2015}
}
\end{filecontents*}

\begin{document}
\cite{DenTool2015}
\bibliographystyle{bibstyle}
\bibliography{\jobname}
\end{document}

Here is the bst-file: https://db.tt/NUW5iXqF

I get this: PDF

Here you can see two urldate entries. Hope you can help, removing the first one. /Tobias


Comment:

After the help from Boris, I got the urldate to work. If you want to edit the date-format to UK or EU standards, use the isodate packages.

Ex:

FUNCTION {format.url}
{ url duplicate$ empty$
    { pop$ "" }
    { "\url{" swap$ * "}" * 
        urldate duplicate$ empty$
        { pop$ }
        { "~(Date last accessed:~\numdate\printdate{"  swap$ * "})" * *}
      if$
    }
  if$
}

will give: pdf

  • You tagged this urlbst. Note that the .bst files generated by urlbst include a lastchecked field which is formatted in a broadly similar way to this. – Norman Gray Mar 31 '15 at 17:28
8

You have two errors in your hack.

First, you leave urldate on stack after your if$ statement. This is how you get two dates. You need to use this instance with swap$ instead of putting the third instance of urldate on stack:

FUNCTION {format.urldate}
{ urldate duplicate$ empty$
    { pop$ "" }
    { "~(Accessed: " swap$ * ")" * }
  if$
}

However, if you make this change, you will see that url and date are separated by comma: url, (Accessed: urldate). I guess it is not what you want. So I suggest deleting format.urldate altogether and putting urldate into format.url instead like this:

FUNCTION {format.url}
{ url duplicate$ empty$
    { pop$ "" }
    { "\url{" swap$ * "}" * 
        urldate duplicate$ empty$
        { pop$ }
        { "~(Accessed: "  swap$ * ")" * *}
      if$
    }
  if$
}

This takes care of the case where you have urldate but not url (a good software must gracefully deal with users' mistakes).

The result is

The Engineering ToolBox, 2015: Density and Specific Weight of Air at Standard Atmospheric Pressure ­ SI Units. http://www.engineeringtoolbox.com/air-density-specific-weight-d_600.html (Accessed: 2015-03-30).

  • Perfect, I had a suspicion that it was the duplicate$, swap$ or * urldate *, which was giving me the headache. Thanks alot! – TobiasDK Mar 31 '15 at 10:48
  • The comma can be removed by another trick: here. Maybe your suggestion is cleaner. – JHBonarius Mar 2 '18 at 10:03
  • btw, I would suggest a space, rather then a ~, because I don't see why a line break woudn't be allowed there. – JHBonarius Mar 2 '18 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.