Constructor
new Guppy(element)
Parameters:
Name | Type | Description |
---|---|---|
element |
string | Node | The string id or the Dom Node of the element that should be converted to an editor. |
Members
engine :Engine
Type:
Methods
(static) add_global_symbol(name, symbol, templateopt)
Add a symbol to all instances of the editor
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name |
string | The name of the symbol to add. This is also the string that will be autoreplaced with the symbol. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
symbol |
Object | If Properties
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
template |
string |
<optional> |
The name of the template to use |
(static) configure(name, val)
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the setting to configure. Can be "xml_content", "autoreplace", "blank_caret", "empty_content", "blacklist", "buttons", or "cliptype" |
val |
Object | The value associated with the named setting:
"xml_content": An XML string with which to initialise the editor's state. (Defaults to " |
(static) event(name, handler)
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of an event. Can be:
change - Called when the editor's content changes. Argument will be a dictionary with keys |
handler |
function | The function that will be called to handle the given event |
(static) remove_global_symbol(name)
Remove a symbol from all instances of the editor
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the symbol to remove |
(static) render_all(type, delimopt, root_nodeopt)
Render all guppy documents on the page.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
string | The type of content to render |
|
delim |
string |
<optional> |
The string to delimit mathematical symbols |
root_node |
string |
<optional> |
The DOM Element object within which to do the rendering |
(static) use_osk(oskopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
osk |
GuppyOSK |
<optional> |
A GuppyOSK object to use for the on-screen keyboard if one is desired |
activate()
Focus this instance of the editor
asciimath()
Get the content of the editor in AsciiMath.
configure(name, val)
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the setting to configure. Can be "xml_content", "autoreplace", "blank_caret", "empty_content", "blacklist", "buttons", or "cliptype" |
val |
Object | The value associated with the named setting:
"xml_content": An XML string with which to initialise the editor's state. (Defaults to " |
deactivate()
Unfocus this instance of the editor
doc()
Get the Doc object representing the editor's contents.
equations()
Get the content of the editor as a list of equations, serialised
using JSON. For example, x < y = z
will be returned as `[["<", [["var", "x"], ["var", "y"]]],["=", [["var", "y"], ["var", "z"]]]]
evaluate(evaluatorsopt)
Recursively evaluate the syntax tree of the editor's contents using specified functions.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
evaluators |
Object |
<optional> |
An object with a key for each
possible symbol type ("exponential", "integral", etc.)
whose values are functions that will be applied whenever that
symbol is encountered in the syntax tree. These functions take a
single argument, |
Returns:
- Whatever the
evaluators
function for the root symbol in the syntax tree returns.
event(name, handler)
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of an event. Can be:
change - Called when the editor's content changes. Argument will be a dictionary with keys |
handler |
function | The function that will be called to handle the given event |
func(evaluatorsopt) → {function}
Get the content of the editor as a Javascript function, with
user-supplied interpretations of the various symbols. If not
supplied, default interpretations will be given for the following
symbols: *,+,/,-,^,sqrt,sin,cos,tan,log
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
evaluators |
Object |
<optional> |
An object with a key for each
possible symbol type ("exponential", "integral", etc.)
whose values are functions. These functions take in a single
argument, |
Returns:
- Returns a function that takes in an
object with a key for each variable in the expression and whose
values are the values that will be passed in for those variables.
In addition, this function is augmented with a
vars
member which is a list of the variables that appear in the expression.
- Type
- function
import_latex(text)
Set the content of the document from input text in "semantic
LaTeX" format. That is, all functions are represented as
\funcname{arg1}{arg2}
. For example,
\defintegral{1}{2}{x^2}{x}
.
Parameters:
Name | Type | Description |
---|---|---|
text |
String | A string representing the document to import. |
import_syntax_tree(tree)
Import a syntax tree from a JSON object formatted as outputted by guppy.syntax_tree()
.
Parameters:
Name | Type | Description |
---|---|---|
tree |
Object | A JSON object representing the syntax tree to import. |
import_text(text)
Set the content of the document from text in the format outputted by guppy.text()
.
Parameters:
Name | Type | Description |
---|---|---|
text |
String | A string representing the document to import. |
import_xml(xml)
Set the content of the document from XML in the format outputted
by guppy.xml()
.
Parameters:
Name | Type | Description |
---|---|---|
xml |
String | An XML string representing the document to import. |
latex()
Get the content of the editor as LaTeX
render(updatedopt)
Render the document
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
updated |
boolean |
<optional> |
false
|
Whether there have been visible changes to the document (i.e. that affect the positions of elements) |
symbols_used(groupsopt)
Get a list of the symbols used in the document, in order of
appearance, with each kind of symbol appearing only once. For
example, a document representing sin(x^3)+sqrt(x^2+x)
will
have symbols ["sin","exponential","square_root"]
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
groups |
Array.<String> |
<optional> |
A list of the groups whose symbols may be included in the output. If absent, all symbols in the document will be returned. |
syntax_tree()
Get the content of the editor as a syntax tree, serialised using JSON
text()
Get the content of the editor in a parseable text format.
vars()
Get a list of the variable names used in the document.
xml()
Get the content of the editor as XML