About autoindent and postbreak in the package listings [closed]

I am using the package listings to show my Matlab code. The code was pre-typed in a file and everything will be loaded from the file and a .tex file will be generated automatically to show the code with lstlisting. Now, I am worrying about the long line and I need it break line automatically so I add the breaklines options. It works but if the breaking point is on the comment string, the line break will break the comment into two parts which look pretty ugly because in Matlab the comment must start with % symbol and now the second line is shown in comment style but not prefixed with %. I read the listings package documentation and it mention the postbreak and autoindent options. I don't understand how it work, I try the example shown in the document but didn't get the same results as shown there. Anyway, my question is if it is possible for listings package or other package to break the comment in a smart way such that the broken line will be aligned and correct prefix with be added to the broken comment. For example, a long command is shown as

delta = 0.001;    % interval of the time slice between two different signals measured in different point


In the following environment,

\begin{lstlisting}[postbreak=\space, breakautoindent=true, breakindent=10pt, breaklines]
delta = 0.001;    % interval of the time slice between two different signals measured in different point
\end{lstlisting}


It shows

  delta = 0.001;    % interval of the time slice between two
different signals measured in different point


But I want it to be

  delta = 0.001;    % interval of the time slice between two
% different signals measured in different point

-

closed as off-topic by Jubobs, Peter Jansson, Claudio Fiandrino, Svend Tveskæg, JesseMar 2 '14 at 12:52

• This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

Sounds tricky, but would be cool. – Joachim Breitner Mar 12 '13 at 11:14
Use listings line-numbering functionality. No matter where line breaks occur, your readers will then be able to easily determine whether a given line break was present in the source code or was introduced by listings. Also, consider using the matlab-prettifier package; see this answer. – Jubobs Mar 2 '14 at 11:32
This question appears to be off-topic because it is about a feature request for listings. – Jubobs Mar 2 '14 at 11:45

The listings package doesn't offer the possibility to align broken lines with an arbitrary part of the output, so some hand adjustment is needed. For example

\documentclass{article}
\usepackage{color,listings}
\begin{document}

\begin{lstlisting}[postbreak=\%\space,
breakautoindent=true, breakindent=108pt, breaklines]
delta = 0.001;    % interval of the time slice between two different signals measured in different point
\end{lstlisting}

\end{document}


seems to print the desired output, but does rely on the fact that the comments all start in the same column. I suspect going beyond that is a non-trivial feature request.

-