[Tex/LaTex] How to display colors of Octave code in latex with listings

codecolorlistingsoctave

In my paper I include Octave code with

\usepackage{listings}

No I want that the text and numbers be written in the same colors as the are represented with in Octave. Everything is fine, except that I don't know how to color the symbols red that have to be red.

For example keywords could easily be colored blue by writing

keywordstyle=\color{blue}

Is there a similar way for doing this with symbols written in red?
I did it manually, but this doesn't work as expected.

This is what I wrote in LaTeX:

\documentclass[a4paper]{report}

\usepackage{color}
\usepackage{listings}
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\definecolor{myorange}{rgb}{0.855,0.576,0.027}
\lstset{
language=Octave,
frame=single,   
morecomment = [l][\itshape\color{blue}]{\%},
keywordstyle=\color{blue},
commentstyle=\color{mygreen},
breakatwhitespace=false,         
breaklines=true,  
numbers=left,
numbersep=5pt,
numberstyle=\tiny\color{mygray}, 
showstringspaces=false,
showtabs=false,                  
tabsize=2,
stringstyle=\color{myorange},
title=\lstname,
literate=
{+}{{{\color{red}+}}}1
{-}{{{\color{red}-}}}1
{*}{{{\color{red}*}}}1
{,}{{{\color{red},}}}1
{=}{{{\color{red}=}}}1
{)}{{{\color{red})}}}1
{(}{{{\color{red}(}}}1
{;}{{{\color{red};}}}1
{:}{{{\color{red}:}}}1
{[}{{{\color{red}[}}}1
{]}{{{\color{red}]}}}1
{>}{{{\color{red}>}}}1
}

\begin{document}

\begin{lstlisting}
function out = invar_table(n,m,N)
if n>m, error('first number must be smaller than the second'), endif

t = cputime;
out = zeros(m-n+1,2);

for i=n:m
  out(i+1-n,1) = i;
  out(i+1-n,2) = invar(braidmatrix(i),N);
end

printf('Total CPU time: %f seconds\n', cputime-t);

end
\end{lstlisting}

\end{document}

An example of code in my LaTeX document:

enter image description here

And this is how it should look like:

enter image description here

How can I display the colors correctly?

Best Answer

Probably too late for an answer :P

Try adding this line in your \lstset.

basicstyle=\linespread{0.9}\ttfamily\small,
Related Question