Wikipedia:Non-breaking hyphen

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

This essay explains use of the non-breaking hyphen character , U+2011, coded by ‑ or ‑. Once displayed in a page, the non-breaking hyphen can be copied into words, or abbreviations, so they will not wrap at the hyphen character, such as an interstate highway symbol, "I‑94" which would always wrap to the next line as a whole word.

Not allowed in calculations[edit]

Unlike the ASCII hyphen-minus character "-", the non-breaking hyphen character is typically rejected if used as a negative sign or minus sign in calculations:

  • Using hyphen for minus:      {{#expr: 34 - 56}} → -22
  • Using non-breaking hyphen: {{#expr: 34 ‑ 56}}Expression error: Unrecognized punctuation character "‑".
  • Using − for minus:      {{#expr: 34 − 56}} → -22

Similarly, PC pop-up calculators might typically reject the non-breaking hyphen as a character to be ignored, rather than as a form of minus sign.

Judge if worth possible confusion[edit]

When using a non-breaking hyphen, care must be taken to ensure whether other editors would understand the unusual nb-hyphen when used in typical text. Confusion can be eliminated by using the HTML character entity ‑ or the template {{nbh}} to insert a non-breaking hyphen.

Search will not match[edit]

Whether inserted directly or through use of the template {{nbh}}, the rendered character, although visually identical, or nearly so (compare:‑-), will not match any search using a standard ASCII hyphen-minus “-”. This is unlike the non-breaking space &nbsp;, whose rendering on the page is indistinguishable from a regular space. This can be fixed by using a regular hyphen and making it and its bordering words non-breaking with the {{nowrap}} template (shortcut {{nobr}}), for example, {{nowrap|I-94}}. Unfortunately, making only the hyphen nonwrapping has no effect, which precludes redefining the template {{nbh}} as {{nowrap|-}}. It will work if a hyphen is followed by U+2060 WORD JOINER, but this character fails to render as zero width as it is supposed to when using the Wikipedia app (only tested on Android) (example: xxx-⁠xxx). This can be fixed by enclosing it in <span style=font-size:0>&#x2060;</span> (example: xxx-xxx). Another solution is to follow a hyphen with U+FEFF BYTE ORDER MARK in its deprecated (since Unicode 3.2) use as ZERO-WIDTH NO-BREAK SPACE. Also usable following a hyphen are <span style=visibility:hidden;font-size:0>&nbsp;</span> and <span class=nowrap style=visibility:hidden;font-size:0>x</span>. All of these satisfy the following three criteria:

  • They prevent post-hyphen breaks.
  • Nothing shows on the page.
  • They are “invisible” to searches.

However, none of these can be used inside wikilinks interchangeably with a standard hyphen. While &nbsp; links to a standard space, e.g., [[J.R.R.&nbsp;Tolkien]] links to J.R.R. Tolkien, both U+2060 and U+FEFF are not invisible, I-⁠94 and I-94, while anything with <span>...</span> in it is not recognized as a wikilink, e.g., [[I-94]]. Thus {{nobr}} must be used outside a non-piped link: {{nobr|[[I-94]]}}I-94. If only part of the link text is to be made non-wrapping then a piped link must be used: [[I-94|route {{nobr|I-94}}]]route I-94.

See also[edit]