# [Tex/LaTex] hack for including doi in agsm bibliography style

bibtexdoiharvard-style

Is there a way of including a doi in agsm bibliography style? I know I can create my own file using latex makebst but I was hoping there was a way of altering the agsm.bst file to include doi in the references. Is there a way?

You could proceed as follows:

• Find the file agsm.bst in your TeX distribution. Make a copy of this file and call the copy, say, agsmdoi.bst. (Don't edit the file agsm.bst directly.)

• Open the file agsmdoi.bst in a text editor. The editor you use to edit your .tex files will do fine.

• You first need to add a field type named doi. To this effect, find the ENTRY list (it starts on ca. line 20 of the file). Find the lines

    chapter
edition


and insert the line

    doi


between these two lines.

• Find the function write.url. (It'll should start around line 162.)

After this function, insert the following code in the file to define a new function named write.doi:

FUNCTION {write.doi}
{ doi empty${ "" } { new.block "doi: " doi * "" * } if$
}


If you want to use a prefix other than doi:, change the string to whatever suits your needs.

• Next, find the following group of four lines in each of about 14 functions -- starting with FUNCTION {article} and ending with FUNCTION {unpublished} -- that serve to format and typeset the contents of these entry types:

  new.block
note output
fin.entry
write.url


Assuming that you want the contents of the entry's doi field to by typeset after note but before url, you should insert the line

  write.doi output


between the lines that say note output and fin.entry; repeat up to 13 times. I suppose that if you know for sure that your bibliography will never contain entries of type mastersthesis or phdthesis, say, you can skip editing the corresponding functions. Likewise, if you know that certain entry types never have a doi field, you needn't edit the corresponding functions.

• Save the file agsmdoi.bst either in the same directory where your main tex file is stored or in a directory that's searched by BibTeX. If you choose the latter method, be sure to update the filename database of your TeX distribution.

• Use the modified bibliography style by issuing the command \bibliographystyle{agsmdoi}. Run LaTeX, BibTeX, and LaTeX twice more to propagate all changes.

Here's a self-contained MWE (minimum working example) that uses the agsmdoi bibliography style. Note that I don't load the harvard package but, instead, both the natbib and har2nat packages; doing so provides full compatibility with the hyperref package (if that's needed). Note further the use of the \url{...} wrapper around the contents of the doi field. Providing this wrapper allows line breaks and provides a mechanism for making the doi string clickable if the hyperref package is loaded as well. Observe that this treatment is somewhat specific to working with the bibliography styles of the harvard package. If you used a style such as plainnat you should not provide an \url wrapper for doi fields.

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@incollection{abcd:2013,
author = "Torben G. Andersen and Tim Bollerslev and Peter F. Christoffersen and Francis X. Diebold",
title = "Chapter 17 --- {Financial Risk Measurement for Financial Risk Management}",
editor = "George M. Constantinides and Milton Harris and Ren{\'e} M. Stulz",
publisher = "Elsevier",
year = "2013",
volume = "2, Part B",
pages = "1127-1220",
series = "Handbook of the Economics of Finance",
issn = "1574-0102",
doi = "\url{http://dx.doi.org/10.1016/B978-0-44-459406-8.00017-2}",
url = "http://www.sciencedirect.com/science/article/pii/B9780444594068000172",
}
\end{filecontents*}
\usepackage[margin=1.5in]{geometry}
\usepackage{natbib,har2nat,url}
\urlstyle{same}
\bibliographystyle{agsmdoi}
\begin{document}
\noindent
\citet{abcd:2013}
\bibliography{\jobname}
\end{document}