Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiline latex equation in R Markdown and Windows

Tags:

r

r-markdown

The following code works fine on linux:

---
title: "LaTeX test"
author: "Ignacio"
output: html_document
---


## Latex

$$ 
\begin{aligned}

y_j \sim N(\theta_j , \sigma_j^2) \\

\sigma_j = \nu/\sqrt{n_j}   \\

\theta = \mu +\tau \times \eta \\

\eta \sim N(0,1) \\

\mu + \tau\times\eta = \theta \sim N(\mu , \tau^2)

\end{aligned}
$$

On Windows, rstudio renders the equations correctly:

enter image description here

But, when I Knit the file and open the HTML with chrome or ie the latex is not rendered correctly:

enter image description here

Is there a way to fix this?

like image 588
Ignacio Avatar asked Dec 20 '17 19:12

Ignacio


People also ask

How do you make a multiline equation in LaTeX?

How do you make a multiline equation in LaTeX? For equations longer than a line use the multline environment. Insert a double backslash to set a point for the equation to be broken. The first part will be aligned to the left and the second part will be displayed in the next line and aligned to the right.

Can I use LaTeX in R markdown?

In our experience, it is also mostly workable to include LATEX code in R markdown documents. Recall that documents in R markdown are converted from Rmd to md by the knitting process, and then into LATEX by pandoc, and then into PDF by a LATEX compiler (pdflatex, xetex or similar).

How do I insert an equation into RMarkdown?

Math inside RMarkdownIn 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. Example: $\sum_{n=1}^{10} n^2$ is rendered as ∑10n=1n2.

Does Markdown support LaTeX equations?

You can now use LaTeX style syntax to render math expressions within Markdown inline (using $ delimiters) or in blocks (using $$ delimiters).


1 Answers

In case someone else is encountering this problem, @YihuiXie was right. Removing the empty lines solves the problem:

---
title: "LaTeX test"
author: "Ignacio"
output: html_document
---


## Latex

$$
\begin{aligned}
y_j \sim N(\theta_j , \sigma_j^2) \\
\sigma_j = \nu/\sqrt{n_j}   \\
\theta = \mu +\tau \times \eta \\
\eta \sim N(0,1) \\
\mu + \tau\times\eta = \theta \sim N(\mu , \tau^2)
\end{aligned}
$$
like image 168
Ignacio Avatar answered Oct 25 '22 09:10

Ignacio