Verbatim environment to split long words over lines
You can iterate through the verb, adding a breakpoint after each character.
\documentclass{article}
\makeatletter
\let\old@sverb\@sverb
\def\@sverb#1{\old@sverb{#1}\zz}
\def\zz#1{#1\ifx\@undefined#1\else\penalty\z@\expandafter\zz\fi}
\makeatother
\begin{document}
\raggedright
\verb|lllllllllllllllllllllloooooooooooooooooonnnnnnnnnnnnnggggggg$$$$$$$$$$$$$$$$llllllllllllloooooooooooooooonnnnnnnnnnnnnnnngggggggg$$$$$$$|
\verb|`?<<---|
\verb|`?<<---ooooooooooooooooonnnnnnnnnnnnnggggggg$$$$$$$$$$$$$$$$llllllllllllloooooooooooooooonnnnnnnnnnnnnnnngggggggg$$$$$$$|
\end{document}
A solution with xparse
:
\documentclass[draft]{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\splitverb}{v}
{
\group_begin:
\use:c { verbatim@font }
\seq_set_split:Nnn \l_tmpa_seq {} {#1}
\seq_use:Nn \l_tmpa_seq { \hspace{0pt plus .2em}\penalty\c_zero\hspace{0pt plus -.2em} }
\group_end:
}
\ExplSyntaxOff
\begin{document}
Some text \splitverb|lllllllllllllllllllllloooooooooooooooooonnnnnnnnnnnnnggggggg$$$$$$$$$$$$$$$$llllllllllllloooooooooooooooonnnnnnnnnnnnnnnngggggggg$$$$$$$|
Let's see that ligatures are not formed: \splitverb|`?<<---|
\end{document}
The combination of \hspace
and \penalty
ensures you don't get overfull boxes.
You may want to add some glue with small flexibility instead.
\documentclass[draft]{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\splitverb}{v}
{
\group_begin:
\use:c { verbatim@font }
\seq_set_split:Nnn \l_tmpa_seq {} {#1}
\seq_use:Nn \l_tmpa_seq { \hspace{0pt plus 0.1pt} }
\group_end:
}
\ExplSyntaxOff
\begin{document}
Some text \splitverb|lllllllllllllllllllllloooooooooooooooooonnnnnnnnnnnnnggggggg$$$$$$$$$$$$$$$$llllllllllllloooooooooooooooonnnnnnnnnnnnnnnngggggggg$$$$$$$|
Let's see that ligatures are not formed: \splitverb|`?<<---|
\end{document}