adaptiveInlineMatrix: Latex Matrix

Description Usage Arguments Value Creation notes Examples

View source: R/Rmd_helpers.R

Description

Creates a matrix formated for latex with brackets in Rmarkdown. Needs to be inserted "asis" inside of an existing formula by surrounding the code chunk in `$$` signs or having this built into the output of the code chunk (see Examples).

Usage

1

Arguments

mat

numeric matrix.

Value

Returns the plain text latex code needed to create the formatted matrix.

Creation notes

First created on 2019-Jul-10 as I was working on STAT 512 homework.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 # Data
```{r}
Q1n <- 6
Q1Y <- matrix(c(1,2,4,3,3,2), ncol = 1)
Q1X0 <- rep(1,Q1n)
Q1X1 <- c(1,1,2,3,2,2)
Q1X2 <- c(2,3,6,3,2,4)
Q1X <- cbind(Q1X0, Q1X1, Q1X2)
```

### FIRST OPTION (Better when you need to make multiple matrices in equation)
# Start math formula outside chunck
$$\mathbf{X} =

# First matrix
```{r echo=FALSE, results='asis'}
cat(adaptiveInlineMatrix(Q1X))
```
*
# Second matrix
```{r echo=FALSE, results='asis'}
cat(adaptiveInlineMatrix(Q1Y))
```

# End math formula
$$


### SECOND OPTION
# Define it all in one chuck (have to remember to do extra escape characters)
```{r echo=FALSE, results='asis'}
cat(paste0("$\mathbf{X} = ", adaptiveInlineMatrix(Q1X)), "$")
```

jacpete/jpfxns2 documentation built on Nov. 22, 2019, 3:33 a.m.