Convert matrix or string to LaTeX format
stm_to_latex.Rd
stm_to_latex()
converts a matrix or string into LaTeX code for
rendering mathematical expressions. Supports optional alignment and
decimal rounding.
Usage
stm_to_latex(
x,
align = c("right", "center", "left"),
symbol = "$",
name = NULL,
digits = NULL
)
Arguments
- x
The matrix, vector, or string to convert to LaTeX format.
- align
Optional. The alignment for matrix columns. Choices are
"right", "center",
or"left"
. Default is"right"
.- symbol
Optional. The symbol to wrap around the LaTeX expression. Default is
"$"
.- name
Optional. The name for the equation. If provided, it will appear before the LaTeX code.
- digits
Optional. The number of digits to round the matrix elements to. Default is
NULL
(no rounding).
Details
The function supports both converting a matrix and rendering a string as a LaTeX equation. It also allows custom alignment of matrix columns and rounding of matrix values to the specified number of digits.
Examples
stm_to_latex("x^2 + y^2 - z^2")
#> [1] "$\\displaystyle x ^{2} + y ^{2} - z ^{2}$"
stm_to_latex(matrix(1:4, nrow = 2), align = "center", digits = 2)
#> [1] "$\\left[\\begin{array}{cc} 1 & 3 \\\\ 2 & 4 \\end{array}\\right]$"
stm_to_latex(matrix(1:4, nrow = 2), name = "A")
#> [1] "$A = \\left[\\begin{array}{rr} 1 & 3 \\\\ 2 & 4 \\end{array}\\right]$"