Rules🔗

Fifteen rules run over every file, in the order below. The rules repairing a value run before the rules comparing fields and entries, so that a single fix merges the repeats that only become identical once repaired. bibclean check and bibclean fix report the same violations; only fix writes the result.

Reading a rule section🔗

Fix: yes means the rule always repairs what it reports, Fix: partial that it repairs some cases only, and Fix: no that the repair needs a human decision. bibclean check marks the violations that fix repairs with [*].

Scope says what the rule looks at: a whole file, one block, one entry, one field or one value.

The pybtex: paragraph of each rule says what pybtex does with the construct, which is what a sphinxcontrib-bibtex documentation build sees.

Turning a rule off🔗

A rule can be disabled by name, either for a project with ignore in the configuration file, or for one run with --ignore:

[tool.bibclean]
ignore = ["strip-field"]
bibclean check --ignore strip-field doc/references.bib

Individual entries are exempted from every rule by cite key with exclude, and whole entry types with exclude-types. Exempted entries are still formatted. See Configuration.

Formatting itself is not a rule and cannot be disabled: a file whose layout differs from the canonical style is reported once, without a position, by a file is not formatted line. See Canonical format.

syntax-error🔗

Fix: no. Scope: block.

Report a block that could not be read.

The block is reported once, at the @ that opens it, with the reason and the position at which reading failed. A file with a syntax error is never rewritten: every rule still reports its violations, but none of them is fixable, as the text swallowed by the broken block cannot be reordered safely.

Like BibTeX, every @ starts a block, so an e-mail address in a % line is a syntax error too.

% write to me@example.org

