I tried copying the example from Example about hyphenation with ttfamily font and using the name ttfamily as \ttfamily{Some text} and \begin{ttfamily} & \end{ttfamily}.
However why the first line using the macro ttfamily is not hyphenated, but the second using the environment \begin{ttfamily} is hyphenated?
\documentclass[10pt,a5paper,twoside]{memoir}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[main=english]{babel}
\usepackage[showframe,pass]{geometry}
%THIS IS THE IMPORTANT PART % <=========================================
\usepackage{letltxmacro}
\LetLtxMacro\origttfamily\ttfamily
\DeclareRobustCommand*{\ttfamily}{%
\origttfamily
\hyphenchar\font=`\-\relax
\fontdimen3\font=.25em\relax
\fontdimen4\font=.167em\relax
\fontdimen7\font=.167em\relax
}
\makeatletter
\DeclareRobustCommand\vttfamily{%
\not@math@alphabet\vttfamily\relax
\fontfamily{cmvtt}% cmvtt (Computer Modern) or lmvtt (Latin Modern)
\selectfont
}
\DeclareTextFontCommand{\textvtt}{\vttfamily}
\makeatother % <=========================================================
\begin{document}
\frenchspacing
\ttfamily{Typewriter/teletype family - (encoding: T1, family: pcr, series: m,
shape: n, size: 10.5, baseline: 11.0pt)}
\bigskip
\begin{ttfamily}
Typewriter/teletype family - (encoding: T1, family: pcr, series: m,
shape: n, size: 10.5, baseline: 11.0pt)
\end{ttfamily}
\end{document}
On the question How can I use `\texttt{Some text}` with automatic hyphenation? we can see the same text without the tttext hyphenation, it causing Overfull \hbox:
test2.tex:182: Overfull \hbox (11.9992pt too wide) in paragraph at lines 182--183[]\T1/lmtt/m/n/10 Typewriter/teletype family - (encoding: T1, family:
test2.tex:182: Overfull \hbox (33.7491pt too wide) in paragraph at lines 182--183\T1/lmtt/m/n/10 pcr, series: m, shape: n, size: 10.5, baseline: 11.0pt)



{\ttfamily Some text}and not\ttfamily{Some text}.That is,\ttfamilytakes no argument (perhaps you are confusing it with\texttt{}). Not that that fixes your problem. – Steven B. Segletes Aug 22 '17 at 18:27\ttfamily, the two examples typeset identically. – Steven B. Segletes Aug 22 '17 at 18:31\fontdimen4\font=.167em\relaxpart of your redefinition, both paragraphs hyphenate. – Steven B. Segletes Aug 22 '17 at 18:34