# .bbl file confusing order

I am using TexShop on the Mac with BibDesk as my citation manager.

Here's the short version of my question, if you can answer this then no need to read on: how do I amend my .bst to sort by author, but when the Author and Year both match, to then sort according to the order in which they are cited in the article?

Now for the longer version, which includes MWEs.

Here are two MWEs, where the error occurs in the second. When authoring my MWE, I used all code referring to my bibliography as it appeared in my article.

\documentclass{article}

\usepackage{natbib,url}
\bibpunct{(}{)}{;}{a}{ }{,}

\begin{document}
Minimal working example \citep{Author:2013}.

\newpage
\bibliographystyle{myapalike-url}
\bibliography{\string~/Desktop/Test}
\end{document}


This is how it prints out:

Minimal working example (Author 2013).

The .bbl created is as follows:

\begin{thebibliography}{}

\bibitem[{Author}, 2013]{author:2013}
{Author} (2013).
\newblock {Protected Sites Map}.
\newblock Available from:
\url{http://}
[Accessed 1 October 2013].

\end{thebibliography}


As soon as I add a second reference for that year, albeit with a different citekey, the suffixing goes to pot:

\documentclass{article}

\usepackage{natbib,url}
\bibpunct{(}{)}{;}{a}{ }{,}

\begin{document}
Minimal working example \citep{author:2013}.

And another \citep{author:2013b}.

\newpage
\bibliographystyle{myapalike-url}
\bibliography{\string~/Desktop/Test}
\end{document}


Which prints out as follows:

Minimal working example (Author 2013b). And another (Author 2013a).

Notice that the first citation, which previously printed out as (Author 2013), has been amended to (Author 2013b)

The .bbl now looks like this:

\begin{thebibliography}{}

\bibitem[Author, 2013a]{author:2013b}
Author (2013a).
\newblock {Eryri}.

\bibitem[Author, 2013b]{author:2013}
Author (2013b).
\newblock {Protected Sites Map}.

\end{thebibliography}


Now, I'm aware that I'm using my own myapalike-url.bst, but that's because I have edited it (very carefully and sparsely to alter the URL).

I'm also aware that I could use a package like unsrtnat, which makes my citations appear in the same order in-text as they are input (i.e. it doesn't confuse the 'a' and 'b' suffixes), but also removes any sorting from the full bibliography. This also makes me think that it's during the generation of the .bbl file and the process of sorting that the error occurs (rather than a bad command within the .tex file).

And as I'm working this through, I think I've found the problem, but I don't know how to fix it. The citation referred to as 2013b has a Title of 'Eryri', where the citation referred to as 2013a has a Title of 'Protected Sites Map'. It appears that, if the Author is the same then it checks the Year, but if the year is the same then it checks the Title, and then sorts alphabetically.

So here's the question: how do I amend my .bst to sort by author, but when the Author and Year both match, to then sort according to the order in which they are cited in the article?

Edit:

Looking inside the .bst it says, on lines 42-43, the following:

%   24-jan-88   (OP)    Updated for BibTeX version 0.99a, from alpha.bst 0.99a;
%           apalike now sorts by author, then year, then title;


So I want to change that to sort by author, then year, then order called in article. I think you can agree, putting the first reference to an author as 2013b, and the second reference as 2013a, is just plain wrong.

• What do you mean by 'wrong'? Is there a specific style that you need to follow that uses this convention of 'author' > 'year' > 'order of citation'? (Or is it just that you'd rather have it that way?) I've never heard of it, but 'author' > 'year' > 'title' is very common. Think, too, what happens if you use the same bibliography file in another paper but end up citing them in a different order? Then the '2013a' and '2013b' (as bib keys) won't make sense in that file. Anyway, if you like forcing arbitrary bibliography arrangements, biblatex+biber makes it much easier. – jon Oct 24 '13 at 20:45
• Jon: by 'wrong' I simply mean I think it looks undesirable. Also, I think it makes a certain sense, when reading an article, to have them follow in order of citation. Take the example of Figures, it would make sense to include Figure 1 before Figure 2, and Table 1 before Table 2. However, your example of cross-referencing makes a good argument. I will consider it and look into biblatex + biber. @cbowern: You didn't actually answer the question. You told me I was wrong without any explanation. See Jon's comment for an example of an informative response. – Pwdr Oct 25 '13 at 6:45
• To each their own. To me it makes sense for references to the same author/author(s) to be sorted either chronologically and/or alphabetically. If you have ten items by 'Smith', you'll never remember if it was the 6th or 7th time you've encountered that name anyway. However, what matters about the bibliography is only providing clear information so that the interested reader can track it down for him-/herself; any internal sorting scheme is irrelevant as long as it is consistent and not confusing. So if you want to force the issue, use biblatex and the entry fields sortkey and `sortyear'. – jon Oct 25 '13 at 13:35