[R] Colors in Sweave

From: Stephen Tucker <brown_emu_at_yahoo.com>
Date: Sun, 27 Jul 2008 12:10:21 -0700 (PDT)


Hi list,

I was using Sweave and was wondering if anyone has had any luck changing the font colors of the code chunks. For instance, in my .Rnw preample I tried including:

===
\usepackage[usenames]{colors}
\definecolor{darkred}{rgb}{0.545,0,0}
\definecolor{midnightblue}{rgb}{0.098,0.098,0.439}
\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl,formatcom={\color{midnightblue}}}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{formatcom={\color{darkred}}}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl,formatcom={\color{blue}}}
===

which works in the sense that colors do show up in the processed pdf document, but extra spaces in between the input and output code chunks appear (which is not the case when colors are not specified), resulting in a long document with many blank lines.

Alternatively, in the resulting tex document I replaced all instances of \begin{Sinput}... \end{Sinput} with {\color{midnightblue}\begin{Sinput} ... \end{Sinput}} and darkred for Soutput and so on. When I do this, I get the following error message:

l.13 \end{Sinput}}
===

I guess I don't know enough of the Schunk/Sinput/Soutput definitions to toy with it and was wondering if anyone had tried something similar.

Thanks!

Stephen



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 27 Jul 2008 - 19:14:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 Jul 2008 - 00:33:00 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive