to_latex {lazy.symbolic} | R Documentation |
Convert the input string to LaTex and display it on the RStudio viewer
Description
Convert the input string to LaTex and display it on the RStudio viewer
Usage
to_latex(
expr_str,
dollar = TRUE,
mat2sum = FALSE,
simple_mat2sum = FALSE,
print_html = FALSE,
undef_Greek = c("strip", "keep", "initial"),
safe_prod = FALSE
)
Arguments
expr_str |
The input expression as a string |
dollar |
= FALSE to omit the encompassing dollar signs |
mat2sum |
= TRUE if the input expression contains summation |
simple_mat2sum |
= TRUE if the input expression contains summation and the simpler LaTeX is prefered |
print_html |
= TRUE to display the result in RStudio's Viewer pane. |
undef_Greek |
Character string specifying how to handle undefined Greek macros (e.g., \Zeta). Use '"strip"' to print them as plain strings (e.g., '\Zeta' → '"Zeta"'), or '"initial"' to print only their initial character (e.g., '"Z"'). |
safe_prod |
Logical. If 'FALSE', the '"*"' operator is interpreted in some cases as an implicit scalar multiplication or a Hadamard product ('\odot'), and is replaced accordingly to improve readability. However, since it is not possible to definitively determine from the string whether each object is a scalar or a vector (e.g., is "x" a vector or scalar?), setting 'safe_prod = TRUE' is recommended if you prefer to consistently replace all '"*"' operators with '\cdot'. |
Details
This function requires htmltools
package when print_html=TRUE
.
Value
LaTeX expression of expr
Author(s)
Contributed by Dr. Kentaro Fukushima of Osaka University.
Examples
modify_math_operators()
A <- demomat(2,3, root="a")
B <- demomat(3,2, root="b")
AB=A%*%B
printm(AB)
AB_tex <- to_latex( AB )
printm(AB_tex)
sexpr <- mat2sum( "A%*%B+C" )
printm(sexpr)
sexpr_tex <- to_latex( sexpr, mat2sum=TRUE )
to_latex("a*b", print_html = TRUE)
to_latex("A*B", print_html = TRUE)
to_latex("X%.%B", print_html = TRUE)
to_latex("a*B", print_html = TRUE)
to_latex("mD0(tr(X%*%B), X)", print_html=TRUE)
to_latex("mD0('tr(X%*%B)', 'X')", print_html=TRUE)
to_latex('mD0("tr(X%*%B)", "X")', print_html=TRUE)
to_latex('mD0("tr(X%*%B)")', print_html=TRUE)
## Not run:
library(htmltools)
print_tex_as_html(AB_tex)
AB_tex <- to_latex( t(A)+B, print_html=TRUE )
sexpr_tex <- to_latex( sexpr, mat2sum=TRUE, print_html=TRUE )
sexpr_tex <- to_latex( sexpr, simple_mat2sum=TRUE, print_html=TRUE )
## End(Not run)