如何在Github上的Rmd文件中显示数学

如何在Github上的Rmd文件中显示数学

问题描述:

我用RStudio在.rmd中创建了一个具有很多数学表达式的技术报告.用knit到html,效果很好.由于html文件无法在GitHub存储库上很好地呈现,因此我将.rmd输出更改为github_document(.md)文件.但是,当我将文件上传到GitHub时,我发现公式无法正确显示.它们是乳胶脚本格式.

I created a technical report in .rmd in RStudio with much math expression. With knit to html, it worked very well. As html file cannot rendered well on GitHub repository, I changed my .rmd output to github_document (.md) file. However, when I upload the file onto GitHub, I found formulas cannot be shown correctly. They are in the latex script format.

我想知道哪种有效的策略将渲染的.rmd文件(在RStudio中)上传到GitHub存储库中? (不是GitHub Pages).

I was wondering which is a valid strategy to upload a rendered .rmd file (in RStudio) into a GitHub repository? (Not GitHub Pages).

谢谢.

Pandoc支持转换Markdown文件中的数学,以通过--webtex参数显示在GitHub上.只需在Rmd序言中添加必要的参数,RMarkdown会将参数传递给Pandoc:

Pandoc supports converting maths in Markdown files for displaying on GitHub via the --webtex parameter. Just add the necessary argument to your Rmd preamble and RMarkdown will pass the parameter on to Pandoc:

---
title: "My Title"
output:
  github_document:
    pandoc_args: --webtex
---

# R Markdown Document

Maths expression embedded in GitHub Markdown:

$$
E = \frac{mc^2}{\sqrt{1-\frac{v^2}{c^2}}}
$$

with some more inline Latex $\gamma$, $\lambda$, $\theta$

呈现文档时,中间的Latex块呈现为 https://latex.codecogs.com/并自动嵌入到您的文档中.

When the document is rendered, the intermediate Latex chunks are rendered to https://latex.codecogs.com/ and embedded in your document automatically.

此功能已在Pandoc 2.0.4中添加,因此请确保您的版本足够新.

This feature was added in Pandoc 2.0.4 so make sure your version is recent enough.

由于输出只是嵌入式Web链接,因此输出显示在SO以及markdown支持的任何其他网站上:

Since the output is just embedded web links, the output displays here on SO as well as any other markdown-supported site:

嵌入在GitHub Markdown中的数学表达式:

Maths expression embedded in GitHub Markdown:

>

更多内联乳胶 , ,

with some more inline Latex , ,