BibTex Writer

This notebook shows how to generate BibTex metadata from a scholarly resource in commonmeta format generated by commonmeta-py.

Fetch metadata

As with all commonmeta-by notebooks, we start by fetching metadata, in this example a journal article via its Crossref DOI, and then convert it to the commonmeta format.

from commonmeta import Metadata

# Fetch metadata from a DOI
string = '10.7554/elife.01567'
metadata = Metadata(string)

# Check that metadata was fetched successfully
print(metadata.state)
findable

Generate BibTex

We can now generate BibTex metadata from the article metadata. We use the commonmeta pid (here a doi) to generate a BibTex key. Because BibTex has been around for more than 30 years, there are many flavours of it, including the list of supported types and the fields that are included. We try to align with the fields supported by Zotero, which is a popular reference manager. We for example include the abstract, copyright and language fields.

bibtex = metadata.bibtex()
print(bibtex)
AttributeError: module 'bibtexparser' has no attribute 'parse_string'

Supported BibTex Types

commonmeta-py supports the following BibTex types: article, book, booklet, conference, inbook, incollection, inproceedings, manual, mastersthesis, misc, phdthesis, proceedings, techreport, unpublished. Types that are not supported are mapped to misc, and that includes software and dataset, which were not part of the original BibTex specification. Below are examples of BibTex metadata for types other than article:

Book chapter

metadata = Metadata('10.1007/978-3-662-46370-3_13')
bibtex = metadata.bibtex()
print(bibtex)
AttributeError: module 'bibtexparser' has no attribute 'parse_string'

Conference proceedings

metadata = Metadata('10.1109/iccv.2007.4408927')
bibtex = metadata.bibtex()
print(bibtex)
{'submitted': None, 'accepted': None, 'published': '2007', 'updated': '2017-06-18T02:39:45Z'}
@inproceedings{https://doi.org/10.1109/iccv.2007.4408927,
    author = {Sinop, Ali Kemal and Grady, Leo},
    booktitle = {2007 IEEE 11th International Conference on Computer Vision},
    doi = {10.1109/iccv.2007.4408927},
    month = mar,
    publisher = {Institute of Electrical and Electronics Engineers (IEEE)},
    title = {A Seeded Image Segmentation Framework Unifying Graph Cuts And Random Walker Which Yields A New Algorithm},
    url = {http://ieeexplore.ieee.org/document/4408927},
    urldate = {2007},
    year = {2007}
}

PhD thesis

metadata = Metadata('10.14264/uql.2020.791')
bibtex = metadata.bibtex()
print(bibtex)
{'submitted': None, 'accepted': None, 'published': '2020-06-08T05:08:58Z', 'updated': '2020-06-08T05:08:59Z'}
@phdthesis{https://doi.org/10.14264/uql.2020.791,
    author = {Collingwood, Patricia Maree},
    doi = {10.14264/uql.2020.791},
    institution = {University of Queensland Library},
    month = jun,
    title = {School truancy and financial independence during emerging adulthood: a longitudinal analysis of receipt of and reliance on cash transfers},
    url = {http://espace.library.uq.edu.au/view/UQ:23a1e74},
    urldate = {2020-06-08},
    year = {2020}
}

Differences between Crossref JSON and XML

The metadata provided by the Crossref JSON REST API are slightly different than the UNIXREF XML submitted to Crossref upon DOI registration. Compare the following two examples (the default is ‘crossref’ for Crossref DOIs):

string = '10.1145/3448016.3452841'
metadata = Metadata(string, via='crossref')
bibtex = metadata.bibtex()
print(bibtex)
{'submitted': None, 'accepted': None, 'published': '2021-06-09', 'updated': '2023-01-06T22:59:32Z'}
@inproceedings{https://doi.org/10.1145/3448016.3452841,
    author = {Pandey, Prashant and Conway, Alex and Durie, Joe and Bender, Michael A. and Farach-Colton, Martin and Johnson, Rob},
    booktitle = {Proceedings of the 2021 International Conference on Management of Data},
    copyright = {https://www.acm.org/publications/policies/copyright_policy#Background},
    doi = {10.1145/3448016.3452841},
    month = jun,
    publisher = {Association for Computing Machinery (ACM)},
    title = {Vector Quotient Filters},
    url = {https://dl.acm.org/doi/10.1145/3448016.3452841},
    urldate = {2021-06-09},
    year = {2021}
}
string = '10.1145/3448016.3452841'
metadata = Metadata(string, via='crossref_xml')
bibtex = metadata.bibtex()
print(bibtex)
@misc{https://doi.org/10.1145/3448016.3452841,
    author = {Pandey, Prashant and Conway, Alex and Durie, Joe and Bender, Michael A. and Farach-Colton, Martin and Johnson, Rob},
    copyright = {https://www.acm.org/publications/policies/copyright_policy#Background},
    doi = {10.1145/3448016.3452841},
    month = jun,
    publisher = {Association for Computing Machinery (ACM)},
    title = {Vector Quotient Filters},
    url = {https://dl.acm.org/doi/10.1145/3448016.3452841},
    urldate = {2021-06-09},
    year = {2021}
}

BibTex Author names

BibTex writes author names as a single string, joined by and. Personal names are written as family, given and organizational names as name. An example for the latter:

# Organizations as authors
metadata = Metadata('10.26301/qdpd-2250')
bibtex = metadata.bibtex()
print(bibtex)
[{'rights': 'Creative Commons Attribution Non Commercial Share Alike 4.0 International', 'rightsUri': 'https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode', 'schemeUri': 'https://spdx.org/licenses/', 'rightsIdentifier': 'cc-by-nc-sa-4.0', 'rightsIdentifierScheme': 'SPDX'}]
@misc{https://doi.org/10.26301/qdpd-2250,
    abstract = {USS Pampanito was towed to Bay Ship Yacht shipyard and raised out of the water in a dry dock for repairs. On Friday, November 11, 2016 the submarine was scanned. Our goal was to create a baseline scan for future comparison, to inform future repairs, to compare to her builders drawings, and to facilitate interpretation and research. USS Pampanito made six patrols in the Pacific during World War II during which she sank six Imperial Japanese ships and damaged four others. Operated by the Maritime Park Association, Pampanito hosts over 100,000 visitors a year and is one of the most popular historic vessels in the country. In addition to day time visitors, over 1,500 kids a year participate in Pampanito's educational day and overnight programs. Pampanito is a National Historic Landmark. External Project Link: \N Additional Info Link: https://maritime.org/sub/},
    author = {USS Pampanito and Autodesk and Topcon and 3D Robotics and CyArk and San Francisco Maritime National Park Association},
    copyright = {https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode},
    doi = {10.26301/qdpd-2250},
    month = mar,
    publisher = {OpenHeritage3D},
    title = {USS Pampanito Submarine},
    url = {https://openheritage3d.org/project/qdpd-2250},
    urldate = {2020},
    year = {2020}
}