1

I'm using the natbib package with BibTeX to manage and cite my bibliography. I want in-text citations to be cited as [2], [3], etc, which is achievable using the \bibliographystyle{unsrt}. However, I want my final bibliography to be harvard referencing (see picture below), which is only achievable if I use \bibliographystyle{agsm}. This style however changes the in-text citations to (authors, (year of publication)).

Is there a way of having my in-text citation be in the unsrt style, but the final bibliography to be in the agsm style?

enter image description here

  • 2
    And how should the reader find out which bib entry is meant by [42]? – Ulrike Fischer Nov 25 '18 at 14:53
  • Good point Ulrike. I would still need the numbers next to each citation, just the actual citation in the harvard style. I didn't mean get rid of the numbers altogether. Also, I've realised I need the unsrt style in order for my citations to be listed in the order in which they are cited, which the Harvard style agsm doesn't do. – martina Nov 25 '18 at 15:24
1

If you want the exact bibliography style that agsm gives you, but unsrt citations and sorting order you can modify agsm.bst to stop sorting.

The required changes are a bit longer than usual, so I have uploaded the new file agsm-unsrt.bst at https://gist.github.com/moewew/c4b7c0908a69b108d13b6469f09b7a07. The diff to agsm.bst is

--- agsm.bst    2009-01-30 02:49:00.000000000 +0100
+++ agsm-unsrt.bst  2018-11-25 17:42:24.054011800 +0100
@@ -1,3 +1,6 @@
+%% `agsm-unsrt.bst' (2018-11-25) for https://tex.stackexchange.com/q/461677/
+%% removed all SORT code, and added longest.label back in
+%% original copyright header follows
 % BibTeX standard bibliography style `agsm' (one of the harvard family)
    % version 0.99a for BibTeX versions 0.99a or later, LaTeX version 2.09.
    % Copyright (C) 1991, all rights reserved.
@@ -43,7 +46,7 @@
     year
   }
   { field.used etal.allowed etal.required} %%%XXX change
-  { extra.label sort.label list.year }
+  { label }

 INTEGERS { output.state before.all mid.sentence after.sentence after.block }

@@ -675,7 +678,7 @@
   if$
   make.full.label write$
   "}{" write$
-  list.year write$
+  year write$
   "}{" write$
   cite$ write$
   "}" write$
