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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With