[Tex/LaTex] Push long words in a new line

line-breaking

I have sometimes very long words, which are for example method names and so on.

Is there any possibility to force LaTeX to push them to a new line, if they overflow the margins?

It is possible to push them into a new line, because I know in my document aren't words which are too long for a line.

Here a mini example which produce the problem:

\documentclass{scrartcl}

\begin{document}
\section{Test}
Finally there is a simple solution using \textsc{\textbf{XMLResource.OPTION\_RECORD\_UNKNOWN\_FEATURE}} option. And the
text must go on \ldots.
\par
And another example the show must go on, but we have too less text (\textbf{createUnspecifiedNodeWarningMarker} and
\textbf{createUnspecifiedNodeErrorMarker}, sdjklashjksa \textbf{createUnspecifiedLinkWarningMarker} and
\textbf{createUnspecifiedLinkErrorMarker}).
\end{document}

Thanks for any advices.

Best Answer

If your text has a lot of these words it's probably best to go with fully unjustified text as in the first answer, but sometimes you have text which would look best justified apart from occasional outcrops of unbreakable words. In these cases you can just use a definition as below which allows lines to break short before such words but otherwise tries to justify both paragraph margins.

enter image description here

\documentclass{scrartcl}

\newenvironment{foo}
{\par
\hyphenpenalty=10000
\exhyphenpenalty=10000
}
{\par}

\newcommand\lword[1]{\leavevmode\nobreak\hskip0pt plus\linewidth\penalty50\hskip0pt plus-\linewidth\nobreak\textbf{#1}}
\begin{document}
\section{Test}
\begin{foo}
Finally there is a simple solution using \textsc{\lword{XMLResource.OPTION\_RECORD\_UNKNOWN\_FEATURE}} option. And the
text must go on \ldots.

And another example the show must go on, but we have too less text (\lword{createUnspecifiedNodeWarningMarker} and
\lword{createUnspecifiedNodeErrorMarker}, sdjklashjksa \lword{createUnspecifiedLinkWarningMarker} and
\lword{createUnspecifiedLinkErrorMarker}).
More text, more text. More text, more text. More text, more text.
More text, more text. More text, more text. More text, more text.
More text, more text. More text, more text. More text, more text.
\end{foo}
\end{document}

Note, unrelated to the linebreaking issue the standard fonts don't include a bold small caps, so you get a font warning and bold normal text for the first case.