我使用bookdown来生成html和PDF文档。如何在定理和示例环境中使用内联R代码的结果?
以下是我的尝试:
---
title: "Test"
output:
bookdown::pdf_book:
toc: false
html_document:
toc: false
---
```{r}
a <- 2
b <- 3
```
If $a = `r a`$ and $b = `r b`$, then $a + b = `r a + b`$.
```{theorem}
If $a = `r a`$ and $b = `r b`$, then $a + b = `r a + b`$.
```
```{example}
If $a = `r a`$ and $b = `r b`$, then $a + b = `r a + b`$.
```
我得到了
答案 0 :(得分:1)
您可以使用显式Latex标记:
---
title: "Test"
output:
bookdown::pdf_book:
toc: false
html_document:
toc: false
---
```{r}
a <- 2
b <- 3
```
\begin{theorem}
If $a = `r a`$ and $b = `r b`$, then $a + b = `r a + b`$.
\end{theorem}
\begin{example}
If $a = `r a`$ and $b = `r b`$, then $a + b = `r a + b`$.
\end{example}