LyXHow to insert correctly A Matlab code within Lyx

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
Post Reply
newnoise
Posts: 19
Joined: Thu Aug 21, 2008 11:57 am

How to insert correctly A Matlab code within Lyx

Post by newnoise »

Hello guys!

Someone know how can I copy&paste a matlab script within lyx without loosing all the structure and colors?

Thank You!

/davide

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

How to insert correctly A Matlab code within Lyx

Post by Juanjo »

Select Insert > Program Listing. Then type the program. To get colors and control many aspects of the listing format, go to Document > Settings... > LaTeX Preamble and copy there something like:

Code: Select all

Code, edit and compile here:
\usepackage{color}
\definecolor{hellgelb}{rgb}{1,1,0.85}
\definecolor{colKeys}{rgb}{0,0,1}
\definecolor{colIdentifier}{rgb}{0,0,0}
\definecolor{colComments}{rgb}{1,0,0}
\definecolor{colString}{rgb}{0,0.5,0}
\lstset{%
language=Matlab,%
float=hbp,%
basicstyle=\footnotesize\ttfamily,%
identifierstyle=\color{colIdentifier},%
keywordstyle=\color{colKeys},%
stringstyle=\color{colString},%
commentstyle=\itshape\color{colComments},%
columns=fixed,
tabsize=4,%
frame=single,%
framerule=1pt,
extendedchars=true,%
showspaces=false,%
showstringspaces=false,%
numbers=left,%
numberstyle=\tiny\ttfamily,%
numbersep=1em,%
breaklines=true,%
breakindent=10pt,%
backgroundcolor=\color{hellgelb},%
breakautoindent=true,%
captionpos=t,%
xleftmargin=1em,%
xrightmargin=\fboxsep%
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The above code is extracted and adapted from the config file of the showexpl package. In your case, perhaps you don't like some of the above settings. Remove them to conform to defaults or change them according to your needs. The description of each option is given in the doc of the listings package.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
newnoise
Posts: 19
Joined: Thu Aug 21, 2008 11:57 am

Re: How to insert correctly A Matlab code within Lyx

Post by newnoise »

Thank You very much! It works! Just to know: as I do the PDF, the Program Listing is contained within a black frame. It is possible to take out that frame in some way?

Thank You,
davide
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How to insert correctly A Matlab code within Lyx

Post by localghost »

newnoise wrote:Thank You very much! It works! Just to know: as I do the PDF, the Program Listing is contained within a black frame. It is possible to take out that frame in some way? [...]
Take a look at the code Juanjo gave you. There you will find lines which specify the layout of the listing.

Code: Select all

Code, edit and compile here:
\lstset{%
...
frame=single,%
framerule=1pt,%
...
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Refer to the documentation of lstlistings and you will know how to change the appearance.


Best regards
Thorsten¹
newnoise
Posts: 19
Joined: Thu Aug 21, 2008 11:57 am

Re: How to insert correctly A Matlab code within Lyx

Post by newnoise »

THANK YOU very much!!

/davide
Post Reply