Constructor
new Guppy(id, configopt)
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
string | The string ID of the element that should be converted to an editor. |
|||||||||||||
config |
Object |
<optional> |
The configuration options for this instance Properties
|
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) init(config)
Initialise global settings for all instances of the editor. Most of these can be overridden for specific instances later. Should be called before instantiating the Guppy class.
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object | The configuration options for this instance Properties
|
(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 |
activate()
Focus this instance of the editor
asciimath()
Get the content of the editor in AsciiMath.
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.
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