Stop Zotero from escaping special characters in journal abbreviations

Hi all,

I'm trying to use the IEEEabrv file which contains a bunch of string definitions for abbreviated journal titles. This means exporting to a bibtex file and checking the "Use journal abbrevs." option. My journal abbrevs are like this: IEEE_J_AWPL. Unfortunately, Zotero exports that as IEEE\_J\_AWPL, and so a string replacement looking for IEEE_J_AWPL fails. Is there a way to tell zotero NOT to escape special latex characters?

Thanks,

Lefty
  • no. It's been discussed, but devs are very reluctant to implement a feature that would have people enter data into Zotero "incorrectly" (in the sense that it produces incorrect citations via Zotero proper. Is there any reason those abbreviations need to contain bibtex protected characters? It's not like there are that many.
  • Ok, I've changed my copy of IEEE's abbreviations bib file so the strings it's looking to replace also have the backslash before the underscore.

    Now I've got a different problem. Zotero is wrapping the journal name in {}s. It seems that bibtex's @string command will not replace strings which are inside {}s. That's not an issue of using "bad" characters in the abbreviation strings, so is there a way to get zotero to stop wrapping journal abbreviations in curly brackets?
  • Zotero does that to preserve the uppercasing of acronyms (like IEEE). It is my understanding that bibtex will otherwise force the entire string to lowercase when you actually cite it.
  • edited January 9, 2014
    Thanks for the reply adam. I understand that's why it's done, but it makes it impossible to use the bibtex @string command to do string replacement...is there a way to control this behavior so it could be turned off just for the journal entry when journal abbreviations is checked? Having it default to protecting strings like that makes a lot of sense, but if I know I want it off, it would be nice to be able to change that. If there's a file I can modify just on my own install that would be fine, but I'm not sure where to start looking for where this behavior is controlled.

    EDIT: Alternatively, is there somewhere I can just define my own "abbreviated journal titles" within zotero?
  • if you're willing to hack your bibtex export that wouldn't be terribly hard: the file to modify is BibTeX.js in the translators folder in your data directory:
    http://www.zotero.org/support/zotero_data
    The relevant line is
    https://github.com/zotero/translators/blob/master/BibTeX.js#L2155
    for escaping and
    https://github.com/zotero/translators/blob/master/BibTeX.js#L2174
    for the curly brackets
    note that both operations already don't run on some fields, so you could just add more.
    Note that translators auto-update, so your customization would be overwritten on each translator update and, I believe, Zotero update, but since they're tiny changes they are easy to put back in.
    EDIT: Alternatively, is there somewhere I can just define my own "abbreviated journal titles" within zotero?
    note quite sure I understand: you want an algorithm to create abbreviations? Or a list that Zotero uses for export? That's not possible. What is possible is to add a list that Zotero uses for citations with the Word/LibreOffice plugin
  • Ah, thanks for pointing me to the translator file, that might do the trick.

    What I'm trying to achieve is basically a library of correct abbreviations. There is already a file that has the "standard" IEEE abbreviations; for instance it turns "Transactions on medicine and biology" into "Trans. Med. Biol." This is achieved by loading a IEEEabrv.bib file which adds a bunch of @string replacement lines before the main bib file is loaded, but the strings it's trying to replace are "IEEE_J_MB," so I need zotero's "use journal abbreviations" check box to generate the correct "IEEE_J_MB" type tags.

    I would be equally happy if I could somehow teach zotero to automatically populate the journal abbreviation field based on some catalog, I could adapt that from this IEEE file. Currently the journal abbreviation field doesn't seem to be populated for most of my entries, although it is for some.

    ps, here's information on the IEEEabrv file in question, if you're curious: http://www.michaelshell.org/tex/ieeetran/bibtex/
  • no, you can't easily populate the journal Abbr. field in Zotero. As I say, Zotero has it's own built in list that includes the IEEE abbreviations (and many more), but that's only usable currently via the word processor plugin. But because of that option, the journal Abbr field in Zotero proper is becoming less important. Whether the field is populated or not depends on where you import from, but you're right, most sites aren't very good at supplying that data.
  • Ah, ok. So since I'm using bibtex rather than a word processor plugin things get a bit more complicated.

    I'm trying to hack the BibTeX.js file and it doesn't seem to have any effect. To test things, I'm first trying to remove the braces from around the "author" field. (I'm not sure what the journal abbreviation field is called in the code). This doesn't appear to work. I've tried modifying line 2152 to be this:

    if (!isMacro || field != "author" ) Zotero.write("{");

    I also modified the corresponding close bracket code on line 2185.

    If I understand correctly, with this modification if the field is "author" it won't write the opening or closing curly brackets. But when I open the .bib file the author list is still enclosed in curly brackets.

    Am I misunderstanding what the BibTeX.js file is doing?
    Thanks again for your help!
  • edited January 10, 2014
    you generally have the right idea but
    1. It should be if (!isMacro && field != "author" ) Zotero.write("{");

    2. the author field isn't actually written in that function - write fields deals with all the "normal" fields (e.g. for volume the above code works).
    The author treatment is a bit more complicated, but should be pretty straightforward in terms of removing the curly brackets. It starts here, right in doExport:
    https://github.com/zotero/translators/blob/master/BibTeX.js#L2424
  • Well, i was only trying author as a test case with a known field name. I could just as well try "volume" if it's simpler.
    Unfortunately if I do this:

    if (!isMacro && field != "volume" ) Zotero.write("{");

    the volume is still enclosed in brackets, so it seems I'm still missing something.

    Also, do you know what the name of the journal abbreviation field is? I see that the "Short Title" field gets referenced as "shorttitle" in the code. Does "Journal Abbreviation" become "journalabbreviation"?
  • mappings are here: http://aurimasv.github.io/z2csl/typeMap.xml#map-journalArticle

    the above definitely works for volume, I tested it. Make sure you're modifying the right translator (there are separate bibtex and biblatex ones)
  • Turns out when I set up a custom directory for zotero I ended up with two copies of the translate folder and I was editing the wrong one, sorry!

    Here's what I've learned: it looks like if the code detects that the user wants to use journal abbreviations it copies the journalAbbreviation field into the journal field and then runs writeField(). This means that writeField never knows that the field in question is actually an abbreviation, so testing for journalAbbreviation will always fail.

    Here's what I did instead:
    I modified line 2410 to flag the entry as a macro:

    writeField("journal", item.journalAbbreviation,true);

    This means escape characters, extra braces, etc are all skipped. I think this is reasonably correct, I'm basically wanting to use the journal abbreviation as a macro that gets interpreted by a separate .bib file.

    What do you think? Too ugly? Some nasty consequence I'm not anticipating?

    Thanks for your help!
  • haven't thought this through, but sounds good to me.
  • For anyone stumbling across this thread, you probably don't want to do what I did, I've gone and un-done the changes I made to the translator.

    It turns out that the entries which lacked text versions of the abbreviated journal title (and for which I was trying to set up these keys with underscores) were just the entries I'd populated by pasting the DOI into Zotero. Entries grabbed from the journal website have the journal abbreviation in there just fine, so aside from papers I downloaded before I got Zotero, everything works fine with the default behavior, and for non-IEEE journals (ones where I don't have the keys for abbreviations anyway) my original solution breaks the abbreviations completely.
Sign In or Register to comment.