0

I can hyphenate inline verbatim text at a ':'; however, I want to hyphenate inline verbatim text at an underscore '_', but I can not find a solution. The MWE is as follows.

\documentclass{article}

\usepackage{geometry} \usepackage{listings} \usepackage[htt]{hyphenat}

\lstset{ basicstyle=\ttfamily\linespread{1.0}\normalsize, breaklines=true }

\geometry{hmargin={6cm,6cm}}

\begin{document}

\lstinline¦hello_world_hello_world_hello_world_hello_world_hello_world_hello_world_hello_world_hello_world¦.

\lstinline¦hello:world:hello:world:hello:world:hello:world:hello:world:hello:world:hello:world:hello:world¦.

\end{document}

The typeset result is MWE typeset result.

Is there any solution to hyphenate inline verbatim text at '_' without introducing '-', since \texttt macro can hyphenate the above example, but the result is not what I want.

\texttt{hello\_world\_hello\_world\_hello\_world\_hello\_world\_hello\_world\_hello\_world\_hello\_world\_hello\_world}.
  • Looks related to https://tex.stackexchange.com/questions/65743/how-can-i-make-the-listings-package-break-lines (same package, although in this case it's inline) – user202729 Nov 10 '21 at 16:58
  • Welcome to tex.se! Does the solution given at https://tex.stackexchange.com/a/140725/15925 help? I.e. use listings and change the class of _ to other rather than letter – Andrew Swann Nov 10 '21 at 17:03
  • 1
    Your MWE shows no examples of hyphenation except for the \texttt code. I have a feeling that your problem might lie with the listings package, not hyphenat. – Peter Wilson Nov 10 '21 at 18:19
  • @user202729: Yes, the message linked is helpful, and the redefinition of \lst@lettertrue leads to break inline verbatim text anywhere if necessary, including underscore ('_') of course. – user2182284 Nov 11 '21 at 01:49
  • @AndrewSwann: The solution linked is helpful too. With \lstset{alsoother={_}}, breaking inline verbatim text at underscore comes true, and this is the original goal I want to achieve, and I am very thankful. – user2182284 Nov 11 '21 at 01:53
  • @PeterWilson: Yes, your feeling is correct, and the problem does lie with the listings package. Under user202729 and Andrew's help, I have got the solution. Besides, I think that I have misused the word 'hyphenating', it should be 'breaking'. – user2182284 Nov 11 '21 at 01:56

0 Answers0