How to force LaTeX not to break the line after a hyphen “-”?
If you put it in a mbox
, it can't get broken up:
\mbox{(re-)creation}
But that means it can't get broken up anywhere in the word!
Do not reinvent the wheel – there is a package for that
It is called the extdash
package and adds multiple commands for new behaviour with dashes.
Important: load this package as the very last package (even after hyperref
)
Add the shortcuts
option: \usepackage[shortcuts]{extdash}
if you want to use \-/
instead of \Hyphdash
. More details at https://www.ctan.org/pkg/extdash.
You can then use new dashes to control breaking behaviour of words with dashes.
Standard LaTeX dashes
-
Standard LaTeX hyphen--
Standard LaTeX en-dash---
Standard LaTeX em-dash
extdash
breakable dashes
Words hyphened with these dashes can also be broken at other positions than the dash
\-/
hyphen\--
en-dash\---
em-dash
extdash
unbreakable dashes
No line breaks possible at the hyphen
\=/
hyphen\==
en-dash\===
em-dash
Useful for expressions like $x$\=/axis
or $x$\=/$y$\=/plane
or your question ;)
The amsmath
package provides the \nobreakdash
command to insert before the relevant dash:
\documentclass{article}
\usepackage{amsmath}
\usepackage[width=1.5cm]{geometry}
\begin{document}
A (re\nobreakdash-)creation.
A (re-)creation.
\end{document}