Brian Guenter wrote:
I'm new to Lyx and I'm hoping that the problems I'm encountering are
just due to my ignorance.  I have a large existing code base in my
development environment which I am going to be copying into my Lyx
document as program listings.  I had an existing Latex document with
program listings in it using the lstlisting environment. When I
imported this document into Lyx all of the newlines in the program
listings disappeared.


Similarly, if I copy code from my development environment (Visual
Studio 2008) and paste it into a program listing block in Lyx all of
the newlines are discarded.

Try Edit -> Paste Special -> Plain Text (C-S-V). This works for me (meaning the newlines are preserved).

If I have a properly formatted program
listing, with newlines,  in a Lyx document and I export the Lyx
document to a Latex file and then import the Latex file back into Lyx
all of the newlines in program listing blocks disappear.


It's terribly inconvenient and time-consuming to have to reinsert all
of the newlines by hand and retyping the code in Lyx is also an
unattractive option because I have so much of it and because this
will certainly introduce transcription errors.

Is this newline deletion a bug or is there something I can set to
prevent the newlines from disappearing?

It's a bug (or a lack of a feature, or a lag in implementing a feature). Support for the listings environment is relatively new to LyX. LyX uses a program called tex2lyx to convert LaTeX files to LyX file. My guess is that tex2lyx has not caught up to the implementation of the listings package, and it's tex2lyx that's eating the newlines.

You might want to file a bug report against this. (I did a quick search and couldn't find one.) Also, if you run 'tex2lyx --help', you'll see a rather intriguing reference to the -s option: "-s syntaxfile read additional syntax file". Assuming one can find some documentation on syntax files for tex2lyx (so far I can't), perhaps one can implement a modification to preserve newlines in listings that way.


Reply via email to