R 注释中的动态 LaTeX 引用与 knitr [英] Dynamic LaTeX references in R comment with knitr

查看:19
本文介绍了R 注释中的动态 LaTeX 引用与 knitr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾就 Sweave 提出过类似的问题(动态引用 Sweave 文档中 R 注释中的图形) 并想看看是否有人在使用 knitr 时有类似的答案.

I had ask a similar question to this with respect to Sweave ( Dynamic references to figures in a R comment within Sweave document ) and would like to see if anyone as a similar answer when using knitr.

目标是拥有以下代码块

<<"example", fig.cap = "some figure", highlight = FALSE>>=
# the following code generated Figure 
ef{fig:example}
plot(1:10, 1:10)
@

已在生成的 .pdf 中显示为

have be displayed in the resulting .pdf as

# the following code generated Figure 1.1
plot(1:10, 1:10)

到目前为止,我发现通过设置 highlight = FALSE 可以将 R 代码放入生成的 .tex 文件中的 verbatim 环境中.如果环境可以是 alltt 而不是 verbatim 那么我们就会得到想要的输出.是否可以通过 knitr 选项将未突出显示的代码块放置在 alltt 环境中?

So far I have found that by setting highlight = FALSE the R code is placed into a verbatim environment in the resulting .tex file. If the environment could be alltt instead of verbatim then we'd have the desired output. Is it possible to have the non-highlighted code chunks be placed in alltt environments via a knitr option?

推荐答案

我添加了一个例子 072-latex-reference.Rnw.基本思想是恢复转义的 ef{}(在默认输出中应该是 extbackslash{}ref{}).

I have added an example 072-latex-reference.Rnw in the knitr-examples repository. The basic idea is to restore the escaped ef{} (which should have been extbackslash{}ref{} in the default output).

这篇关于R 注释中的动态 LaTeX 引用与 knitr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