在R降价中产生下标 [英] Producing subscripts in R markdown

查看:84
本文介绍了在R降价中产生下标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道R降价可以产生上标:

I'm aware that R markdown can produce superscripts:

text^superscript

但是有可能产生适当的下标吗?或这样做是欺骗和使用LaTeX数学模式的唯一方法:

But is it possible to produce proper subscripts? Or is the only way to do so to cheat and use LaTeX math mode:

$\sf{text_{subscript}}$

最终的预期输出是HTML.

The intended final output is HTML.

推荐答案

由于您在评论中提到了Pandoc,所以依赖于Pandoc的 subscript superscript扩展名可能并不是欺骗. em>.从此处,我们可以创建一个最小的Rmd示例文件:

Since you mention Pandoc in your comments, maybe it's not cheating to depend on Pandoc's extensions for subscript and superscript. From here, we can create a minimal example Rmd file:

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))))    
  }
}
```

使用Knitr会生成一个如下所示的HTML文件:

Using Knitr results in an HTML file that renders like this:

那显然是行不通的.但是您可以在生成的markdown文件(我将其命名为"Subscripts.md")上运行pandoc:

That clearly doesn't work. But you can run pandoc on the resulting markdown file (which I've named "Subscripts.md"):

pandoc -o Subscripts.html Subscripts.md -s -S

您会得到的:

CSS是不同的,但是也许您可以使用自定义CSS参数调用pandoc以使用Knitr使用的相同CSS.

The CSS is different, but perhaps you can call pandoc with a custom CSS argument to use the same CSS used by Knitr.

PDF文件中的下标也可以与该Markdown文件一起正常使用:

Subscripts in PDF files also work as expected with that markdown file:

pandoc -o Subscripts.pdf Subscripts.md

如果要使pandoc输出与编织RStudio时的输出外观相匹配,请下载RStudio使用的CSS文件

If you want the pandoc output to match the visual appearance of the output when you knit with RStudio, download the CSS file that RStudio uses here and make a reference to that file when you create your HTML file from pandoc. (The following assumes you have kept the name as markdown.css an it is in the same directory as your other files.)

pandoc -o Subscripts.html Subscripts.md -s -S --css=markdown.css

这篇关于在R降价中产生下标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