如何在书本定理或示例环境中使用内联R代码 [英] How to use inline R code in a bookdown theorem or example environment
本文介绍了如何在书本定理或示例环境中使用内联R代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用书本来生成html和PDF格式的文档.在定理和示例环境中,如何使用内联R代码的结果?
I use bookdown to generate documents in both html and PDF. How could I use results from inline R code in theorem and example environments?
这是我尝试过的:
---
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`$.
```
我得到
推荐答案
您可以使用显式的Latex标签:
You could go with explicit Latex tags:
---
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}
这篇关于如何在书本定理或示例环境中使用内联R代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文