adsfolio.bibtex.sanitize
Repair malformed field values in ADS BibTeX exports.
ADS sometimes escapes math inside keyword or abstract strings
asymmetrically, e.g. 2001 KX\$\_\{76}. BibTeX counts every brace,
escaped or not, so the \{ opens a group that never closes; BibTeX then
reads the following entry as part of this one, reports an error, and
latexmk stops before resolving any citation.
Only single-line field values whose braces do not balance are touched; well-formed output passes through unchanged.
- adsfolio.bibtex.sanitize.BIBTEX_FORMATS = frozenset({'bibtex', 'bibtexabs'})
ADS export formats whose output is BibTeX.
- adsfolio.bibtex.sanitize.brace_balanced(text)[source]
Check braces the way BibTeX does (backslash escapes are ignored).
- adsfolio.bibtex.sanitize.remove_fields(text, fields)[source]
Remove named fields from every BibTeX entry and keep the other text.
- Parameters:
- Returns:
The same text without those fields. Other fields, their order and spacing, comments, and
@stringor@preambleblocks are kept. An entry whose braces do not close is kept unchanged.- Return type:
- adsfolio.bibtex.sanitize.repair_bibtex(text)[source]
Repair brace-unbalanced field values in ADS BibTeX output.
- adsfolio.bibtex.sanitize.repair_field_text(text)[source]
Return a brace-balanced version of a field’s content.
- Parameters:
text (str) – Field content without its outer delimiters.
- Returns:
text unchanged if already balanced. Otherwise ADS escapes of
$ _ { } ^are undone, open groups are closed, and an unpaired$is closed. If that still does not balance, unmatched braces are dropped instead of closed.- Return type:
Examples
>>> repair_field_text(r"28978 Ixion: 2001 KX\$\_\{76") '28978 Ixion: 2001 KX$_{76}$'