【发布时间】:2020-11-16 20:26:30
【问题描述】:
我想我的问题是How to use inline R code in a bookdown theorem or example environment 的潜在(如果不是可能的话)重复。自从提出这个问题以来已经将近 3 年了,因此无论如何都可能欢迎刷新,尤其是考虑到 @YiHui 的评论:“bookdown 不可能做到这一点(至少现在)” ?
背景:我正在尝试使用@YiHui bookdown 包来制作一本带有演讲幻灯片的书(参见creating accompanying slides for bookdown project)。为此目的的一个关键功能是能够使用条件格式,例如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/)?有一个 hack 可以强制 pandoc 在 latex 环境中解析,但我认为它不适用于这里。 lua filter 会起作用吗(我不知道如何使用它)?
顺便说一句,我也很惊讶地看到$\digamma$ 在html 输出中正确显示,但在pdf 输出中却没有出现,尽管它在tex 文件中被正确解析。 amssymb 包已加载,并且应该在其中定义 - 我错过了什么?
非常感谢您对此提供的任何帮助。这是一个 MWE - 我刚刚编辑了默认 bookdown 项目的第 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.
```
【问题讨论】:
-
使用子文档有用吗?
-
我也希望像
::: {.proof}等:::能够工作,但它没有 - 它无法提供证明环境,尽管它允许内联表达式等 - 下面的所有内容都会解析正确。
标签: r r-markdown knitr pandoc bookdown