normalize_bibtex_key#

documenteer.citations.normalize_bibtex_key(value)#

Validate a BibTeX citation key, returning it stripped of surrounding whitespace.

Parameters:

value (str) – The key the entry is to be written under.

Returns:

The key, with surrounding whitespace removed.

Return type:

str

Raises:

ValueError – Raised if the key is empty, or carries whitespace, a character BIBTEX_KEY_RESERVED names, or a character outside printable ASCII.

Notes

The key is the one part of a BibTeX entry a reader retypes — it is what their \cite commands name — so a key BibTeX cannot read is rejected where it is written rather than composed into an entry that breaks the .bib file it is pasted into. Non-ASCII is rejected for the same reason: BibTeX’s own key syntax is ASCII, and a key a reader cannot type is a key they cannot cite.