The question says it all: how does one convert every dash between numbers to en-dash (a common publishing convention)? That is, change e.g. “27-32” to “27–32” without changing the hypen in, e.g. “bitter-sweet” to an en-dash as well?
It turns out there is a trick to the use LibreOffice’s regular expressions that took a bit of head-scratching. For changing hyphen/dash to en-dash between numbers only, this is what to do:
- CTRL-H to open search/replace dialog, then click the “More Options” button (if not already displayed) and enable the “[x] Regular expressions” option.
- In the “Search for” box, paste in:
([0-9])-([0-9])
- In the "Replace with box, paste in:
$1–$2
- Click “Replace All” button. Done!
Commentary: the “search” looks for any dash that is preceded and followed by a number. The “replace” value changes only the dash to an en-dash, while $1
and $2
represent the values found in the search for the first and second terms, and retains them unchanged.
That ought to do it. It works for me, at any rate! Hope this is a help for others.
Sorry I messed up the attempt to make a corrective comment to my answer. Here the correction - and I hope not save mistake happens again.
Orignal answer:
actually there should be space between figures and a hyphen/dash/en-dash when you write a text in writer. (mathematical formulas in Calc are different!!!)
Thus when you type: “2 space hyphen space 3 space” the hyphen (short) changes to the en-dash (longer) The “space” after the “3” triggers writer to change the hyphen to the en-dash.
Corrective comment:
i need to apologize because me answer above contains an error. My statement “actually there should be space between figures and a hyphen/dash/en-dash when you write a text in writer.” is wrong. Between to numbers, indicating a range from a to b there should be no space before and after the en dash.
Best to read: Dash - Wikipedia and note there under “Em dash” the paragraph “According to most American sources (such as The Chicago Manual of Style) and some British sources (such as The Oxford Guide to Style), an em dash should always be set closed, meaning it should not be surrounded by spaces. But the practice in some parts of the English-speaking world, including the style recommended by The New York Times Manual of Style and Usage, sets it open, separating it from its surrounding words by using spaces or hair spaces (U+200A) when it is being used parenthetically. Some writers, finding the em dash unappealingly long, prefer to use an open-set en dash. This “space, en dash, space” sequence is also the predominant style in German and French typography. See En dash versus em dash below.”
@ROSt53 - thanks for the update. I’m sure there are variations between publishers, regions, disciplines, etc. It’s good to have the extra information!
@dajare - I am glad I could give you some hints. I personally stick with the way LibO deals with en-dash and em-dash. It takes for the hyphen, minus as en dash and the em dash as created by LibO. For me it is more important to have a clear view on the text written and follow the exceptions.
Thank you David for a brilliant solution! I’m editing 18 x 50 page documents to unify the format, with thousands of references this ‘trick’ has saved me a lot of time. I did not know ‘regular expressions’, now you’ve whetted my appetite to master more.
Thank you!
@Yohane - Zikomo! If quotation marks in your documents are an issue, then have a look here: How do I convert straight quotes to typographic quotes?