Module to complete bibtex files by polling online databases
Project description
Bibtex Autocomplete
bibtexautocomplete or btac is a python package to autocomplete BibTeX bibliographies. It is inspired and expanding on the solution provided by thando in this TeX stack exchange post.
It attempts to complete a BibTeX file by querying the following domains:
Big thanks to all of them for allowing open, easy and well-documented access to their databases.
Contents:
Demo
Quick overview
How does it find matches?
btac
queries the websites using the entry DOI if known otherwise the title. So entries that don't have one of those two fields will not be completed.
- Titles should be the full title, they are compared excluding case and punctuation, but titles with missing words will not match.
- If one or more authors are present, entries with no common authors will not match. Authors are compared using lower case last names only. Be sure to use one of the correct BibTeX format for the author field:
author = {First Last and Last, First and First von Last}
(see https://www.bibtex.com/f/author-field/ for full details)
Disclaimers
-
There is no guarantee that the script will find matches for your entries, or that the websites will have any data to add to your entries, (or even that the website data is correct, but that's not for me to say...)
-
The script is designed to minimize the chance of false positives - that is adding data from another similar-ish entry to your entry. If you find any such false positive please report them using the issue tracker.
How are entries completed?
Once responses from all websites have been found, the script will add fields from website with the following priority : crossref > arxiv > dblp > researchr > unpaywall.
So if both crossref's and dblp's response contain a publisher, the one from crossref will be used.
The script will not overwrite any user given non-empty fields, unless the -f/--force-overwrite
flag is given.
The script checks that the DOIs or URLs found correspond (or redirect to) a valid webpage before adding them to an entry.
Installation
Can be installed with pip :
pip install bibtexautocomplete
You should now be able to run the script using either command:
btac --version
python3 -m bibtexautocomplete --version
Dependencies
This package has two dependencies (automatically installed by pip) :
- bibtexparser
- alive_progress (>= 2.4.0) for the fancy progress bar
Usage
The command line tool can be used as follows:
btac [--flags] <input_files>
Examples :
btac my/db.bib
: reads from./my/db.bib
, writes to./my/db.btac.bib
btac -i db.bib
: reads fromdb.bib
and overwrites it (inplace flag)btac db1.bib db2.bib -o out1.bib -o out2.bib
reads multiple files and write their outputs toout1.bib
andout2.bib
respectively.btac folder
: reads from all files ending with.bib
in folder. Excludes.btac.bib
files unless they are the only.bib
files present. Writes tofolder/file.btac.bib
unless inplace flag is set.btac
with no inputs is same asbtac .
Note: the parser doesn't preserve format information, so this script will reformat your files. Some formatting options (see below) are provided.
Optional arguments:
-
-o --output <file.bib>
Write output to given file. Can be used multiple times when also giving multiple inputs. Maps inputs to outputs in order. If there are extra inputs, uses default name (
old_name.btac.bib
). Ignored in inplace (-i
) mode. -
-q --only-query <site>
or-Q --dont-query <site>
Restrict which websites to query from.
<site>
must be one of:crossref
,dblp
,arxiv
,researchr
,unpaywall
. These arguments can be used multiple times, for example to only query crossref and dblp use-q crossref -q dblp
or-Q researchr -Q unpaywall -Q arxiv
-
-e --only-entry <id>
or-E --exclude-entry <id>
Restrict which entries should be autocomplete.
<id>
is the entry ID used in your BibTeX file (e.g.@inproceedings{<id> ... }
). These arguments can also be used multiple times to select only/exclude multiple entries -
-c --only-complete <field>
or-C --dont-complete <field>
Restrict which fields you wish to autocomplete. Field is a BibTeX field (e.g.
author
,doi
,...). So if you only wish to add missing DOIs use-c doi
.
Output formatting:
Unfortunately bibtexparser doesn't preserve format information, so this script will reformat your BibTeX file. Here are a few options you can use to control the output format:
-
--fa --align-values
pad field names to align all values@article{Example, author = {Someone}, doi = {10.xxxx/yyyyy}, }
-
--fc --comma-first
use comma first syntax@article{Example , author = {Someone} , doi = {10.xxxx/yyyyy} , }
-
--fl --no-trailing-comma
don't add the last trailing comma -
--fi --indent <space>
space used for indentation, default is a tab. Can be specified as a number (number of spaces) or a string with spaces and_
,t
, andn
characters to mark space, tabs and newlines.
Flags:
-
-i --inplace
Modify input files inplace, ignores any specified output files -
-f --force-overwrite
Overwrite already present fields. The default is to overwrite a field if it is empty or absent -
-t --timeout <float>
set timeout on request in seconds, default: 10.0 s, increase this if you are getting a lot of timeouts. -
-S --ignore-ssl
bypass SSL verification. Use this if you encounter the error:[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)
another (better) fix for this is to run
pip install --upgrade certifi
to update python's certificates. -
-d --dump-data <file.json>
writes matching entries to the given JSON files.This allows to see duplicate fields from different sources that are otherwise overwritten when merged into a single entry.
The JSON file will have the following structure:
[ { "entry": "<entry_id>", "new-fields": 8, "crossref": { "query-url": "https://api.crossref.org/...", "query-response-time": 0.556, "query-response-status": 200, "author" : "Lastname, Firstnames and Lastname, Firstnames ...", "title" : "super interesting article!", "..." : "..." }, "arxiv": null, // null when no match found "dblp": ..., "researchr": ..., "unpaywall": ... }, ... ]
-
-O --no-output
don't write any output files (except the one specified by--dump-data
) -
-v --verbose
verbose mode shows more info. It details entries as they are being processed and shows a summary of new fields and their source at the end. Using it more than once prints debug info (up to four times). -
-s --silent
hide info and progress bar. Keep showing warnings and errors. Use twice to also hide warnings, thrice to also hide errors and four times to also hide critical errors, effectively killing all output. -
-n --no-color
don't use ANSI codes to color and stylize output -
--version
show version number -
-h --help
show help
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bibtexautocomplete-1.1.3.tar.gz
.
File metadata
- Download URL: bibtexautocomplete-1.1.3.tar.gz
- Upload date:
- Size: 40.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d89252f0da051676a10bf3b79d38256da3d7e013aac2aaded8be43e21fd7c595 |
|
MD5 | d8486c2898bf210528e4acf5b439fb64 |
|
BLAKE2b-256 | 4ec45936ed17210841daf1ec9ff64b9ab41bdc15322dbbf8db8266bb899c9d37 |
File details
Details for the file bibtexautocomplete-1.1.3-py3-none-any.whl
.
File metadata
- Download URL: bibtexautocomplete-1.1.3-py3-none-any.whl
- Upload date:
- Size: 48.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2717bc00fc0229098d9506db14e12dd428bde9881c14a66cc03ab6a4b86b2f7 |
|
MD5 | 35232852185c85659ba7eb1e0e1bc5b1 |
|
BLAKE2b-256 | 80bba65667cdb736aa3884a8ca2df0fa623c178765ee54a9fd908204104753de |