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:
But, when I Knit the file and open the HTML with chrome or ie the latex is not rendered correctly:
Is there a way to fix this?
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.
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).
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.
You can now use LaTeX style syntax to render math expressions within Markdown inline (using $ delimiters) or in blocks (using $$ delimiters).
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}
$$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With