Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sweave syntax highlighting in output

Has anyone managed to get color syntax-highlighting working in the output of Sweave documents? I've been able to customize the output style by adding boxes, etc. in the Sweave.sty file as follows:

\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontseries=bc,frame=single}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{frame=leftline}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontseries=bc}

And I can get the minted package to do syntax highlighting of verbatim-code blocks in my document like so:

\begin{minted}{perl}
use Foo::Bar;
...
\end{minted}

but I'm not sure how to combine the two for R input sections. I tried the following:

\DefineVerbatimEnvironment{Sinput}{minted}{r}
\DefineVerbatimEnvironment{Scode}{minted}{r}

Any suggestions?

like image 520
Ken Williams Avatar asked Jan 26 '11 17:01

Ken Williams


1 Answers

Yes, look at some of the vignettes for Rcpp as for example (to pick just one) the Rcpp-FAQ pdf.

We use the highlight by Romain which itself can farm out to the hightlight binary by Andre Simon. It makes everything a little more involved---Makefiles for the vignettes etc pp---but we get colourful output from R and C/C++ code. Which makes it worth it.

like image 52
Dirk Eddelbuettel Avatar answered Sep 25 '22 06:09

Dirk Eddelbuettel