BibLaTeX customize translator

edited February 18, 2019
I'm trying to create a slightly modified translator for biblatex exports (based on biblatex.js). Despite my lack of javascript knowledge :/ I've been able to figure most of it out based on other discussions here on the forum. But here are a few things I'm still having trouble with:

Is there a way to replace “typographic quotes” with "straight quotes" in any of the fields, or, even better, the proper ``latex quotes''?

Then, for entries that don't have a subtitle, is there a way to make it duplicate the (entire) title to the shorttitle field?

I know that biblatex includes day and moth in the "date" field, however, I don't use those, and try to keep every entry minimal. Is there a way to strip the -MM-DD information from the date?

Lastly, for book entrytypes is there a way to make it duplicate the title to booktitle (for traditional bibtex crossrefs)?

EDIT: And one more: I'm also trying to get rid of the Googlebooks ID, which gets written into the notes field. Any way to omit that?

Thanks very much!
  • I recommend you install the BetterBibTeX plugin, which greatly expands Zotero's BibTeX features, including converting Unicode characters and quotes, etc., as well as allowing you the option to omit fields from export.
  • edited February 18, 2019

    I'm trying to create a slightly modified translator for biblatex exports (based on biblatex.js). Despite my lack of javascript knowledge :/ I've been able to figure most of it out based on other discussions here on the forum. But here are a few things I'm still having trouble with:

    Is there a way to replace “typographic quotes” with "straight quotes" in any of the fields, or, even better, the proper ``latex quotes''?

    BBT will replace those by default if you have "export as plain-text latex commands" on, and there's also https://retorque.re/zotero-better-bibtex/configuration/#csquotes

    Then, for entries that don't have a subtitle, is there a way to make it duplicate the (entire) title to the shorttitle field?

    Note that most of this can also be handled inside your latex document using biblatex macros, but if you insist:

    https://retorque.re/zotero-better-bibtex/scripting/ :

    if (Translator.BetterBibLaTeX && !this.has.shorttitle) this.add({ name: 'shorttitle', value: item.title })

    I know that biblatex includes day and moth in the "date" field, however, I don't use those, and try to keep every entry minimal. Is there a way to strip the -MM-DD information from the date?

    if (Translator.BetterBibLaTeX && item.date) {
    const date = Zotero.BetterBibTeX.parseDate(item.date)
    if (date.type === 'date') this.add({ name: 'date', value: date.year })
    }

    Lastly, for book entrytypes is there a way to make it duplicate the title to booktitle (for traditional bibtex crossrefs)?

    if (Translator.BetterBibLaTeX && item.itemType === 'book') this.add({ name: 'shorttitle', booktitle: item.title })

    EDIT: And one more: I'm also trying to get rid of the Googlebooks ID, which gets written into the notes field. Any way to omit that?

    BBT will probably have stripped the google books ID anyhow.

  • edited February 19, 2019
    Oh, thank you, that's great actually. And I don't even have to tweak the translator itself but can do it in the postscript window of Better BibLaTeX!

    OK, but in that case, now I need to ask a few further questions:

    I had modified a number of other things when creating my custom translator.
    I figured out how to omit fields in the user interface directly.
    But, instead of "journaltitle" and "langid" I'd like to have the traditional bibtex "journal" and "language" fields.

    Then, is there a way to replace typographic quotes without checking "export as plain-text latex commands"? I prefer unicode characters (of umlauts and accents etc.) to be preserved.

    And finally, I'm now getting capitalized strings enclosed in {{double braces}} – I prefer to protect strings manually, as websites are so inconsistent in how they display titles.

    Also, "booktitle" still doesn't get copied with the code you've provided above.

    Thanks so much for your help!
  • But, instead of "journaltitle" and "langid" I'd like to have the traditional bibtex "journal" and "language" fields.

    That's not traditional for biblatex though. Those are bibtex fields, for which biblatex provides fallback support. In any case:

    if (Translator.BetterBibLaTeX) {
    if (this.has.journaltitle) this.has.journaltitle.name = 'journal'
    /* or less hacky:
    if (this.has.journaltitle) {
    this.add({ name: 'journal', value: this.has.journaltitle.value })
    this.remove('journaltitle')
    }
    */
    if (this.has.langid) this.has.langid.name = 'language'
    }

    Then, is there a way to replace typographic quotes without checking "export as plain-text latex commands"? I prefer unicode characters (of umlauts and accents etc.) to be preserved.

    That's a reasonable request. Please open an issue on https://github.com/retorquere/zotero-better-bibtex/issues

    And finally, I'm now getting capitalized strings enclosed in {{double braces}} – I prefer to protect strings manually, as websites are so inconsistent in how they display titles.

    https://retorque.re/zotero-better-bibtex/faq/#bbt-is-changing-the-capitalization-of-my-titles--why has an explanation and a way to prevent case-meddling (which is a standard Zotero feature that BBT just happens to support).

    Also, "booktitle" still doesn't get copied with the code you've provided above.

    Sorry, that should have been

    if (Translator.BetterBibLaTeX && item.itemType === 'book') this.add({ name: 'booktitle', value: item.title })
  • Thank you, this is great!

    I've also opened an issue on github as you suggest. :)
  • A quick meta-question:
    Is it preferred to raise Better BibTeX specific issues on the github page instead of here (if they only apply to Better BibTeX)?
    (I mean user help questions, not bug reports/feature requests, the latter obviously belong there anyways)
  • We certainly don't mind them here, but Emiliano is more likely to see them quickly on github, so depends somewhat on how likely you think it is that you need him for an answer (in other words, the more technical the question, the better you'll probably fare on github).
  • I personally prefer everything BBT related to be handled on github, but I'll take my bug reports (and questions are potential bug reports) where I can get them. Once changes are going to be made in response to questions it does need to move to github since my workflow for releasing test builds only works there.
Sign In or Register to comment.