LaTeX’te kodları renklendirmek
Açıklama: Latex’te kodları renklendirebilmek için listings paketi kullanılıyor. Örnek bir MATLAB kodunun renklendirilmesi yapılıyor. Başka birçok dil de destekleniyor.
Kaynaklar:
Kaynak kod
\documentclass{article}
\usepackage[margin=0.75in]{geometry}
\usepackage{courier}
\usepackage{color}
\usepackage{listings}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{bg}{rgb}{0.8,0.8,1}
\begin{document}
\lstset{language=Matlab,
keywords={break,case,catch,continue,else,elseif,end,for,function,
global,if,otherwise,persistent,return,switch,try,while},
basicstyle=\footnotesize,
keywordstyle=\color{blue},
commentstyle=\color{red},
stringstyle=\color{dkgreen},
numbers=left,
numberstyle=\footnotesize,
stepnumber=1,
frame=shadowbox, rulesepcolor=\color{bg},
caption=Ornek Renkli Matlab Kodu,
label=ornekkod1,
numbersep=10pt,
backgroundcolor=\color{white},
tabsize=4,
showspaces=false,
showstringspaces=false}
\begin{lstlisting}
function y = demo(x) % Bu bir yorumdur.
str = 'merhaba oradakiler';
y = x + 1;
end
\end{lstlisting}
\end{document}


