# When I prevent hyphenation using an \mbox, the box gets pushed into the right margin

I've used \mbox to prevent LaTeX from breaking certain long words into hyphenated pairs. Now I have a new problem: the unbroken words are extending into the right margin. Here's some minimal sample code that reproduces my problem:

\documentclass[12pt,draft,letterpaper]{report}
\setlength{\textwidth}{5.8in}

\begin{document}
We summarize our method in algorithm 1. The functions \mbox{Update''}
and \mbox{BatchUpdate''} implement single and multi-constraint updates
as described above, using interpolated solving to solve for no more than
$D_{max}$ nodes at a time. The \mbox{GetUpstreamGPSes($b$, $n$)''}
function crawls up the tree from node $b$, and returns the first $n$ GPS
edges along that path.
\end{document}

When I compile this with pdflatex, the "BatchUpdate" and "GetUpstreamGPSes(b, n)" function names get pushed into to right margin. I wanted them to get moved to the next line.

How can I prevent particular words from being broken across lines, while preventing them from extending into the right margin?

-

## 1 Answer

I found that in the Related Links to your question. It worked for me with your text.

To fix just a part of the document:

surround the offending paragraph with \begin{sloppypar} and \end{sloppypar} commands. Then LaTeX will not break words up but rather will allow more spacing between words in the given paragraph.

-
Is there no way of fixing this problem without affecting the whole document? The example I quoted is just part of a 100-page document. It'd be nice if I could just tell LaTeX not to push those three particular mboxes into the right margin, rather than making a systematic change to how it performs line breaks everywhere. –  SuperElectric Apr 26 '12 at 18:00
@SuperElectric Answer edited to answer this question. –  Ethan Bolker Apr 27 '12 at 1:37