Highlighting Sweave Syntax Out

Has anyone been able to get the color syntax highlighting working in conclusion Sweave documents? I was able to customize the output style by adding fields, etc. To file Sweave.styas follows:

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

And I can get a package mintedto highlight the syntax of the blocks of verbatim code in my document like this:

\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?

+5
source share
4 answers

tex.StackExchange , SweaveListingUtils package R .

+3

, Rcpp, ( ) Rcpp-FAQ pdf.

highlight Romain, hightlight, . - Makefiles .. Pp, R C/++. .

+5

, , , . https://gist.github.com/797478, Rweave, .

, Sweave driver = RweaveLatexMinted().

+5

, @daroczig.

\usepackage{minted}

\renewenvironment{Sinput}{\minted[frame=single]{r}}{\endminted}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{frame=leftline}
\DefineVerbatimEnvironment{Scode}{Verbatim}{}

While I was on it, I needed to work in caching, because I use large data sets, and one piece takes about 3 minutes. Therefore, I wrote this shell function zshto process a file .Rnwwith caching:

function sweaveCache() {
    Rscript -e "library(cacheSweave); setCacheDir(getwd()); Sweave('$1.Rnw', driver = cacheSweaveDriver)" &&
    pdflatex --shell-escape $1.tex &&
    open $1.pdf
}

Now I just do sweaveCache myFile, and I get the result opened in Preview (on OS X).

+4
source

All Articles