0

I was using this procedure to display publications on my webpage. After implementing it all, I discovered that when I populated the .bib file, the resulting display was sorting everything in random year order. Also, some entries would have the same year but would still have their own categories, meaning instead of seeing all publications from 2011 listed under 2011, one would see some entries under 2011 and then others under another 2011 at a random place. Since I cannot fix that code after trying for some time, I am now looking for anything that would reverse sort entries from my .bib files by year, so I could display publications on my webpage.

I have seen other solutions that talk about reverse sorting citations in a LaTeX document but in this case, I am not citing anything so I do not want to create a .tex document and then \cite all my publications, just so I can see them.

How do I reverse sort my publications in a .bib file to be displayed on my webpage?

  • You can use bibtool or Biber to sort a .bib file, see tex.stackexchange.com/q/426341/35864. For bibtool you'd use bibtool -S --sort.format='{%4d($year)}' -i bibsort.bib -o bibsorted.bib – moewe Apr 25 '18 at 4:14
  • For Biber you need to add replace the two <sort order="_"> blocks with one block of the form <sort order="1" sort_direction="descending"><sortitem order="1">year</sortitem></sort>. – moewe Apr 25 '18 at 4:21
1

You can sort an existing .bib file descending by year with Biber.

Create a file called ydsort.conf with the following contents.

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <output_align>true</output_align>
  <output_fieldcase>lower</output_fieldcase>
  <sortingtemplate name="tool">
    <sort order="1" sort_direction="descending">
      <sortitem order="1">year</sortitem>
    </sort>
  </sortingtemplate>
</config>

Then call Biber in tool mode

biber --tool --configfile=ydsort.conf <yourbibfile>.bib

this will produced a sorted file called <yourbibfile>_bibertool.bib

The standard Biber --tool mode caveats apply: Prevent `biber --tool` from removing non-standard fields in .bib files. Only fields known in the data model will survive tool mode (so if you use fields that are not recognised by the standard data model, you will have to make them known to Biber in a custom data model, see gusbrs' answer).


You could also try the BibTool programme. I don't have it installed on my system, but I'm lead to believe that

bibtool -S --sort.format='{%4d($year)}' -i <yourbibfile>.bib -o <yourbibfile>_sorted.bib

might be what you want.

Depending on your OS you may need to use double quotes (") instead of single quotes (') here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.