输出中的 Sweave 语法突出显示 - 重新访问
Sweave syntax highlighting in output - revisit
我的问题与linkSweave syntax highlighting in output中的问题相同。
我遵循了 daroczig https://tex.stackexchange.com/questions/5113/how-to-colorize-syntax-using-r-sweave 的建议,并创建了以下 test.Rnw 文件:
\documentclass{article}
\RequirePackage{fancyvrb}
\RequirePackage{listings}
\SweaveOpts{keep.source=TRUE}
<<SweaveListingsPreparations, results=tex, echo=FALSE, strip.white=false>>=
require(SweaveListingUtils)
SweaveListingPreparations()
setToBeDefinedPkgs(pkgs = c("SweaveListingUtils","distr"),
keywordstyles = c("\bf\color{blue}","\bf\color{red}"))
@
\begin{document}
\SweaveOpts{concordance=TRUE}
\section{Example}
This is an example with three variables in R.
<<>>=
options(continue = " ")
x <- 10
t <- 'The brown fox'
b <- TRUE
@
<<>>=
x
@
<<>>=
t
@
<<>>=
b
@
\end{document}
<<cleaup, echo=FALSE>>=
unloadNamespace("SweaveListingUtils")
@
但是,我收到以下错误消息:
建议?
由于您的文档中没有 \usepackage{Sweave}
,Sweave 会插入它。但是 SweaveListingsUtils
包也插入了冲突代码。
因此您需要遵循SweaveListingsUtils
文档中的建议,并发表评论
% \usepackage{Sweave}
靠近文档的开头。这将阻止 R 插入它。
但是请注意,对 SweaveListingsUtils
的支持即将结束;你最好使用 knitr
.
我的问题与linkSweave syntax highlighting in output中的问题相同。
我遵循了 daroczig https://tex.stackexchange.com/questions/5113/how-to-colorize-syntax-using-r-sweave 的建议,并创建了以下 test.Rnw 文件:
\documentclass{article}
\RequirePackage{fancyvrb}
\RequirePackage{listings}
\SweaveOpts{keep.source=TRUE}
<<SweaveListingsPreparations, results=tex, echo=FALSE, strip.white=false>>=
require(SweaveListingUtils)
SweaveListingPreparations()
setToBeDefinedPkgs(pkgs = c("SweaveListingUtils","distr"),
keywordstyles = c("\bf\color{blue}","\bf\color{red}"))
@
\begin{document}
\SweaveOpts{concordance=TRUE}
\section{Example}
This is an example with three variables in R.
<<>>=
options(continue = " ")
x <- 10
t <- 'The brown fox'
b <- TRUE
@
<<>>=
x
@
<<>>=
t
@
<<>>=
b
@
\end{document}
<<cleaup, echo=FALSE>>=
unloadNamespace("SweaveListingUtils")
@
但是,我收到以下错误消息:
建议?
由于您的文档中没有 \usepackage{Sweave}
,Sweave 会插入它。但是 SweaveListingsUtils
包也插入了冲突代码。
因此您需要遵循SweaveListingsUtils
文档中的建议,并发表评论
% \usepackage{Sweave}
靠近文档的开头。这将阻止 R 插入它。
但是请注意,对 SweaveListingsUtils
的支持即将结束;你最好使用 knitr
.