This is probably not as obvious as other hooks, since I did not export
the function to highlight source code. Anyway, it is certainly
possible because the inline hook has access to the code in \Sexpr{}.
Here is a quick experiment (note I quoted read.table() so that it is a
character string otherwise it will be an R expression to be evaluated;
you may need to try() highlighting because not all results are valid R
code):
\documentclass{article}
<<setup, include=FALSE>>=
knit_hooks$set(inline = function(x) {
if (is.numeric(x)) return(knitr:::format_sci(x, 'latex'))
x = as.character(x)
knitr:::hilight_source(x, 'latex', list(prompt=FALSE, size='normalsize'))
})
@
\begin{document}
the value of $\pi$ is \Sexpr{pi}, and the function to read a table is
\Sexpr{'read.table()'}.
<<test2>>=
rnorm(10)
@
\end{document}
Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
baptiste
Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA