4

If I write a word that itself contains a hyphen, and it happens to be near the end of a line, then it will get split at the hyphen during word wrapping.

But sometimes this has undesirable (to me, anyways) results. For example, in a recent post I made, I typed this:

- The active chemical in most consumer-grade CA glues† is ethyl 2-cyanoacrylate (CAS [7085-85-0][cas]).

And it ended up rendered like this:

enter image description here

If "7085-85-0" was actually a word, it'd probably make sense, but it's a numeric identifier whose format contains hyphens, so it's a little awkward to split it. Plus, only one character ended up on the next line.

Is there some way (or hack) to prevent certain words from being split, when that word contains a hyphen? I.e. to have it be treated like a non-hyphenated word?

10

Replacing the - with a non-breaking Hyphen works as well: ‑

Giving: CAS [7085‑85‑0][cas] in your makrdown.

Or copy it as char:

giving

CAS [7085‑85‑0][cas]

Result:

  • The active chemical test to in most consumer-grade CA glues† is ethyl 2-cyanoacrylate (CAS 7085‑85‑0).

Without non-breaking hyphen:

  • The active chemical test to in most consumer-grade CA glues† is ethyl 2-cyanoacrylate (CAS 7085-85-0).

Here is the Windows Character map tool to find and select that character:

charactermap tool

Find it on Windows 10 via the Search: "Character" should do the trick

5
  • even better than mine with half the entities – Cave Johnson Apr 29 at 17:05
  • 1
    You don't even need to use the entities with this version, as you aren't inserting an invisible character. You can just copy-paste an actual non-breaking hyphen and it will still be readable in the editor as well. – animuson Apr 29 at 17:07
  • @animuson fair point – rene Apr 29 at 17:08
  • 2
    It's also semantically concise and accurate, which gives me the warm fuzzies because I'm a huge nerd. – Jason C Apr 29 at 17:10
  • 3
    @JasonC your nerdness is served ... – rene Apr 29 at 17:11
2

From this answer, looks like you can use a word joiner character  immediately before and after the dash. So in markdown it would look like this:

7085⁠-⁠85⁠-⁠0

The above text is 7085-85-0 with ⁠ before and after the dashes.

Live test:

  • The active chemical in most consumer-grade CA glues† is ethyl 2-cyanoacrylate (CAS [7085⁠-⁠85⁠-⁠0][cas]).
4
  • Trying it now and... beautiful. Nailed it. – Jason C Apr 29 at 17:04
  • 1
    @JasonC I think rene's solution is even better, feel free to accept theirs. – Cave Johnson Apr 29 at 17:07
  • Ah, I agree, actually. The non-breaking hyphen is more semantically appropriate. But I learned something from this, too. Sorry for the emotional checkbox roller coaster, haha. Thank you!! – Jason C Apr 29 at 17:09
  • 1
    This is actually super useful in cases where the character isn't a hyphen but you want to accomplish the same thing (and there's no non-breaking version of the character). Filed away for future reference. – Jason C Apr 29 at 17:25
0

Try homoglyphs:

test˗test..........................................................................................................................................................................................................
test۔test..........................................................................................................................................................................................................
test‑test..........................................................................................................................................................................................................
test‑test..........................................................................................................................................................................................................
test‒test..........................................................................................................................................................................................................
test⁃test..........................................................................................................................................................................................................
test−test..........................................................................................................................................................................................................
test⁃test..........................................................................................................................................................................................................
test−test..........................................................................................................................................................................................................
testⲺtest..........................................................................................................................................................................................................
test﹘test..........................................................................................................................................................................................................

10
  • Hm, that renders like this for me (Chrome, Windows). Was that the intent? – Jason C Apr 29 at 17:02
  • @JasonC Yes, isn't that the expected result? – Anonymous Apr 29 at 17:02
  • I don't know, lol. Let me try replacing my hyphens with full-width ones. – Jason C Apr 29 at 17:05
  • 1
    @JasonC My mistake, it isn't working on Chrome. It renders fine on Firefox... – Anonymous Apr 29 at 17:07
  • Unfortunately, it still splits it. Also confirmed it splits after the hyphen by removing a few letters. – Jason C Apr 29 at 17:07
  • 1
    @JasonC I'll try some of the other homoglyphs: ˗۔‐‑‒–⁃−Ⲻ﹘. Maybe one of those will render on Chrome. – Anonymous Apr 29 at 17:09
  • @JasonC Try this: . – Anonymous Apr 29 at 17:16
  • Which one is that? It actually got posted as a vanilla U+002D hyphen in your comment. Rene's answer, though, identified a working character U+2011 (non-breaking hyphen). Oh I see your edit. Interesting. FYI, on Chrome: i.stack.imgur.com/Jqaxn.png – Jason C Apr 29 at 17:21
  • @JasonC It's the MODIFIER LETTER MINUS SIGN (U+02D7). I chose it because it looks close to a regular hyphen on all browsers. – Anonymous Apr 29 at 17:23
  • 1
    Huh, I wonder why it got transformed. Anyways, +1 for your persistence here, haha. Thank you, it's very much appreciated. :) – Jason C Apr 29 at 17:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .