I want code in parentheses and in brackets to appear in different colors. In the following document, the words brackets again appear in green as intended, and outside again is black as intended, but stretches into the margin of the page.
If I uncomment the line ,breaklines=true
, the line is broken between brackets and again, however, these words and the following are red, i.e. as if a (
-)
-delimited section was detected but then the closing )
was ignored.
What is going on here?
Addition: The problem occurs also if there is no line break present, e.g. if I shorten all words in the text to their first letter. The problem goes away in any case if I pick any other kind of delimiter instead of ()
, e.g. {}
.
\documentclass{article}
\usepackage{color}
\usepackage{listings}
\lstdefinelanguage{new}{
moredelim=*[s][\color{red}]{(}{)},
moredelim=*[s][\color{green}]{[}{]},
}
\lstset{
language=new
%,breaklines=true
}
\begin{document}
\begin{figure}
\begin{lstlisting}
outside(in paren) [in brackets (paren+brackets) brackets again] outside again
\end{lstlisting}
\end{figure}
\end{document}