poly2latex: Convert a Numeric Vector to LaTeX code for a Polynomial...

Description Usage Arguments Value Examples

View source: R/poly2latex.R

Description

This function transforms a numeric vector representing a polynomial in polynomial space into LaTeX code to render that polynomial. Such vectors represent linear combinations of coefficient and unknown terms, which form the basis of the space. This function is intended for use in Rmarkdown documents with PDF output, where it can convert vectors into formatted equations automatically.

Usage

1
2
3
4
5
6
7
poly2latex(
  v,
  sym = "t",
  dir = "forward",
  lhs = paste0("f(", sym, ") = "),
  sink = FALSE
)

Arguments

v

A numeric vector of arbitrary length

sym

A character to represent the unknown in the polynomial expression. Defaults to "t"

dir

Direction in which the terms of the polynomial represented by the vector increase. For "forward", the default, the constant term is the leftmost, for "backward" the rightmost

lhs

Value to use to represent the left-hand side of the equation. Defaults to f(t) = Set to "" or NULL to obtain only the right-hand side.

sink

Logical determining whether to return the output conventionally or print it directly to console. Defaults to FALSE.

Value

If sink = TRUE, a character vector containing LaTeX code to represent v as a polynomial. If FALSE, outputs code directly to console.

Examples

1
2
3
4
poly2latex(1:5)
#Constant function
poly2latex(-7)
poly2latex(round(rnorm(5), digits = 2))

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