# Modifying agsm.bst package bibliography output

I would like to change the URL output from:

into:

[Online]URL: [Accessed on]

I am using:

\usepackage[comma]{natbib}
\bibliographystyle{agsm}


Here I have explained the step by step to modify another bst from the harvard bundle; please refer to it for the step-by-step.

agsm.bst does not provide a urldate field, so you'd have to add by yourself to a modified bibtex style. I created the agsm-url.bst from the original agsm.bst and added a urldate field to it as in this answer. The diff:

43a44
>     urldate
165c166,171
<     { "\newline\harvardurl{" URL * "}" * write$newline$ }
---
>     { "\newline\harvardurl{" URL * "}" * write$newline$
>     urldate empty$> { skip$ }
>       { "[Accessed on: " urldate * "]" * write$newline$ }
>       if\$
>     }


If you don't want the linebreak before the URL block, just delete the \newline

Then I redefined the \harvardurl macro with

\renewcommand{\harvardurl}[1]{[Online] URL: \textit{#1}}


See this answer about redefining it to add hyperlinks with hyperref

Here's a MWE:

% Adapted bib file from tugboat.bib
\begin{filecontents}{\jobname.bib}
@article{online,
author = {Robert Welland},
journal = {TUGboat},
volume = {1},
number = {1},
pages = {2--3},
month = oct,
year = {1980},
ISSN = {0896-3207},
urldate = {Fri Jul 13 10:24:20 MDT 2007},
url = {http://www.math.utah.edu/pub/tex/bib/tugboat.bib}
}
@article{offline,
author = {Richard Palais},
title = {{Message from the Chairman}},
journal = {TUGboat},
volume = {1},
number = {1},
pages = {3--7},
month = oct,
year = {1980},
}
\end{filecontents}
\documentclass{article}
\usepackage[comma]{natbib}
% natbib.sty, line 1042:
\renewcommand{\harvardurl}[1]{[Online] URL: \textit{#1}}
\begin{document}
\cite{online,offline}
\bibliographystyle{agsm-url}
\bibliography{\jobname}
\end{document}


And the output:

• Thank you for your prompt response. However I am facing a problem because of the bst file. While I am tryinf to generate the bibtex I am having an error "pte=20, stack='20---the literal stack isnt empty for entry online while executing---line 1349 of file agsm-url.bst – Kerk Aug 23 '15 at 1:10
• I tried so many alternatives by the same error keeps happening with the .bst file. I even tried the example file you posted as it is: ptr=2, stack= '20 0 ---the literal stack isn't empty for entry online while executing---line 1350 of file agsm-url.bst – Kerk Aug 23 '15 at 9:30
• I just did it again here with no errors. What I've done is: 1. I copied the diff and put it in an agsm-url.diff file; 2. I copied the agsm.bst locally with a cp kpsewhich agsm.bst agsm-url.bst; 3. I patched the new agsm-url.bst file with the diff file mentioned before with patch agsm-url.bst < agsm-url.diff; 4. I copied the MWE and compiled it perfectly. – henrique Aug 23 '15 at 23:03
• In case anybody has problems applying the patch, the patched file is at gist.github.com/moewew/6c65c256c9420d64f3b264c0a78774c0 – moewe Apr 17 '18 at 12:14