I need to quote some R commands and a few scripts, and sometimes to show the output. I would like that the output had a different colour than the input, but I have no idea how to. A minimal example could be this.
\documentclass{article}
\usepackage{listings}
\usepackage[svgnames]{xcolor}
\lstset{frame=none,
language=R,
showstringspaces=false,
columns=flexible,
numbers=none,
basicstyle={\small\ttfamily},
keywordstyle=\color{Blue},
stringstyle=\color{Red},
commentstyle=\color{DarkGreen},
breaklines=true,
breakatwhitespace=true,
tabsize=3}
\begin{document}
\begin{lstlisting}
# First attempt
# to use R
> x <- c(1, 2, 3, 4)
> x
[1] 1 2 3 4
> sum(x)
[1] 10
> mean(x)
[1] 2.5
\end{lstlisting}
\end{document}
What I would like to achieve is to have [1] 1 2 3 4
, [1] 10
and [1] 2.5
in another colour, for instance in DarkBlue
. Is it possible with listings? I have only found a similar reference in the post "Coloring R input and output differently using knitr" which I don't understand because I don't know what knitr
is!
knitr
tag, so you have enough examples for a rough idea of what you're missing.