Suggestion for next version: automatically changing hyphen to en-dash in page ranges

As a copyeditor, I can't say how many thousands of times I've manually changed a citation page range to replace hyphens with en-dashes. I actually do a search for all hyphens for this purpose as one of my first steps every time I open a new project. I've noticed that page ranges in Zotero are mixed...some are expressed with a hyphen and others have an en-dash. Given that en-dash is correct, maybe the next version can automatically replace hyphens with en-dashes in the "Pages" field?

Thanks for considering!
  • The latest versions of Zotero apply en-dash more aggressively. I think we've covered all but a few edge cases. If you find particular patterns that fail in current Zotero, do post a note and I'll take a look.
  • I know Zoter handles this automatically for page ranges and dates, which is great! But I have not been able to figure out a way to deal with titles that have number ranges in them. This is a very common feature of titles in my field of biblical studies where a title might include part that refers to a bible reference such as John 5:1-10. Many styles in my field expect the hyphen in those cases to be an en-dash. I have not found a quick way to enter en-dashes when manually inputting titles, and more often I am importing references into zotero with ISBN numbers or DOI's etc. In those cases I have to be careful to check the titles and manually change it.

    Is there a way for CSL to do with number ranges in titles what it already does with other fields with number ranges in them? Meanwhile, is there a fast way to enter en-dash manually in a title? I am making one in Word with a keyboard short cut and then copy/pasting it to the title in Zotero.
  • I don’t think there is a reliable way to do this in titles that wouldn’t break other cases where hyphens are appropriate.

    On Mac, you can type Alt/Opt+hyphen to get an en dash. On Windows, you can type Alt+0150. You can also install a keyboard layout that mimics the Mac behavior (I can link to one if you like).
  • hallo. is it possible to to use hyphen instead of en-dashes? in my citation style zotero changes automatically all the hyphens with en-dashes.
  • This can be set via page-range-delimiter in the citation style, yes, but for almost all cases I'd strongly recommend an en dash for page ranges.
  • @adamsmith
    Thank you for your response. But what presicely should I do use hyphens automatically intead of of en-dashes?
  • You would insert this between the info section and the first macro of the style, this is for a style in English language:

    <locale xml:lang="en">
    <terms>
    <term name="page-range-delimiter">-</term>
    </terms>
    </locale>
  • I have some hyphens in my volume field that should remain hyphens in the output but I want the hyphens used in my pages field to switch to en dashes in the output. Inserting the text suggested above results in hyphens in both the outputted volume and pages. Is there a way to have just the volume data output as hyphens, because these are not really ranges and should be hyphens not en dashes.
  • Unfortunately not, no, sorry. What's an example for a volume that should keep the hyphen?
  • A journal Phytoneuron (see https://www.phytoneuron.net/2022-publications/) has volumes with dashes. For example 2022-1.

    Any thoughts on a work around?

  • Using a non-breaking hyphen for the volume works and that isn't changed by Zotero/CSL ( ‑ https://en.wikipedia.org/wiki/Wikipedia:Non-breaking_hyphen)
  • Thanks. That should work.
  • A related question. Is there a way I can use find and replace to replace my hyphens with a non-breaking hyphen for this journal on the database side?
  • This thread comes pretty close to having the instructions/code, though filtering by the journal is an extra step: https://forums.zotero.org/discussion/101104/find-replace-javascript-batch-editing-partial-item-field-info#latest
  • edited December 10, 2022
    Thanks.
    This code seemed to do it. The item that looks like a hyphen in the new part is a non-breaking hyphen. Also once my document is ready for publication I can do a find and replace in the document and change the non-breaking hyphen to a hyphen.

    var fieldName = "volume";
    var newPart = "‑";
    var fieldName2 = "publicationTitle";


    let oldPart = "-";
    let s = new Zotero.Search();
    s.libraryID = ZoteroPane.getSelectedLibraryID();
    s.addCondition(fieldName2, "is", "Phytoneuron");
    let ids = await s.search();
    if (!ids.length) {
    return "No items found";
    }
    await Zotero.DB.executeTransaction(async function () {
    for (let id of ids) {
    let item = await Zotero.Items.getAsync(id);
    let oldWhole = item.getField(fieldName);
    let newWhole = oldWhole.replace(oldPart, newPart);
    item.setField(fieldName, newWhole);
    await item.save();
    }
    });
    return ids.length + " item(s) updated";
  • Why would you need to change it to normal hyphens in the end? In that place I'd logically expect non-breaking hyphens anyway. Provided there are no font-related issues, I'd keep them.
  • No need really. Your suggestion makes sense.
Sign In or Register to comment.