问题
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