8

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

1
  • 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. Commented Mar 31, 2015 at 17:28

1 Answer 1

10

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).

5
  • Perfect, I had a suspicion that it was the duplicate$, swap$ or * urldate *, which was giving me the headache. Thanks alot!
    – TobiasDK
    Commented Mar 31, 2015 at 10:48
  • The comma can be removed by another trick: here. Maybe your suggestion is cleaner.
    – JHBonarius
    Commented Mar 2, 2018 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
    Commented Mar 2, 2018 at 10:26
  • When using this approach, I get the result: The Engineering ToolBox, 2015: Density and Specific Weight of Air at Standard Atmospheric Pressure ­ SI Units. (Accessed: engineeringtoolbox.com/air-density-specific-weight-d_600.html), with no date. What gives? Commented Apr 4, 2022 at 13:05
  • For this to work, "urldate" needs to be included as an ENTRY in the .bst file (maybe this is trivial but I was struggling with it for hours). Commented Apr 4, 2022 at 14:20

You must log in to answer this question.

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