使用Knitr的R注释中的动态LaTeX引用

使用Knitr的R注释中的动态LaTeX引用

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

问题描述

对于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 \ref{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选项将未突出显示的代码块放置在环境中?

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?

推荐答案

我添加了一个示例.基本思想是还原转义的\ref{}(在默认输出中应该为\textbackslash{}ref\{\}).

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

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

08-20 10:49