seb*_*n-c 42 markdown r subscript knitr r-markdown
我知道R markdown可以产生上标:
text^superscript
Run Code Online (Sandbox Code Playgroud)
但是可以生成适当的下标吗?或者是欺骗和使用LaTeX数学模式的唯一方法:
$\sf{text_{subscript}}$
Run Code Online (Sandbox Code Playgroud)
预期的最终输出是HTML.
A5C*_*2T1 27
既然你在评论中提到了Pandoc,那么依赖Pandoc对下标和上标的扩展也许不是作弊.从这里,我们可以创建一个最小的示例Rmd文件:
Testing Subscript and Superscript
========================================================
This is an R Markdown document.
Pandoc includes numerous extensions to markdown, and one
of them is *subscript* and *superscript*.
Here's the example from the Pandoc help page
(http://johnmacfarlane.net/pandoc/README.html#superscripts-and-subscripts):
H~2~O is a liquid. 2^10^ is 1024.
For fun, here's an R code block with some code from @Spacedman:
```{r}
list.depth <- function(this, thisdepth = 0) {
# http://stackoverflow.com/a/13433689/1270695
if(!is.list(this)) {
return(thisdepth)
} else {
return(max(unlist(lapply(this, list.depth, thisdepth = thisdepth+1))))
}
}
```
Run Code Online (Sandbox Code Playgroud)
使用Knitr会生成一个HTML文件,呈现如下:

这显然不起作用.但是您可以在生成的markdown文件(我将其命名为"Subscripts.md")上运行pandoc:
pandoc -o Subscripts.html Subscripts.md -s -S
你会得到这个:

CSS是不同的,但也许您可以使用自定义CSS参数调用pandoc以使用Knitr使用的相同CSS.
PDF文件中的下标也可以按预期使用该markdown文件:
pandoc -o Subscripts.pdf Subscripts.md

如果您希望在使用RStudio编织时pandoc输出与输出的可视外观相匹配,请下载RStudio 在此处使用的CSS文件,并在从pandoc创建HTML文件时引用该文件.(以下假设您将名称保留为markdown.css,它与其他文件位于同一目录中.)
pandoc -o Subscripts.html Subscripts.md -s -S --css=markdown.css
Dan*_*ust 16
R Markdown下标正常工作.
也许这是一个老帖子.我在Mac上使用RStudio版本0.99.902 + R版本3.4.
下标:H~2~O是液体.
上标:2 ^ 10 ^是1024.
我发现在RStudio中编织时,下标的X~j~语法在Rmarkdown中工作正常.但是,如果您在一个闪亮的应用程序中嵌入编织,它就不起作用.在我的应用中,
Run Code Online (Sandbox Code Playgroud)knit2html("Steps.Rmd") browseURL("Steps.html")
除下标外,其他工作正常.但是,对于RStudio和来自闪亮应用程序的内容,vanilla HTML下标语法都适用于您的Rmd文档:X <sub> j </ sub>呈现为X j.