Bookdown(proof)自定义环境:如何在自定义(例如proof)环境中嵌套代码块或内联R并获得正确的解析



我想我的问题是如何在bookdown定理或示例环境中使用内联R代码的潜在(如果不是可能的话(重复。这个问题被问到已经快3年了,所以无论如何,更新可能是受欢迎的,尤其是考虑到@YiHui的评论:">这在预订时是不可能的(至少目前是这样(";?

背景:我正在尝试使用@YiHui bookdown包制作一本带有讲座幻灯片的书(请参阅为bookdown项目创建附带幻灯片(。为此目的的一个关键功能是能够使用条件格式,例如eval = (out_type=="beamer")。因此,我面临的问题是能够在bookdown自定义环境中添加代码块或内联R代码(请参阅https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#theorems和https://bookdown.org/yihui/bookdown/custom-blocks.html)。我希望能正确编译以下内容。有解决方案吗?挂钩能用吗(参见https://yihui.org/knitr/hooks/)?有一种破解方法可以强制pandoclatex环境中进行解析,但我认为它不适用于此。lua filter能工作吗(我不知道如何使用它(?

顺便说一句,我也很惊讶地看到$digamma$html输出中正确显示,但在pdf输出中没有显示,尽管它在tex文件中被正确解析。amssymb包已经加载,并且应该在其中定义它——我缺少什么?

非常感谢在这方面的任何帮助。这是一个MWE-我刚刚编辑了默认预订项目的第4章。您可以简单地将文件03-method.Rmd的内容替换为以下内容:

# Methods
We describe our methods in this chapter.
So here is a theorem to prove 1+1 = `r 1+1`.
```{theorem, echo=TRUE}  
we want to show that in R, 1+1 = 2.  
We also wonder why `$digamma$` ($digamma$) not showing.  
Shows in the html output only, not pdf.  
But when I recompile the tex file produced by bookdown - shows up just fine!!  
Indeed, is defined correctly from `usepackage{amssymb}`.  
```
```{proof, echo=TRUE}  
- If I am not mistaken, I cannot get an Rmarkdown style list to work either in the proof environment.
- Well, this is where i would like to be able to use inline code.  
- we use r to compute 1+1: `r 1+1`.  
- Does not work.  
- Just shows verbatim inline code.  
```

使用bookdown的当前开发版本

remotes::install_github('rstudio/bookdown')

你可以在Pandoc's fenced Divs中写出定理,例如

# Methods
We describe our methods in this chapter.
So here is a theorem to prove 1+1 = `r 1+1`.
::: {.theorem}  
we want to show that in R, 1+1 = 2.  
We also wonder why `$digamma$` ($digamma$) not showing.  
Shows in the html output only, not pdf.  
But when I recompile the tex file produced by bookdown - shows up just fine!!  
Indeed, is defined correctly from `usepackage{amssymb}`.  
:::
::: {.proof}  
- If I am not mistaken, I cannot get an Rmarkdown style list to work either in the proof environment.
- Well, this is where i would like to be able to use inline code.  
- we use r to compute 1+1: `r 1+1`.  
- Does not work.  
- Just shows verbatim inline code.  
:::

但是,请注意,波束形成器输出还不支持这种新语法。

最新更新