How to display math in an Rmd file on Github

我怕爱的太早我们不能终老 提交于 2020-01-14 10:38:08

问题


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.

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

Thank you.


回答1:


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$

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

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

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


My Title

R Markdown Document

Maths expression embedded in GitHub Markdown:

with some more inline Latex

,

,



来源:https://stackoverflow.com/questions/48511527/how-to-display-math-in-an-rmd-file-on-github

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!