Skip to main content

Transform Zotero BibTex files to LaTeX friendly representation.

Project description

zotero-bibtize

Refurbish exported Zotero-BibTex bibliographies into a more latex friendly representation.

In the current state exporting the contents of a Zotero database to Bibtex format most special characters are replaced by Zotero internal versions or escaped before written to the output file. This behavior is exceptionally annoying if entries contain code which is meant to be processed by latex (i.e. chemical or mathematical expressions and formulas in the title, etc.).

zotero-bibtize can be used to post-process the generated Zotero output files and remove added escape sequences (i.e. the output is an identical replica of the raw entry contents stored in the Zotero interface)

Usage

After installing the package zotero-bibtize can be invoked via a call to the zotero-bibtize command on the command line:

$ zotero-bibtize zotero_bibliography.bib bibtized_bibliography.bib

which will process the original contents zotero_bibliography.bib and writes the processed contents to the new bibtized_bibliography.bib file. Note that specifying a target file is optional and the input file will be overwritten if left out.

Example

Original bibtex entry generated by Zotero export:

$ cat zotero_bibliography.bib
@article{LangCM2015,
  title = {Lithium {Ion} {Conduction} in {\textbackslash}ce\{{LiTi}2({PO}4)3\} and {Related} {Compounds} {Based} on the \{{NASICON}\} {Structure}: {A} {First}-{Principles} {Study}},
  volume = {27},
  issn = {0897-4756, 1520-5002},
  shorttitle = {Lithium {Ion} {Conduction} in {\textbackslash}ce\{{LiTi}2({PO}4)3\} and {Related} {Compounds} {Based} on the {NASICON} {Structure}},
  url = {http://pubs.acs.org/doi/10.1021/acs.chemmater.5b01582},
  doi = {10.1021/acs.chemmater.5b01582},
  language = {en},
  number = {14},
  urldate = {2019-02-11},
  journal = {Chem. Mater.},
  author = {Lang, Britta and Ziebarth, Benedikt and Els{\textbackslash}"\{a\}sser, Christian},
  month = jul,
  year = {2015},
  pages = {5040--5048}
}

After running zotero-bibtize zotero_bibliography.bib:

$ cat zotero_bibliography.bib
@article{LangCM2015,
  title = {Lithium Ion Conduction in \ce{LiTi2(PO4)3} and Related Compounds Based on the NASICON Structure: A First-Principles Study},
  volume = {27},
  issn = {0897-4756, 1520-5002},
  shorttitle = {Lithium Ion Conduction in \ce{LiTi2(PO4)3} and Related Compounds Based on the NASICON Structure},
  url = {http://pubs.acs.org/doi/10.1021/acs.chemmater.5b01582},
  doi = {10.1021/acs.chemmater.5b01582},
  language = {en},
  number = {14},
  urldate = {2019-02-11},
  journal = {Chem. Mater.},
  author = {Lang, Britta and Ziebarth, Benedikt and Els\"{a}sser, Christian},
  month = jul,
  year = {2015},
  pages = {5040--5048}
}

Custom BibTex Keys (very experimental)

Custom BibTex keys can be defined through the optional --key-format option that will be written to the bibliography file instead of the default keys generated by Zotero. The key format defines the way how to combine and format contents taken from the BibTex entry fields to build a custom key format. In general the format key is of the form [field1:option][field2:option]... where field defines the BibTex entry field to take the contents from and the options defines different format options that will be applied to the contents. Currently the following fields are implemented:

author

Adds the author's lastnames to the key entry
General format: [author:num:options]

num

Defines the maximal number of author names used for the key

options

The format options that will be applied to the author names, i.e.

  • capitalize: Capitalize the names
  • upper: Transform names uppercase
  • lower: Transform names to lowercase
  • abbreviate: Only us the first letter instead of the full name

title

Adds contents of the title string to the key entry
General format: [title:num:options]

num

Defines the maximal number of words in the title used for the key (Note that function keys will not be taken into account)

options

The format options that will be applied to the title contents, i.e.

  • capitalize: Capitalize the names
  • upper: Transform names uppercase
  • lower: Transform names to lowercase
  • abbreviate: Only us the first letter instead of the full name

journal

Adds contents of the journal name to the key entry
General format: [journal:options]

options

The format options that will be applied to the journal name, i.e.

  • capitalize: Capitalize the names
  • upper: Transform names uppercase
  • lower: Transform names to lowercase
  • abbreviate: Only us the first letter instead of the full name

year

Add the publication year to the key entry
General format: [year:option]

option

Adding the year only allows to specify two types of options:

  • short: Add the year to the key as 2-digit quantity
  • long: Add the full year to the (i.e. as 4-digit quantitiy)

Example

In the following example we create a custom key containing the first author name and the abbreviated journal name followed by the publication year. The key format defining such a key is of the following form: [author:1:capitalize][journal:capitalize:abbreviate][year] The original entry generated by Zotero looks like this:

$ cat zotero_bibliography.bib
@article{lang_lithium_ion_conduction_2015,
  title = {Lithium {Ion} {Conduction} in {\textbackslash}ce\{{LiTi}2({PO}4)3\} and {Related} {Compounds} {Based} on the \{{NASICON}\} {Structure}: {A} {First}-{Principles} {Study}},
  volume = {27},
  issn = {0897-4756, 1520-5002},
  shorttitle = {Lithium {Ion} {Conduction} in {\textbackslash}ce\{{LiTi}2({PO}4)3\} and {Related} {Compounds} {Based} on the {NASICON} {Structure}},
  url = {http://pubs.acs.org/doi/10.1021/acs.chemmater.5b01582},
  doi = {10.1021/acs.chemmater.5b01582},
  language = {en},
  number = {14},
  urldate = {2019-02-11},
  journal = {Chem. Mater.},
  author = {Lang, Britta and Ziebarth, Benedikt and Els{\textbackslash}"\{a\}sser, Christian},
  month = jul,
  year = {2015},
  pages = {5040--5048}
}

After running zotero-bibtize zotero_bibliography.bib --key-format [author:1:capitalize][journal:capitalize:abbreviate][year] the original contents will be processed by zotero-bibtize and the original Zotero key will be replaced with the modified version:

$ cat zotero_bibliography.bib
@article{LangCM2015,
  title = {Lithium Ion Conduction in \ce{LiTi2(PO4)3} and Related Compounds Based on the NASICON Structure: A First-Principles Study},
  volume = {27},
  issn = {0897-4756, 1520-5002},
  shorttitle = {Lithium Ion Conduction in \ce{LiTi2(PO4)3} and Related Compounds Based on the NASICON Structure},
  url = {http://pubs.acs.org/doi/10.1021/acs.chemmater.5b01582},
  doi = {10.1021/acs.chemmater.5b01582},
  language = {en},
  number = {14},
  urldate = {2019-02-11},
  journal = {Chem. Mater.},
  author = {Lang, Britta and Ziebarth, Benedikt and Els\"{a}sser, Christian},
  month = jul,
  year = {2015},
  pages = {5040--5048}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for zotero-bibtize, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size zotero_bibtize-0.1.0-py3-none-any.whl (10.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size zotero-bibtize-0.1.0.tar.gz (9.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page