Transform complex LaTex mathematical expressions into readable, composable R code. Instead of wrestling with backslashes and braces, express your mathematics naturally using familiar R syntax.
\frac{d}{dt} \left \langle V,W \right \rangle = \left \langle \frac{DV}{dt}, W \right \rangle + \left \langle V, \frac{DW}{dt} \right \rangle
<- lsymb("V")
vf1 <- lsymb("W")
vf2 <- function(x, y) ang(lsymb(x, ",", y))
inner <- function(x) lsymb("D", x) / "dt"
cov.der <- function(x) lsymb("d", x) / "dt"
ddt
ddt(inner(vf1, vf2)) *eq* inner(cov.der(vf1), vf2) + inner(vf1, cov.der(vf2))
# Division automatically becomes \frac
/ y # → \frac{x}{y}
x
# Powers become superscripts
^2 # → x^{2}
x
# Subscripts with under()
|> under(i) # → x_{i} x
No more \left
and \right
headaches!
pths(x / y) # Parentheses with auto-sizing
ang(x, y) # Angle brackets ⟨x,y⟩
sqbr(x + y) # Square brackets [x+y]
br(condition) # Braces {condition}
Build complex expressions from simple, reusable parts:
# Define semantic functions
<- function(x) lsymb("\\mathbb{E}") * sqbr(x)
exp_val <- function(x) pths(x)^2
sq <- function(x) lsymb("\\abs{", x, "}")
abs
# Compose naturally
exp_val(sq(abs(x) - y)) # → 𝔼[(|x| - y)²]
<- list(
proof_steps * dist(x, y) * leq * dist(x, z) + dist(z, y) * endl,
ruler * thus * dist(x, y) - dist(x, z) * leq * dist(z, y)
ruler |>
) lenv("align*", rows = _)
data(common)
attach(common)
# Instantly use: alpha, beta, mu, sigma, eq, leq, sum, int, infty...
Released version from CRAN:
install.packages("latexSymb")
Development version from GitHub:
# install.packages("devtools")
::install_github("nicoesve/latexSymb") devtools
library(latexSymb)
data(common)
attach(common)
# Define components
<- lsymb("\\bar{x}")
sample_mean <- function(x) lsymb("\\sqrt{", x, "}")
sqrt <- lsymb("\\overset{d}{\\rightarrow}")
conv_distr
# Express the theorem
<- sqrt(n) * (pths(sample_mean - mu) / si) * conv_distr * lsymb("N(0,1)") clt
vignette("vignette1", package = "latexSymb")
for getting
startedvignette("advanced_usage", package = "latexSymb")
for
complex examples?latexSymb
Stop fighting with LaTex syntax. Start expressing your mathematics naturally with latexSymb!