-
-
Save labouz/d2e012f638864b9af061afe648ce441b to your computer and use it in GitHub Desktop.
RMarkdown Latex Notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.Rproj.user | |
.Rhistory | |
.RData | |
.Ruserdata | |
*.Rproj | |
*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Appendix {.unnumbered #latex} | |
Ray's Formatting Notes: version 2021-12-31 | |
https://gist.github.com/RaymondBalise/ee4b7da0a70087317dc52bf479a4e2b6 | |
```{=html} | |
<style> | |
.col2 { | |
columns: 2 150px; /* number of columns and width in pixels*/ | |
-webkit-columns: 2 150px; /* chrome, safari */ | |
-moz-columns: 2 150px; /* firefox */ | |
} | |
.col3 { | |
columns: 3 100px; | |
-webkit-columns: 3 100px; | |
-moz-columns: 3 100px; | |
} | |
</style> | |
``` | |
## Markdown highlighting {.unnumbered} | |
| Formatting | Code | | |
|:-----------|:-------------| | |
| **bold** | \*\*bold\*\* | | |
| __bold__ | \_\_bold\_\_ | | |
| *italic* | \*italic\* | | |
| _italic_ | \_italic\_ | | |
## Text coloring {.unnumbered} | |
To add color you can use CSS or R code like this: | |
```{r, include=TRUE} | |
color_text <- function(x, color){ | |
if(knitr::is_latex_output()) | |
paste("\\textcolor{",color,"}{",x,"}",sep="") | |
else if(knitr::is_html_output()) | |
paste("<font color='",color,"'>",x,"</font>",sep="") | |
else | |
x | |
} | |
red <- function(x){ | |
if(knitr::is_latex_output()) | |
paste("\\textcolor{",'red',"}{",x,"}",sep="") | |
else if(knitr::is_html_output()) | |
paste("<font color='red'>",x,"</font>",sep="") | |
else | |
x | |
} | |
``` | |
The strng `r red("This is colored with the red function")` comes from: | |
```{r eval=FALSE} | |
`r red("This is colored with the red function")` | |
``` | |
The string `r color_text("This is colored with the color_text function set to mauve", "#E0B0FF")` comes from: | |
```{r eval=FALSE} | |
`r color_text("This is colored with the color_text function set to mauve", "#E0B0FF")` | |
``` | |
## Section references {.unnumbered #x99.4} | |
Section [99.4](#x99.4) comes from `Section [99.4](#x99.4)` | |
## Footnotes {.unnumbered} | |
^[A footnote] comes from `^[A footnote]` | |
## Formatting Text {.unnumbered} | |
| Appearance | Code | | |
|:---------------------------------------------------------|:-------------------------------------------------------| | |
| `r xfun::n2w(3, cap = TRUE)` | `xfun::n2w(3, cap = TRUE)` | | |
| `r scales::percent(0.1447, accuracy= .1)` | `scales::percent(0.1447, accuracy= .1)` | | |
| `r scales::pvalue(0.1447, accuracy= .001, add_p = TRUE)` | `scales::pvalue(0.1447, accuracy= .001, add_p =TRUE)` | | |
## Figures {.unnumbered} | |
Name a figure chunk with a name like figure99-1 and include fig.cap="something" then reference it like this: `\@ref(fig:figure99-1)` | |
## Displaying Formula {.unnumbered} | |
### Formatting Text Font {.unnumbered} | |
To tweak the appearance of words use these formats: | |
| Formatting | Looks like | Code | | |
|:------------------|:------------------------|:------------------------| | |
| plain text | $\text{text Pr}$ | \\text{text Pr} | | |
| bold Greek symbol | $\boldsymbol{\epsilon}$ | \\boldsymbol{\\epsilon} | | |
| typewriter | $x\ \tt{sentence}\ x$ | \\tt{sentence} | | |
| teletype | $x\ \texttt{blah}\ x$ | \\texttt{blah} | | |
| slide font | $\sf{blah}$ | \\sf{blah} | | |
| bold | $\mathbf{x}$ | \\mathbf{x} | | |
| plain | $\mathrm{text Pr}$ | \\mathrm{text Pr} | | |
| cursive | $\mathcal{S}$ | \\mathcal{S} | | |
| Blackboard bold | $\mathbb{R}$ | \\mathbb{R} | | |
### Symbols {.unnumbered} | |
| Symbols | Code | | |
|:--------------------------------------------|:------------------------------------------| | |
| $\stackrel{\text{def}}{=}$ | \\stackrel{\\text{def}}{=} | | |
| $\nabla$ | `\nabla` | | |
| $\partial$ | `\partial` | | |
| $\vert$ or use $\lvert a \rvert$ | `\vert \text{ or use } \lvert a \rvert` \ | | |
| $\Vert$ | `\Vert` | | |
| $\mid$ in set notation; `\given` is missing | `\mid` | | |
### Brackets and Parentheses {.unnumbered} | |
| Looks like | Code | | |
|:---------------------------|:------------------------------| | |
|$\big( \Big( \bigg( \Bigg($ | \\big( \\Big( \\bigg( \\Bigg( | | |
|$\big] \Big] \bigg] \Bigg]$ | \\big] \\Big] \\bigg] \\Bigg] | | |
### Notation {.unnumbered} | |
Based on: <https://www.calvin.edu/~rpruim/courses/s341/S17/from-class/MathinRmd.html> | |
| Math | Code | | |
|:--------------------------------------------------------------|:-------------------------------------------------------------------| | |
| $x = y$ | `$x = y$` | | |
| $x \approx y$ | `$x \approx y$` | | |
| $f_k(X) \equiv Pr(X|Y = k)$ | `f_k(X) \equiv Pr(X|Y = k)` | | |
| $x \lt y$ | `$x < y$` | | |
| $x \gt y$ | `$x > y$` | | |
| $x \le y$ | `$x \le y$` | | |
| $x \ge y$ | `$x \ge y$` | | |
| $x \times y$ | `$x \times y$` | | |
| $x^{n}$ | `$x^{n}$` | | |
| $x_{n}$ | `$x_{n}$` | | |
| $x_1, x_2, \dots, x_n$ | `$x_1, x_2, \dots, x_n$` | | |
| $x_1 + x_2 + \cdots + x_n$ | `$x_1 + x_2 + \cdots + x_n$` | | |
| $\overline{x}$ | `$\overline{x}$` | | |
| $\hat{x}$ | `$\hat{x}$` | | |
| $\widehat{SE}$ | `$\widehat{SE}$` | | |
| $\tilde{x}$ | `$\tilde{x}$` | | |
| $\frac{a}{b}$ | `$\frac{a}{b}$` | | |
| $\displaystyle \frac{a}{b}$ | `$\displaystyle \frac{a}{b}$` | | |
| $\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$` | | |
| $x \in A$ | `$x \in A$` | | |
| $\lvert A \rvert$ | `$\lvert A \rvert$` | | |
| $\big \langle x_i, x_{i'}\big \rangle$ | `\big \langle x_i, x_{i'}\big \rangle` | | |
| $x \in A$ | `$x \in A$` | | |
| $x \subset B$ | `$x \subset B$` | | |
| $x \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)$` | | |
| $\mathrm{P}(X \le x) = {\tt pbinom}(x, n, \pi)$ | `$\mathrm{P}(X \le x) = {\tt pbinom}(x, n, \pi)$` | | |
| $P(A \mid B)$ | `$P(A \mid B)$` | | |
| $\mathrm{P}(A \mid B)$ | `$\mathrm{P}(A \mid B)$` | | |
| $\{1, 2, 3\}$ | `$\{1, 2, 3\}$` | | |
| $\sin(x)$ | `$\sin(x)$` | | |
| $\log(x)$ | `$\log(x)$` | | |
| $\exp(x)$ | `$\exp(x)$` | | |
| $\exp{\big(\sum_{i=1}^p x_i\big)}$ | `$\exp{\big(\sum_{i=1}^p x_i\big)}$` | | |
| $\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)$` | | |
| $RMSE = \sqrt{\frac{1}{n}\sum_{i=1}^{n} (Y_n - \hat{Y}_i)^2}$ | `$RMSE = \sqrt{\frac{1}{n}\sum_{i=1}^{n} (Y_n - \hat{Y}_i)^2}$` | | |
| $(\texttt{pop} - \overline{ \texttt{pop}})$ | `$(\texttt{pop} - \overline{\texttt{pop}})$` | | |
| $\hat{f}(x) \leftarrow \hat{f}(x) + \lambda\hat{f}^b(x)$ | `\hat{f}(x) \leftarrow \hat{f}(x) + \lambda\hat{f}^b(x)` | | |
#### Stacked text (for finding maximum): | |
To get text stacked below a word for optimization formulas use `\mathop` with `$$` | |
| Math | Code | | |
|:--------------------------------------------------------------|:-------------------------------------------------------------------| | |
| $$\mathop{\text{max}}_{k}(\hat{p}_{mk})$$ | `$$\mathop{\text{max}}_{k}(\hat{p}_{mk})$$` | | |
#### Adjust position of limits: | |
To have limits appear next to sigma or pi (not above): | |
| Math | Code | | |
|:--------------------------------------------------------------|:-------------------------------------------------------------------| | |
| $\sum\nolimits_{i=1}^{n}X_i.$ | `\sum\nolimits_{i=1}^{n}X_i.` | | |
### Matrices {.unnumbered} | |
\begin{equation} | |
A = | |
\begin{bmatrix} | |
1 & \cdots & 3\\ | |
\vdots & \ddots & \vdots\\ | |
7 & \cdots & 9 | |
\end{bmatrix} | |
\end{equation} | |
Comes from this code: | |
``` | |
\begin{equation} | |
A = | |
\begin{bmatrix} | |
1 & \cdots & 3\\ | |
\vdots & \ddots & \vdots\\ | |
7 & \cdots & 9 | |
\end{bmatrix} | |
\end{equation} | |
``` | |
Options to surround the matrix: | |
| Type | Code | | |
|:----------------|:------------------| | |
| Nothing | `\begin{matrix}` | | |
| Parentheses | `\begin{pmatrix}` | | |
| Square Brackets | `\begin{bmatrix}` | | |
| Curly brackets | `\begin{Bmatrix}` | | |
| Pipes | `\begin{vmatrix}` | | |
| Double Pipes | `\begin{Vmatrix}` | | |
## Equations {.unnumbered} | |
These are formulas that appear with an equation number. | |
### Basic Equation {.unnumbered} | |
The names of equations can not include . or \_ but it can include - | |
\begin{equation} | |
1 + 1 = 2 | |
(\#eq:eq99-1) | |
\end{equation} | |
Which appears as: | |
\begin{equation} | |
1 + 1 = 2 | |
(\#eq:eq99-1) | |
\end{equation} | |
The reference to the equation is \@ref(eq:eq99-1) which comes from this code `\@ref(eq:eq99-1)` | |
### Case-When Equation (Large Curly Brace) {.unnumbered} | |
Based on: <https://tex.stackexchange.com/questions/9065/large-braces-for-specifying-values-of-variables-by-condition> | |
Case when formula: | |
```{=tex} | |
\begin{equation} | |
y = | |
\begin{cases} | |
0, & \text{if}\ a=1 \\ | |
1, & \text{otherwise} | |
\end{cases} | |
(\#eq:eq99-2) | |
\end{equation} | |
``` | |
Which comes from this code: | |
```{} | |
\begin{equation} | |
y = | |
\begin{cases} | |
0, & \text{if}\ a=1 \\ | |
1, & \text{otherwise} | |
\end{cases} | |
(\#eq:eq99-2) | |
\end{equation} | |
``` | |
The reference to equation is \@ref(eq:eq99-2) which comes from this code `\@ref(eq:eq99-2)` | |
### Alligned with Underbars {.unnumbered} | |
\begin{equation} | |
\begin{aligned} | |
\mathrm{E}(Y-\hat{Y})^2 & = \mathrm{E}[f(X) + \epsilon -\hat{f}(X)]^2 \\ | |
& = \underbrace{[f(X) -\hat{f}(X)]^2}_{\mathrm{Reducible}} + \underbrace{\mathrm{var}(\epsilon)}_{\mathrm{Irreducible}} \\ | |
\end{aligned} | |
(\#eq:eq99-3) | |
\end{equation} | |
Comes from this code: | |
```{} | |
\begin{equation} | |
\begin{aligned} | |
\mathrm{E}(Y-\hat{Y})^2 & = \mathrm{E}[f(X) + \epsilon -\hat{f}(X)]^2 \\ | |
& = \underbrace{[f(X) -\hat{f}(X)]^2}_{\mathrm{Reducible}} + \underbrace{\mathrm{var}(\epsilon)}_{\mathrm{Irreducible}} \\ | |
\end{aligned} | |
(\#eq:eq99-3) | |
\end{equation} | |
``` | |
## Greek letters {.unnumbered} | |
Based on: <https://www.calvin.edu/~rpruim/courses/s341/S17/from-class/MathinRmd.html> | |
::: {.col2} | |
| letters | code | | |
|:--------------------------|:----------------------------| | |
| $\alpha A$ | `$\alpha A$` | | |
| $\beta B$ | `$\beta B$` | | |
| $\gamma \Gamma$ | `$\gamma \Gamma$` | | |
| $\delta \Delta$ | `$\delta \Delta$` | | |
| $\epsilon \varepsilon E$ | `$\epsilon \varepsilon E$` | | |
| $\zeta Z \sigma$ | `$\zeta Z \sigma` | | |
| $\eta H$ | `$\eta H$` | | |
| $\theta \vartheta \Theta$ | `$\theta \vartheta \Theta$` | | |
| $\iota I$ | `$\iota I$` | | |
| $\kappa K$ | `$\kappa K$` | | |
| $\lambda \Lambda$ | `$\lambda \Lambda$` | | |
| $\mu M$ | `$\mu M$` | | |
| $\nu N$ | `$\nu N$` | | |
| $\xi\Xi$ | `$\xi\Xi$` | | |
| $o O$ | `$o O$ (omicron)` | | |
| $\pi \Pi$ | `$\pi \Pi$` | | |
| $\rho\varrho P$ | `$\rho\varrho P$` | | |
| $\sigma \Sigma$ | `\sigma \Sigma$` | | |
| $\tau T$ | `$\tau T$` | | |
| $\upsilon \Upsilon$ | `$\upsilon \Upsilon$` | | |
| $\phi \varphi \Phi$ | `$\phi \varphi \Phi$` | | |
| $\chi X$ | `$\chi X$` | | |
| $\psi \Psi$ | `$\psi \Psi$` | | |
| $\omega \Omega$ | `$\omega \Omega$` | | |
::: | |
## Calligraphic Letters {.unnumbered} | |
| letters | code |meaning | | |
|:--------------------------|:-------------------------|:-----------------| | |
| $\mathcal{S}$ | `$\mathcal{S}$ ` | A set | | |
| $\mathcal{B}$ | `$\mathcal{B}$` | Basis | | |
| $\mathcal{P}$ | `$\mathcal{P}$` | Power set, probability function | | |
| $\mathcal{O}$ | `$\mathcal{O}$` | Used for Big-O notation | | |
| $(\Omega, \mathcal{F}, \mathcal{P})$ | `$(\Omega, \mathcal{F}, \mathcal{P})$` |Probability space/triple| |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment