matrix2latex: (Deprecated) Convert matrix to LaTeX equation

View source: R/matrix2latex.R

matrix2latexR Documentation

(Deprecated) Convert matrix to LaTeX equation

Description

(This function has been deprecated; see latexMatrix instead). This function provides a soft-wrapper to xtable::xtableMatharray() with additional support for fractions output and brackets.

Usage

matrix2latex(
  x,
  fractions = FALSE,
  brackets = TRUE,
  show.size = FALSE,
  digits = NULL,
  print = TRUE,
  ...
)

Arguments

x

a numeric or character matrix. If the latter a numeric-based arguments will be ignored

fractions

logical; if TRUE, try to express non-integers as rational numbers, using the fractions function; if you require greater accuracy, you can set the cycles (default 10) and/or max.denominator (default 2000) arguments to fractions as a global option, e.g., options(fractions=list(cycles=100, max.denominator=10^4)).

brackets

logical or a character in "p", "b", "B", "V". If TRUE, uses square brackets around the matrix, FALSE produces no brackets. Otherwise "p") uses parentheses, ( ); "b") uses square brackets [ ], "B") uses braces { }, "V") uses vertical bars | |.

show.size

logical; if TRUE shows the size of the matrix as an appended subscript.

digits

Number of digits to display. If digits == NULL (the default), the function sets digits = 0 if the elements of x are all integers

print

logical; print the LaTeX code for the matrix on the console?; default: TRUE

...

additional arguments passed to xtable::xtableMatharray()

Details

The code for brackets matches some of the options from the AMS matrix LaTeX package: \pmatrix{}, \bmatrix{}, \Bmatrix{}, ... .

Author(s)

Phil Chalmers

Examples

A <- matrix(c(2, 1, -1,
             -3, -1, 2,
             -2,  1, 2), 3, 3, byrow=TRUE)
b <- c(8, -11, -3)

matrix2latex(cbind(A,b))
matrix2latex(cbind(A,b), digits = 0)
matrix2latex(cbind(A/2,b), fractions = TRUE)

matrix2latex(A, digits=0, brackets="p", show.size = TRUE)

# character matrices
A <- matrix(paste0('a_', 1:9), 3, 3)
matrix2latex(cbind(A,b))
b <- paste0("\\beta_", 1:3)
matrix2latex(cbind(A,b))


friendly/matlib documentation built on Sept. 8, 2024, 11:35 a.m.