I'm looking to get a \verb string to output with bold font style as well as word wrapping. The closest I've come is by using the commented code rather than the currently live one. I realize I'm breaking the cardinal rule of never using \BF. I couldn't repeat the results with \textbf nor with \bfseries. Any thoughts on that?
\documentclass{article}
\usepackage{lmodern,verbatim}
\makeatletter
\newenvironment{boldverb}
{\def@xobeysp{\ }
%{\def@xobeysp{\bf \ }
\verbatim\rightskip=0pt plus 6em\relax}
{\endverbatim}
\makeatother
\begin{document}
\begin{boldverb}
\ \verb|\hspace{20pt}\newpageOkay, so where do we start, right? \textbf{Why is it that I can bold this stuff} but not \verb|
\end{boldverb}
\end{document}
Even if I'm allowed in this case to use \bf, the beginning of the string is always going to have to be a backslash. Is there a latex argument that recognizes elements such as Word-Initial or Word-Final?


\verbinside a verbatim environment will do nothing at all except printing\verb. – egreg Feb 08 '24 at 18:17