Latex-workshop: sorting .bib file items

Created on 24 Mar 2019  Â·  5Comments  Â·  Source: James-Yu/LaTeX-Workshop

This wonderful plug-in already supports formatting the .tex files. It would be great if advanced formatting option for .bib file could be supported. The most common demand is to sort the bib items by some rules. (e.g. first by 'year' then by 'title')

There are several tools such as "biber", 'bibtool' designed for such functionality. However, they are quite complicated to learn and use. Adding an encapsulation for such tools could be a good idea. Here is a sample, the initial bib file look like this:

@article{art1,
title={zzz},
year={2010},
publisher={IEEE}
}

@article{art2,
title={ddd},
year={2011},
publisher={IEEE}
}

@article{art3,
title={aaa},
year={2010},
publisher={IEEE}
}

After sorted:
@article{art3,
title={aaa},
year={2010},
publisher={IEEE}
}

@article{art1,
title={zzz},
year={2010},
publisher={IEEE}
}

@article{art2,
title={ddd},
year={2011},
publisher={IEEE}
}

Here is a discussion about formatting .bib file in stackoverflow:
https://tex.stackexchange.com/questions/318448/ordering-bib-file-alphabetically
Currently this solution requires writing an independent configuration file.

feature-request

Most helpful comment

Has formatting *.bib using bibtool been considered, the same way that latexindent is used for *.tex files?

All 5 comments

There are many Python and Perl tools to interact with bibtex files, unfortunately no javascript library for doing so seems to really be maintained. It would require a huge effort to implement this in the extension and I think it goes a bit beyond the extension's scope. If the community wants to implement this, we will be happy to integrate it.

@wstcegg What I'd reccomend for this sort of thing is creating a task, named something like Sort Bibtex Items by [Alphanumeric/Date/...]

@jlelong Extensions can contribute default tasks can't they? I've set up a recipie for _'precompiling'_ the preamble (makes a difference when loading ~50 packages), however it's linux-only. At some point in the future I want to somehow add it to the extension so that others may benefit from it. I was thinking a extension-contributed task may be the best bet.

Yes, extensions can contribute tasks.
For bib sorting, it would be great to rely on an existing bibtex manipulation library but they are mainly written in Perl or Python

Has formatting *.bib using bibtool been considered, the same way that latexindent is used for *.tex files?

Since it is impossible to reimplement the features in this delicate extension and tools provided by latex toolkit are difficult to grasp, currently, using a speciallized software for .bib file processing is a good choice. JabRef is strongly recommened.
http://www.jabref.org.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

s-ilic picture s-ilic  Â·  3Comments

TiemenSch picture TiemenSch  Â·  6Comments

tenhobi picture tenhobi  Â·  4Comments

jose-a-sa picture jose-a-sa  Â·  4Comments

tillahoffmann picture tillahoffmann  Â·  6Comments