Cleanup bibtex entries on the clipboard or grab them from a DOI.
cleanbib
is a python script built using the python-bibtexparser library which accomplishes two simple tasks:
- If you have copied a bibtex entry (it exists on the clipboard) apply some formatting that is standard for physics journals and return the new bibtex entry to the clipboard.
- If you have a DOI, get the bibtex from http://dx.doi.org and format it as above.
At present it uses a hard-coded dictionary for journal abbreviations. This needs to be expanded upon.
- python-bibtexparser for bibtex parsing
- docopt for processing command line options
- pyperclip for communicating with the clipboard
- requests for getting the bibtex from a DOI.
Clone via clone https://github.com/agdelma/cleanbib.git cleanbib
and copy cleanbib.py
to somewhere on your $PATH
.
Description:
Clean up a latex .bib record on the clipboard or retrieved from the doi.
Usage:
cleanbib [--doi=<doi>]
cleanbib -h | --help
Options:
-h --help Show this screen.
-d <doi> --doi=<doi> A valid doi.
Suppose you had the following bibtex (generated by Papers3) on the clipboard:
@article{Herdman:2014jq,
author = {Herdman, C M and Roy, P N and Melko, R G and Del Maestro, Adrian},
title = {{Particle entanglement in continuum many-body systems via quantum Monte Carlo}},
journal = {Physical Review B},
year = {2014},
volume = {89},
number = {14},
pages = {140501},
month = apr,
doi = {10.1103/PhysRevB.89.140501},
language = {English},
read = {Yes},
rating = {0},
date-added = {2014-04-09T12:59:48GMT},
date-modified = {2017-04-25T00:15:16GMT},
url = {http://link.aps.org/doi/10.1103/PhysRevB.89.140501},
uri = {\url{papers3://publication/doi/10.1103/PhysRevB.89.140501}}
}
running ./cleanbib
from the command line would yield:
@article{Herdman:2014jq,
author = {Herdman, C.~M. and Roy, P.~N. and Melko, R.~G. and Del Maestro, Adrian},
doi = {10.1103/PhysRevB.89.140501},
journal = {Phys. Rev. B},
number = {14},
pages = {140501},
title = {{P}article entanglement in continuum many-body systems via quantum {M}onte {C}arlo},
url = {http://link.aps.org/doi/10.1103/PhysRevB.89.140501},
volume = {89},
year = {2014}
}
which includes all the essential information that is needed.
If you don't have the record, but instead only the DOI, then you could type:
./cleanbib.py -d 10.1103/PhysRevB.89.140501
which would copy the following text to your clipboard
@article{Herdman:2014ye,
author = {Herdman, C.~M. and Roy, P.-N. and Melko, R.~G. and Del Maestro, A.},
doi = {10.1103/physrevb.89.140501},
journal = {Phys. Rev. B},
number = {14},
publisher = {American Physical Society (APS)},
title = {{P}article entanglement in continuum many-body systems via quantum {M}onte {C}arlo},
url = {http://dx.doi.org/10.1103/PhysRevB.89.140501},
volume = {89},
year = {2014}
}