, knitr hooks. LaTeX .
TOC:
1. framed.
---
title: "Output Hook"
output: pdf_document
---
```{r setup, include = F}
library(knitr)
opts_chunk$set(comment=NA)
def_hook <- knit_hooks$get("output")
knit_hooks$set(output = function(x, options) {
out <- def_hook(x, options)
return(paste("\\begin{framed}\\begin{verbatim}", x, "\\end{verbatim}\\end{framed}", collapse = "\n"))
})
```
```{r}
lm(mpg ~ hp, data = mtcars)
```

2. fancyvrb
fancyvrb (. ):
---
title: "Output Hook"
output: pdf_document
header-includes:
- \DefineVerbatimEnvironment{myVerb}{Verbatim}{numbers=left,numbersep=1mm,frame=lines,framerule=0.4mm,rulecolor=\color{blue}}
---
```{r setup, include = F}
library(knitr)
opts_chunk$set(comment=NA)
def_hook <- knit_hooks$get("output")
knit_hooks$set(output = function(x, options) {
out <- def_hook(x, options)
return(paste("\\begin{myVerb}\n", x, "\\end{myVerb}", collapse = "\n"))
})
```
```{r}
lm(mpg ~ hp, data = mtcars)
```
