equation2latex: Transform an R Expression into LaTeX Code

Description Usage Arguments Value Examples

View source: R/equation2latex.R

Description

This function converts unquoted R expressions into LaTeX code. It uses extract values to substitute for each symbol in the expression its value in env. Then it deparses the expression and inserts LaTeX code in the appropriate places, including handling matrices and vectors.

Usage

1
equation2latex(eqn, env, emBiggen = TRUE)

Arguments

eqn

An R expression, optionally containing matrices.

env

Environment in which to evaluate the expression. Defaults to the caller environment of equation2latex.

emBiggen

Logical determining whether to apply the LaTeX Bigg modifier to parentheses in the output, which looks better with matrices. "Embiggens" is a perfectly cromulent word. Defaults to TRUE.

Value

LaTeX code for rendering the expression, as a length-one character vector.

Examples

1
2
3
4
5
6
7
8
A <- matrix(c(1, 2, 3, 4), nrow = 2)
B <- A + diag(x = 3, nrow = 2)
C <- matrix(c(7, 8, 9, 10), nrow = 2)
D <- matrix(c(1, 7, 9,-9), nrow = 2)
k <- 7

print_eqn(equation2latex(A))
print_eqn(equation2latex(k *A + (B + C) %*% D))

ryan-heslin/matador documentation built on Dec. 22, 2021, 8:17 p.m.