Hello guys!
Someone know how can I copy&paste a matlab script within lyx without loosing all the structure and colors?
Thank You!
/davide
LyX ⇒ How to insert correctly A Matlab code within Lyx
NEW: TikZ book now 40% off at Amazon.com for a short time.
How to insert correctly A Matlab code within Lyx
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:
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.
Code: Select all
\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%
}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Re: How to insert correctly A Matlab code within Lyx
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
Thank You,
davide
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
How to insert correctly A Matlab code within Lyx
Take a look at the code Juanjo gave you. There you will find lines which specify the layout of the listing.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? [...]
Code: Select all
\lstset{%
...
frame=single,%
framerule=1pt,%
...
}
Best regards
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: How to insert correctly A Matlab code within Lyx
THANK YOU very much!!
/davide
/davide