Constructor
new Guppy(id, configopt)
- Source:
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
| Name |
Type |
Attributes |
Description |
events |
Object
|
<optional>
|
A dictionary of events.
Available events are as specified in Guppy.init. Values in this
dictionary will, for this instance of the editor, override events
specified through Guppy.init. |
settings |
Object
|
<optional>
|
A dictionary of settings.
Values in this dictionary will override any global settings
specified in Guppy.init. This dictionary takes the same keys as
the config.settings dictionary passed to Guppy.init. See that
function's documentation for the complete list. |
|
Members
- Source:
Type:
Methods
(static) add_global_symbol(name, symbol, templateopt)
- Source:
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 template is present, this is just
the template arguments. Otherwise, it is the complete symbol
specification
Properties
| Name |
Type |
Attributes |
Description |
output |
Object
|
|
Key/value pairs where the key is
the output type (such as "latex" or "asciimath") and the value is
the string by which the output will be rendered in that format.
In this string, {$n} will be substituted with the rendering of the
nth argument. If the nth argument is a d-dimensional list, then
the argument should be specified as {$n{sep_1}{sep_2}...{sep_d}}
where sep_i will be the separator used to separate entries in the
ith dimension. Note that keys are not necessary to describe the
AST or plain-text outputs. |
keys |
Array
|
|
A list of strings representing
keystrokes that can be used to trigger the insertion of this
symbol. For example, "^" or"shift+up"for theexponential`
symbol. |
attrs |
Object
|
|
A specification of the attributes
of the symbol
Properties
| Name |
Type |
Description |
type |
string
|
A longer description of the
symbol type, suitable for searching and text rendering. |
group |
string
|
The group in which to place
this symbol (for OSK) |
|
input |
Object
|
<optional>
|
If the symbol should subsume part
of the existing content of the editor (as in, for example, the
case of exponent), this object will contain the (1-based) index of
the argument in which that content should be placed. |
ast |
Object
|
<optional>
|
Modifies the default construction
of an entry in the AST for this symbol.
Properties
| Name |
Type |
Attributes |
Default |
Description |
type |
Object
|
<optional>
|
"operator"
|
The type of symbol
for AST purposes. Can be "name" (meaning this symbol represents
a variable, as in the case of pi), "number" (meaning this symbol
is a literal value), "operator" (meaning this symbol is a
function or otherwise takes arguments (as in cos or +), or
"pass" (meaning this symbol's first argument will be used as its
AST entry, as in the case of brackets/parentheses). |
|
args |
Array.<Object>
|
<optional>
|
A list of specifications, one
for each argument
Properties
| Name |
Type |
Attributes |
Default |
Description |
down |
string
|
<optional>
|
|
The index of the argument
to jump to when the "down" arrow is pressed in this argument |
up |
string
|
<optional>
|
|
The index of the argument
to jump to when the "up" arrow is pressed in this argument |
small |
string
|
<optional>
|
"no"
|
"yes" if the symbol is
small (as in an exponent) |
name |
string
|
<optional>
|
|
The name of this particular
argument (suitable for searching) |
bracket |
string
|
<optional>
|
"no"
|
"yes" if brackets
should automatically be rendered around this argument when they
might be needed to disambiguate. |
delete |
string
|
<optional>
|
|
If present, when the
"backspace" key is pressed at the beginning of this argument,
the symbol will be deleted and replaced with the argument whose
index is specified in this parameter. For example, the second
argument of an exponent has this value set to "1", so that when
the exponent is deleted, the base remains. |
mode |
string
|
<optional>
|
"math"
|
Change the mode of an
argument. Can be "text" (meaning the argument will be editable
as and rendered as plain text), "symbol" (meaning the argument
will specify a symbol name and will complete to an actual symbol
when this is entered--only used for the backslash symbol), or
"math" (the default) |
is_bracket |
string
|
<optional>
|
"no"
|
Set to "yes" if
the symbol is itself a bracket/parenthesis equivalent. |
|
|
template |
string
|
<optional>
|
The name of the template to use |
(static) init(config)
- Source:
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
| Name |
Type |
Attributes |
Default |
Description |
symbols |
Array.<string>
|
<optional>
|
|
A list of URLs for symbol JSON files to request |
path |
string
|
<optional>
|
"/lib/guppy"
|
The path to the guppy build folder. |
osk |
GuppyOSK
|
<optional>
|
|
A GuppyOSK object to use for the on-screen keyboard if one is desired |
events |
Object
|
<optional>
|
|
A dictionary of events
Properties
| Name |
Type |
Attributes |
Description |
ready |
function
|
<optional>
|
Called when the instance is ready to render things. |
change |
function
|
<optional>
|
Called when the editor's content changes. Argument will be a dictionary with keys old and new containing the old and new documents, respectively. |
left_end |
function
|
<optional>
|
Called when the cursor is at the left-most point and a command is received to move the cursor to the left (e.g., via the left arrow key). Argument will be null. |
left_end |
function
|
<optional>
|
Called when the cursor is at the right-most point and a command is received to move the cursor to the right (e.g., via the right arrow key). Argument will be null. |
done |
function
|
<optional>
|
Called when the enter key is pressed in the editor. |
completion |
function
|
<optional>
|
Called when the editor outputs tab completion
options. Argument is a dictionary with the key candidates, a
list of the options for tab-completion. |
debug |
function
|
<optional>
|
Called when the editor outputs some debug information.
Argument is a dictionary with the key message. |
error |
function
|
<optional>
|
Called when the editor receives an error. Argument is
a dictionary with the key message. |
focus |
function
|
<optional>
|
Called when the editor is focused or unfocused.
Argument will have a single key focused which will be true
or false according to whether the editor is newly focused or
newly unfocused (respectively). |
|
settings |
Object
|
<optional>
|
|
A dictionary of settings
Properties
| Name |
Type |
Attributes |
Default |
Description |
xml_content |
string
|
<optional>
|
<m><e/></m>
|
An XML
string with which to initialise the editor's state. |
autoreplace |
string
|
<optional>
|
"auto"
|
Determines
whether or not to autoreplace typed text with the corresponding
symbols when possible. |
blank_caret |
string
|
<optional>
|
""
|
A LaTeX string
that specifies what the caret should look like when in a blank
spot. If "", the default caret is used. |
empty_content |
string
|
<optional>
|
\color{red}{[?]}
|
A
LaTeX string that will be displayed when the editor is both
inactive and contains no content. |
blacklist |
Array.<string>
|
<optional>
|
[]
|
A list of string
symbol names, corresponding to symbols that should not be
allowed in this instance of the editor. |
buttons |
Array.<string>
|
<optional>
|
["osk","settings","symbols","controls"]
|
A list of strings corresponding to the helper buttons that should be displayed in the editor when focused. |
cliptype |
string
|
<optional>
|
|
A string, either
"text" or "latex". If this option is present, when text is
placed onto the editor clipboard, the contents of the editor
will be rendered into either plain text or LaTeX (depending on
the value of this option) and an attempt will be made to copy
the result to the system clipboard. |
|
callback |
function
|
<optional>
|
|
A function to be called when
initialisation is complete. |
|
(static) remove_global_symbol(name)
- Source:
Remove a symbol from all instances of the editor
Parameters:
| Name |
Type |
Description |
name |
string
|
The name of the symbol to remove |
activate()
- Source:
Focus this instance of the editor
asciimath()
- Source:
Get the content of the editor in AsciiMath.
deactivate()
- Source:
Unfocus this instance of the editor
doc()
- Source:
Get the Doc object representing the editor's contents.
equations()
- Source:
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)
- Source:
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, args, which is a list of the results of
evaluating that symbol's arguments. |
Returns:
- Whatever the
evaluators function for the root symbol
in the syntax tree returns.
func(evaluatorsopt) → {function}
- Source:
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, args, which is an array of that symbol's arguments,
and should return a function that takes in an object argument
vars. In this inner function, to compute e.g. the sum of the
first and second arguments, you would do
args[0](vars)+args[1](vars). This function should return the
result of that symbol's operation. |
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)
- Source:
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)
- Source:
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)
- Source:
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)
- Source:
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()
- Source:
Get the content of the editor as LaTeX
render(updatedopt)
- Source:
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)
- Source:
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()
- Source:
Get the content of the editor as a syntax tree, serialised using JSON
text()
- Source:
Get the content of the editor in a parseable text format.
vars()
- Source:
Get a list of the variable names used in the document.
xml()
- Source:
Get the content of the editor as XML