[Tex/LaTex] order the list of reference by lead author(ignore others), then publish year

bibtexsorting

How to edit the .bst file to order reference by only lead author then publishing year. Most of refercence style order all the authors first.
I try to edit the FUNCTION {sort.format.names} in .bst file, but not familiar with the syntax.

Best Answer

I can't remember the logic with complete certainty, but I think you've found the right function to edit. The .bst syntax is slightly ... odd, but the key couple of lines in plain.bst are:

  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    {
    ...
    }
  while$

(this is from plain.bst – many other .bst files are derived from this). I suspect that, as a quick hack, if you were to replace that first line with

#1 'numnames :=

then the function would go round the loop only once, and so would add only a single name to the sort key, which would get the effect you're looking for.


To give you an idea of what's going on, the way that BibTeX works here is that:

  1. The ITERATE {presort} call iterates through all of the entries that are to be processed, calling the presort function on each. The presort function, you'll see, defines the magic value sort.key$ for each entry.

  2. The SORT call sorts all the entries in alphabetical order of their sort.key$.

  3. The ITERATE function (which is called twice after SORT, in plain.bst) then runs through each of the entries again, this time in their sorted order. The ITERATE{call.type$} call is what actually writes out the .bbl file, since it calls the function article, or inproceedings, or whatever, as appropriate.

The authoritative documentation for this is in the file btxhak.pdf, which might be on your system already, or which you can find at CTAN.