I'm currently writing a book chapter in bioinformatics, and I would like to provide my readers some useful command lines to invoke recent software. To that purpose, I'm using the listings package to format minimal python scripts, whose execution would produce the figures in the chapter.
The package works great in general, but I'm having difficulties getting it to break-lines properly on long strings, as shown by the following MWA, in which the string is simply not broken.
\documentclass{minimal}
\usepackage{listings}
\lstloadlanguages{Python}
\lstset{
language=Python,
basicstyle=\ttfamily,
morekeywords={rna},
breaklines=true,
keywordstyle={\bfseries\color{purple}},
}
\begin{document}
\begin{lstlisting}[caption={No line breaking}]
rna = "ACUUGUAUAACCUCAAUAAUAUGGUUUGAGGGUGUCUACCAGGAACCGUAAAAUGGUGAUUACAAAAUUUGUUUAUGACAUUUUUUGUAAUCAGGAUUUUUUUU"
\end{lstlisting}
\end{document}
In Listings package does not break, a Tex hack was given, to take the 'letter' status away from every character, thus allowing the listings package to treat long ids/strings as sequences of 'atomic tokens'. The new MWA would read:
\documentclass{minimal}
\usepackage{listings}
\lstloadlanguages{Python}
\lstset{
language=Python,
basicstyle=\ttfamily,
morekeywords={rna},
breaklines=true,
keywordstyle={\bfseries\color{purple}},
}
\begin{document}
\makeatletter
\def\lst@lettertrue{\let\lst@ifletter\iffalse}
\makeatother
\begin{lstlisting}[caption={No line breaking}]
rna = "ACUUGUAUAACCUCAAUAAUAUGGUUUGAGGGUGUCUACCAGGAACCGUAAAAUGGUGAUUACAAAAUUUGUUUAUGACAUUUUUUGUAAUCAGGAUUUUUUUU"
\end{lstlisting}
\end{document}
However, compiling the above code no longer provides any syntax highlighting, as shown in the following picture (red line represents the edge of the margin):

Can one get, at the same time, line-breaking of long ids/strings without losing syntax highlighting?

listingsto get something likemaxcharnumber=40orforcebreakat=\linewidth. Or you try to find a macro to insert a comment after x characters and let it insert(*@\allowbreak@*)at such places. – LaRiFaRi Jul 23 '13 at 09:11