Ask Your Question

How to convert every hyphen/dash between numbers to en-dash? [closed]

asked 2012-10-22 09:35:23 +0200

David gravatar image

updated 2013-10-26 15:14:24 +0200

manj_k gravatar image

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?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2015-10-18 22:24:51.248046

2 Answers

Sort by » oldest newest most voted

answered 2012-10-22 09:42:37 +0200

David gravatar image

updated 2012-10-22 11:42:32 +0200

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:

  1. CTRL-H to open search/replace dialog, then click the "More Options" button (if not already displayed) and enable the "[x] Regular expressions" option.
  2. In the "Search for" box, paste in: ([0-9])-([0-9])
  3. In the "Replace with box, paste in: $1–$2
  4. 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.

edit flag offensive delete link more

answered 2012-10-28 06:52:19 +0200

ROSt52 gravatar image

updated 2012-10-28 06:53:31 +0200

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: 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."

edit flag offensive delete link more


@ROSt52 - thanks for the update. I'm sure there are variations between publishers, regions, disciplines, etc. It's good to have the extra information!

David gravatar imageDavid ( 2012-10-29 00:15:13 +0200 )edit

@David - 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.

ROSt52 gravatar imageROSt52 ( 2012-10-29 04:32:53 +0200 )edit

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 gravatar imageYohane ( 2012-10-30 13:17:51 +0200 )edit

@Yohane - Zikomo! ;) If quotation marks in your documents are an issue, then have a look here:

David gravatar imageDavid ( 2012-10-31 21:52:40 +0200 )edit

Question Tools

1 follower


Asked: 2012-10-22 09:35:23 +0200

Seen: 4,062 times

Last updated: Oct 31 '12