# Linebreak before \texttt

I have text and there are some commands, that should be write in \texttt. It's one word, that shouldn't be broken and should be on next line, but LaTeX doesn't put a line break before it and lays it over the border of paragraph. I don't want put there \\\\* or \newline there, because our professors get mad about these commands.

I translate it with pdflatex in Texmaker.

## migrated from stackoverflow.comMay 12 '13 at 0:07

This question came from our site for professional and enthusiast programmers.

• Would you be able to replicate this problem via a minimal working example (MWE) and include it in your post? That would make it easier for the community to work on a solution. – Werner May 11 '13 at 13:42
• Oh, I'm sorry. MWE is problem, because it's pretty complex document from school template, with a lot of packages and stuff that I don't really understand. Simply, I've text, that is justified. When I've word in \texttt, that layed over the margin, it should be on next line and the spaces in original line should be longer, but LaTeX doesn't put line break before it and the word lays over margin... – Honza Zerdik May 11 '13 at 17:10
• What about a screen shot with the problematic behaviour... – user13907 May 12 '13 at 1:18
• If  \\  gives the optical result you want to achieve (the previous line will be shorter than usual) then use it in this case - if you can't change the order of the words. It is not good to use  \\  regularly but a large unbreakable word don't give you a choice: you have to revert to second-best solutions. – Ulrike Fischer May 12 '13 at 8:59
• Welcome to TeX.SX! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Reinstate Monica - M. Schröder May 12 '13 at 14:45

It depends whether you want to place an explicit command in that one place or use a setting that is generally applicable. As you didn't supply an example I borrowed one from the other answer, to show various possibilities.

the main choice to make is whether to stretch white space to compensate, or whetehr to break the line and leave it short.

\documentclass{scrartcl}
\usepackage[margin=15mm]{geometry}

\begin{document}

\def\test#1{%
Test test test test. Test test test test. Test test test test. Test test test test. Test test test #1{Supercalifragilisticexpialidocious} test. Test test test test.

Test test test test. Test test test test. Test test test test. Test test test test. Test test test test. #1{Supercalifragilisticexpialidocious} test test test test.

Test test test test. Test test test test. Test test test test. Test test test test. Test test test test. Test #1{Supercalifragilisticexpialidocious} test test test.

Test test test test. Test test test test. Test test test test. Test test test test. Test test test test. Test test #1{Supercalifragilisticexpialidocious} test test.

Test test test test. Test test test test. Test test test test. Test test test test. Test test test test. Test test test #1{Supercalifragilisticexpialidocious} test.

}

\test\texttt

\bigskip\hrule\bigskip

\begin{sloppypar}
\test\texttt
\end{sloppypar}

\bigskip\hrule\bigskip

{\setlength\emergencystretch{3cm}
\test\texttt
}

\bigskip\hrule\bigskip

\test{\hskip 0pt plus 3pt \penalty0 \hskip 0pt plus -3pt \texttt}

\end{document}
• This answer would have been more helpful if you had explained the different solutions instead of just throwing out the code. – Lii Jul 10 '13 at 13:47
• @Lii - Sigh. Exactly this. Here I have an answer that seems to have the solution in it, but is completely unusable to me. I haven't got the slightest idea what half of this code does, nor which parts of it are related to line breaks. – Davor Aug 5 '14 at 10:15