GeneralHow to use the listings package

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
DavidTTT
Posts: 1
Joined: Wed Aug 09, 2023 11:22 pm

How to use the listings package

Post by DavidTTT »

Hello,
I am a bit inexperienced with LaTeX and I have a code called "My code" that I want to make look like "Example". I have been trying to do it, but I don't know how to make it exactly similar. Here is the code:

Code: Select all

\begin{lstlisting}[language=Pascal, basicstyle=\ttfamily\small,frame=single,title=SCRIPT,framesep=9pt,stringstyle=\color{violet},showstringspaces=false,keywordstyle=\color{blue},backgroundcolor=\color{white!90},rulecolor=\color{gray!30},identifierstyle=\color{black!85}]
format long
disp('Dada la sucesion a = 1/(1 + 1/sqrt(n))^n')
n=input('Coloque un numero mayor que 0. n = ');
if n <= 0
    disp('(ERROR)El numero debe ser entero mayor que 0.')
else
    disp(['Estos son los ',num2str(n),' terminos de la sucesion'])
end
a=zeros(1,n);
for m=1:n
  a(m)= 1 ./ (1 + 1 ./ sqrt(m)) .^ m;
  disp(a(m));
end
if n>0
    disp(['La suma de los ',num2str(n),' terminos es ',num2str(sum(a))])
end
\end{lstlisting}
I literally need it to have the same font, color, and other things because it is a university assignment and I will get less points for every thing that is not similar. Thanks
Attachments
My code.png
My code.png (34.31 KiB) Viewed 7333 times
Example.png
Example.png (28.42 KiB) Viewed 7333 times
Last edited by Stefan Kottwitz on Sat Aug 12, 2023 10:25 am, edited 1 time in total.
Reason: code marked

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

How to use the listings package

Post by rais »

Looks more like Matlab code to me...why do you tell listings it would be Pascal?

If you wish to have others tell you what kind of colors were used, me, for one, would need a better picture of `how it should be'---did you have a closer look at `Example.png'? The colors aren't uniform within their areas.

KR
Rainer
Post Reply