语法着色输入使用Sweave与TeXShop?

时间:2021-02-15 06:13:20

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?

我刚刚开始在TeXShop上使用Sweave(在OSX上运行)。有可能有源代码的语法着色,以便我可以区分原始文本和r代码吗?

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.

例如,在我的Sweave文件中,下面的代码片段与文本的其他部分是一样的,这使得它比具有语法着色的R编辑器更难阅读。

<<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.)

(我也尝试过使用很棒的RStudio,它确实对R和Latex都有语法着色,但我认为TexShop在Latex上更胜一筹。)

2 个解决方案

#1


2  

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:

我认为TexShop不支持模式切换(比如在同一个文件中突出显示两种不同的语言——R和LaTeX),因为它是围绕一种语言(LaTeX)设计的。据我所知,编辑如果能做到,并因此能妥善处理Sweave问题:

  • Eclipse with Stat/ET
  • Eclipse与统计/等
  • RStudio
  • RStudio
  • Emacs with ESS
  • Emacs和ESS

#2


1  

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.

实际上,您可以直接使用突出显示的语法。使用pgfSweave包。只要将pgf=TRUE(和echo=TRUE)添加到您的Sweave块中,就可以了。安装pgfSweave,并加载一个软件包插图(“pgfSweave”)以获得进一步的帮助。

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.

pgfSweave的1.1.0版本引入了突出显示选项。默认情况下默认为TRUE,因此代码将在突出显示包中以语法突出显示。

#1


2  

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:

我认为TexShop不支持模式切换(比如在同一个文件中突出显示两种不同的语言——R和LaTeX),因为它是围绕一种语言(LaTeX)设计的。据我所知,编辑如果能做到,并因此能妥善处理Sweave问题:

  • Eclipse with Stat/ET
  • Eclipse与统计/等
  • RStudio
  • RStudio
  • Emacs with ESS
  • Emacs和ESS

#2


1  

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.

实际上,您可以直接使用突出显示的语法。使用pgfSweave包。只要将pgf=TRUE(和echo=TRUE)添加到您的Sweave块中,就可以了。安装pgfSweave,并加载一个软件包插图(“pgfSweave”)以获得进一步的帮助。

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.

pgfSweave的1.1.0版本引入了突出显示选项。默认情况下默认为TRUE,因此代码将在突出显示包中以语法突出显示。