knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(iomath)
tex
e <- Ryacas::ysym("((2*Sin(2+x))^2 + (a+b)^2)^3") e o <- Ryacas::tex(e) o
$$
r o
$$
All as hard brackets:
o2 <- hbtex(e) o2
$$
r o2
$$
Customised bracketing:
o3 <- btex(e) o3
$$
r o3
$$
An argument specifying brackets
can be given (recycled):
o4 <- btex(e, brackets = list( c("\\langle", "\\rangle"), c("\\{", "\\}"))) o4
$$
r o4
$$
2x
to mean 2*x
make_products_explicit("2x") make_products_explicit("2(1+2)") make_products_explicit("x(y)") make_products_explicit("(1+2)3") # Not allowed by definition make_products_explicit("(1+2)x") # Is allowed make_products_explicit("x(2+1) + sin(y)") make_products_explicit("sin(2+1) + x(y+1)") make_products_explicit("(2x)(y+1)")
By default, the allowed functions are those of getGroupMembers("Math")
:
getGroupMembers("Math")
This can be changed:
make_products_explicit("sin(1) + cos(1)", allowed_functions = c('cos'))
By default, safe evaluation inserts inner products.
safe_eval("2.2", vars = NULL) safe_eval("2.2x^2", vars = list(x = 0.2)) safe_eval("2.2*x^2", vars = list(x = 0.2)) safe_eval("2,2*x^2", vars = list(x = 0.2))
Efterything after first ;
is ignored:
safe_eval("1; 2; 3")
safe_eval("print(2)")
grd <- expand.grid(x = seq(-10, 10, length.out = 10)) answer <- Ryacas::ysym("2*x^2") compare_reply_answer(reply = "2x^2", answer = answer, compare_grid = grd) compare_reply_answer(reply = "2.3x^2", answer = answer, compare_grid = grd)
m <- matrix(c("2+z^3", "2*sin(x)", "3*y^2", "1.1*x^2"), 2, 2) m ans <- Ryacas::ysym(m) ans grd <- expand.grid(x = seq(-10, 10, length.out = 5), y = seq(-10, 10, length.out = 5), z = seq(-10, 10, length.out = 5)) compare_reply_answer(reply = m, answer = ans, compare_grid = grd) compare_reply_answer(reply = m[1, 1], answer = ans, compare_grid = grd) m2 <- apply(m, 2, paste0, '+0.1') m2 compare_reply_answer(reply = m2, answer = ans, compare_grid = grd)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.