9

Please consider the MWE below, I want to globally invoke hyphenation of already hyphenated words using Babel package, Hyphenat package in English, to get the same effect when using <word1>-\hspace{0pt}<word2> as shown in the output below.

This is hopefully to avoid tracking down every hyphenated word in a thesis last-minute scenario, especially after doing some text edit in a 200-page thesis. I am quite satisfied with the effect of \hspace{0pt}, and I don't see any reason against using it blindly, or am I missing something?

MWE Code

\documentclass{scrartcl} % complied with XeLaTeX
\usepackage[english]{babel}
%\defineshorthand{"-}{\babelhyphen{hard}} % didn't work
\usepackage{fontspec}
\usepackage{libertine}

\begin{document}
In summary, IL-17 can be produced by innate and adaptive cells, but more profoundly from innate sentinel cells of the immune system. 
The nTh17 is a novel subset that is thymic-\hspace{0pt}dependent and shows a distinct developmental pathway from iTh17 cells that are derived from naive T cells.

In summary, IL-17 can be produced by innate and adaptive cells, but more profoundly from innate sentinel cells of the immune system. 
The nTh17 is a novel subset that is thymic"-dependent and shows a distinct developmental pathway from iTh17 cells that are derived from naive T cells.
\end{document}

Output
enter image description here

doctorate
  • 4,173
  • It is not clear to me what you want. You can use \- and when necessary LaTeX will broken the word there. Or you can define on preamble the hyphenation using \hyphenation{ba\-be\-bi\-bo\-bu}. – Sigur May 19 '14 at 13:22
  • @Sigur I guess the problem are words that already contain a hyphen by themselves, such as "thymic-dependent". – Benedikt Bauer May 19 '14 at 13:24
  • @lockstep, ngerman in babel has its own shorthands, english doesn't, so need to be defined; the very question. – doctorate May 19 '14 at 13:28
  • the suggested duplicate question is not helpful, pls reconsider your vote. – doctorate May 19 '14 at 13:32
  • My suggestion does not depend on babel shorthands (or babel). It does, however, provide a global way to set hyphenation of words already containing hyphens, so it seems relevant for your question. If you can't use LuaLaTeX, that would be a valid reason to retract my closing vote; however, your question didn't specify whether LuaLaTeX would be acceptable or not. – lockstep May 19 '14 at 13:50
  • To the voters for closing: how can this one be a duplicate of that question, where just German is concerned, which already has all the features for the problem at hand? – egreg May 19 '14 at 14:55
  • @egreg The OP mentions "hopefully to avoid tracking down every hyphenated word in a thesis last-minute scenario". IMO, a preamble-only solution (involving LuaLaTeX which the OP didn't rule out) is at least as appropriate as a solution involving babel shorthands at every instance of the respective words in the document body. – lockstep May 19 '14 at 15:30
  • @lockstep I interpreted “avoiding tracking down” as “leaving TeX hyphenate the second part in a compound word”. Possibly LuaTeX can do better than using "-, but this is surely neater than -\hspace{0pt} – egreg May 19 '14 at 15:49

1 Answers1

7

You're forgetting to add the shorthands to the list of enabled shorthands:

\documentclass{scrartcl}
\usepackage[english]{babel}

\usepackage{fontspec}
\usepackage{libertine}

\useshorthands{"}
\defineshorthand[english]{"-}{\babelhyphen{hard}} % didn't work
\addto\extrasenglish{\languageshorthands{english}}

\begin{document}

\makeatletter
\show"

In summary, IL-17 can be produced by innate and adaptive cells, but more profoundly from innate
sentinel cells of the immune system. The nTh17 is a novel subset that is thymic-\hspace{0pt}dependent
and shows a distinct developmental pathway from iTh17 cells that are derived from naive T cells.

In summary, IL-17 can be produced by innate and adaptive cells, but more profoundly from innate
sentinel cells of the immune system. The nTh17 is a novel subset that is thymic"-dependent and shows a
distinct developmental pathway from iTh17 cells that are derived from naive T cells.

\end{document}

enter image description here

Of course you can also get

                     thymic-dep-
endent

which is horrible. If you aren't afraid of hideous hyphenation of composite words, the shorthand is for you. If you're careful about your typesetting, you'll take your time in analyzing what hyphens in compound words are really necessary. And maybe try changing the wording, instead of allowing a hyphen.

egreg
  • 1,121,712
  • Final paragraph has some truth but in some technical areas it's very tricky to avoid (try doing chemical names!). – Joseph Wright May 19 '14 at 15:20
  • @JosephWright I agree; but in that case a specialized package should be used in order to correctly typeset those weird names. – egreg May 19 '14 at 16:48