45

How can I validate the correctness a biblatex .bib file?

Where validate means checking for:

  • Duplicate keys
  • Missing mandatory fields

What tools do you use?

8 Answers8

31

To validate my .bib files, I put together a Python script called Biblatex Checker.

It checks for missing fields, provides suggestions for common mistakes when using biblatex and identifies duplicate IDs.

It's based on BibTeX Check by Fabian Beck, which can be used for BibTeX files.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • 21
    I use biber --tool -V bib.bib. It doesn't complain about missing fields but I didn't try yet to find out how to change it (or in case in can't do it yet to make a feature request). – Ulrike Fischer Apr 26 '14 at 18:52
  • Actually, -V in tool mode didn't do anything in 1.8. It does in 1.9 dev version. For example it will report on mandatory fields missing from the default data model (in the tool mode config file). You can add any datamodel constraint you want to the data model (either by biblatex macros or via the biber config file for tool mode). The blx-dm.def file that comes with biblatex contains the default data model and its mandatory field constraints. – PLK Apr 26 '14 at 22:42
  • @UlrikeFischer: I think biber --tool -V my.bib should be a separate answer and, IMHO, the recommended way. I definitely would vote for it. – Hotschke Feb 02 '17 at 12:39
16

I use jabref. Install jabref, set it to biblatex mode. To do this go to OptionsPreferences. In the window that opens, selectAdvanced and check BibLaTeX mode as shown below.

enter image description here

Then open your .bib file using jabref. Select the entries to be cleaned up. Under Tools menu, select cleanup entries. This window opens:

enter image description here

Now you know what to do :)

For duplicate keys, simply go to ToolsAutogenerate BibTeX keys. It will rewrite the duplicate key with some other name.

  • So easy it was! So, one needs to maintain different versions of references? one for BibTeX and another one for BibLaTeX? – Nikos Alexandris Oct 09 '15 at 06:14
  • @NikosAlexandris: For those who want perfection, it is the way. But for general needs bibtex is enough. The bibtex file serves for biblatex too if one is willing to live with some warnings etc. –  Oct 09 '15 at 07:44
  • I have an error now using BibLaTeX and XeLaTeX which was not there when using BibTeX and PDFLaTeX. Need to understand what is wrong and correct it. Two of my citations are printed with some long dash instead of the corresponsing author's name. – Nikos Alexandris Oct 09 '15 at 08:10
  • @NikosAlexandris Some where you are using abbrv style. –  Oct 09 '15 at 08:19
  • The .log has the following entry: \c@abbrvpenalty=\count217. I'll try to find the "error". – Nikos Alexandris Oct 09 '15 at 08:22
  • Actually, the solution to my "problem" is http://tex.stackexchange.com/a/49142/8272 – Nikos Alexandris Oct 09 '15 at 09:09
14

If you are only given the .bib file, try

biber --tool --validate-datamodel <filename>.bib

If your TeX document uses custom data types, try

biber --validate-datamodel <filename>.bcf

This should check all data sources.

pavel
  • 861
  • 4
    Note that the exact data model is style dependent, so usually the most complete and relevant report that you can get is the one issued by biber --validate-datamodel <texfilebasename> where <texfilebasename> is the basename of the .tex document you are writing at the moment. – moewe Oct 30 '18 at 10:33
  • I was assuming that one is given just a .bib file. Users of custom data models probably already know that biber can replace 3rd party tools. – pavel Oct 31 '18 at 11:14
  • 1
    Mhhh, I'm not so sure if people would realise that. Anyhow, at least for me biber --tool did not catch the four obvious errors in @article{sugfridsson, editor = {Sigfridsson, Emma and Ryde, Ulf}, title = {Title}, blournal = {Journal}, } that --validate-datamodel reported. So at least for the mandatory field validation --tool mode alone is not enough. I guess what I'm saying is that your answer would be better if you suggested biber --validate-datamodel --tool <filename>.bib – moewe Oct 31 '18 at 11:29