@@ -691,7 +694,7 @@
 FUNCTION {article}
 { output.bibitem
   list.label.output
-  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
+  " \harvardyearleft " year * "\harvardyearright " * output.nonnull
   author "author" item.check
   title.field field.used =
     { skip$ }
@@ -714,7 +717,7 @@
 FUNCTION {book}
 { output.bibitem
   list.label.output
-  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
+  " \harvardyearleft " year * "\harvardyearright " * output.nonnull
   author empty$
     { editor "author and editor" item.check }
     { crossref missing$
@@ -747,7 +750,7 @@
 FUNCTION {booklet}
 { output.bibitem
   list.label.output
-  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
+  " \harvardyearleft " year * "\harvardyearright " * output.nonnull
   title.field field.used =
     { skip$ }
     { format.title quote "title" output.check }
@@ -763,7 +766,7 @@
 FUNCTION {inbook}
 { output.bibitem
   list.label.output
-  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
+  " \harvardyearleft " year * "\harvardyearright " * output.nonnull
   author empty$
     { editor "author and editor" item.check }
     { crossref missing$
@@ -797,7 +800,7 @@
 FUNCTION {incollection}
 { output.bibitem
   list.label.output
-  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
+  " \harvardyearleft " year * "\harvardyearright " * output.nonnull
   title.field field.used =
     { skip$ }
     { format.title "title" output.check }
@@ -824,7 +827,7 @@
 FUNCTION {inproceedings}
 { output.bibitem
   list.label.output
-  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
+  " \harvardyearleft " year * "\harvardyearright " * output.nonnull
   title.field field.used =
     { skip$ }
     { format.title "title" output.check }
@@ -859,7 +862,7 @@
 FUNCTION {manual}
 { output.bibitem
   list.label.output
-  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
+  " \harvardyearleft " year * "\harvardyearright " * output.nonnull
   title.field field.used =
     { skip$ }
     { format.btitle "title" output.check }
@@ -884,7 +887,7 @@
 FUNCTION {mastersthesis}
 { output.bibitem
   list.label.output
-  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
+  " \harvardyearleft " year * "\harvardyearright " * output.nonnull
   author "author" item.check
   title.field field.used =
     { skip$ }
@@ -902,7 +905,7 @@
 FUNCTION {misc}
 { output.bibitem
   list.label.output
-  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
+  " \harvardyearleft " year * "\harvardyearright " * output.nonnull
   title.field field.used =
     { skip$ }
     { format.title quote output }
@@ -918,7 +921,7 @@
 FUNCTION {phdthesis}
 { output.bibitem
   list.label.output
-  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
+  " \harvardyearleft " year * "\harvardyearright " * output.nonnull
   author "author" item.check
   title.field field.used =
     { skip$ }
@@ -936,7 +939,7 @@
 FUNCTION {proceedings}
 { output.bibitem
   list.label.output
-  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
+  " \harvardyearleft " year * "\harvardyearright " * output.nonnull
   title.field field.used =
     { skip$ }
     { format.btitle "title" output.check }
@@ -968,7 +971,7 @@
 FUNCTION {techreport}
 { output.bibitem
   list.label.output
-  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
+  " \harvardyearleft " year * "\harvardyearright " * output.nonnull
   author "author" item.check
   title.field field.used =
     { skip$ }
@@ -986,7 +989,7 @@
 FUNCTION {unpublished}
 { output.bibitem
   list.label.output
-  " \harvardyearleft " list.year * "\harvardyearright " * output.nonnull
+  " \harvardyearleft " year * "\harvardyearright " * output.nonnull
   author "author" item.check
   title.field field.used =
     { skip$ }
@@ -1067,6 +1070,31 @@

 READ

+STRINGS { longest.label }
+
+INTEGERS { number.label longest.label.width }
+
+FUNCTION {initialize.longest.label}
+{ "" 'longest.label :=
+  #1 'number.label :=
+  #0 'longest.label.width :=
+}
+
+FUNCTION {longest.label.pass}
+{ number.label int.to.str$ 'label :=
+  number.label #1 + 'number.label :=
+  label width$ longest.label.width >
+    { label 'longest.label :=
+      label width$ 'longest.label.width :=
+    }
+    'skip$
+  if$
+}
+
+EXECUTE {initialize.longest.label}
+
+ITERATE {longest.label.pass}
+
 EXECUTE {init.field.constants}

 FUNCTION {sortify}
@@ -1136,198 +1164,6 @@
   if$
 }

-FUNCTION {sort.format.title}
-{ 't :=
-  "A " #2
-    "An " #3
-      "The " #4 t chop.word
-    chop.word
-  chop.word
-  sortify
-  #1 global.max$ substring$
-}
-
-FUNCTION {calc.label} %%%XXX change
-{ make.abbr.label
-  title.field field.used =
-    { sort.format.title }
-    { sortify.names }
-  if$
-  year field.or.null purify$ #-1 #4 substring$ sortify
-  *
-  'sort.label :=
-}
-
-FUNCTION {preliminaries} %%%XXX change
-{ type$ "book" =
-  type$ "inbook" =
-  or
-    'author.editor.key.label
-    { type$ "proceedings" =
-   'editor.key.organization.label
-   { type$ "manual" =
-       'author.key.organization.label
-       'author.key.label
-     if$
-   }
-      if$
-    }
-  if$
-  author.field field.used = %%%XXX change
-    {
-      author num.names$ #2 >
-        { #1 }
-        { #0 }
-      if$
-      'etal.required :=
-    }
-    {
-      editor.field field.used = 
-        {
-          editor num.names$ #2 >
-            { #1 }
-            { #0 }
-          if$
-        }
-        { #0 }
-      if$
-      'etal.required :=
-    }
-  if$
-  #1 'etal.allowed :=
-}
-
-FUNCTION {first.presort}
-{ calc.label
-  sort.label
-  title.field field.used =
-    { skip$ }
-    { "    "
-      *
-      make.list.label sortify.names
-      *
-      "    "
-      *
-      title field.or.null
-      sort.format.title
-      *
-    }
-  if$
-  #1 entry.max$ substring$
-  'sort.key$ :=
-}
-
-ITERATE {preliminaries}
-
-ITERATE {first.presort}
-
-SORT
-
-STRINGS { last.sort.label next.extra last.full.label}
-
-INTEGERS { last.extra.num last.etal.allowed}
-
-FUNCTION {initialize.confusion}
-{ #0 int.to.chr$ 'last.sort.label :=
-  #0 int.to.chr$ 'last.full.label :=
-  #1 'last.etal.allowed :=
-}
-
-FUNCTION {confusion.pass}
-{ last.sort.label sort.label =
-    { last.etal.allowed 
-        { last.full.label make.full.label sortify.names =
-            { skip$ }
-            { #0 'etal.allowed :=
-              #0 'last.etal.allowed :=
-            }
-          if$
-        }
-        { #0 'etal.allowed := }
-      if$
-    }
-    { sort.label 'last.sort.label :=
-      make.full.label sortify.names 'last.full.label :=
-      #1 'last.etal.allowed :=
-    }
-  if$
-}
-
-EXECUTE {initialize.confusion}
-
-ITERATE {confusion.pass}
-
-EXECUTE {initialize.confusion}
-
-REVERSE {confusion.pass}
-
-FUNCTION {initialize.last.extra.num}
-{ #0 int.to.chr$ 'last.sort.label :=
-  "" 'next.extra :=
-  #0 'last.extra.num :=
-}
-
-FUNCTION {forward.pass}
-{ last.sort.label sort.label =
-    { last.extra.num #1 + 'last.extra.num :=
-      last.extra.num int.to.chr$ 'extra.label :=
-    }
-    { "a" chr.to.int$ 'last.extra.num :=
-      "" 'extra.label :=
-      sort.label 'last.sort.label :=
-    }
-  if$
-}
-
-FUNCTION {reverse.pass}
-{ next.extra "b" =
-    { "a" 'extra.label := }
-    'skip$
-  if$
-  year empty$
-    { "n.d." extra.label emphasize * 'list.year := }
-    { year extra.label emphasize * 'list.year := }
-  if$
-  extra.label 'next.extra :=
-}
-
-ITERATE {first.presort}
-
-SORT
-
-EXECUTE {initialize.last.extra.num}
-
-ITERATE {forward.pass}
-
-REVERSE {reverse.pass}
-
-FUNCTION {second.presort}
-{ make.list.label
-  title.field field.used =
-    { sort.format.title }
-    { sortify.names }
-  if$
-  "    "
-  *
-  list.year field.or.null sortify
-  *
-  "    "
-  *
-  title.field field.used =
-    { skip$ }
-    { title field.or.null
-      sort.format.title
-      *
-    }
-  if$
-  #1 entry.max$ substring$
-  'sort.key$ :=
-}
-
-ITERATE {second.presort}
-
-SORT
-
 FUNCTION {begin.bib}
 { preamble$ empty$
     'skip$
@@ -1336,7 +1172,7 @@
       "\harvardpreambletext{%" write$ newline$
       preamble$ write$ "}" write$ newline$ }
   if$
-  "\begin{thebibliography}{xx}" write$ newline$
+  "\begin{thebibliography}{"  longest.label  * "}" * write$ newline$
 }

 EXECUTE {begin.bib}

Note that the new file must bear a different name than agsm.bst (and a few others) for license reasons.

There are essentially three steps here

  1. Remove the sorting code (ll. 1139-1330)
  2. Clean up loose ends from the sorting code
    • Replace all occurrences of list.year with year
    • Remove extra.label sort.label list.year
  3. Add the longest.label measurement back in (just a copy from unsrt.bst, ll. 907-930; that's the new ll. 1073-1097)

You can then use it as

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[numbers]{natbib}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{appleby,
  author  = {Humphrey Appleby},
  title   = {On the Importance of the Civil Service},
  year    = {1980},
  publisher = {C Press},
}
@book{elk,
  author  = {Anne Elk},
  title   = {A Theory on Brontosauruses},
  year    = {1972},
  publisher = {B Press},
}
@article{hacker,
  author  = {James Hacker},
  title   = {A Title},
  journal = {A Journal},
  volume  = {14},
  number  = {3},
  pages   = {110-123},
  year    = {1981},
}
\end{filecontents}


\begin{document}
\cite{elk,hacker,appleby}
\bibliographystyle{agsm-unsrt}
\bibliography{\jobname}
\end{document}

Numbered agsm bibliography, sorted by citation order

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.