7

In the amsmath package documentation it is written:

\newcommand{\n}[1]{$n$\nobreakdash-\hspace{0pt}}

The last example shows how to prohibit a linebreak after the hyphen but allow normal hyphenation in the following word. (It suffices to add a zero-width space after the hyphen.)

I am thinking that this can be used to make the more general commands \nbhyphen and \nbendash like this :

\documentclass{minimal}
\usepackage{mathtools}
\newcommand{\nbhyphen}{\nobreakdash-\hspace{0pt}}
\newcommand{\nbendash}{\nobreakdash--\hspace{0pt}}
\begin{document}
Electron\nbhyphen electron interaction. Maxwell\nbendash{}Boltzmann distribution.
\end{document}

and then use them in my document instead of writing the dashes explicitly.

Questions:

Is this a good idea? Will it work everywhere, or is it like to cause unforeseen problems? Should I use the commands with space after, or {}? Why is this not default behavior in LaTeX?

2 Answers 2

6

Why something isn't available as a default is a difficult question to answer. In this particular case, who wants to mark up a document source always with such long commands? If fear only a few people so that such commands would end up not being very useful as such.

However, LaTeX offers something like this as part of the Babel interface for languages and there in a manner that makes input fairly painless: all languages that support " as a babel shorthand have abbreviations like "= (compound word mark allowing hyphenation in the remainder) and a bunch of others like "" and "- and "~ defining various alternative behaviors for explicit or implict hyphens.

However, none of them is really what you are looking for, the reason being that in languages like German the compound word mark is really a preferable break point (not a forbidden one).

Also those shorthands are only set up for some languages typically those that needed input methods for diacritical character. So, for example, for English nothing is being set up by default. But you can always define your own shorthands, so to achieve what you are looking for with a (imho) useful input syntax you could do

\documentclass{article}

\usepackage[english]{babel}
\useshorthands{"}
\defineshorthand{"=}{\mbox{-}\nobreak\hspace{0pt}}

\begin{document}
  \fbox{\parbox{22mm}{Gutenberg-Universit\"at}}

  \fbox{\parbox{22mm}{Gutenberg"=Universit\"at}}
\end{document}

which gives you

enter image description here

5

By all means have them in macros (but another two macro names to remember). They can produce bad output in minipars and possibly captions and other narrow texts. See MWE for marginpar problems.

\documentclass[11pt]{scrartcl}
\usepackage{mathtools,lipsum}
\newcommand{\nbhyphen}{\nobreakdash-\hspace{0pt}}
\newcommand{\nbendash}{\nobreakdash--\hspace{0pt}}
\usepackage{tikz}    
\begin{document}

\marginpar{\raggedright Electron\nbhyphen electron interaction. Maxwell\nbendash{}Boltzmann distribution.}
\lipsum*[1]

\marginpar{\raggedright Electron-electron interaction. Maxwell--Boltzmann distribution.}
\lipsum*[1]
\end{document}

This is the sort of micro corrections I would rather do manually once the manuscript is finished.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .