The line breaks within lstlisting environments do not function properly for URLs, even though breaklines and breakatwhitespace are both set to true. The URLs are not being broken, and the text exceeds the boundary of the page.
Could someone please assist me in resolving this issue? I have already set breaklines and breakatwhitespace to true, but URLs within lstlisting environments are not being properly broken across lines, causing the text to extend beyond the page margins. You can see the problem in this screenshot.
Any help or suggestions would be greatly appreciated. Thank you!
\documentclass{article}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{listingsutf8}
\lstset{
basicstyle=\ttfamily\color{black}\small,
frame=tb,
extendedchars=true,
showspaces=false,
showstringspaces=false,
numbers=left,
numberstyle=\tiny,
breaklines=true,
backgroundcolor=\color{yellow!20!white},
breakautoindent=true,
breakatwhitespace=true
}
\begin{document}
\section{Introduction}
Test this part of the file: breaking line shouldn't be a problem
in the normal text. But as soon as I have a Listing with a long
text (e.g. token or a hash) then it doesn't work properly. What
also doesn't work is when I'm having a \ texttt in the end of the
line like \texttt{ThisExampleForLongTextWhichDoesNotBreakeAtTheEndOfTheLine}
\begin{lstlisting}
GET https://192.168.178.73:8443/v1/devices/ HTTP/1.1
Authorization: Bearer eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjEwOWMwNTA5MDYzYTk3YmFkMGE2ZWEzMmM3MmE3NmExMzg4NWFkOWRiMmM5OWY0ZmNiNDJiZGEwNQ3OTYwMDcifQ.eyJpc3MiOiJhN2ZkMDAyNi01NTc5LTQ4ZTItYjg3MS1hMjA5YWExNjhhYmUiLCJ0eXBlIjoiYWNjZXNzIiwiYXVkIjoiaG9tZXNtYXJ0LmxvY2FsIiwic3ViIjoiZTQwNTUwMjYtY2JkMC00MjgyLWE0NmEtZWRhOTI5OTE2Zjk1IiwiaWF0IjoxNjgyMDMDc1LCJleHAiOjE5OT2NTQwNzV9.dhX3QfPqVYklVYGWWskvvpi81tVl6k7dZEJFbGNfOncnq2ATnkzR1HZsdFSNbirsu59k2xv2LKdwq5kR_HxEA
Host: 192.168.178.73:8443
Connection: Keep-Alive
\end{lstlisting}
\end{document}

breakatwhitespace=true? Based on your screenshot, it seems that the line is broken at the space between GET and the url because ofbreakatwhitespace. Because the line is already "broken" at the space, listings doesn't perform further breaks within the url. – gz839918 Aug 27 '23 at 23:19