[Tex/LaTex] Nonbreaking dash that allows hyphenation

babelhyphenationline-breaking

The babel package provides useful dash variants, e.g. "~ for a non-breaking dash that forbids hyphenation in the parts, and "= for a breaking dash that allows hyphenation in the parts.

However, "words" like

$x$-Koordinaten

do not quite fit; we would not want to have the dash breaking, but we would want to allow hyphenation of "Koordinaten". Of course,

$x$"~Ko\-or\-di\-na\-ten

works but has to be specified locally, which we do not want to do either (favoring a global \hyphenation{...} setting).

Is it possible to achieve the above in a form that does not force us to specify hyphenation locally?

Best Answer

enter image description here

If there is not already a shortcut you can as below, or better as egreg points out in comments

\makeatletter
 \defineshorthand[ngerman]{"/}{\mbox{-}\bbl@allowhyphens}
\makeatother

Then use "/.

\documentclass{article}
\usepackage[german]{babel}

\setlength\textwidth{5cm}
\newcommand\zz{-\nolinebreak\hspace{0pt}}
\begin{document}


\noindent X\dotfill X


aaaa aaaa aa $x$-Koordinaten

aaaa aaaa aaa $x$-Koordinaten

aaaa aaaa aaaa $x$-Koordinaten

aaaa aaaa aaaaa $x$-Koordinaten

===

aaaa aaaa aa $x$\zz Koordinaten

aaaa aaaa aaa $x$\zz Koordinaten

aaaa aaaa aaaa $x$\zz Koordinaten

aaaa aaaa aaaaa $x$\zz Koordinaten


\end{document}