TexFormatter | R Documentation |
R6 class to typeset R expressions as latex equations
R6 class to typeset R expressions as latex equations
symbols
a named list that matches R names (names in the list) to latex symbols (values in the list). Trig functions, greek letters and infinity are altomatically defined. They do not need to be defined in this list.
new()
constructor
TexFormatter$new(symbols = list())
symbols
a named list that matches R names (names in the list) to latex symbols (values in the list). Trig functions, greek letters and infinity are automatically defined. They do not need to be defined in this list. But they may be redefined here
tex = TexFormatter$new(II="[I\gets I]") tex$typeset(quote(sin(alpha*I)/II))
set.symbols()
set/change the tex symbols of R names
TexFormatter$set.symbols(symbols)
symbols
a named list that matches R names (names in the list) to latex symbols (values in the list). Trig functions, greek letters and infinity are automatically defined. They do not need to be defined in this list. But they may be redefined here
an invisible self to chain methods
tex = TexFormatter$new(II="[I\gets I]") tex$set.symbols(list(alpha="a")$typeset(quote(sin(alpha*I)/II)) description typeset an R expression
typeset()
TexFormatter$typeset(R)
R
the R expression to be typeset.
a character holding the latex commands
tex = TexFormatter$new(II="[I\gets I]") tex$typeset(quote(sin(alpha*I)/II))
enclose()
enclose the tex commands in brackets
TexFormatter$enclose(..., closure = c("{", "}"))
...
the tex commands to enclose
closure
a character vector of the brackets to be used. It defaults to 'c("","")'. If the vector is length 1, then it is used as both the opening and closing bracket.
the enclosed tex command
tex = TexFormatter$new() tex$enclose("\\bf This is a test") tex$enclose(tex$typeset.equation(quote(alpha==beta)), closure=c("\\begin{align}", "\\end{align}"))
command()
generate a latex command
TexFormatter$command(name, ..., argument = NULL, option = NULL)
name
the name of the latex command.
...
the arguments of the latex command.
argument
a character vector as an alternative way to provide arguments for the latex command
option
the optional argument to latex command (the one that is enclosed in square brackets.)
a character holding the latex command
tex=TexFormatter$new() tex$command("textcolor", "blue", "this text is blue") tex$command("documentclass", argument="article", option="12pt")
environment()
generate a latex environment
TexFormatter$environment(name, ..., argument = NULL, option = NULL)
name
the name of the latex environment
...
the contents of the latex environment
argument
a named list to provide arguments for the latex environment
option
the optional argument to latex environment (the one that is enclosed in square brackets.)
a character holding the latex environment
tex = TexFormatter$new() tex$environment("frame", argument="frame title", "line 1", "line 2")
typeset.equation()
typeset a system of equations
This method typesets a system of equations that can be used as the content of a latex align or eqnarray environments.
TexFormatter$typeset.equation(equations, align = c("left", "right", "both"))
equations
a list of equations or inequalities. The left and right sides of the equations may be connected using "<-" or "==".
align
can be one of "left", "right", "both", which specifies if the ampersand (&) is placed on the left, right or both sides of the equal (or other comparison) sign. The default value is left.
Note that the latex environment itself (e.g., \beginalign\endalign) is not returned.
a character holding the latex commands.
SIR = Model$new( title = "SIR", S ~ -beta*S*I/N, # the dS/dt equation I ~ beta*S*I/N - gamma*I, # the dI/dt equation R ~ gamma*I, # the dR/dt equation N = S + I + R # the total population N ) tex = TexFormatter$new() tex$typeset.equation(SIR$equations$equations) tex$typeset.equation(SIR$equations$where)
format()
a text representation of the class
TexFormatter$format()
clone()
The objects of this class are cloneable with this method.
TexFormatter$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------
## Method `TexFormatter$new`
## ------------------------------------------------
tex = TexFormatter$new(II="[I\gets I]")
tex$typeset(quote(sin(alpha*I)/II))
## ------------------------------------------------
## Method `TexFormatter$set.symbols`
## ------------------------------------------------
tex = TexFormatter$new(II="[I\gets I]")
tex$set.symbols(list(alpha="a")$typeset(quote(sin(alpha*I)/II))
description typeset an R expression
## ------------------------------------------------
## Method `TexFormatter$typeset`
## ------------------------------------------------
tex = TexFormatter$new(II="[I\gets I]")
tex$typeset(quote(sin(alpha*I)/II))
## ------------------------------------------------
## Method `TexFormatter$enclose`
## ------------------------------------------------
tex = TexFormatter$new()
tex$enclose("\\bf This is a test")
tex$enclose(tex$typeset.equation(quote(alpha==beta)),
closure=c("\\begin{align}", "\\end{align}"))
## ------------------------------------------------
## Method `TexFormatter$command`
## ------------------------------------------------
tex=TexFormatter$new()
tex$command("textcolor", "blue", "this text is blue")
tex$command("documentclass", argument="article", option="12pt")
## ------------------------------------------------
## Method `TexFormatter$environment`
## ------------------------------------------------
tex = TexFormatter$new()
tex$environment("frame", argument="frame title", "line 1", "line 2")
## ------------------------------------------------
## Method `TexFormatter$typeset.equation`
## ------------------------------------------------
SIR = Model$new(
title = "SIR",
S ~ -beta*S*I/N, # the dS/dt equation
I ~ beta*S*I/N - gamma*I, # the dI/dt equation
R ~ gamma*I, # the dR/dt equation
N = S + I + R # the total population N
)
tex = TexFormatter$new()
tex$typeset.equation(SIR$equations$equations)
tex$typeset.equation(SIR$equations$where)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.