Closing parenthesis as delimiter not matched when breaklines=true

You might have come across a bug arising from the special treatment of the right parenthesis by the line-breaking algorithm of the listings package. In fact, when the SelectCharTable hook used by the listings package is executed and line breaking is enabled ) is defined as a macro, namely by



#1->\lccode `\~=#1\lowercase {\def ~}.

Unfortunately, this means that ) is not recognized as a delimiter any more, which eventually leads to your observation.

I’ve put some effort in finding a fix for this bug, but haven’t succeeded so far. (My TeX programming skills are still limited.) So, the only thing I can provide right now is a workaround in the form of a patch that simply cancels the special treatment of ) by the line-breaking algorithm:











outside (in paren) [in brackets (paren+brackets) brackets again] outside again


The resulting output is:

A simple workaround would be, instead of using closing parenthesis ')', one can use another character e.g ']' and replace it with closing parenthesis ')'.

(In text I'm closing using]