Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using the listings package to include GAUSS code to Latex.

E.g. like this:

\lstset{
emph={proc,retp,endp,local}, emphstyle=\color{blue}\textbf,
emph={[2]=,.^,./,=}, emphstyle={[2]\color{red}}
}

\begin{lstlisting}
proc(1) = tdist(n,v);
local x, z, z2, u, t;
x=rndn(n,1); 
z=rndn(n,v);
z2=z.^2; 
t=x./((U./v)^(1/2));
retp(t);
endp;
\end{lstlisting}

While the strings (proc, retp etc.) are highlighted, the math operators (=, *, /) are not. What am I doing wrong here?

share|improve this question

1 Answer 1

up vote 9 down vote accepted

You can't do this with the emph key. But you can do it using the literate key:

\documentclass{article}
\usepackage{listings,xcolor}
\begin{document}

\lstset{
emph={proc,retp,endp,local}, emphstyle={\color{blue}\textbf},
literate={./}{{{\color{red}./}}}2 {.^}{{{\color{red}.\^{}}}}2 {=}{{{\color{red}=}}}1
}

\begin{lstlisting}
proc(1) = tdist(n,v);
local x, z, z2, u, t;
x=rndn(n,1); 
z=rndn(n,v);
z2=z.^2; 
t=x./((U./v)^(1/2));
retp(t);
endp;
\end{lstlisting}

\end{document}

Note that all the braces are required, since you need to limit the scope of the \color command.

output of code

share|improve this answer
    
brilliant, thanks a lot! –  godasu May 8 '11 at 14:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.