matrix2latex: Convert matrix to LaTeX equation

View source: R/matrix2latex.R

matrix2latexR Documentation

Convert matrix to LaTeX equation

Description

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,
  ...
)

Arguments

x

a matrix

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

...

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)


friendly/matlib documentation built on March 3, 2024, 12:18 p.m.