[Tex/LaTex] How to sort entries in a .bib file with biber

bibersorting

My question is similar to How to sort a .bib file with biber?

I have a .bib file which is generated by Mendeley. Because it is generated, the entries are not formatted nor ordered. Also the order changes completley whenever I add something in Mendeley.

Because I use git to track changes, I want to have a sorted and formatted bib file. This would lead to nice diffs/commits where one could easily see what has changed.

I got the formatting part, but I am not able to make biber sort the file. For my task it is irrelevant what the sorting parameter is, as long as sorting two different files with the same entries leads to the same sorting. So lets assume we want to sort according to the citation key.

What I got so far is:

biber -tool C:\SomePath\unordererd.bib --output_indent=4 --output_fieldcase=lower --output-file=C:\AAAA\SomePath\output.bib

This gives me a nice format, but the entries are not sorted.

This is the output i get

INFO - This is Biber 2.3 running in TOOL mode
...
INFO - Overriding locale 'en_US' defaults 'variable = shifted' with 'variable = non-ignorable'
INFO - Overriding locale 'en_US' defaults 'normalization = NFD' with 'normalization = prenormalized'
INFO - Sorting list 'none' of type 'entry' with scheme 'none' and locale 'en_US'
INFO - No sort tailoring available for locale 'en_US'
...

Obviously, biber thinks about sorting, but does nothing about it. I also tried providing a biber.conf like in the other question, but with no success.

Solution

If someone has the same issue, this is my final config file. It also includes some filter to clean up the file:

  • it removes abstract, file, keywords and mendeley-tags fields from every entry
  • it removes url fields from some entries
<config>
  <sorting>
    <presort>mm</presort>
    <sort order="1">
      <sortitem order="1">title</sortitem>
    </sort>
    <sort order="2">
      <sortitem order="1">year</sortitem>
    </sort>
  </sorting>
  <sourcemap>
    <maps datatype="bibtex" map_overwrite="1">
        <map>
            <map_step map_field_set="ABSTRACT" map_null="1"/>
            <map_step map_field_set="FILE" map_null="1"/>
            <map_step map_field_set="keywords" map_null="1"/>
            <map_step map_field_set="mendeley-tags" map_null="1"/>
        </map>
        <map>
            <per_type>ARTICLE</per_type>
            <per_type>BOOK</per_type>
            <per_type>inproceedings</per_type>
            <per_type>incollection</per_type>
            <map_step map_field_set="URL" map_null="1"/>
        </map>    
    </maps>
  </sourcemap>  
</config>

I also added these two parameters to the commandline:

--output_indent=4 --output_fieldcase=lower

Best Answer

Actually with biber 2.3, which is what you are using, it should work with a suitable <sorting> specification in your biber.conf. There was a bug in 2.4, fixed in the 2.5 dev version currently on Sourceforge. As your log says, the default sorting in tool mode is none because people don't always want to change the order of things in their data sources if they are nicely commented etc.

Try something like this in your .conf file (pass the file name with --configfile=<file>

<config>
  <sorting>
    <presort>mm</presort>
    <sort order="1">
      <sortitem order="1">author</sortitem>
    </sort>
    <sort order="2">
      <sortitem order="1">year</sortitem>
    </sort>
  </sorting>
</config>

This would be the full commandline:

biber --tool unsorted.bib --output-file=sorted.bib --configfile=biber-sorting.conf

If the files are not in the current folder, you need to specify the path correctly. If you name the config file biber.conf, biber will use it even without the --configfile parameter as this is the default.