[Tex/LaTex] How to change in a bst file in order to have numbered entries in the bibliography

bibtexharvard-style

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

This is a link to the .bst file. [jon]

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?

Best Answer

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

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

@book{Chomsky1957,
    Address = {The Hague},
    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).

enter image description here

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,
    Address = {Philadelphia},
    Author = {William Labov},
    Publisher = {University of Pennsylvania Press},
    Title = {Sociolinguistic Patterns},
    Year = {1972}}

@book{Chomsky1957,
    Address = {The Hague},
    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,
    Address = {Cambridge, MA},
    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,
    Address = {Chicago},
    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,
    Address = {Cambridge, Massachusetts},
    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}

enter image description here