I was looking for a way to enable hyphenation within \texttt
.
I found this answer and it seemed perfect: simple and useful to many people.
I chose to enable hyphenation globally in \texttt
and as suggested there, I added the following line:
\DeclareFontFamily{\encodingdefault}{\ttdefault}{\hyphenchar\font=`\-}
Unfortunately, it did not work and had an undesired side-effect: the typewriter font was no longer used inside \texttt
and the following error appeared in the console output:
LaTeX Font Warning: Some font shapes were not available, defaults substituted.
This error pointed me right on track: I always use the T1 encoding and lmodern fonts in my LaTeX documents:
\usepackage[T1]{fontenc}
\usepackage{lmodern}
and as soon as I commented out those lines, everything worked fine.
Is there a way to adapt the original answer to this case as well? I'd have added a comment to that post, but unfortunately I still haven't sufficient reputation to do that.
Thank you very much.