katex: render function for KaTeX in R

Description Usage Arguments Examples

View source: R/katex.R

Description

render function for KaTeX in R

Usage

1
katex(tex = "", tag = "div", inline = FALSE, style = NULL)

Arguments

tex

String containing the formula to be parsed and rendered

tag

String for the type of html tag to use. tag = "div" is the default.

inline

Logical to use \displaystyle. Default is FALSE. Change to TRUE if you would like your formula to be included inline. See this issue for more details.

style

String with the style attributes, such as style = "font-size:20px;text-align:center;". Note, the behavior of katexR is different from standard htmlwidgets, and height and width parameters will not work.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
## Not run: 
# a simple mean formula
katex("\\frac{1}{n} \\sum_{i=i}^{n} x_{i}")

# to illustrate use with a different tag and some styling
katex(
 "\\frac{1}{n} \\sum_{i=i}^{n} x_{i}"
 ,tag = "p"
 ,style = "color:blue; font-size:300%; text-align:center;"
)

# katex plays nicely with htmltools
library(htmltools)

html_print(tagList(
 tags$div(
   tags$pre( "\\frac{1}{n} \\sum_{i=i}^{n} x_{i}" )
   , katex( "\\frac{1}{n} \\sum_{i=i}^{n} x_{i}", tag="span" )
 )
))

# or if you want to customize your KaTeX experience
#   use katex to just get the required dependencies
html_print(tagList(
  tags$p( id = "katex-one" )
  ,tags$script( "
     katex.render('\\\\frac{1}{n} \\\\sum_{i=i}^{n} x_{i}',document.getElementById('katex-one'))
  ")
  ,katex() # empty means just use for js/css dependencies
))



## End(Not run)

timelyportfolio/katexR documentation built on May 27, 2017, 8:39 a.m.