# Hyphenation in listings captions doesn't work correctly

I have the problem that automatic hyphenation in listings caption doesn't work if automatic linebreaking is activated. It works if I set breaklines=false or captionpos=t, which is weird. Is there a workaround? I want to have captions at the bottom and I need automatic line-breaking.

\documentclass{article}
\usepackage[english]{babel}

\usepackage{listings}

\lstset{
breaklines=true,
captionpos=b
}

\begin{document}

\begin{lstlisting}[caption={information information information information information information information}]
A = B
C = D
\end{lstlisting}

\end{document}


captionpos=b (WRONG):

captionpos=t (correct):

-

The problem is the line

\hbadness\@M \pretolerance\@M


of lstmisc and the macro \lst@AddToHook{Init} which is set before the listings contents with breaklines=true. With captionpos=t it doesn't belong to the caption, but with captionpos=b it does. It prevents hyphenation. A simple fix is to reset \pretolerance:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{listings}
\lstset{
breaklines=true,
}

\begin{document}

\begin{lstlisting}[caption=information  information  information information information information information,captionpos=t]
A = B
C = D
\end{lstlisting}

\begin{lstlisting}[caption={\pretolerance=100 information information information information
information information information},captionpos=b]
A = B
C = D
\end{lstlisting}

\end{document}


A better solution is to reset the values inside \lst@MakeCaption which should be reported to the current maintainer of listings.

-