1

The \texttt normally does not lead to automatic hyphenation or linebreaks. However, it apparently does when using the underscore package:

\documentclass{article}
\usepackage[nohyphen]{underscore}
\begin{document}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam diam \texttt{_nonumynonumy} eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.

\end{document}

Results in enter image description here

The underscore is displayed in the first line, and the rest in the second line. Without the [nohyphen] option, it even adds a hyphen. I need the underscore package, because otherwise LaTeX only allows _ in math mode.

How can I disable line-breaking and still use underscores in \texttt?

  • why not use \_? Is it too much text with _? – koleygr Sep 8 '18 at 18:32
2

That's wanted. After the underscore, \usc@dischyph is inserted, which is, with the nohyphen option, \discretionary{}{}{} (it would be \- without the option).

You can change the meaning of \usc@dischyph, so no line break will be allowed after an underscore.

\documentclass{article}
\usepackage[nohyphen]{underscore}

\makeatletter
\def\usc@dischyph{}
\makeatother

\begin{document}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam 
diam \texttt{_nonumynonumy} eirmod tempor invidunt ut labore et 
dolore magna aliquyam erat, sed diam voluptua.

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.