show_math: Show math equations

View source: R/utils2.R

show_mathR Documentation

Show math equations

Description

Displays math equations in rstudioapi::viewer or browser using the MathJax javascript engine.

Usage

show_math(..., css = "", use_viewer = !is.null(getOption("viewer")))

Arguments

...

one or more character strings

css

optional css formatting

use_viewer

logical; if TRUE, attempts to use rstudioapi::viewer or opens in default browser on error

Value

The html code (invisibly) as a character string.

See Also

show_html, show_markdown, draw math symbols, https://stackoverflow.com/q/31193843/2994949

Examples

## Not run: 
form1 <- '$$A=\\frac{B}{C}$$'

form2 <- '$$
  \\frac{1}{\\displaystyle 1+
  \\frac{1}{\\displaystyle 2+
  \\frac{1}{\\displaystyle 3+x}}} +
  \\frac{1}{1+\\frac{1}{2+\\frac{1}{3+x}}}
$$'

form3 <- '\\frac{d}{dx}\\left( \\int_{0}^{x} f(u)\\,du\\right)=f(x)'

form4 <- "
  \\forall a,b,c \\in \\mathbb{R} \\\\
  \\begin{align}
                        a + b &= c \\\\
               (a + b)(a - b) &= c(a - b) \\\\
                    a^2 - b^2 &= ca - cb \\\\
                     a^2 - ca &= b^2 - cb \\\\
    a^2 - ca + \\frac{c^2}{4} &= b^2 - cb + \\frac{c^2}{4} \\\\
         (a - \\frac{c}{2})^2 &= (b - \\frac{c}{2})^2 \\\\
             a - \\frac{c}{2} &= b - \\frac{c}{2} \\\\
                            a &= b \\qquad \\qquad \\blacksquare \\\\
   \\end{align}
"

show_math(form1)
cat(show_math(form4))

## use default browser
show_math(form2, use_viewer = FALSE)

## concatenate multiple expressions
show_math(form1, form2, form3, css = 'color: red; font-size: 15px;')

## End(Not run)


raredd/rawr documentation built on March 4, 2024, 1:36 a.m.