Use package listings... Here is an example file to include some Matlab code. 
It works for C and many other languages.

On Friday 05 October 2001 07:04, Ben Logan wrote:
> Hi,
>
> I'm helping write a book (http://opencbp.sourceforge.net) in LyX, and
> we need to include examples of C source code.  The way I'm doing it
> right now is to use the Include File feature and check the Verbatim
> option.  This works just fine, except that I wish LyX could take care
> of automatically numbering the examples, and I wish I could add a
> caption.  The reason I'm not using algorithm floats is that the images
> generated are large, and seem to cause problems (if, for example, the
> source code spans multiple pages).
>
> Is there any way to do this?
>
> Thanks,
> Ben
#LyX 1.1 created this file. For more info see http://www.lyx.org/
\lyxformat 218
\textclass scrreprt
\begin_preamble
\usepackage[breaklines]{listings}
\renewcommand\lstlistingname{Program}%                     default is Listing
\renewcommand\lstlistlistingname{List of Programs}%        default is Listings
\renewcommand\thelstlisting{\thechapter .\arabic{lstlisting}}% captionstyle
\newcommand{\lst}[2]{%
    \noindent\rule[-1ex]{\textwidth}{0.3mm}\vspace{-1ex}
    
\lstinputlisting[caption={#2},label={#1},stringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,%
    
basicstyle=\footnotesize\tt,labelstep=1,labelstyle=\tiny,indent=2em,language=Matlab,breaklines]{#1}
    \vspace{1ex}%
}
\end_preamble
\language english
\inputencoding auto
\fontscheme times
\graphics default
\paperfontsize default
\spacing single 
\papersize Default
\paperpackage a4
\use_geometry 0
\use_amsmath 0
\paperorientation portrait
\secnumdepth 2
\tocdepth 2
\paragraph_separation indent
\defskip medskip
\quotes_language english
\quotes_times 2
\papercolumns 1
\papersides 1
\paperpagestyle default

\layout Comment


\backslash 
setcounter{page}{36}
\layout Standard


\latex latex 
DRAWP3.M
\layout Standard


\latex latex 

\backslash 
lstinputlisting[stringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,b
asicstyle=
\backslash 
footnotesize,labelstep=1,labelstyle=
\backslash 
tiny,indent=2em,language=Matlab,breaklines]{drawp3.m}
\layout Standard


\latex latex 

\backslash 
newpage
\layout Standard


\latex latex 
DRAWPLET.M
\layout Standard


\latex latex 

\backslash 
lstinputlisting[stringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,b
asicstyle=
\backslash 
footnotesize,labelstep=1,labelstyle=
\backslash 
tiny,indent=2em,language=Matlab,breaklines]{drawplet.m}
\layout Standard


\latex latex 

\backslash 
newpage
\layout Standard


\latex latex 
GGRID.M
\layout Standard


\latex latex 

\backslash 
lstinputlisting[stringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,b
asicstyle=
\backslash 
footnotesize,labelstep=1,labelstyle=
\backslash 
tiny,indent=2em,language=Matlab,breaklines]{ggrid.m}
\layout Standard


\latex latex 

\backslash 
newpage
\layout Standard


\latex latex 
FPOLY.M
\layout Standard


\latex latex 

\backslash 
lstinputlisting[stringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,b
asicstyle=
\backslash 
footnotesize,labelstep=1,labelstyle=
\backslash 
tiny,indent=2em,language=Matlab,breaklines]{fpoly.m}
\layout Standard


\latex latex 

\backslash 
newpage
\layout Standard


\latex latex 
QANLYZ3.M
\layout Standard


\latex latex 

\backslash 
lstinputlisting[stringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,b
asicstyle=
\backslash 
footnotesize,labelstep=1,labelstyle=
\backslash 
tiny,indent=2em,language=Matlab,breaklines]{qanlyz3.m}
\layout Standard


\latex latex 

\backslash 
newpage
\layout Standard


\latex latex 
QANLYZ2.M
\layout Standard


\latex latex 

\backslash 
lstinputlisting[stringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,b
asicstyle=
\backslash 
footnotesize,labelstep=1,labelstyle=
\backslash 
tiny,indent=2em,language=Matlab,breaklines]{qanlyz2.m}
\layout Standard


\latex latex 

\backslash 
newpage
\layout Standard


\latex latex 
IRREGF.M
\layout Standard


\latex latex 

\backslash 
lstinputlisting[stringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,b
asicstyle=
\backslash 
footnotesize,labelstep=1,labelstyle=
\backslash 
tiny,indent=2em,language=Matlab,breaklines]{irregf.m}
\layout Standard


\latex latex 

\backslash 
newpage
\layout Standard


\latex latex 
IRREGFP.M
\layout Standard


\latex latex 

\backslash 
lstinputlisting[stringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,b
asicstyle=
\backslash 
footnotesize,labelstep=1,labelstyle=
\backslash 
tiny,indent=2em,language=Matlab,breaklines]{irregfp.m}
\layout Standard


\latex latex 

\backslash 
newpage
\layout Standard


\latex latex 
PSIDESF.M
\layout Standard


\latex latex 

\backslash 
lstinputlisting[stringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,b
asicstyle=
\backslash 
footnotesize,labelstep=1,labelstyle=
\backslash 
tiny,indent=2em,language=Matlab,breaklines]{psidesf.m}
\layout Standard


\latex latex 

\backslash 
newpage
\layout Standard


\latex latex 
DRAWQ2.M
\layout Standard


\latex latex 

\backslash 
lstinputlisting[stringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,b
asicstyle=
\backslash 
footnotesize,labelstep=1,labelstyle=
\backslash 
tiny,indent=2em,language=Matlab,breaklines]{drawq2.m}
\layout Standard


\latex latex 

\backslash 
newpage
\layout Standard


\latex latex 
DRAWQIR.M
\layout Standard


\latex latex 

\backslash 
lstinputlisting[stringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,b
asicstyle=
\backslash 
footnotesize,labelstep=1,labelstyle=
\backslash 
tiny,indent=2em,language=Matlab,breaklines]{drawqir.m}
\layout Standard


\latex latex 

\backslash 
newpage
\layout Standard


\latex latex 
QSPIND.M
\layout Standard


\latex latex 

\backslash 
lstinputlisting[stringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,b
asicstyle=
\backslash 
footnotesize,labelstep=1,labelstyle=
\backslash 
tiny,indent=2em,language=Matlab,breaklines]{qspind.m}
\layout Standard


\latex latex 

\backslash 
newpage
\layout Standard


\latex latex 
SHANR3.M
\layout Standard


\latex latex 

\backslash 
lstinputlisting[stringspaces=false,frame={tb},lineskip=-1pt,extendedchars=true,b
asicstyle=
\backslash 
footnotesize,labelstep=1,labelstyle=
\backslash 
tiny,indent=2em,language=Matlab,breaklines]{shanr3.m}
\the_end

Reply via email to