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.
  1. Have a working Zotero installation
  2. Install MozRepl http://github.com/bard/mozrepl/wikis/home and restart firefox
  3. Start MozRepl in Firefox: Tools->MozRepl->Start (if you want, you can select to make it start automatically for the future)
  4. Check that you can access MozRepl:
    telnet localhost 4242
    You should get some welcome message (Welcome to MozRepl . . . ). You can quit:
    repl.quit()
  5. Have a working Perl installation
  6. 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).
  7. Now you can run the perl program which will get the bibtex: getBibTeXFromZotero
  8. 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:
  1. Find the file: ~/.mozilla/XXXXXXX/zotero/translators/BibTeX.js, where XXXXXXXX will be some random string
  2. 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.
  3. 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:
    return date.year.toString().substring(2);
  4. You can also use another field if you prefer, e.g. call number, by changing
    var citekey = buildCiteKey(item, citekeys);
    to
    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)
getZoteroPDFs
Jason Friedman
Last modified: Fri Mar 12 12:03:58 EST 2010