【问题标题】:Sweave syntax highlighting in output - revisit在输出中突出显示 Sweave 语法 - 重温
【发布时间】:2018-05-31 17:57:49
【问题描述】:

我的问题与链接Sweave 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")
@

但是,我收到以下错误消息:

建议?

【问题讨论】:

    标签: r syntax-highlighting sweave


    【解决方案1】:

    由于您的文档中没有\usepackage{Sweave},Sweave 将插入它。但是SweaveListingsUtils 包也插入了冲突代码。

    所以你需要遵循SweaveListingsUtils 文档中的建议,并发表评论

    % \usepackage{Sweave}
    

    靠近文档的开头。这将阻止 R 插入它。

    但是,请注意对SweaveListingsUtils 的支持即将结束;你最好使用knitr

    【讨论】:

    • 谢谢它的工作。我很想改用 Knitr,但我不知道如何将它与 Latex 集成。任何建议/阅读将不胜感激。
    • 它是自动的,只要 pdflatex 在你的路径上。可以与 texworks 等各种前端集成,但需要一些工作。
    • 您应该发布一个新问题,而不是在评论中提出新问题。
    猜你喜欢
    • 1970-01-01
    • 2012-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-10
    • 2011-05-03
    • 2012-04-19
    • 1970-01-01
    相关资源
    最近更新 更多