11
\documentclass{article}
\begin{document}
\nocite{*}
\bibliographystyle{plain}
\bibliography{mybib}
\end{document}

Run latex and bibtex and then look into the logfile of the bibtex run (<filename>.blg). It has all warnings.

5

https://biblatex-linter.herokuapp.com/ provides an online Bibtex linter.

It's an Heroku app (Python/Django). It's open source and MIT licensed. https://github.com/Pezmc/BibLaTeX-Linter.

It's based on https://github.com/Pezmc/BibLaTeX-Check

scls
  • 151
5

BibTex Tidy is an open source online tool, I've used it, and personally I found it to be very reliable. It supports formatting and clean up, but also checks duplicate entries, including not just the key but also titles.

The tool's self-description is:

This tool tidies bibtex files by fixing inconsistent whitespace, removing duplicates, removing unwanted fields, and sorting entries.

2

bibtool v2.68 (April 2020)

bibtool (github) v2.68 has improved its double check (aka check for duplicates):

  • The behaviour of the resource check.double has been generalized. The requirement of double entries to be adjacent has been dropped. This has the impact that the processing is slightly slower.

and added a new check unique.field:

  • New resource file unique.field introduced. With this resource it is possible to specify additional unique constraints for fields. If different records have the same value for one of those fields, then a warning is issued.

Ensure you have v2.68 or newer (Homebrew for macOS already provides this version when this answer was written, ie. $ brew upgrade bib-tool gives you the new version)

❯ bibtool -V
BibTool Vers. 2.68 (C) 1996-2019 Gerd Neugebauer

Report duplicate keys

Following command reports records which share the same $key

❯ bibtool -- 'unique.field {$key}' -o '' unique_field_test.bib

For example, you could also check for duplicate dois.

❯ bibtool -- 'unique.field {doi}' -o '' unique_field_test.bib

Report about missing fields

I am not sure if this is already possible with bibtool.

Hotschke
  • 5,300
  • 5
  • 33
  • 63
0

On top of the tools that have already been suggested, you can try my bibcop package. You just \usepackage it in the document and any errors found in the .bib file will be reported as LaTeX warnings right in the TeX log:

\documentclass{article}
\usepackage{bibcop}
\begin{document}
\bibliographystyle{plain}
\bibliography{main}
\end{document}

Bibcop checks the formatting of the author, title, year, month, pages, and so on. If is written in Perl and you are welcome to submit your suggestions if you want it to be even stricter (it is pretty strict already!).

BTW, you can also use it as a command line tool to auto-fix your .bib file:

$ tlmgr install bibcop
$ bibcop --fix my.bib > fixed.bib
yegor256
  • 12,021
  • 1
    The package is indeed very strict with rules that seem pretty random and not based on anything other than personal choices. Some of them would also break some styles, e.g. capitalisation of titles/booktitles. Would be best to provide some reasoning behind the rules and/or warn that these are just the package author's preferences. – ArTourter Dec 16 '22 at 16:26
  • This is how most style checkers work (for other languages, like Java, C++, Python, etc.) -- their rules represent personal preferences of their authors. There is no absolute truth in style checking. Almost everything is a matter of taste. However, I agree, the documentation needs better explanation of the reasons behind each rule. I will try to extend it. BTW, the capitalization rule you mentioned is coming from APA (the documentation explicitly mentions this). – yegor256 Dec 19 '22 at 04:03
  • The APA capitalisation is indeed part of their style. encasing the whole field in double {{}} on the other hand means that a different style (thinking of my former institution which explicitly wants titles with only the first character capitalised (except acronyms)) would not be able to apply the correct (for them) capitalisation. A tool to check the validity of a file should not ask to counteract a style. – ArTourter Dec 19 '22 at 15:54
  • 1
    I will add a new package option nocaps, which will disable this particular checker. Also, nobrackets to disable the checker for double brackets. – yegor256 Dec 19 '22 at 17:20