5

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?

3 Answers 3

12

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 Commented Apr 29, 2021 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 StaffMod
    Commented Apr 29, 2021 at 17:07
  • @animuson fair point
    – rene Mod
    Commented Apr 29, 2021 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
    Commented Apr 29, 2021 at 17:10
  • 3
    @JasonC your nerdness is served ...
    – rene Mod
    Commented Apr 29, 2021 at 17:11
4

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
    Commented Apr 29, 2021 at 17:04
  • 1
    @JasonC I think rene's solution is even better, feel free to accept theirs. Commented Apr 29, 2021 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
    Commented Apr 29, 2021 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
    Commented Apr 29, 2021 at 17:25
-1

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
    Commented Apr 29, 2021 at 17:02
  • @JasonC Yes, isn't that the expected result?
    – Anonymous
    Commented Apr 29, 2021 at 17:02
  • I don't know, lol. Let me try replacing my hyphens with full-width ones.
    – Jason C
    Commented Apr 29, 2021 at 17:05
  • 1
    @JasonC My mistake, it isn't working on Chrome. It renders fine on Firefox...
    – Anonymous
    Commented Apr 29, 2021 at 17:07
  • Unfortunately, it still splits it. Also confirmed it splits after the hyphen by removing a few letters.
    – Jason C
    Commented Apr 29, 2021 at 17:07
  • 1
    @JasonC I'll try some of the other homoglyphs: ˗۔‐‑‒–⁃−Ⲻ﹘. Maybe one of those will render on Chrome.
    – Anonymous
    Commented Apr 29, 2021 at 17:09
  • @JasonC Try this: .
    – Anonymous
    Commented Apr 29, 2021 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.sstatic.net/Jqaxn.png
    – Jason C
    Commented Apr 29, 2021 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
    Commented Apr 29, 2021 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
    Commented Apr 29, 2021 at 17:24

You must log in to answer this question.

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