MathJax and Writing Equations

With R Markdown, you can embed LaTeX and MathML equations directly into your document. Equations are displayed using the MathJax JavaScript library. Note that this library is loaded from the MathJax website so readers of your document must be online to see the rendered equations.


Latex Inline Equations

To embed a LaTeX equation inline, wrap it insdie dollar signs with a latex denotation such as:

$latex equation $

For example, the following sentence:

The Arithmetic mean is equal to \( \frac{1}{n} \sum_{i=i}^{n} x_{i} \), or the summation of n numbers divided by n.

Is produced by:

alt text


Latex Display Equations

To display an equation and place it on it's own line (centered), use two dollar signs such as:

$$latex equation $$

For example, to display the Taylor Series nicely:

\[ f(a) + \frac{f'(a)}{1!} (x-a) + \frac{f''(a)}{2!} (x-a)^{2} + \frac{f'''(a)}{3!} (x-a)^{3} + \ldots \]

Enter the following:

alt text


Latex Inline Equations Split Across Multiple Lines

Embedded equations can also span multiple lines. Note however, you must avoid unwanted line breaks around your equation, otherwise a new paragraph will be introduced.

For example, the previous equation can be entered across multiple lines:

The Arithmetic mean is equal to \( \frac{1}{n} \sum_{i=i}^{n} x_{i} \), or the summation of n numbers divided by n.

Is produced by:

alt text


MathML Equations

To insert MathML equations, wrap your equation inside a tag such as:

<math ...> </math>

For example to display the Quadratic Formula:

x=−b±b2−4ac2a

Enter the following:

alt text

Return to Using Markdown with RStudio