[betterbibtex] How to use ShortTitle bibtex field for creating citation keys only if it's present?

Hi,

I'm using the betterbibtex plugin. Sometimes I don't like the citation key that gets generated from the shorttitle function.

Therefore, I tried to leverage the ShortTitle field to set a more meaningful citation key if I set a short title. I used this citation key formula:

```
auth.lower+authForeIni+year+ShortTitle.transliterate.skipwords.clean.capitalize|auth.lower+authForeIni+year+shorttitle(3,3)
```

Unfortunately, zotero always uses first part of the formula—even if ShortTitle is actually empty. This leads to citation keys like this: `hempP2004` (for Hemp's article “Leading Change When Business Is Good”).

This is probably, because `auth.lower+authForeIni+year` is always a non-empty string. Therefore, the second part (after the `|` pipe) isn't used. But that's not what I want.

Is there some sort of ternary operator to achieve what I want?

```
ShortTitle.transliterate.skipwords.clean.capitalize ? auth.lower+authForeIni+year+ShortTitle.transliterate.skipwords.clean.capitalize : auth.lower+authForeIni+year+shorttitle(3,3)
```

Or in other words:

```
if ShortTitle.transliterate.skipwords.clean.capitalize!=""
    auth.lower+authForeIni+year+ShortTitle.transliterate.skipwords.clean.capitalize
else
    auth.lower+authForeIni+year+shorttitle(3,3)
```
  • auth.lower + authForeIni + year + ShortTitle.transliterate.skipwords.clean.capitalize.len;
    auth.lower + authForeIni + year + shorttitle(3,3);


    ternaries are coming but it's not a short-term thing. I need to finish Zotero 7 support first.
  • edited August 4, 2023
    Thanks for your answer. That seems to work quite nicely.

    How does it work? What's the magic behind the semicolon? It either isn't documented, or I must have overlooked it.

    Also: Is there a way to batch refresh citation keys using a filter or condition? I have a bunch of citation keys ending with the year (because ShortTitle was empty). I want to update only those. So, is it possible somehow to filter for citation key=@(.*)\d\d\d\d$
  • edited August 4, 2023
    No magic; | is equivalent to ; except ; is allowed at the end of a formula where | is not. The "magic" is in the .len at the end. If that fails, the formula jumps to the next candidate, regardless of where it appears in the sub-formula.

    No way to filter that way. An item does not remember what formula was used to generate its citekey. You can refresh in bulk (right click, better bibtex, refresh), but that is indiscriminate, it will refresh all selected non-pinned keys.
  • Okay, thank you so much!
  • ternary support turned out to be fairly easy, so that's in now.
Sign In or Register to comment.