LaTeX Syntax

LaTeX syntax only works outside of code chunks. To insert LaTeX equations, enclose with single $ for inline mathematics, and double $$ for displayed equations. Do NOT leave a space between the $ and your mathematical notation.

\(\le\) \le
\(<\) <
\(\ge\) \ge
\(>\) >
\(y_i\) y_i
\(y^2\) y^2
\(y_{ij}\) y_{ij} (enclose longer subscripts/superscripts in brackets)
\(\sqrt{y}\) \sqrt{y}
\(\frac{4}{2}\) \frac{4}{2}
\(\left(\frac{big-parentheses}{around-math} \right)\) enclose with \left( and \right)
\(\frac{\partial f}{\partial x}\) $\frac{\partial f}{\partial x}$
\(\mid\) \mid
\(\sim\) \sim
\(\propto\) \propto
\(\lambda\) \lambda (spell out any greek letter: gamma, delta, eta, etc)
\(\cdots\) \cdots(center dots)
\(\ldots\) \ldots (lower dots)
\(a \mid b\) a \mid b
\(\sum_{0}^{n}\) \sum_{0}^{n}
\(\int_{-\infty}^{\infty}\) \int_{-\infty}^{\infty}
\(\prod_{i=1}^n\) \prod_{i=1}^n
\(\{ blah \}\) \{ \}
\([blah]\) [ ]
\(\log(x)\) \log(x)
\(\sin(x)\) \sin(x)

To specify a non-default font, or make bold, wrap with:

  • \textrm{blah} for \(\textrm{serif (roman)}\)

  • \mathrm{blah} for \(\mathrm{math\ font}\) - only applies to roman characters, other symbols use math font by default

  • \boldsymbol{blah} for \(\boldsymbol{bold}\)

  • \mathbf{blah} for \(\mathbf{bold\ math\ font}\) - only works for roman characters

Remember:

  • notate scalars as lowercase math font: \omega \mathrm{y} \(\rightarrow\) \(\omega\) \(\mathrm{y}\)
  • notate scalars as lowercase math bold font: \boldsymbol{\omega} \mathbf{y} \(\rightarrow\) \(\boldsymbol{\omega}\) \(\mathbf{y}\)
  • notate matrices as uppercase math bold font: \boldsymbol{\Omega} \mathbf{y} \(\rightarrow\) \(\boldsymbol{\Omega}\) \(\mathbf{Y}\)
  • write distribution names in plain text: \textrm{normal} \(\rightarrow\) \(\textrm{normal}\)

To align multiple lines, use “eqnarry”: $$\begin{eqnarray} [\beta_0,\beta_1, \sigma^2 \mid \mathbf{y}] &\sim &\prod_{i=1}^n[y_i\mid \beta_0,\beta_1,\sigma^2] \\ & & \times [\beta_0][\beta_1][\sigma^2] \end{eqnarray}$$

\[\begin{eqnarray} [\beta_0,\beta_1, \sigma^2 \mid \mathbf{y}] &\sim & \prod_{i=1}^n[y_i\mid \beta_0,\beta_1,\sigma^2] \\ & & \times [\beta_0][\beta_1][\sigma^2] \end{eqnarray}\]

Here’s a link to a massive list of LaTeX symbol syntax

Plotmath Expression Syntax

This is probably only relevant for figure labels

N; expression(lambda)
y \(\le\) 5 expression("y"<= "5")
yi expression(y[i])
x2 expression(x^2)
x2 + 5 expression(x^2~"+ 5")) … to add characters after a superscript, end the superscript with a * (no space) or ~ (space)
P(Y < y | \(\phi\)) expression(paste("P(Y", \<, "y | ", phi,")")) … expression(paste(“blah”, symbol, “blah”, symbol, “blah))

Use case example:

…or, you could download the latex2exp package and never use plotmath expressions again:

Just wrap your LaTeX code in Tex("$blah$") and double-escape everything that was single-escaped (i.e. \\). The code used to build the y-axis label was ylab=latex2exp::TeX("$\\[y\\]$")… ok I know square brackets aren’t escaped in the notation list above, but for some reason in this package they were. Rough example, but good to know this library might have some syntax quirks.