2

I've got longer phrases separated with hyphens that I'd like to typeset in typewriter font. I'd like latex to break the lines to avoid them from overflowing:

\documentclass{article}
\begin{document}

    Normal font breaks the line:

    a-very-long-text-in-typewriter-font-separated-by-hyphens-that-should-break-the-line.

    But typewriter font does not:

    \texttt{a-very-long-text-in-typewriter-font-separated-by-hyphens-that-should-break-the-line.}
\end{document}

Just to be clear, I don't want latex to add more hyphens, I just want it to break the line at the existing ones.

Stefan
  • 123

1 Answers1

3

enter image description here

\documentclass{article}
\begin{document}

\raggedright
    Normal font breaks the line:

    a-very-long-text-in-typewriter-font-separated-by-hyphens-that-should-break-the-line.

    But typewriter font does not:

    \texttt{%
     \hyphenchar\font=`\- % enable hyphenation
     \hyphenpenalty=10000 % disable it again
     \exhyphenpenalty=-50 % enable (encourage) it at explicit hyphens
     a-very-long-text-in-typewriter-font-separated-by-hyphens-that-should-break-the-line.}
\end{document}
David Carlisle
  • 757,742