# What should I change in a bst file in order to have numbered entries in the bibliography?

I am using BibTeX with a specific bibliography style (a bst file) which I can't give up.

I need to edit the .bst file in order to get entry numbering. This .bst file is an author-year citation style bibliography, which requires to work with the harvard.sty

I tried to compare plain.bst [entries are numbered within square brackets] to alpha.bst [entries appears with the nick from the bib file as a prefix], thinking I will find the required change this way, but with no luck.

With the above bst file my entries looks like (articles, for example):

LastName, FirstName, year, Title, Journal ...    volume, pages
LastName, FirstName, 2ndAuthorFullName, year, Title, Journal, bla bla bla bla bla
bla bla bla bla bla ...


while I need it to look like this (the numbering is the main issue here) (similar to plain.bst):

[1] LastName, FirstName, year, Title, Journal, volume, pages

[2] LastName, FirstName, 2ndAuthorFullName, year, Title, Journal, bla bla bla bla bla
bla bla bla bla bla ...


The numbers are only for the list of items and NOT for citation. [Alan Munn]

I can't go to latex or replace my .bst file due to compatibility required.

What can be done?

• What is this mysterious .bst file? It might be helpful if you provided it (or a link to it) along with a minimal example (or here).
– jon
Oct 28 '13 at 3:52
• jon- Thank your for your comment. I've just added a link to the post. I hope it would help. Oct 29 '13 at 17:46
• Are the numbers used for citations too, or are they just to number the items in the bibliography itself? Oct 29 '13 at 18:51
• Alan Munn- Thank you for you inquiry. The numbers are only for the list of items and NOT for citation. Oct 29 '13 at 19:16
• Ok. This has been asked twice before: Natbib + BibTeX: How can you show the bibliography in order of appearance AND numbered? and Harvard style citations with numbered bibliography but unfortunately there are no good answers. It's a good question. This is easy to with biblatex but non-trivial with natbib I think. Oct 29 '13 at 19:40

Here's a way (code courtesy of Alan Munn).

\begin{filecontents}{\jobname.bib}
@book{Labov1972,
Author = {William Labov},
Publisher = {University of Pennsylvania Press},
Title = {Sociolinguistic Patterns},
Year = {1972}}

@book{Chomsky1957,
Author = {Noam Chomsky},
Publisher = {Mouton},
Title = {Syntactic Structures},
Year = {1957}}
\end{filecontents}

\documentclass{article}
\usepackage{natbib,etoolbox,lipsum,hyperref}

\bibliographystyle{MyBstFile}

% increase \bibhang to take care of the numbers
\setlength{\bibhang}{2pc}
\makeatletter
% patch \@lbibitem to print the current number before the authors
\patchcmd{\@lbibitem}
{]}
{][\theNAT@ctr] }
{}{}
\makeatother

\begin{document}

\cite{Chomsky1957,Labov1972} \lipsum[2]

\bibliography{\jobname}

\end{document}


I added hyperref just to be sure that the anchors are correctly set (they are).

This simple patch has the defect that numbers are not aligned to the last digit. For this a more complicated route should be taken: I decided to write in the aux file the last number, so we can set the widest label at the next run.

Thanks to Alan Munn for providing meaningful references.

\begin{filecontents}{\jobname.bib}
@book{Labov1972,
Author = {William Labov},
Publisher = {University of Pennsylvania Press},
Title = {Sociolinguistic Patterns},
Year = {1972}}

@book{Chomsky1957,
Author = {Noam Chomsky},
Publisher = {Mouton},
Title = {Syntactic Structures},
Year = {1957}}

@article{Barker1998,
Author = {Chris Barker},
Journal = {Natural Language \& Linguistic Theory},
Pages = {679-717},
Title = {Partitives, Double Genitives and Anti-Uniqueness},
Volume = {16},
Year = {1998}}

@book{Berwick1985,
Author = {Berwick, Robert C.},
Publisher = {MIT Press},
Title = {Acquisition of syntactic knowledge},
Year = {1985}}

@phdthesis{Carlson1977,
Author = {Carlson, Gregory N.},
School = {University of Massachusetts, Amherst},
Title = {Reference to Kinds in {E}nglish},
Year = {1977}}

@book{Carlson1995,
Editor = {Carlson, Gregory N. and Pelletier, Francis Jeffrey},
Publisher = {Chicago University Press},
Title = {The Generic Book},
Year = {1995}}

@article{Chierchia1998,
Author = {Gennaro Chierchia},
Journal = {Natural Language Semantics},
Pages = {339-405},
Title = {Reference to Kinds across Languages},
Volume = {6},
Year = {1998}}

@book{Crain1998,
Author = {Crain, Stephen and Thornton, Rosalind},
Publisher = {The MIT Press},
Title = {Investigations in {U}niversal {G}rammar: A Guide to Experiments on the Acquisition of Syntax and Semantics},
Year = {1998}}

@article{Dayal2004,
Author = {Dayal, Veneeta},
Journal = {Linguistics and Philosophy},
Number = {4},
Pages = {393--450},
Title = {Number Marking and (In)Definiteness in Kind Terms},
Volume = {27},
Year = {2004}}

@article{Dobrovie-Sorin1998b,
Author = {Carmen Dobrovie-Sorin and Brenda Laca},
Journal = {Actes de Langues et Grammaires},
Pages = {165-179},
Title = {La g{\'e}nericit{\'e} entre la r{\'e}f{\'e}rence {\a} l'esp{\e}ce et la quantification g{\'e}n{\'e}rique},
Volume = {III},
Year = {1998}}
\end{filecontents}

\documentclass{article}
\usepackage{natbib,etoolbox,lipsum,hyperref}

\bibliographystyle{MyBstFile}

% increase \bibhang to take care of the numbers (adjust at will)
\setlength{\bibhang}{2pc}
\makeatletter
% patch \@lbibitem to print the current number before the authors
\patchcmd{\@lbibitem}
{]}
{]\bbl@box{\theNAT@ctr} }
{}{}
% add to the aux file the information about the last number
\apptocmd{\endthebibliography}
{\if@filesw\write\@mainaux{\string\bbl@lastnumber{\theNAT@ctr}}\fi}
{}{}
% allocate a length, set to a provisional value
\newlength{\bbl@lastnumberwd}
\setlength\bbl@lastnumberwd{0pt}
% this command will be in the aux file and sets the widest label width
\newcommand\bbl@lastnumber[1]{%
\settowidth\dimen@{[#1]}%
\global\bbl@lastnumberwd\dimen@}
% a command to print the number
\newcommand{\bbl@box}[1]{%
\makebox[\bbl@lastnumberwd][r]{[#1]}%
}
\makeatother

\begin{document}

\cite{Chomsky1957,Labov1972} \lipsum[2]

\nocite{*}

\bibliography{\jobname}

\end{document}


• Thanks, it is very nice. However, I use \usepackage{harvard}, and the combination with the above returns lots of error messages like: Command \harvarditem already defined. } and like: Command \harvardright already defined. \newcommand\harvardright{\NAT@close} Oct 29 '13 at 22:23
• Just don't load harvard and keep natbib. Oct 29 '13 at 22:43
• @Different111222 There's no reason for using harvard, which is an old (and buggy) package, whereas natbib can do the same things and is compatible with your .bst file. Oct 29 '13 at 22:59