# Space for generated text

Throughout my PDF document, generated text on the end of the line is spilled out to the margin. That is, if I use, e.g., \ref{} or \cite{}, then LaTeX does not consider the actual size of the generated text when calculating the output text, so that it is sometimes spilled out to the margin.

I thought to solve this by putting \mbox around the \ref or \cite command, as I thought that the \mbox command forse latex to compile the inner command first, but it did not helped. Am I wrong about the \mbox command?

Anyone has any idea how to solve this?

-
Welcome to TeX.sx! Any text inside \mbox will be placed in an own box which cannot be broken, so using it is counterproductive here. This has nothing to do with the order of compilation. LaTeX just couldn't break the word or place it on the next line, so it went to the margin. It prefers overlong lines before underfull ones. Please consider to add a minimal working example (MWE). –  Martin Scharrer Jul 12 '11 at 6:58

\begin{sloppypar}