【发布时间】:2014-09-10 19:33:56
【问题描述】:
在 Rnw/LaTeX 中,对来自 knitr hooks 的通用输出的一种使用可能是用一些花哨的环境来装饰来自块的数据。
例如,特定于块的代码可以为表生成核心数据,并且在提供重复修饰之前和之后的钩子代码。
考虑以下 sn-p:
\documentclass{article}
\begin{document}
<<myhooks, include=FALSE>>=
printhook=function(before, options, envir) {
if (before) {
return('\nCommon R \\LaTeX\\ in before-hook')
} else {
return('\nCommon R \\LaTeX\\ in after-hook')
}
}
knit_hooks$set(lprint = printhook)
@
<<test, results='asis', lprint=TRUE, echo=FALSE>>=
cat("R \\LaTeX\\ in current chunk\n")
@
\end{document}
问题在于 LaTeX 输出大致如下:
\begin{kframe}
Common R \LaTeX\ in before-hook
\end{kframe}
R \LaTeX\ in current chunk
\begin{kframe}
Common R \LaTeX\ in after-hook
\end{kframe}
钩子代码实际上并不是asis,而是被包裹在kframe 环境中,这可以防止将三个部分粘合在一起。
我们如何删除封闭的kframe?
【问题讨论】:
标签: r templates latex knitr rnw