Writing Math Equations

With R Markdown, you can embed LaTeX and MathML equations directly into your document.


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:

The Arithmetic mean is equal to $latex \frac{1}{n} \sum{i=i} ^ {n} x{i}$, or the summation of n numbers divided by n.


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:

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


MathML Equations


To insert MathML equations, wrap your equation inside a <math ...> </math> tag.

For example to display the Quadratic Formula: x=b±b24ac2a

Enter the following:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mrow>
    <mi>x</mi>
    <mo>=</mo>
    <mfrac>
      <mrow>
        <mo>&#x2212;</mo>
        <mi>b</mi>
        <mo>&#xB1;</mo>
        <msqrt>
          <mrow>
            <msup>
              <mi>b</mi>
              <mn>2</mn>
            </msup>
            <mo>&#x2212;</mo>
            <mn>4</mn>
            <mi>a</mi>
            <mi>c</mi>
          </mrow>
        </msqrt>
      </mrow>
      <mrow>
        <mn>2</mn>
        <mi>a</mi>
      </mrow>
    </mfrac>
  </mrow>
</math>