print_eqn: Print an Equation for LaTeX Rendering

Description Usage Arguments Value Examples

View source: R/print_eqn.R

Description

This simple function takes a a character vector representing an equation, matrix, or other text interpretable by a LaTeX math environment and outputs it to console. It is used by mat2latex and poly2latex to produce LaTeX-readable code from R objects. This function builds on this StackOverflow post.

Usage

1
print_eqn(eqn, delim = "$$", file = "")

Arguments

eqn

A character vector representing LaTeX code that may be interpreted by a math environment.

delim

Delimiter for the printed code. Defaults to "$$", the TeX standard, which should suit most uses.

file

Passed to cat's file argument, with append = FALSE. Defaults to "" (i.e., print directly to standard output).

Value

The object printed to console, or appended to a file if file is set.

Examples

1
2
3
4
5
# A polynomial transformation - note the escape backslashes!
# Try this in an rmarkdown chunk with `results = asis`
eqn <- c("\\begin{aligned}", "& T(f) = f(3) + f''\\\\",
"& = a + 3b + 9c +b + 2ct", "\\end{aligned}")
print_eqn(eqn)

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