# How to alter sort order to place online url references at the end of the bibliography?

I wish to place less weight on @misc entries in my bibliography by moving them at the end, after academic conference publications. I like the way abbrvnat presents the bibliography items otherwise. I'm also using natbib to get number citations and compaction.

By default it sorts citations by author names (which is fine), and when no author name is available, it seems to be using something else (title?) as a sort field in the bibliography.

What's the easiest way to send all the @misc references at the end of the document, while keeping their relative order?

An example document:

\documentclass[11pt]{article}
\usepackage[hyphens]{url}
\usepackage[numbers,sort&compress]{natbib}

\begin{document}

Website: \cite{example}

\bibliographystyle{abbrvnat}
\bibliography{biblio}

\end{document}

\bibliographystyle{myabbrvnat}
\bibliography{biblio}


Example biblio:

@misc{example,
howpublished = {\url{http://example.org/}},
note = {Accessed: June 2017.}
}

@article{bogus,
title = {A Bogus Article},
year = {1993},
}

title   = {The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})},
year    = {1993},
journal = {TUGBoat},
volume  = {14},
number  = {3},
pages   = {342--351}
}


In that example, I would like the website to move to the end of the list. If there are multiple websites, then their relative order should be kept.

Given that you are willing to alter the bibliography file, you can use the well-known \noopsort workaround (see https://tex.stackexchange.com/search?q=noopsort) to sort the misc entries after the rest. Because sorting is performed on author, you should also change the title field of the misc entries to author. For this solution you don't need to change the .bst-file.

Example:

@PREAMBLE{ {\providecommand{\noopsort}[1]{}} }

@misc{example,
howpublished = {\url{http://example.org/}},
note = {Accessed: June 2017.}
}


Result:

Alternatively, using biblatex it can be done without changing the bibliography file, by printing separate reference sections based on type. Adapted from https://tex.stackexchange.com/a/6966:

\printbibliography[nottype=misc,title={References}]
\vspace{-6mm}


Small problem here is that the second bibliography section, even without heading, still introduces some extra space that needs to be removed (for example with a negative vspace).

• Obviously not "well-known" enough. Ironic. Well-supported? Thank you! Will try. Much simpler. The unmodified abbrvnat BST provides support on a field called "key" (different than the cite key), but for some reason, when the "author" field is missing, the "key" field is displayed in the final output, so I couldn't use it. – init_js Jul 4 '17 at 1:01
• I'll have to check out the rules of expansion on that one. Presumably, {\noopsort{foo} bar} is transformed/sanitized into to foo bar before it's fed through the sort function, and then expanded again after to just bar in the bbl bibitem? – init_js Jul 4 '17 at 1:10
• @init_js this kind of macro is generally used to sort author names with a separate prefix, such as de Jong, von Neumann, de l'Hôpital, according to the main name (J, N, H respectively) - but it can also be used in this case. It is mentioned in the BibTeX documentation (mirrors.ctan.org/biblio/bibtex/base/btxdoc.pdf). Regarding expansion, I'm not sure it is expanded per se, but the argument of the macro is used for sorting (and indeed discarded when typesetting, according to the macro definition). – Marijn Jul 5 '17 at 10:03

I found one way, but it requires editing the BST file. Which feels overkill. The bst file does seem to be responsible for sorting however.

I've tried first changing what I thought was the key of the entry, e.g. changing @misc{foo,...} to @misc{z-foo,...} but this had no effect at all, so I dug deeper.

## Step 1. Edit the bst file

1. copy abbrvnat.bst into the project directory ($cp /usr/share/texlive/texmf-dist/bibtex/bst/natbib/abbrvnat.bst ./myabbrtnat.bst) 2. At the top of the file, notice it says: "Works with identical authors and year are further sorted by citation key, to preserve natural sequence" Abbrvnat sorts first by authors. Which probably means it sorts with the tuple: (author(s), year, key). 3. edit the copied file: 1. In the ENTRY section, after key, add a new field called sortkey on its own line. 2. There is an author.sort function. I've modified it to handle the 'sortkey' field to override the author field: (some citation types don't use author to sort (e.g. sorted on editor), so this might need to be replicated in other places depending on your bibliography) FUNCTION {author.sort} { sortkey empty$
{ author empty${ key empty$
{ "to sort, need author or key in " cite$* warning$
""
}
{ key sortify }
if$} { author sort.format.names } if$
}
{ sortkey sortify }
if\$
}


## Step 2. Use the modified BST

1. In the main latex file: change to \bibliographystyle{myabbrvnat}

2. For each bibliography item whose order needs to be altered, add a field sortkey with the new value that should be used to determine its order. I prepend "zz-" to the name of the entry if I want to send it last.

In tex:

...
Website: F~\cite{example-f}, E~\cite{example-e}, A~\cite{example-a}
...


And biblio:

@misc{example-a,
sortkey = {axample}, % will go before others - starts with 'a'
howpublished = {\url{http://example.org/}},
}

@misc{example-e,
sortkey = {zzz-example},     % send to the back. prefix with 'zzz-'