More precisely, suppose we want to show a piece of computer code in a LaTeX document. The computer code has some parts in colors. How can we tell LaTeX to show the code colors ?
(hmmm, sorry if my English sounds terrible here. I'm doing my best...

NEW: TikZ book now 40% off at Amazon.com for a short time.
Actually it is your homework to submit a small example on which we can test possible solutions. As already mentioned, a search in the forum surely will bring some helpful examples. First sources of information would be the manuals of the above mentioned packages.Cham wrote:Hmmm, can you give a small example of a code snippet with some colors ?
Code: Select all
\documentclass[ ]{revtex4}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{listings}
\pagestyle{plain}
\begin{document}
\begin{lstlisting}
Mu0[t_, x_, y_, z_] := {
Cos[2Pi t - k(r[x, y, z])]Sin[alpha],
Sin[2Pi t - k(r[x, y, z])]Sin[alpha],
Cos[alpha]
}
\end{lstlisting}
\end{document}
Code: Select all
\documentclass[ ]{revtex4}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{listings,xcolor}
\pagestyle{plain}
\begin{document}
\begin{lstlisting}[language=mathematica,basicstyle=\ttfamily,keywordstyle=\color{blue}]
Mu0[t_, x_, y_, z_] := {
Cos[2Pi t - k(r[x, y, z])]Sin[alpha],
Sin[2Pi t - k(r[x, y, z])]Sin[alpha],
Cos[alpha]
}
\end{lstlisting}
\end{document}
Code: Select all
\documentclass[ ]{revtex4}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{listings,xcolor}
\pagestyle{plain}
\begin{document}
This is a test :
\lstset{tabsize=4,frame=single,language=mathematica,stringstyle=\ttfamily,basicstyle=\scriptsize,keywordstyle=\color{blue},backgroundcolor=\color{lightgray},
emph={Mu0},emphstyle=\color{red},
emph={[2]alpha,k},emphstyle={[2]\color{green}},
emph={[3]r},emphstyle={[3]\color{blue}}}
\begin{lstlisting}[title={A title}]
Mu0[t_, x_, y_, z_] :=
{
Cos[2Pi t - k(r[x, y, z])]Sin[alpha],
Sin[2Pi t - k(r[x, y, z])]Sin[alpha],
Cos[alpha]
}
\end{lstlisting}
\end{document}
NEW: TikZ book now 40% off at Amazon.com for a short time.