Bibtex export

  • Given that the last post was quite some time ago, I don't know how useful this will be, but I wanted to share my solution (due in large part to the collective posts here!). My solution is to use the "short title" field for my own citation keys. If that field is empty, then zotero will use it's own default. Note that I don't know the first thing about Java, so I just tinkered until I got functionality.

    1) Open your BibTeX.js translator file (in ....firefox/profiles/####.default/zotero/translators) in a text editor and scroll to (near the end) where you will see, "function doExport() {." A few lines below the function definition, you will see the line, "var citekey = buildCiteKey(item, citekeys);". Replace that line with the following:
    if (item.shortTitle==''){
    var citekey = buildCiteKey(item, citekeys);
    } else {
    var citekey = item.shortTitle

    I found the BibTexCiteKeyOnly.js file on another discussion ( It's a great little hack that allows you to literally drag your reference from zotero into your favorite latex editor! Once you get the BitTexCiteKeyOnly.js file, open it with a text editor and again scroll all the way to the bottom of the file. Replace the line "var citekey = buildCiteKey(item, citekeys);" with the code snippet above and presto.
  • I tried Scaffold, but the Bibtex translator does not show up in the list for some reason.

    I managed to customise the output key and a few other changes, by opening and editing the BibTeX.js file manually. You can modify the key by changing the citeKeyFormat variable. You are restricted to %a %y and %t format specifiers, but you can extend these by adding new functions to citeKeyConversions. It should not be all that hard if you are familiar with js.


    - Sid
  • I'm finding that the standard BibTeX export is doing the wrong thing with HTML entities in notes: it outputs something like this:

    {{\textless}p{\textgreater}Nice} pictures showing how well the {JUMP} math programme works.{\textless}/p{\textgreater}
    {{\textless}p{\textgreater}See} {\textless}a href=""{\textgreater}{\textless}/a{\textgreater} for (maybe?) some details.\ 

    That is really not the desired effect.

    I tried the "BibTex generic citation style (dev)" and it works more consistently, but doesn't export the Notes annotation fields at all.
  • edited April 26, 2011
    It is not suggested that you use the BibTeX CSL style. The right thing to do would be to intelligently transform the html markup into LaTeX markup. This is not trivial. So, perhaps we should strip html tags for now, e.g.:myString.replace(/<[^>]*>?/g, '');It'd be easy enough to put this in the BibTeX translator, but most of the other export formats probably don't expect html markup either. Not sure whether we should strip RIS and other formats or not.
  • Stripping HTML tags would be a big improvement. Transforming HTML markup to LaTeX markup could be done with a pandoc webservice, e.g. see
  • pandoc isn't a bad idea in the long run, but there are issues with setting up a host (if zotero was interested in doing that), degrading gracefully when there was no network connection (it is easy to just strip tags, but end-users may be surprised), and handling data privacy appropriately.

    If you need help implementing stripping, let me know. I'll probably think a bit about whether this should be part of other translators before submitting a patch & it may be sometime before that such a patch would be pushed out....
  • edited April 27, 2011
    There a few related problems,

    (1) the rich text editor saves invisible HTML formatting from copy and paste.

    (2) Exporting as RIS produces valid HTML, which is nice, but some of the links are strangely formatted:

    <a href="../../../../zotero.jar%21/content/zotero/tinymce/note.html">social learning theory</a>

    Not sure where best to report issues like this.
  • @CPLuser: Thanks a million!!!!

    This was a serious problem for me! I was retrofitting Zotero on a big project where I have already 250 citations, and I have spent almost a day searching for the old BibTeX keys manually defined and replacing them with Zotero's auto generated keys (as I found no way to change them). However, this beautiful hack solves the whole issue and I have a one-to-one transparency with the information provided in Zotero ("Short Title") and the BibTeX tag.
  • Hi!
    I want to modify the BibTex.js to get in the final file.bib this "\\~{a}" instead of this "ã".
    How can I do this?

  • The question is: do you really need this? The point is that the BibTeX versions I have used all accept Unicode characters in in the text fields (but not in the tags, so that is why it was good to be able to define the tags in the "Short Title" field).

    Unicode characters are not automatically accepted by TeX though, so you will need to include the following two packets at the beginning of your TeX file:


    Does this solve your problem? Including the two packages does not harm if you do not use special characters like ã. However, if they appear in your references this solves the typesetting issue when the *.bbl file is imported to produce the actual bibliography - and saves you the time to figure out where in the translator this change should be made (you would probably need a big translator table to handle all different accents in all languages).
  • What Geir said, and then, if you insist, enable the export encoding option in the Export pane of the Zotero preferences and choose something other than Unicode.
  • Geir Horn
    I included the two packages to my .tex, but an error appears: "! Latex Error: Option clash for package inputenc"

    Only in the .bib I cannot have accented characters. In the plain text (.tex) I can put ã, õ, ..., normally.
    I'm using this packages:
    But in the .bib I need put \~{o} instead of õ.

    Dan Stillman
    Thanks a lot. Worked very well.

    Best regards,
  • OK, it seems that you have found the solution. Otherwise, I would recommend that you try to comment out the two first packages (% in front) and load the only the two I suggested.

    At least the second one since that is the "inputenc" package I also suggested you to include and it will clash with the second include.

    Good luck!
  • Hello,

    I know this thread has been inactive for some time, but it seemed to be the appropriate place to ask my questions anyhow.
    Please correct me if I'm wrong.

    I have a number of bibtex export issues, a few of which I have fixes for which I have maintained by myself up till now.

    for hyphenation, bibtex uses babel and for this to work, the language field in zotero must be defined properly. This means lower case. I enforced this by changing
    for(var field in fieldMap) {
    if(item[fieldMap[field]]) {
    writeField(field, item[fieldMap[field]]);
    at line 1180 into:
    for(var field in fieldMap) {
    if(item[fieldMap[field]]) {
    // Force lower case for language field
    if(field == "language"){
    writeField(field, item[fieldMap[field]].toLowerCase());
    else {
    writeField(field, item[fieldMap[field]]);

    In a page range a single or multiple '-' are replaced by '--'
    I changed this to also remove space between the numbers and the dashes
    if(item.pages) {
    writeField("pages", item.pages.replace(/[-\u2012-\u2015\u2053]+/g,"--"));
    at line 1305 becomes
    if(item.pages) {
    writeField("pages", item.pages.replace(/\s*[-\u2012-\u2015\u2053]+\s*/g,"--"));

    I added an alternate 'µ' in the mapping table
    "\u03BC":"{\\textmu}", // MICRO SIGN

    I added a character which happened to be in the name of one of my colleagues
    "\u0111":"{\\dj}", // LATIN SMALL LETTER d WITH STROKE

    I fixed the comment at line 2380
    "{\\O}" : "\u00D8", // LATIN SMALL LETTER O WITH STROKE
    to become

    I added an option for a master's thesis type. Bibtex supports this, zotero doesn't. Use the 'type' field for definition
    At line 1163
    // determine type
    var type = zotero2bibtexTypeMap[item.itemType];
    // Add mastersthesis variant. Default is phdthesis
    if (item.itemType == "thesis"){
    if ((item.type == "M.Sc.") || (item.type == "M.Sc. thesis")) {
    type = "mastersthesis";

    A remaining unsolved problem is that \LaTeX, \TeX or \METAFONT cannot be placed in a title. I had fixed this, but since recently, capitalized words are enclosed in {} and now I get \{LaTeX} (with my mod in place) which does not give the desired result....
    The current state of the stock translator returns {\textbackslash}{LaTeX}} which is even worse

    An other problem is a paper:
    "S-D Modulators--Stability Analysis and Optimization" where S and D are actually the capital greek letters Sigma and Delta.
    In the bib file the title is abbreviated to '-', where 'modulators' would be more appropriate.
    In general, titles like "A-D conversion....." give no meaningful results. It seems to me no word less than 3 characters (no matter which alphabet, so before parsing a capital greek Delta to \Delta) should be allowed as title-key, or alternatively use ALL the words until a minimum of x characters is found and then finish the current word.

    I hope my suggestions are useful and maybe someone can help with the two remaining issues

  • I'll look at these, but may take a little; some are obvious, others I'm less sure about -- e.g. I don't think mastersthesis is standard bibtex. We do have a biblatex translator that already does this.
    Same applies for the language field and babel: IIRC, biblatex tries hard to get that right.

    I'm not sure we'll end up fixing the \LaTeX issue. It's a pain (and personally, I think it's stupid). But I suppose you could just run a .replace after everything else is done for whatever it ends up being then.

    Citekeys -- wouldn't be hard to do, would likely have been the right thing to do from the start, but I'm not too keen on changing the citekey algorithm, since people are using those in documents that'd break.
  • Hello,

    Glad to see such a fast response.
    I just found an other issue:
    Σ-Δ Modulators--Stability Analysis and Optimization
    is translated to
    {$\Sigma$-$\Delta$ {Modulators}--{Stability} {Analysis} and {Optimization}}
    which is correct, but the citation style converts the uppercase greek characters to lower case.
    Enclosing either {$\Sigma$} or ${\Sigma}$ fixes this. It would be nice to have that done automatically.

    Best regards,

  • edited April 24, 2015
    That last one may be more difficult to do than it may see, but I'll give it a shot.

    On a slightly unrelated note, I was looking around at best practices for protecting capitals in BibTeX and came across I don't have strong opinion on BibTeX things, but if protecting only capital letters is a better choice (rather than whole words) we can adjust that fairly easily.
  • To react on your remark about masterthesis, all the sources I find mention both mastersthesis and phdthesis
    As far as I understand Oren Patashnik is the (original) developer and he wrote in 1988 (page 9)
    so I think we can assume it is a standard entry type

    Regarding the capitalization issue, maybe what I'm talking about is more specific: preserve the case of non-latin characters. There is a high probability that these are not parts of words, so capitalization rules for words may not be applicable.
    On the other hand, in its current state the bibtex export DOES preserve case in latin-alphabet words, but NOT in greek (single characters? words?) Apparently uppercase/lowercase is only correctly detected for latin characters.

    Best regards,

  • Hi,

    First of all I reject my suggested addition of \u03BC (micro sign) since I found it was already defined in the list with greek letters as \mu.

    I was thinking about the implementation of preserving the upper case of greek letters.
    Maybe it's an idea to simply replace the mapping table entry
    "\u0394":"$\\Delta$", // GREEK Delta
    "\u0394":"{$\\Delta$}", // GREEK Delta

Sign In or Register to comment.