Bulk editing of titles - is it possible?
I need to reformat a bibliography for a particularly persnickety journal.
I know that I can select an individual item in my Zotero library on my Mac, right click on the Title field and convert it to sentence case. But is there a way to do that for a whole group of items that I select?
I also know that I can add HTML tags to scientific names within an individual item in my library, so that they appear in italics. But is there a way to do a search and replace for a whole group of items, so as to add the tags without having to do each item individually?
I know that I can select an individual item in my Zotero library on my Mac, right click on the Title field and convert it to sentence case. But is there a way to do that for a whole group of items that I select?
I also know that I can add HTML tags to scientific names within an individual item in my library, so that they appear in italics. But is there a way to do a search and replace for a whole group of items, so as to add the tags without having to do each item individually?
https://www.zotero.org/support/dev/client_coding/javascript_api#batch_editing
It might also be possible to use the JavaScript API to mass-convert titles to sentence case (you should always store titles in sentence case), but you will want to be careful there to check for proper casing of words afterward (e.g., the genus name).
@dstillman Is the sentence-casing function available in the JavaScript API?
zoteroPane = Zotero.getActiveZoteroPane();
items = zoteroPane.getSelectedItems();
var result = "";
for (item of items) {
var title = item.getField('title');
result += " " + title + "\n";
var new_title = title.replace(/\b([A-Z][a-z0-9]+|A)\b/g, function (x) { return x.toLowerCase(); });
new_title = new_title.replace(/(^|\?\s*)[a-z]/, function (x) { return x.toUpperCase(); });
result += "-> " + new_title + "\n\n";
// // Do it at your own risk
// item.setField('title', new_title);
// await item.saveTx();
}
return result;
My variation of your code simply converts titles of selected items to sentence case. Proper nouns then need to be manually re-capitalised. A marker is added to the extra field so that this code will not overwrite re-capitalised titles. On balance, this saves me time when lots of titles have initially been saved to Zotero in title case.
// this code changes titles in selected items to sentence case
// note that Proper nouns will need to be manually changed(back) to Upper case
// paste and run this code from Zotero>Tools>Developer>Run Javascript
zoteroPane = Zotero.getActiveZoteroPane();
items = zoteroPane.getSelectedItems();
var result = "";
for (item of items)
{
var extra = item.getField('extra');
if(extra.indexOf("sentenceCase:1") === -1)
{
var title = item.getField('title').trim();
if(title)
{
result += " " + title + "\n";
// make first char uppercase and remainder lowercase
var new_title = title[0].toUpperCase() + title.substring(1).toLowerCase();
result += "-> " + new_title + "\n\n";
// add marker in extra to stop title being overwritten by this code after manually (re-)capitalising proper nouns
var new_extra = extra + "\nsentenceCase:1";
// uncomment next line to write changes to title and extra fields
//item.setField('title', new_title); await item.saveTx(); item.setField('extra', new_extra); await item.saveTx();
}
}
}
return result;
Using Better BibTeX plugin: Select the items, right click and choose "Better BibTeX -> BBT Sentence-case".
fter
was something special, like a ligature, but you just meant "after:
". In which case, correct, BBT sentencecase only applies lower-case to parts of the title in the assumption that the title is in Title Case, it doesn't ever upper-case anything.