trying to tweak BibTeX.js to get bibtex keys %A%y%T (capitalized author and title)

I'm trying to add %A and %T (for capitalized author and title) to the BibTeX.js file. I was using citeulike until it was recently discontinued, so most of my library items have keys like %A%y%T and it would be convenient for me to keep this convention.

I must be doing something wrong, but I don't know javascript so it's a bit hard to figure this out by myself. Is there a function similar to toUpperCase() but that changes to uppercase only the first letter?

I just edited the lines below. It does not work as expected, the output is the same as with "%a%y%t" except that some uninformative words at the start of the title are retained. Thanks for any help!

var citeKeyFormat = "%A%y%T";

var citeKeyCleanRe = /[^a-zA-Z0-9\!\$\&\*\+\-\.\/\:\;\<\>\?\[\]\^\_\`\|]+/g;

var citeKeyConversions = {
"a":function (flags, item) {
if (item.creators && item.creators[0] && item.creators[0].lastName) {
return item.creators[0].lastName.toLowerCase().replace(/ /g,"_").replace(/,/g,"");
}
return "noauthor";
},
"A":function (flags, item) {
if (item.creators && item.creators[0] && item.creators[0].lastName) {
return item.creators[0].lastName.toUpperCase().replace(/ /g,"_").replace(/,/g,"");
}
return "noauthor";
},
"t":function (flags, item) {
if (item["title"]) {
return item["title"].toLowerCase().replace(citeKeyTitleBannedRe, "").split(/\s+/g)[0];
}
return "notitle";
},
"T":function (flags, item) {
if (item["title"]) {
return item["title"].toUpperCase().replace(citeKeyTitleBannedRe, "").split(/\s+/g)[0];
}
return "notitle";
},
"y":function (flags, item) {
if (item.date) {
var date = Zotero.Utilities.strToDate(item.date);
if (date.year && numberRe.test(date.year)) {
return date.year;
}
}
return "nodate";
}
};
  • I would recommend instead installing the BetterBibTeX plugin, which lets you customize the citekeys and has other useful enhancements for working with LaTeX.
  • Thanks bwiernik, I will give it a go!
Sign In or Register to comment.