>>From: Gerald Gutierrez <[EMAIL PROTECTED]>
>>To: Lyx Users Mailinglist <[EMAIL PROTECTED]>
>>Subject: Formatting source code
>>Date: Tue, 7 Mar 2000 11:29:01 -0800
>>
>>
>>Hello!
>>
>>I'm currently writing my thesis and need to have some code snippets as part of
>>it. Unfortunately, because I'll be using double spacing, simply putting the
>>code in and changing it to a typewriter font, or using Lyx-Code causes the 
code
>>to be double spaced as well, making it really hard to read (and fairly ugly).
>>
>>Is there a way to separately control the spacing of Lyx-Code? Alternatively,
>>what is There are about 40 known languages.a good way to insert code so that 
it'll look proper? Also, is there
>>such a thing as a "code float" (like a figure float) ?
>>
>>Thanks.
>>
>>
I use the lgrind latex package, which can be used in LyX using ERT.
Works with preprocessing using a shell command (lgrind) which must
be installed in the bin directory of the LaTeX installation.
Provides pretty printing and line numbering of various languages,
and can be used standalone, e.g.
%lgrind -lC -o foo.tex foo.c 
%latex foo;dvips foo
provides a printed version of C code in foo.c.
There are about 40 recognised languages.
Does not fold long lines however, you have to format yourself.

So with LyX:
 - get the package from the nearest CTAN archive
 - install it in the LaTeX tree
 - make it available (texhash with teTeX)
 - preprocess the code for inline inclusion in a latex doc, e.g.
    %lgrind -i -lC -o foo.c.tex foo.c
 - edit the premable in LyX, e.g.:
\usepackage[lineno5,leftno,norules]{lgrind}
 - at the right location in the doc, insert in ERT
\lgrindfile{foo.c.tex}

Should work OK, perhaps a bit sophisticated for simple pieces of code,
in which case a simple Lyx input of the code embedded between
\begin{verbatim}
...
\end{verbatim}
could be sufficient.

Regards

-- 
Jean-Pierre

Reply via email to