Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /homepages/32/d440917654/htdocs/wp/wp-content/plugins/jetpack/_inc/lib/class.media-summary.php on line 77

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /homepages/32/d440917654/htdocs/wp/wp-content/plugins/jetpack/_inc/lib/class.media-summary.php on line 87

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /homepages/32/d440917654/htdocs/wp/wp-content/plugins/jetpack/modules/infinite-scroll/infinity.php on line 153Exporting to BibTeX from Zotero - Melsophia

Exporting to BibTeX from Zotero

As I explained in a previous post (in french), Zotero is a wonderful tool to manage bibliographies, but it is not the end of the story: in order to use these bibliographies in LaTeX documents, one needs to convert them to BibTeX from Zotero. And here the things get complicated: Zotero provides a set of translators, including one for BibTex, but it is far from being perfect. For this reason I have written a bash script which makes some cleanup in the BibTeX files generated from Zotero.

In my Zotero library I have a collection « Papers » where the subcollections are my various projects. Then I just have to export these various projects to a common folder (the variable $BIBPATH in the code below; in my case it is ~/Documents/Bibliographies/zotero/). Everytime I modify a collection, I export it again, and then I run again my script (saved under « ~/bin/bibtrim »): but note that this script has no effect on the files that have been cleaned already, so it is safe to run it several times on the same files.

As you can see all the script relies on sed to remove or replace some contents. Here are a summary of the different operations:

First delete some useless content (or poorly filled – see below for arXiv), like abstract, address, etc. A side-effect is to decrease the file sizes.

Double the bracket around titles to protect the uppercase letters;

It is useful to define the fields « archivePrefix » (to arXiv) and « eprint » (to the paper id) for arXiv entries in order to display them correctly with modern BibTex styles (they display ArXiv followed by the identifier with an url). These entries are defined from the arxiv url, which are themselves removed after that to avoid duplication.
Then the journal entry is removed for modern articles (with id as xxxx.xxxx) because they contain only information about the arXiv eprint, and not on the final publication.
Note that I do not save the primary class since it is not useful to construct the url, and it is not possible to get it (for the moment) for modern id.

Fix LaTex formula in the title (symbols like \ and $ are protected when exporting, but we don’t want that).

Delete the url field if the doi field is present (to avoid duplication).

Finally clean up the garbage that previous commands made (empty url fields, more that two brackets, etc.).

The main problem with arXiv entries (with modern id) is that the publication data (journal, etc.) are stored into the extra field, exported into notes. So they are removed with the first command, while it would be interesting to keep them: but it is quite difficult to convert them from the extra because it is just a string of characters.

Update 12/07/2014: the previous script was introducing a new line at the beginning of the file and deleting the before last line after each run. This bad behavior came from the code used to delete the url fields that came before doi. Now this problem is fixed. I have also added a line to delete leading blank lines.

Update 11/08/2014: there was some problems with the brackets in title, so now all brackets inside the title are removed.

Update 17/04/2016: Here is a new version of the script that is intended to work with Better Bibtex. I am not replacing the previous version because I did not test if this was compatible with normal bibtex export.

Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /homepages/32/d440917654/htdocs/wp/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048