BBT's Citation key formula: Special characters , (comma) and () (parentheses)

Hello,

I am setting up Better BibTeX's Citation key formula. When a paper has three authors, my desired citekey format is Author1name,Author2name,andAuthor3name(Year). A real example would be a paper by Graham, Michaely, and Roberts published in 2003 should have the citekey Graham,Michaely,andRoberts(2003).

I looked at BBT's citekey configuration at https://retorque.re/zotero-better-bibtex/citing/#generating-citekeys, and the Citation key formula I came up with was: authors(n=3,sep=",and",min=3,max=3).replace(/,and/,',') + year.prefix('(').postfix(')').

But with this formula, the generated citekey is Author1nameAuthor2nameandAuthor3nameYear; or using the real example, GrahamMichaelyandRoberts2003. In other words, the special characters , (comma in between author names) and () (parentheses around the year) are missing in the citekey output.

Strangely, in place of , (comma) and () (parentheses), I tried in the formula using other special characters like ; (semicolon), - (dash), or [] (square brackets), and the citekey would show these special characters with no problem. So my questions are:

- How can I change my Citation key formula so that , and () show up in the citekey output?
- Are there reasons against using , or () in citekeys in general that I'm unaware of?

Thank you.
  • edited February 3, 2024

    • You can't with Better BibTeX you shouldn't, but you can. If you go into Zotero's hidden prefs you can search for extensions.zotero.translators.better-bibtex.citekeyUnsafeChars and remove the characters you want to have passed through. You will most likely end up with unparsable output though.
    • Commas and parentheses are not valid in citationkeys; if left there the result would not compile in your document. The other characters you name aren't special, which is why they are passed through.
  • I see. Thank you for the explanation, emilianoeheyns. For some reason, I thought it would make the citekeys more readable by having commas and parentheses in them. It turns out that's treacherous territory.

    - Per your suggestion, I will not remove any unsafe characters in the hidden preferences. For anyone curious, the current list of unsafe characters in that preference is \"#%'(),={}~.
    - I have discarded the idea of using commas and parentheses. But this still leaves the question of which special characters are valid in citekeys for compilation. I searched around and found Pandoc could generally accept _:.#$%&-+?<>~/ (https://pandoc.org/MANUAL.html#citation-syntax). Crossing off BBT's unsafe list from Pandoc's accepted list gave me a subset of characters to choose from. There is still LaTeX to consider, which I believe the characters it allows would vary by the tool. Then that's something for me to experiment with.

    Thank you for helping me with my questions, and I greatly appreciate this awesome plugin you made and continue to develop!
Sign In or Register to comment.