How can I prevent LaTeX from putting line-breaks into a phrase?

I could replace dashes with "~ and spaces with non-breaking spaces, but I'm looking for a more general solution in case I need other characters in such phrases.

  • 9
    Put the phrase in a mbox – Marco Daniel Sep 23 '11 at 8:58
  • Thanks. Does it effect anything else that I should be aware of? – Tim N Sep 23 '11 at 9:00
  • 2
    Inside a \mbox you can't use any linebreaks ;-) – Marco Daniel Sep 23 '11 at 9:08
  • 8
    The effect of \mbox is that it freezes the spaces, so they won't be stretched or shrinked along with the others on the same line. – egreg Sep 23 '11 at 9:11
  • 2
    @egreg: Than that's not what I'm looking for. The only effect I'm looking for is non-breaking; they should still be formatted nicely. – Tim N Sep 23 '11 at 9:18

Telling TeX not to break lines in long phrases will almost certainly produce bad breaks, with overfull or underfull lines. However, here's a possible hack.



{\catcode`\ =\active
\gdef\dononbreakablespace{\catcode`\ =\active\def {\nobreakspace}}}

Here's an example:

Testo per vedere se gli spazi sono uniformi \phrase{anche in una %
\emph{phrase} che non deve essere spezzata neanche dove-si-potrebbe %
ma solo dopo}, quando finisce.

If you need also en-dashes or em-dashes it's more complicated. With babel we can use its nohyphenation feature. It's handy but not necessary, as the same effect can be obtained in different ways.

The definitions can be read as follows.

  1. The macro \phrase will only have a "user level argument" that actually is an argument to \dophrase; the purpose of \phrase is to open a group and do some initializations, in particular to inhibit hyphenation.

  2. \dophrase reads the argument and closes the otherlanguage* environment, so that also all the other assignments will be undone.

  3. \donobreakablespace activates the space and makes it translate to \nobreakspace. See note below.

  4. \donobreakablehyphen activates the hyphen so that it typesets a hyphen which is "masked" and will not be a permissible break point.

Note. In the argument of \phrase (actually of \dophrase) consecutive spaces will not be reduced to one and will not be ignored at the start of an input line. Moreover line breaks in the input will be admissible break points for TeX. Mask them with % (preceded by a space).

If using babel is not a choice, one can do with some changes


The other macros can be the same. The "no hyphenation" feature is obtained by choosing explicitly the "nohyphenation" pseudolanguage or, if it's not defined (which may be the case on some old distributions) by choosing \language255 that is probably not defined (so TeX will use an empty set of hyphenation rules).

  • You code is very nice but you should also recommend the package hyphenat. – Marco Daniel Sep 23 '11 at 12:39
  • @Marco hyphenat doesn't provide an environment form of \nohyphen; moreover in the argument of \nohyphen, explicit hyphens are admissible break points, so there is not really much advantage in using it. – egreg Sep 23 '11 at 12:47
  • The point isn't the advantages or disadvantages. It is a further possibility ;-) (You know what I meean?) – Marco Daniel Sep 23 '11 at 12:49
  • @Marco IMO it doesn't fit at all with the problem, which is mainly not to break at spaces. – egreg Sep 23 '11 at 12:57

The \mbox command does the job.

  • I think maybe \mbox prevents internal glue from stretching or shrinking. – Norman Ramsey Dec 1 '15 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.