multi-line equation in RMarkdown
Asked Answered
C

3

22

I am trying to create a multi-line equation in RMarkdown. I have tried the following code, extracted from http://www.rstudio.com/ide/docs/authoring/using_markdown_equations,

$$
\begin{aligned}
  \dot{x} & = \sigma(y-x) \\
  \dot{y} & = \rho x- y - xz 
\end{aligned}
$$

however the knitred HTML document gives a single-line equation:

screen shot of single line equation from html

Cyanite answered 15/1, 2014 at 0:15 Comment(0)
M
4

This code produced 2 HTML lines, as desired, when cut and paste into RStudio in Windows 7 with knitr. If the second slash at the end of the 3rd line was removed, it produced the result shown in example.

Matias answered 15/1, 2014 at 0:57 Comment(3)
Do you mean as follows: $$ \begin{aligned} \dot{x} & = \sigma(y-x) \ \dot{y} & = \rho x- y - xz \end{aligned} $$ because if so, I still get the same result as above. I also have Windows 7, R Studio 0.98.484 and I am using R version 3.0.2 (32-bit)Cyanite
With R v3.0.2 (64-bit), Windows 7, RStudio 0.98.490 & knitr v1.5, when the code you provided above was copied and pasted into RStudio with no changes, it produced two lines of equations. Also worked properly when code was typed in. As a test, when the 2nd backslash was deleted at the end of the 3rd line of code (\dot{x} & = \sigma(y-x) \), it produced the single line equation you provided as an example.Matias
$$\begin{eqnarray} a^2 + b^2 &=& c^2 \\ &=& 5 \end{eqnarray}$$ works in my environment.Disbar
P
4

It's now a decade since this question was asked, but I'm having good luck with:

$$
\begin{split}
  \dot{x} & = \sigma(y-x) \\
  \dot{y} & = \rho x- y - xz 
\end{split}
$$

Within split, the locations demarcated by & will be aligned.

Solution from @Castel:

enter image description here

Using split:

enter image description here

This is especially useful for derivations:

$$
\begin{split}
x & = \int_{\tau_0}^{\tau_n}\tau^{-\alpha}\; d\tau \\
  & = \frac{\tau_0^{1-\alpha}-\tau_n^{1-\alpha}}{a-1}
\end{split}
$$

enter image description here

Palawan answered 22/12, 2023 at 13:37 Comment(0)
W
0

I'm using markdown with Logseq and in this environment simply entering $$ \dot{x} = \sigma(y-x) \\ \dot{y} = \rho x- y - xz $$, allowed me to enter multi-line equations. Note the I removed the begin and end of the original message and also the &'s.

Whitehouse answered 28/8, 2022 at 10:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.