2

I'm using a .bst file provided by my university. Unfortunately, it doesn't add the urldate to my references. So I'm trying to add it manually in my .bst file.

This is the function for misc:

FUNCTION {misc}
{ output.bibitem
  format.authors output
  author format.key output
  format.date "year" output.check
  date.block
  format.title output
  end.quote.title
  % new.block
  howpublished "howpublished" bibinfo.check output
  % new.block
  format.note output
  fin.entry
  write.url
}

And this is the function for write.url:

FUNCTION {write.url}
{
  url
  duplicate$ empty$
    { pop$ }
    { "\newline\urlprefix\url{" swap$ * "}" * write$ newline$ }
  if$
}

I want to add the urldate to the function write.url. I've never done anything like this before, so I googled it, and found this question: Hack of .bst to add urldate in @misc in BibTex with natbib

I tried to replicate the result for my .bst file and added urldate to the entry, but it doesn't work. The error "you can't pop an empty literal stack…" appears. This is my code:

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

Can anybody tell me what I did wrong or how else I can add the urldate?

  • The * in newline$ * urldate looks suspicious. Does it work if you remove it? You may also want to add a few line breaks and indentation to make things more readable. – moewe Jul 14 '18 at 13:28
  • 1
    You could make it easier to help you if you could share the entire .bst file and a short example document with us (it's probably too long for the question, but you can share the plain text at pastebin.com or gist.github.com) – moewe Jul 14 '18 at 13:30
  • Also, it is duplicate$ not dublicate$. – moewe Jul 14 '18 at 13:34
  • The format.url in tex.stackexchange.com/a/236077/35864 looks promising and is very similar to what you have already. – moewe Jul 14 '18 at 13:35
  • I tried using the format.url from the link, but now it says "the literal stack isn't empty for entry…". I'm working on a MWE. – user160319 Jul 14 '18 at 14:04
1

Make FUNCTION {format.url} read

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

and use it as follows

format.url output

before fin.entry. So that the function for misc looks like

FUNCTION {misc}
{ output.bibitem
  format.authors output
  author format.key output
  format.date "year" output.check
  date.block
  format.title output
  end.quote.title
  % new.block
  howpublished "howpublished" bibinfo.check output
  % new.block
  format.note output
  format.url output
  fin.entry
}

with these changes you get

enter image description here

  • It works. Thank you so much!!! Really appreciate your fast help. – user160319 Jul 14 '18 at 14:25

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.