将bookdown移植到distill::distill_article不支持theorem环境。

huangapple go评论76阅读模式
英文:

Porting bookdown to distill::distill_article doesn't support theorem environment

问题

尝试在R distill::article中实现定理环境。按照Rmarkdown和Bookdown书籍以及R Markdown Cookbook中的说明进行操作。

我发现,定理环境在以下情况下可以正常处理:

bookdown::html_document2:
    base_format: rmarkdown::html_document

bookdown::html_document2:
    base_format: pagedown::html_paged

然而,对于distill_article,它不起作用。有人知道为什么不起作用吗?

以下是一个最小的可复现示例。

---
title: "将bookdown功能移植到Rmarkdown"
author: "Bookdown Rmarkdown"
output:
  bookdown::html_document2:
    base_format: distill::distill_article
---

# 定理

```{theorem, name="毕达哥拉斯定理"}
对于一个直角三角形,如果$c$表示斜边的长度,
$a$和$b$表示另外两边的长度,我们有
$$a^2 + b^2 = c^2$$。

<details>
<summary>英文:</summary>

Trying to implement theorem environment to R distill::article. Followed the instructions from the books on Rmarkdown and Bookdown, and the [R Markdown Cookbook](https://bookdown.org/yihui/rmarkdown-cookbook/figure-number.html)

I found that theorem environments were processed well for

bookdown::html_document2:
base_format: rmarkdown::html_document

and

bookdown::html_document2:
base_format: pagedown::html_paged


However, it doesn&#39;t work for `distill_article`. Anyone knows why it doesn&#39;t work?

The following is a minimal reproducible example.

````rmarkdown
---
title: &quot;Port the bookdown features to Rmarkdown&quot;
author: &quot;Bookdown Rmarkdown&quot;
output:
  bookdown::html_document2:
    base_format: distill::distill_article
---

# Theorems

```{theorem, name=&quot;Pythagorean theorem&quot;}
For a right triangle, if $c$ denotes the length of the hypotenuse
and $a$ and $b$ denote the lengths of the other two sides, we have
$$a^2 + b^2 = c^2.$$


</details>


# 答案1
**得分**: 3

在检查`distll_article.R`中的代码后,我认为我找出了为什么定理没有显示的原因。默认情况下,在`distll_article`中,`knitr_options$opts_chunk$echo`被分配了值`FALSE`,我认为这会隐藏定理环境,因为它被定义为bookdown中的代码块。要切换该值,只需在YAML头之后添加以下代码块即可。

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

<details>
<summary>英文:</summary>

After checking the codes in distll_article.R, I think that I figured out why the theorem was not display. By default, in distll_article, `knitr_options$opts_chunk$echo` is assigned with the value `FALSE`, which I think hides the theorem environment as it was defined as a code chunk in bookdown. To switch the value, adding the following code chunk right after the yaml header will do the work.
knitr::opts_chunk$set(echo = TRUE)

</details>



huangapple
  • 本文由 发表于 2020年1月6日 23:53:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/59615126.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定