[Tex/LaTex] How to modify apalike.bst to sort references chronologically

apa-stylebibtexsorting

I want to sort chronologically a list of references using the apalike.bst style, since this order seems more natural for showing in a CV. I tried to follow the approach outlined in https://tex.stackexchange.com/a/33332/56546 but without success (I really do not understand too much about .bst syntax). Any help on how to conveniently hack apalike.bst to do the job?

PS. I know that I can perform this switching to the biblatex package, but for the moment I would like to solve the problem without it, since I am using multibib.

EDIT: The kind of sorting I am looking for is: 1) by year of publication; 2) by alphabetical order of the author's surnames. I do not care about sorting by month after year in 1), but it is OK.

Best Answer

I modified the apalike.bst entry for bib.sort.order and merely swapped sort.label (which had been first) with year field.or.null sortify, to read as

FUNCTION {bib.sort.order}
{ year field.or.null sortify
  "    "
  *
  sort.label
  *
  "    "
  *
  title field.or.null
  sort.format.title
  *
  #1 entry.max$ substring$
  'sort.key$ :=
}

Thus, with the following MWE,

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{junk.bib}
@ARTICLE{bake67,
        TITLE   = "Prediction and scaling of reflected impulse from
                        strong blast waves",
        AUTHOR  = "Baker, W. E.",
        JOURNAL = "International Journal of Mechanical Sciences",
        VOLUME  = "9",
        NUMBER  = "1",
        PAGES   = "45--51",
        YEAR    = "1967"                        }
@ARTICLE{Acme72,
        TITLE   = "Prediction and scaling of reflected impulse from
                        strong blast waves",
        AUTHOR  = "Acme, W. E.",
        JOURNAL = "International Journal of Mechanical Sciences",
        VOLUME  = "9",
        NUMBER  = "1",
        PAGES   = "45--51",
        YEAR    = "1972"                        }
@ARTICLE{cake71,
        TITLE   = "Prediction and scaling of reflected impulse from
                        strong blast waves",
        AUTHOR  = "Cake, W. E.",
        JOURNAL = "International Journal of Mechanical Sciences",
        VOLUME  = "9",
        NUMBER  = "1",
        PAGES   = "45--51",
        YEAR    = "1971"                        }
@ARTICLE{Delta71,
        TITLE   = "Prediction and scaling of reflected impulse from
                        strong blast waves",
        AUTHOR  = "Delta, W. E.",
        JOURNAL = "International Journal of Mechanical Sciences",
        VOLUME  = "9",
        NUMBER  = "1",
        PAGES   = "45--51",
        YEAR    = "1971"                        }
\end{filecontents}
\begin{document}
cite \cite{bake67, Acme72, cake71, Delta71}
\bibliographystyle{apalike}
\bibliography{junk}
\end{document}

I get the following result, sorted by year and, within a year, by surname:

enter image description here

If you wish the reverse order (chronologically descending), then the line near the end of the apalike.bst file that reads

ITERATE {call.type$}

must be changed to

REVERSE {call.type$}

Of course, this means that, within a given year, surnames will likewise be sorted in reverse order, too (alphabetically backwards).


When using the original definition, which was

%                               Now that the label is right we sort for real,
%                               on sort.label then year then title.  This is
%                               for the second sorting pass.
FUNCTION {bib.sort.order}
{ sort.label
  "    "
  *
  year field.or.null sortify
  *
  "    "
  *
  title field.or.null
  sort.format.title
  *
  #1 entry.max$ substring$
  'sort.key$ :=
}

the result is sorted by surname as

enter image description here