@article{broken,
  title = {Missing closing brace,
  year = {2002}
}

pybtex: the documentation build fails on the file.

doi-prefix🔗

Fix: yes. Scope: value.

Report a doi field carrying a resolver prefix.

The prefix is removed and the bare identifier is kept. Recognised prefixes are https://doi.org/, https://dx.doi.org/, https://www.doi.org/, their http:// forms and doi:, matched case-insensitively.

@article{k, doi = {https://doi.org/10.1/x}}

pybtex: the styles prepend the resolver themselves, producing a broken double link.

empty-field🔗

Fix: yes. Scope: field.

Report a field whose value is empty once whitespace is collapsed.

The field is removed. A value holding a macro is never empty and is left alone.

@article{k, volume = {}, note = {  }}

pybtex: the field is dropped silently, so the file lies about its content.

strip-field🔗

Fix: yes. Scope: field.

Report a field that the entry type does not keep.

The field is removed. The kept names of a type always contain its required names, doi and url are never stripped so that a citation keeps its link, and crossref is never stripped so that the entry keeps the fields it inherits. A type without a keep list is never stripped, and neither is an entry that another entry references with crossref, since its fields are inherited.

@article{k, abstract = {...}, file = {...}, urldate = {...}}

pybtex: nothing, noise only.

url-with-doi🔗

Fix: yes. Scope: entry.

Report a url field in an entry that has a doi field.

The url field is removed, whatever it points to: the DOI is the stable link to the work.

@article{k, doi = {10.1/x}, url = {https://example.org}}

pybtex: nothing, the reference simply carries two links to the same work.

month-format🔗

Fix: yes. Scope: value.

Report a month field that is not in the configured form.

The value is rewritten as the macro, the English name or the number, following the month option. Recognised are the twelve macros, the English names, the three-letter abbreviations with or without a trailing period, in any case, and the numbers 1 to 12 with or without a leading zero. Any other value is reported and left untouched, except a concatenation such as jan # {~15}, which is not inspected.

@article{k, month = {September}}

pybtex: macros are substituted while literal names are printed as they are, so both forms render the same but a canonical file needs one of them.

pages-range🔗

Fix: yes. Scope: value.

Report a numeric page range that does not use an en dash.

A value made of digits, a dash and digits is rewritten with --, whatever dash and spacing it used. Anything else, such as {e12--e19} or a single page, is left untouched.

@article{k, pages = {4101-4105}}

pybtex: nothing, typography of the rendered reference.

unescaped-percent🔗

Fix: yes. Scope: value.

Report a % that is not escaped by a backslash.

Every unescaped % of the value becomes \%, and one finding is emitted per field or @string value whatever the number of occurrences. The fields url, doi and file are exempt, where a % is legitimate URL encoding, and so are the argument of \url and the first argument of \href in any other field or @string value. A @string value is always checked, since it is expanded into the fields using it.

@article{k, title = {Filtering (50% of the signal)}}

pybtex: latexcodec treats % as the start of a comment and drops the rest of the value when the reference is decoded.

duplicate-field🔗

Fix: partial. Scope: entry.

Report a field defined twice in one entry, case-insensitively.

The repeat is removed when both definitions render to the same value, otherwise it is reported and both are kept.

@article{k, title = {Other}, title = {Other}}
@article{k, title = {Other}, title = {Another}}

pybtex: the documentation build fails on the repeated field.

duplicate-key🔗

Fix: partial. Scope: file.

Report a cite key that is already defined, case-insensitively.

The repeat is removed when it renders exactly like the first occurrence, entry type and fields included; otherwise both entries are kept and the repeat is reported, because only the author knows which of the two keys the documentation cites. A third occurrence is reported against the first.

@article{Smith2020, author = {Smith, John}, title = {On things}}
@article{smith2020, author = {Smith, John}, title = {On things}}

pybtex: cite keys are stored in a case-insensitive dictionary and the documentation build fails on the repeat.

duplicate-doi🔗

Fix: no. Scope: file.

Report two entries carrying the same DOI.

DOIs are compared once the resolver prefixes are stripped and the case is folded. Both entries are kept and the repeat is reported: the documentation may cite either cite key, so only the author can merge them. A DOI identifies one work, so this catches a re-export under a second cite key without the false positives of comparing author, title and year.

@article{a, doi = {10.1/x}}
@article{a-1, doi = {https://doi.org/10.1/X}}

pybtex: nothing, the bibliography simply lists the work twice.

duplicate-string🔗

Fix: no. Scope: file.

Report a @string macro that is already defined, case-insensitively.

The canonical format writes every @string before the entries, which changes the value of a redefined macro in the entries written between two definitions. A file redefining a macro is therefore never rewritten: every rule still reports its violations, but none of them is fixable. A third definition is reported against the first.

@string{venue = {NeurIPS}}
@inproceedings{a, booktitle = venue}
@string{Venue = {ICML}}
@inproceedings{b, booktitle = venue}

pybtex: a macro takes its latest definition at each point of the file, so reordering the blocks changes the values of the entries.

undefined-string🔗

Fix: no. Scope: value.

Report a bare macro that no @string block defines.

The twelve month macros are always defined. An entry may reference any @string of the file, since the canonical format writes every @string before the entries. A @string or @preamble block may only reference macros defined above it, since definitions are processed in order. Names are compared case-insensitively.

@string{jneuro = {Journal of Neuroscience}}
@article{k, journal = jnuero}

pybtex: the documentation build fails with an undefined macro error.

author-format🔗

Fix: no. Scope: value.

Report a name with more than two commas in an author or editor field.

The value is split into names on the word and surrounded by whitespace, in any case, and a name is reported when it holds more than two commas, all outside braces. A comma-separated list of authors is the usual cause. A value made of a macro or of a concatenation is not inspected.

@article{k, author = {Jack Dongarra, Kevin London, Shirley Moore, Phil Mucci}}

pybtex: the name is rejected with Too many commas and the documentation build fails.

required-field🔗

Fix: no. Scope: entry.

Report a field that the entry type requires but the entry does not have.

The requirements come from the shipped tables and can be overridden per type with required. A name spelled 'author|editor' is satisfied when at least one of the alternatives is present, and the message lists it as written. An entry with a crossref field also has every field of the entry with that cite key in the same file, compared case-insensitively. An entry type without a table is never reported.

@article{k, author = {A}, title = {T}, year = {2021}}

pybtex: the style prints an incomplete reference, or fails outright. Like BibTeX, pybtex fills the fields missing from an entry with those of its crossref target.