In 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 \(\sum_{n=1}^{10} n^2\).
Example: $$\sum_{n=1}^{10} n^2$$
is rendered as \[\sum_{n=1}^{10} n^2\].
The mathematical typesetting is based on LaTeX, so if you need to search for the way to make a particular symbol, include latex
in your search. But note: Not all LaTeX macros are available without using additional packages, and those packages likely will only work if you are creating a PDF. On the plus side, if you are working in PDF, you can use additional packages that give much better control and/or easier syntax.
In LaTeX,
\
){
and }
) are used to surround items that are to be considered as one object from LaTeX’s perspective.$$\sum_{x=1}^{10} x^2$$
produces \[\sum_{x=1}^{10} x^2\]Here are some common mathematical things you might use in statistics. (Note: Some of these look better in PDF than in HTML.)
\(x = y\) |
$x = y$
|
\(x \neq y\) |
$x \neq y$
|
\(x \approx y\) |
$x \approx y$
|
\(x < y\) |
$x < y$
|
\(x > y\) |
$x > y$
|
\(x \le y\) |
$x \le y$
|
\(x \ge y\) |
$x \ge y$
|
\(x^{n}\) |
$x^{n}$
|
\(x_{n}\) |
$x_{n}$
|
\(\overline{x}\) |
$\overline{x}$
|
\(\hat{x}\) |
$\hat{x}$
|
\(\tilde{x}\) |
$\tilde{x}$
|
\(\frac{a}{b}\) |
$\frac{a}{b}$
|
\(\frac{\partial f}{\partial x}\) |
$\frac{\partial f}{\partial x}$
|
\(\displaystyle \frac{\partial f}{\partial x}\) |
$\displaystyle \frac{\partial f}{\partial x}$
|
\(\binom{n}{k}\) |
$\binom{n}{k}$
|
\(x_{1} + x_{2} + \cdots + x_{n}\) |
$x_{1} + x_{2} + \cdots + x_{n}$
|
\(x_{1}, x_{2}, \dots, x_{n}\) |
$x_{1}, x_{2}, \dots, x_{n}$
|
\(\mathbf{x} = \langle x_{1}, x_{2}, \dots, x_{n}\rangle\) |
\mathbf{x} = \langle x_{1}, x_{2}, \dots, x_{n}\rangle$ (\bm from the bm package would be better)
|
\(x \in A\) |
$x \in A$
|
\(|A|\) |
$|A|$
|
\(x \in A\) |
$x \in A$
|
\(A \subset B\) |
$x \subset B$
|
\(A \subseteq B\) |
$x \subseteq B$
|
\(A \cup B\) |
$A \cup B$
|
\(A \cap B\) |
$A \cap B$
|
\(X \sim {\sf Binom}(n, \pi)\) |
$X \sim {\sf Binom}(n, \pi)$ (sf for “slide font”
|
\(\mathrm{P}(X \le x) = {\tt pbinom}(x, n, \pi)\) |
$\mathrm{P}(X \le x) = {\tt pbinom}(x, n, \pi)$ (tt for “typewriter type”)
|
\(P(A \mid B)\) |
$P(A \mid B)$
|
\(\mathrm{P}(A \mid B)\) |
$\mathrm{P}(A \mid B)$ (mathrm for “math roman font”
|
\(\{1, 2, 3\}\) |
$\{1, 2, 3\}$
|
\(\sin(x)\) |
$\sin(x)$
|
\(\log(x)\) |
$\log(x)$
|
\(\int_{a}^{b}\) |
$\int_{a}^{b}$
|
\(\left(\int_{a}^{b} f(x) \; dx\right)\) |
$\left(\int_{a}^{b} f(x) \; dx\right)$
|
\(\left[\int_{-\infty}^{\infty} f(x) \; dx\right]\) |
$\left[\int_{\-infty}^{\infty} f(x) \; dx\right]$
|
\(\left. F(x) \right|_{a}^{b}\) |
$\left. F(x) \right|_{a}^{b}$
|
\(\sum_{x = a}^{b} f(x)\) |
$\sum_{x = a}^{b} f(x)$
|
\(\prod_{x = a}^{b} f(x)\) |
$\prod_{x = a}^{b} f(x)$
|
\(\lim_{x \to \infty} f(x)\) |
$\lim_{x \to \infty} f(x)$
|
\(\displaystyle \lim_{x \to \infty} f(x)\) |
$\displaystyle \lim_{x \to \infty} f(x)$
|
\(\alpha A\) |
$\alpha A$
|
\(\nu N\) |
$\nu N$
|
\(\beta B\) |
$\beta B$
|
\(\xi\Xi\) |
$\xi\Xi$
|
\(\gamma \Gamma\) |
$\gamma \Gamma$
|
\(o O\) |
$o O$ (omicron)
|
\(\delta \Delta\) |
$\delta \Delta$
|
\(\pi \Pi\) |
$\pi \Pi$
|
\(\epsilon \varepsilon E\) |
$\epsilon \varepsilon E$
|
\(\rho\varrho P\) |
$\rho\varrho P$
|
\(\zeta Z\) |
$\zeta Z \sigma \,\!$
|
\(\sigma \Sigma\) |
$\sigma \Sigma$
|
\(\eta H\) |
$\eta H$
|
\(\tau T\) |
$\tau T$
|
\(\theta \vartheta \Theta\) |
$\theta \vartheta \Theta$
|
\(\upsilon \Upsilon\) |
$\upsilon \Upsilon$
|
\(\iota I\) |
$\iota I$
|
\(\phi \varphi \Phi\) |
$\phi \varphi \Phi$
|
\(\kappa K\) |
$\kappa K$
|
\(\chi X\) |
$\chi X$
|
\(\lambda \Lambda\) |
$\lambda \Lambda$
|
\(\psi \Psi\) |
$\psi \Psi$
|
\(\mu M\) |
$\mu M$
|
\(\omega \Omega\) |
$\omega \Omega$
|
It is possible to define macros to make your mathematics easier to read. Macros are written in text chunks (because they are not R code).
Example: The following text
\newcommand{\intersect}{\operatorname{\cap}}
\newcommand{\union}{\operatorname{\cup}}
\newcommand{\Prob}{\operatorname{P}}
$$\Prob(A \union B) = \Prob(A) + \Prob(B) - \Prob(A \intersect B)$$
turns into
\[\operatorname{P}(A \operatorname{\cup}B) = \operatorname{P}(A) + \operatorname{P}(B) - \operatorname{P}(A \operatorname{\cap}B)\]