3
votes

I've just started using Sweave on TeXShop ( which runs on OSX). Is it possible to have syntax coloring of the source code so that I can distinguish between raw text and R-code?

For example, the following code snippet in my Sweave file is the same as the rest of the text, which makes it harder to read than an R editor that has syntax coloring.

<<reg, fig=TRUE, echo=FALSE>>=
a = c(10,15)
plot(a, a)
@

(I have also tried this out using the wonderful RStudio which does have syntax coloring for both R and Latex, but I think TexShop is superior for LaTeX.)

2
You should take a look at highlight package. It can produce LaTeX output.aL3xa
My mistake, you need pgfSweave - take a look at my answer bellow.aL3xa

2 Answers

2
votes

I don't believe TexShop supports mode switching (e.g. highlighting in two different languages--R and LaTeX--within the same file), since it was designed around a single language (LaTeX). Editors that do and therefore properly handle Sweave are to my knowledge:

  • Eclipse with Stat/ET
  • RStudio
  • Emacs with ESS
1
votes

Actually, you can use highlighted syntax out of the box. Use pgfSweave package. Just add pgf=TRUE (and echo=TRUE) to your Sweave chunk, and you're good to go. Install pgfSweave, and load a package vignette (vignette("pgfSweave")) for further assistance.

Version 1.1.0 of pgfSweave introduced the highlight option. The default is TRUE by default so code will be syntax-highlighted with the highlight package.