On 05.03.2008, at 05:55, Bo Peng wrote:
Have you checked out the support for lstlisting in LyX 1.5.x? I
gather
from the wiki that Bo Peng is responsible for it (props to Bo). It's
not on the environment roster; you get it with Insert -> Program
Listing. Right click the widget handle to see all the controllable
stuff.
I know the mentioned problems with listings but they are not easy to
solve. I also recommend using a listings child document for long
listings.
I have been using the listings package quite a lot. Since LyX 1.4 it
works perfectly if used in ERT boxes (pre 1.4 versions added an extra
new-line after every hard line break, which required some trickery
with negative linkeskip values to yield a good result.)
I never used the new listings inset, though. In my opinion, ERT boxes
are just perfect for in-text listings of code. Listings clearly is one
of the best documented packages available in the LaTeX world and has a
very convenient interface, so "hand coding" listings options is not at
all painful. All one should do is to define a listings style with all
necessary default settings in the preamble (a good practice anyway).
Then only two actual LaTeX lines have to be in each ERT box:
\begin{lstlisting}[style=ac]
#include "Win32Error.h"
aspect ThrowWin32Errors {
advice call( win32::Win32API() ) : after() {
if( win32::IsError( *tjp->result() ) {
throw win32::Exception();
}
}
};
\end{lstlisting}
Keeping (short) listings in ERT boxes this way has a some clear
advantages:
- The on-screen formatting is easy, as within ERT a typewriter font is
used.
- The spell checker skips ERT boxes, hence the listings do not get
spell checked (that always annoyed me with LyxCode)
- Extra options can easily be passed as additional optional parameters
in the square brackets.
For longer listings I recommend to not input them as LyX child
documents, but keep them in ordinary text files using the
\lstinputlisting command in ERT:
\lstinputlisting[style=aclisting]{../src/win32eh-app.cpp}
Just my two cents,
Daniel