"Extra" field usage when future-proofing for Better BibTeX usage?

edited 11 days ago
Is there a proper way for me to use the "Extra" field if I'd like to potentially use Better BibTeX in the future?

I already tried out Better BibTeX. My intention was to use it to connect Zotero to Obsidian with the Obsidian Zotero Integration plug-in. But that didn't work for me. So I removed Better BibTeX . But then I noticed it left behind all of the `Citation Key: a-citation-key` lines in the "Extra" field of my bibliographic items. I had to run the Javascript below to remove them.

Basically, I'd like to use the "Extra" field now for some other use cases of mine. But I'd like to do so in a way that wouldn't require me to muck around in Javascript if I wanted to use Better BibTeX at some point.


```
await Zotero.DB.executeTransaction(async function() {
let items = await Zotero.Items.getAll(Zotero.Libraries.userLibraryID, true); // Add parameters to getAll
let count = 0;
let errors = [];

try {
for (let item of items) {
if (!item.isRegularItem()) continue;

let extra = item.getField('extra');
if (!extra || !extra.includes('Citation Key:')) continue;

try {
const newExtra = extra
.split('\n')
.filter(line => !line.startsWith('Citation Key:'))
.filter(line => line.trim())
.join('\n');

item.setField('extra', newExtra);
await item.save();
count++;
Zotero.debug(`Updated item ${item.id}: ${item.getField('title')}`);
} catch (itemError) {
errors.push(`Failed to update item ${item.id}: ${item.getField('title')}: ${itemError.message}`); // More context in error
}
}

const message = [
`${count} items updated successfully.`,
errors.length ? `\nErrors encountered: ${errors.length}` : '',
...errors
].join('\n');

Zotero.debug(message);
return message;

} catch (error) {
Zotero.debug(`Transaction failed: ${error.message}`);
throw error;
}
});
```
  • Can you say what exact scenario you want to future proof against? BBT should not overwrite Extra with Citation keys -- it should just add them to existing content.
  • Ok, so, BBT would just add citation keys in the format `Citation Key: a-citation-key` as the first line of the "Extra" field, not modifying any other info therein, right? If that's the case, then there's really nothing for me to worry about. I just ask because I was surprised that BBT left behind all its citation keys in the "Extra" field and was wondering if there might be some other unexpected behavior if I tried to plug-in BBT again in the future.
  • You'd have had to 'pin' citation styles with BBT for it to write to Extra, which is a separate operation. Since the whole point of this is to generate editable, stable citekeys, I think it makes sense that BBT wouldn't try to clean this up. I'm fairly certain it wouldn't overwrite existing information in Extra -- Zotero translators, e.g., also often write important metadata into the Extra field, it'd be very bad if BBT were to erase that.
Sign In or Register to comment.