knitr::opts_chunk$set(echo = TRUE)
library(knitr)

R build status License: GPL v3 Codecov test coverage Lifecycle: experimental

NOTE: Markdown does not support well for mathematical equations. And some equations not displayed properly in this page, such as $\frac{x}{y}$, $\sqrt[y]{x}$ and $\prod_{i = 1}^{n} x_i$, . See the html vignette for all the correct displayed equations.

Tools for converting R expressions to latex mathematical equations. This project is scratch from the section 21.3 transforms mathematically R code into its LaTeX equivalent.

Usage

Special symbols

library(rlatexmath)
translate_latexmath(pi)

# quoted object
translate_latexmath_(quote(pi))

Known functions

R expression |latex math
-------------------|------------------------------------------ Binary operators| x + y |r translate_latexmath(x+y) x - y |r translate_latexmath(x - y) x * y |r translate_latexmath(x * y) x / y |r translate_latexmath(x / y) x %+-% y |r translate_latexmath(x %+-% y) x %/% y |r translate_latexmath(x %/% y ) x %*% y |r translate_latexmath(x %*% y ) x %.% y |r translate_latexmath(x %.% y ) x[i] |r translate_latexmath(x[i]) x^i |r translate_latexmath(x^i) Grouping| (x + y) |r translate_latexmath((x+y)) {x y} |r translate_latexmath({x + y}) Juxtaposition| paste(x, y, z) |r translate_latexmath(paste(x, y, z)) Comma separated lists| list(x + y, z) |r translate_latexmath(list(x + y, z)) Fractions| frac(x, y) |r translate_latexmath(frac(x, y)) atop(x, y) |r translate_latexmath(atop(x, y)) Ellipsis| list(x[1], cdots, x[2])|r translate_latexmath(list(x[1], cdots, x[2])) list(x[1], ldots, x[2])|r translate_latexmath(list(x[1], ldots, x[2])) Radicals| sqrt(x) |r translate_latexmath(sqrt(x)) sqrt(x, y) |r translate_latexmath(sqrt(x, y)) Relation| x == y | r translate_latexmath(x == y) x != y | r translate_latexmath(x != y) x < y | r translate_latexmath(x < y) x > y | r translate_latexmath(x > y) x >= y | r translate_latexmath(x >= y) x <= y | r translate_latexmath(x <= y) x %==% y | r translate_latexmath(x %==% y) x %~~% y | r translate_latexmath(x %~~% y) x %=~% y | r translate_latexmath(x %=~% y) x %prop% y | r translate_latexmath(x %prop% y) Set| x %supset% y | r translate_latexmath(x %supset% y) x %supseteq% y | r translate_latexmath(x %supseteq% y) x %subset% y | r translate_latexmath(x %subset% y) x %notsubset% y | r translate_latexmath(x %notsubset% y) x %subseteq% y | r translate_latexmath(x %subseteq% y) x %in% y | r translate_latexmath(x %in% y) x %notin% y | r translate_latexmath(x %notin% y) Arrow | x %<->% y |r translate_latexmath(x %<->% y) x %<-% y |r translate_latexmath(x %<-% y) x %up% y |r translate_latexmath(x %up% y) x %->% y |r translate_latexmath(x %->% y) x %down% y |r translate_latexmath(x %down% y) x %<=>% y |r translate_latexmath(x %<=>% y) x %<=% y |r translate_latexmath(x %<=% y) x %dblup% y |r translate_latexmath(x %dblup% y) x %=>% y |r translate_latexmath(x %=>% y) x %dbldown% y |r translate_latexmath(x %dbldown% y) Accent| tilde(x)|r translate_latexmath(tilde(x)) hat(x)|r translate_latexmath(hat(x)) widetilde(x)|r translate_latexmath(widetilde(x)) widehat(x)|r translate_latexmath(widehat(x)) bar(x)|r translate_latexmath(bar(x)) Operators| sum(x[i])| r translate_latexmath(sum(x[i]))sum(x[i], i==1, n)| r translate_latexmath(sum(x[i], i==1, n)) prod(x[i])| r translate_latexmath(prod(x[i])) prod(x[i], i==1, n)| r translate_latexmath(prod(x[i], i==1, n)) integral(f(x)*{dx}, a, b)| r translate_latexmath(integral(f(x)*{dx}, a, b)) union(A[i], i==1, n)| r translate_latexmath(union(A[i], i==1, n)) intersect(A[i], i==1, n)| r translate_latexmath(union(A[i], i==1, n)) lim(f(x), x %->% infty)| r translate_latexmath(lim(f(x), x %->% infty)) min(f(x), x >= 0)|r translate_latexmath(min(f(x), x >= 0)) max(f(x), x >= 0)|r translate_latexmath(max(f(x), x >= 0)) Typeface| plain(x)| r translate_latexmath(plain(x)) bold(x)| r translate_latexmath(bold(x)) italic(x)| r translate_latexmath(italic(x)) bolditalic(x)| r translate_latexmath(bolditalic(x)) Delimiters| group("(", list(a,b), "]")|r translate_latexmath(group("(", list(a,b), "]")) bgroup("[", frac(a,b), "]")|r translate_latexmath(bgroup("[", frac(a,b), "]")) abs(x)| r translate_latexmath(abs(x))

related projects

Acknowledgements



yiluheihei/rlatexmath documentation built on Jan. 1, 2021, 1:44 p.m.