使用 Sweave 和 TeXShop 进行语法着色输入?
我刚刚开始在 TeXShop(在 OSX 上运行)上使用 Sweave。是否可以对源代码进行语法着色,以便我可以区分原始文本和 R 代码?
例如,我的 Sweave 文件中的以下代码片段与文本的其余部分相同,这使得它比具有语法着色的 R 编辑器更难阅读。
<<reg, fig=TRUE, echo=FALSE>>=
a = c(10,15)
plot(a, a)
@
(我还使用精彩的 RStudio 进行了尝试,它确实为 R 和 Latex 提供了语法着色,但我认为 TexShop 优于 LaTeX。)
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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不相信 TexShop 支持模式切换(例如,在同一文件中以两种不同的语言突出显示——R 和 LaTeX),因为它是围绕单一语言(LaTeX)设计的。据我所知,能够正确处理 Sweave 的编辑器有:
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:
实际上,您可以立即使用突出显示的语法。使用 pgfSweave 包。只需将
pgf=TRUE
(和echo=TRUE
)添加到您的 Sweave 块中,就可以开始了。安装 pgfSweave 并加载 vignette 包 (vignette("pgfSweave")
) 以获得进一步帮助。Actually, you can use highlighted syntax out of the box. Use
pgfSweave
package. Just addpgf=TRUE
(andecho=TRUE
) to your Sweave chunk, and you're good to go. InstallpgfSweave
, and load a package vignette (vignette("pgfSweave")
) for further assistance.