I'm using bookdown to create an HTML gitbook from R markdown files (i.e. .Rmd
), with the default option of split_bib = TRUE
resulting in a bibliography at the end of each chapter, as well as a complete bibliography at the end of the book.
The end-of-book bibliography is in alphabetical order, but the end-of-chapter bibliographies are not. (Here's an example).
How can I arrange all reference lists alphabetically?
$(function(){
var elems = $('#refs').children('div').remove();
elems.sort(function (a, b) {
return b.id > a.id ? -1 : 1;
});
$('#refs').append(elems);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="refs" class="references">
<div id="ref-Goloboff2016">
<p>Goloboff, P. A., and S. A. Catalano. 2016: TNT version 1.5, including a full implementation of phylogenetic morphometrics. Cladistics 32:221–238.</p>
</div>
<div id="ref-Goloboff1999">
<p>Goloboff, P. 1999: Analyzing large data sets in reasonable times: solutions for composite optima. Cladistics 15:415–428.</p>
</div>
<div id="ref-Nixon1999">
<p>Nixon, K. C. 1999: The Parsimony Ratchet, a new method for rapid parsimony analysis. Cladistics 15:407–414.</p>
</div>
<div id="ref-Goloboff1997">
<p>Goloboff, P. A. 1997: Self-weighted optimization: tree searches and character state reconstructions under implied transformation costs. Cladistics 13:225–245.</p>
</div>
</div>
My solution sorts by the id
of the div
s within #refs
. You didn't specify whether you wanted to sort by surname ascending and year descending, which would necessitate something more complicated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With