Dynamic LaTeX references in R comment with knitr

白昼怎懂夜的黑 提交于 2019-12-13 11:34:39

问题


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.

The goal is to have the following code chunk

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

have be displayed in the resulting .pdf as

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

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?


回答1:


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).



来源:https://stackoverflow.com/questions/14058832/dynamic-latex-references-in-r-comment-with-knitr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!