[Tex/LaTex] How to prevent linebreaks after hyphen if word starts with hyphen

hyphenationline-breakingpunctuation

(Remark: Maybe this is a typically German problem, I'm not sure in which other languages that might be relevant)

Sometimes there are words which start with a hyphen, as they are connected with a word used before, e. g. Werkstoffforschung und -entwicklung is a shorter (and I think more elegant) way to say Werkstoffforschung und Werkstoffentwicklung.

However, if the second word, which starts with the hyphen, is at the beginning of a new line, it can happen that the hyphen stays in the previous line and the word itself is the first one in the next line.

Minimal example:

\documentclass[11pt]{scrreprt}
\usepackage[ngerman]{babel}  
\begin{document}
Das ist ein Mustertext, der dazu da ist, um diese aa Textsatzproblematik
    bzw. -schwierigkeit zu demonstrieren 
\end{document}

output

(I hope that the example "works" for you to demonstrate the problem, when I typeset it with pdflatex, the "-" is at the end of the first line and the "schwierigkeit" is in the second one which is not wanted.)

Is there a smart* way to avoid that problem?
* pdflatex shall handle this automatically and "know" that a hyphen at the beginning of a word always has to stay connected to the word and shall not be separated from it.

Best Answer

UPDATE: babel v3.9, released in March 2013, introduces a set of \babelhyphen macros -- see section 1.6 of the manual for details. In particular, \babelhyphen{nobreak} (the non-starred version) provides a non-breakable hyphen which allows hyphenation in the rest of the word -- for the present question, this may be used to define a new shorthand which removes the need to look up allowed breakpoints. (Note: Sometimes, the first allowed breakpoint will be located three or less characters after the non-breakable hyphen; if you consider such a breakpoint as inadequate, use my original answer.)

\documentclass[11pt]{scrreprt}
\usepackage[ngerman]{babel}  
% The following requires babel v3.9 (released March 2013)
\defineshorthand[ngerman]{"+}{\babelhyphen{nobreak}}
\begin{document}
Das ist ein Mustertext, der dazu da ist, um diese aa Textsatzproblematik
    bzw. "+schwierigkeit zu demonstrieren 
\end{document}

ORIGINAL ANSWER: Use babel's "~ shorthand to add an explicit hyphen with prohibited line break; supplement this by using the "- shorthand to specify the first allowed follow-up breakpoint. (You will have to look up those with \showhyphens{Schwierigkeit}. See pp. 5--7 of the documentation of the german package for details and other shorthands. (Note: the babel shorthands originate from the german package, which is considered obsolete nowadays.)

By the way, using "~ but not "- in your example would produce an overfull hbox.

\documentclass[11pt]{scrreprt}
\usepackage[ngerman]{babel}  
\begin{document}
Das ist ein Mustertext, der dazu da ist, um diese aa Textsatzproblematik
    bzw. "~schwie"-rigkeit zu demonstrieren 
\end{document}

enter image description here

Related Question