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
listingsline-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 bylistings. Also, consider using thematlab-prettifierpackage; see this answer. – jub0bs Mar 02 '14 at 11:32listings. – jub0bs Mar 02 '14 at 11:45