Automate case protection enabling/disabling

Hello

I have asked a question on tex Stack Exchange about how one could change multiple entries' sentence case/title case at once but we have not reached a solution. My current practice is to click each title field and select Sentence case of Title Case. Please see if you could help me out.
https://tex.stackexchange.com/questions/546976/is-there-a-command-to-make-reference-entries-type-consistent/548122?noredirect=1#comment1388897_548122
  • edited June 18, 2020
    You should always store your titles in sentence case in Zotero, then put any proper nouns in uppercase. If you need a Word to always be lowercase, wrap it in <span class="nocase"> </span> Tags
  • Thanks for the response. All of my entries are imported to Zotero with the web browser add-in. I know I should save them in sentence case but that currently involves me modifying entries one by one. I would appreciate an automated option.
  • See https://www.zotero.org/support/kb/sentence_casing — there's simply no way to reliably automate a conversion to sentence case.
  • I think the question is whether the existing convert to (pseudo-)sentence-case option could be run in batch
  • We could obviously provide a way to batch-convert titles to sentence case, but I'm not sure it makes sense, given that you need to correct any proper nouns, and there's a good chance some/many of your titles are truncated in the middle pane and wouldn't be fully visible.

    (For what it's worth, I've wondered before whether it would make sense to bring an auto-conversion feature like we have in ZoteroBib to Zotero, but it'd be a bit more dangerous without the kind of explicit review step we have in ZoteroBib. Data can also get into a Zotero library in so many ways that it might get confusing. For example, we'd want it for saving from the web or Add Item by Identifier, but I'm not sure we'd want it to apply to imports from a file, but if you click a RIS file in the browser and the connector intercepts it, does that count as saving from the browser or as an import? Joining a group library obviously doesn't convert the items in that library, but if you drag an item from a group library to your own library, does it get converted? Also worth noting that in ZoteroBib it's only a soft conversion — if you change back to another style, it goes back to its original form, unless you made a manual edit in the meantime.)
  • I found this thread by searching for "batch sentence case." I would far rather correct some individual proper nouns in a few citations before submitting a manuscript than have to go through thousands of citations individually right-clicking on them to convert them. Could there be a setting on the import tool that automatically saves the citations in sentence case? Or just a way to let us batch-edit to sentence case with the caveat that yes, we might lose some proper nouns in the process but c'est la vie?
  • edited December 4, 2023
    At your own risk:

    1. Go into Tools -> Developer -> Run Javascript
    2. Check "Run as async"
    3. Paste in the script below, verbatim
    4. select some items in the main zotero pane
    5. click "Run"
    const sentenceCase = Zotero.Utilities.sentenceCase || function (val) {
    newVal = val.toLowerCase().replace(/\s*:/, ":");
    newVal = newVal.replace(/(([\?!]\s*|^)([\'\"¡¿“‘„«\s]+)?[^\s])/g, function (x) {
    return x.replace(/\s+/m, " ").toUpperCase();});
    return newVal
    }
    let title
    for (const item of Zotero.getActiveZoteroPane().getSelectedItems()) {
    if (item.isFeedItem || !item.isRegularItem() || !(title = item.getField('title'))) continue
    item.setField('title', sentenceCase(title))
    await item.saveTx()
    }
  • I presume 'Short Title' and 'Series Title' should also be sentence-cased? What about other fields, like 'Proceedings Title', 'Conference Name', or even 'Publication', however?

    @emilianoeheyns Very handy, thank you.
Sign In or Register to comment.