To automatically get bibtex from Zotero
Zotero is a great tool, it is very easy to collect and organise your references with it. However, if you are a LaTeX user and use BibTeX, then it is a pain to have to continually export your bibliography to be able to use it with LaTeX. The solution described below allows you to have a script extract the bibliography automatically for you in BibTex form, saving a few precious seconds.
[Program last updated 4th October 2015 to set libraryID to prevent crashing on Zotero >= 188.8.131.52 (thanks to Werner Koch)]
- Have a working Zotero installation
- Install MozRepl http://github.com/bard/mozrepl/wikis/home (in Zotero standalone, go to tools->Add Ons -> Extensions -> Install add-on from file).
- Restart firefox (or Zotero standalone)
- Start MozRepl in Firefox: Tools->MozRepl->Start (if you want, you can select to make it start automatically for the future) (In Zotero standalone, if it does not appear in the tools menu, you can turn it on via the preferences: Preferences-> advanced -> Open about:config. Change extensions.mozrepl.autoStart to true)
- Check that you can access MozRepl:
telnet localhost 4242
You should get some welcome message (Welcome to MozRepl . . . ).
You can quit:
- Have a working Perl installation
- Install the CPAN package MozRepl: http://search.cpan.org/~zigorou/MozRepl-0.06/ (if you have not done this before google for "install CPAN tutorial" to find out how to do it such that the dependencies will be automatically installed).
- Now you can run the perl program which will get the bibtex: getBibTeXFromZotero
- If you only want the references from a single collection, you can use getBibTeXFromZoteroCollection instead (and edit the program to specify the collection you want).
You can then use a program such as bibtool if you want to sort your bibtex file or extract only those records with particular keywords.
Enjoy! Any comments or fixes would be appreciated by email
How to change the key format used by Zotero
Another somewhat annoying "feature" of Zotero is that when exporting to bibtex, it automatically sets the key for you. Many people have preferred key styles. This introduces two problems - for old references, you want your old key, not an autogenerated one, secondly, for new references, you would like the key in "your style". The second problem is relatively easily solved:
- Find the file: ~/.mozilla/XXXXXXX/zotero/translators/BibTeX.js, where XXXXXXXX will be some random string
- The line to change is:
var citeKeyFormat = "%a_%t_%y";
For example, I changed it to
var citeKeyFormat = "%a%y%t";
%a is first author, %t is first word from title, %y is the year.
- I also prefer two digit years. For as long as I can foresee myself living, 2 digit years are sufficient. To "fix" this, change the line with date.year (line 1848 in the version when this was written) to:
- You can also use another field if you prefer, e.g. call number, by changing
var citekey = buildCiteKey(item, citekeys);
var citekey = item.callNumber;
How to get all PDFs with a particular tag
I organise my references in zotero with a tag to designate which project it is associated with. I also tag new stuff with "toread" to remind me to read it. I wanted
to be able to extract easily all the pdfs with a given tag. The attached program (also using MozRepl, same instructions as above) will do this (updated 21/4/10 to delete files if they already exist to prevent it crashing; updated 4/10/15 to prevent crashing if filename is undefined)
Last modified: Fri Mar 12 12:03:58 EST 2010