bibtex key format cutomizable?

Is it possible to customize the format in which bibtex keys are automatically generated? I would simply like to change _ to - for better compatibility with my editor's auto-complete feature.
  • Yes, but not in the interface. You can edit the variable in the JavaScript file that does Zotero's BibTeX export (BibTeX.js in the translators directory):

    //%a = first author surname
    //%y = year
    //%t = first word of title
    var citeKeyFormat = "%a_%t_%y";

    One way to do this is to make these changes in a renamed copy of BibTeX.js file so as not to have your changes clobbered whenever there is an update in the file. It's not too hard. Copy the file to BibTeX-myversion.js and just change those underscores to hyphens. You also need to generate a new ID for the translator. There are instructions under Roll Your Own" at the link below. It will show up as an export format when you restart Firefox.

    For what it's worth I have a few hacked version of BibTeX.js here.

    http://github.com/commonman/zotero-bibtex-sb

    I've made other changes, but haven't changed that line (I'm still trying to decide how I want my keys to look), but the README tells where the file is, and details some changes I had to make.

    The other way is to postprocess your .bib file and re-generate the keys. There are a few cross platform tools which can do that. The ones I know about are in the link above.
  • Thanks, most useful!
  • This is a very nice solution. I also added to it the option to take the "Extra" field as a manually set bibtex key if it is not empty. For that in the file:

    .mozilla/firefox/xxxxxx/zotero/translators/BibTeX.js

    replace the line:

    var citekey = buildCiteKey(item, citekeys);

    by:

    // Take the extra field as citekey
    var citekey = item.extra;
    if (citekey == "") {
    // if empty then create a unique citation key
    var citekey = buildCiteKey(item, citekeys);
    }
  • edited April 24, 2012
    I'm wondering if there's a particular reason that zotero uses name_word_year as the bibtex cite key? To me it'd seem more sensible to use name_year for any refs that don't have name-year clashes, and name_year_word for any that do. This makes it easier to type, and easier to remember, and it's probably more closely related to the in-text citation style (for name-date styles, anyway, are there any that use part of the title?).

    Before I try to change my export style to suit, I'd like to check that this isn't just an arbitrary choice that hasn't been changed for historical reasons...
  • Hi Zaher

    Is there a way to do it for Better BibTeX.js translation directory? I assume I would have to edit this one if this is my setup. I can't find the lines in the file though.

    Thanks
  • You don’t need to edit the JS files at all. Just install BetterBibTeX and you can set the Citekey format on the Preferences pane.
Sign In or Register to comment.