目标
我想转换为乳胶的R/Markdown文档中的 的.RMD文档,
```{r}
x <- 1 + 1
```
是设置 knitr
选项,以便整个文档默认情况下使用所有代码输入的普通代码块。因此,对于带有我希望
```
x <- 1 + 1
```
使用突出显示选项
我希望可以使用 imak>亮点= false
选项。更确切地说,对于上面的简单示例, knit()
默认情况下会产生一个R型(即,带有 ighlight = true
true ):
```r
x <- 1 + 1
```
设置 knitr ::后opts_chunk $ set(亮点= false)
产生了文本锁定:
```text
x <- 1 + 1
```
但是我想拥有一个没有任何特殊语言的普通块,请参见上文。
结合Lang选项,
我可以通过所需的内容
knitr::opts_chunk$set(highlight = TRUE, lang = "")
,因此可以启用突出显示,但将 lang
设置为空字符串。这确实产生了我想拥有的普通代码。
不过,至少有一个缺点(除了这种解决方案的骇人听闻的感觉之外)。也就是说,如果在同一文档中我想在一个特定块的选项中启用突出显示,我必须设置 lang =“ r”
现在而不是 right = right = true = true
,例如,
```{r, lang="r"}
x <- 1 + 1
```
我想知道是否有更好的解决方案?
pandoc
(我尝试的2.9.x)的旧版本中的背景
转换为 {verbatim}
latex输出中的代码块。
但是, pandoc
(我尝试的2.17.x)的最新版本将文本个铃声转换为 {shaded}
而不是将普通的块转换为 {verbatim }
。
Goal
In an R/Markdown document that I want to convert to LaTeX I want to set knitr
options so that the entire document uses plain code chunks for all code inputs by default. Thus, for a .Rmd document with
```{r}
x <- 1 + 1
```
I want to obtain the output
```
x <- 1 + 1
```
Using the highlight option
I had hoped that the highlight=FALSE
option could be used for this but this generates text-chunks rather than plain chunks. More precisely, for the simple example above, knit()
produces an R-chunk by default (i.e., with highlight = TRUE
):
```r
x <- 1 + 1
```
After setting knitr::opts_chunk$set(highlight = FALSE)
a text-chunk is produced:
```text
x <- 1 + 1
```
But what I would like to have a plain chunk without any special language, see above.
Combination with lang option
I can obtain what I want via
knitr::opts_chunk$set(highlight = TRUE, lang = "")
Thus, I do enable highlighting but set the lang
to an empty string. This indeed yields the plain code I want to have.
There is at least one disadvantage, though (apart from the rather hacky feel of this solution). Namely, if in the same document I do want to enable highlighting in the options of one specific chunk, I have to set lang = "r"
now instead of highlight = TRUE
, e.g.,
```{r, lang="r"}
x <- 1 + 1
```
So I wonder whether there is a better solution for this?
Background
In older versions of pandoc
(I tried 2.9.x) text-chunks were converted to {verbatim}
code chunks in LaTeX output.
However, more recent versions of pandoc
(I tried 2.17.x) text-chunks are converted to {Shaded}
instead and only plain chunks are converted to {verbatim}
.
发布评论
评论(2)
另一个黑客解决方案是(我什至不敢解释它):
语言名称
text
right = false = false 当前在 knitr ,因此您无法更改它:我愿意使其可配置,但我不确定如何(我希望不添加新的新在亮点= false
的情况下设置语言的块选项。Another hacky solution is (I don't even dare to explain it):
The language name
text
whenhighlight = FALSE
is currently hard-coded in knitr, so you cannot change it: https://github.com/yihui/knitr/blob/907184f82/R/hooks-md.R#L171 I'm open to making it configurable, but I'm not sure how (I hope not to add a new chunk option for setting the language in the case ofhighlight = FALSE
).我不确定我是否完全了解您想要什么,但是在YAML标题中是否有帮助?
I'm not sure I entirely understand what you want, but does this in the yaml header help?