Sweave syntax highlighting in output

前端 未结 4 1280
鱼传尺愫
鱼传尺愫 2021-01-01 04:20

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 boxe

相关标签:
4条回答
  • 2021-01-01 04:45

    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.

    0 讨论(0)
  • 2021-01-01 04:47

    This topic on tex.StackExchange might be interesting for you, as it suggest loading the SweaveListingUtils package in R for easy solution.

    0 讨论(0)
  • 2021-01-01 04:47

    I have a solution that has worked for me, I have not tried it on any other systems though so things may not work out of the box for you. I've posted some code at https://gist.github.com/797478 that is a set of modified Rweave driver functions that make use of minted blocks instead of verbatim blocks.

    To use this driver just specify it when calling the Sweave function with the driver=RweaveLatexMinted() option.

    0 讨论(0)
  • 2021-01-01 04:52

    Here's how I've ended up solving it, starting from @daroczig's suggestion.

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

    While I was at it, I needed to get caching working because I'm using large data sets and one chunk was taking around 3 minutes to complete. So I wrote this zsh shell function to process an .Rnw file with 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).

    0 讨论(0)
提交回复
热议问题