[Tex/LaTex] When I prevent hyphenation using an \mbox, the box gets pushed into the right margin

boxeshyphenationline-breaking

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?

Best Answer

Try \sloppy (How can I make my text never go over the right margin by always hyphenating or breaking on word-boundaries?).

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.

(from http://ece.uprm.edu/~caceros/latex/introduction.pdf)

Related Question