# Why doesn't \nolinebreak work in this case?

When I have something like:

(Some-)Thing


at the end of the line, LaTeX always breaks after the '-', even when I use:

(Some-\nolinebreak)Thing


I do know about solutions like using \mbox{}, but I ask for an explanation, not a way to work around, but if there's a "better" way to do this, I'm grateful for any recommondations!

I also tried \nolinebreak[4] which although should be the same.

• Because the - is set as \hyphenchar. The \hyphenchar has two meanings in TeX: 1) it is printed when\- primitive (or automatic hyphenation) is activated at the point where line is broken and 2) if it is used in the middle of the word then \discretionary{}{}{} is added. And the second meaning is the reason of the described behaviour. No matter that the \penalty10000 follows after such character. – wipet Oct 28 '15 at 20:21
• Ah okay, Iso basically the \nolinebreak has no effect as it doesn't break after but at the '-'? Well learned something new! Thanks for the explanation. (Why don't you move it to the answers?^^) – ljrk Oct 28 '15 at 20:25
• Also (Some\mbox{-})Thing, which doesn't require any extra package. – egreg Oct 28 '15 at 23:13

If you use babel in German, you can use "~ that produces exactly what you want:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

\begin{document}

\parbox{0pt}{\hspace{0pt}(Some"~)Thing}

\end{document}


The \parbox{0pt} is for inviting TeX to break wherever possible, but if you try you'll see that no break at all is taken.

What "~ does is, basically, issuing \mbox{-}.

If you don't use ngerman, but still use babel, you could import the German shorthands (see Babel: two languages, active shorthands) or, more simply, define a macro:

\newcommand{\ppref}[1]{(#1\mbox{-})} % Parenthesized PREFix


and input the text as

\ppref{Some}Thing


The reason why \nolinebreak is ineffective is that - in normal text inserts a discretionary break after it, so typing

(Some-\nolinebreak)Thing


is the same as typing

(Some-\discretionary{}{}{}\nolinebreak)Thing


and TeX is allowed to break lines at discretionaries. The penalty that follows cannot change this. There is no \undiscretionary similar to \unskip or \unpenalty.

The \nobreakdash macro of amsmath just encloses in an \mbox the -, -- or --- that follows, so typing

(Some\nobreakdash-)Thing


is exactly the same as typing

(Some\mbox{-})Thing


If you use the amsmath package, you could type

(Some\nobreakdash-)Thing


A full MWE (minimum working example):

\documentclass{article}
\usepackage{amsmath}  % for '\nobreakdash' macro
\usepackage[textwidth=1mm]{geometry} % set a very narrow measure
\begin{document}
\hspace{0pt}(Some-)Thing  % this will produce a line break

\hspace{0pt}(Some\nobreakdash-)Thing % no linebreak here...
\end{document}

• This is definitely a cool macro! Weird that one needs a maths package, but I have them anyway :D – ljrk Oct 28 '15 at 20:19