Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display math in an Rmd file on 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.

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.

like image 259
Undecided Avatar asked Jan 29 '18 23:01

Undecided


People also ask

How do you show math in Markdown?

Math inside RMarkdown In side a text chunk, you can use mathematical notation if you surround it by dollar signs $ for “inline mathematics” and $$ for “displayed equations”. Do not leave a space between the $ and your mathematical notation.

How do you display formulas in Markdown?

To write formulas using the displayed mode, they should be surrounded by a $$ . Here are a few examples: This expression $\sum_{i=1}^n X_i$ is inlined.

Can you write math in Markdown?

We are pleased to announce that math expressions can now be rendered natively in Markdown on GitHub. Support for displaying math expressions has been a highly requested feature for over 8 years.


1 Answers

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:

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

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

like image 185
ruaridhw Avatar answered Sep 21 '22 23:09

ruaridhw