DocumentTools[Canvas]
GetElements
extract elements from a canvas
Calling Sequence
Parameters
Description
Examples
Compatibility
GetElements(canvas)
GetElements(canvas, kind)
GetElements(canvas, options)
canvas
-
XML canvas string, or table
kind
(optional) one of the following strings or a set containing one or more of "math", "plot", "plot3d", "text", "checkbox", "button", "line", "state"
The GetElements command extracts the content from a canvas inserted by the ShowCanvas command, or Maple Learn canvas constructed by a command, or fetched by the GetCanvas command.
Note that ShowCanvas and button actions clicked in an active canvas will set the global variable, _canvas. If the first argument is omitted, the _canvas global is used. The returned list will contain Record structures describing the content. Each Record will have a type field, such that elem[i]:-type will return "math", "text", or other identifier. For elements that have their type member set to "math", there will be a math member containing the value. Similarly text elements will have a text member containing the value.
A "canvas" is an interactive section of a Maple document created by the NewCanvas command, or a shared web-based Maple Learn document. See the Script command for a more complete description.
When the keeptext=true option is given, the text content is returned in addition to the math. The default is to return only the math content.
When the keepall=true option is given, text and other content such as buttons are returned in addition to the math.
Empty math structures are normally pruned from the result. Use the keepempty=true option to retain these. Their math member will be set to the empty string, "".
When the inert=true option is specified, operators will remain in InertForm style. This prevents simplification, for example, returning `%+`(1,1) instead of 2.
When the mathmlonly=true option is specified, the record's math field will be set to NULL, but the mathml field will remain populated.
By default math markup such as overbar division, exponent superscripts and other "2D" elements in text will cause a retrieved text-field value to be delivered as MathML. Use textconvert=true to cause the MathML to be converted to a linear "1D" format.
When the custom=string option is specified, only elements that match the given custom attribute will be returned.
A filter={name=value} option can be used to specify arbitrary properties of any element. Only elements with the given named properties that also match the given values will be returned in the result.
When group=N is given, only elements that appear in the Nth group will be returned. In this context a group is a canvas group element with the first group starting at 1. You can also specify group as a range, eg. group=2..4. Leaving the end-point blank is a short-hand for beginning or end, as group=2.. will find all elements in groups 2 or bigger.
When contentgroup=N is given, only elements that appear with an id prefix of N will be returned. The first contentgroup is 0.
When id=X is given, only the element with the given id will be returned.
By default empty math inputs are excluded from the returned elements. To include empty elements set keepempty=true.
If position=[a,b] is given, where a and b are numbers or ranges, only elements in the given bounds will be returned.
Similar to the position option, you can provide the option exclude_column=N, where all elements with an x-position greater than N will be excluded.
Process a canvas from Maple Learn
In this section we will fetch a shared canvas from Maple Learn, and process it. This is similar to the processing that is done when clicking a button in Maple Learn.
with⁡DocumentTools:-Canvas:
url≔https://learn.maplesoft.com/?d=OULPGFDHIFNKDLJJGGMKJKNOARBJLHGRPOOKHKCQHPMFKMOTBFEHCUBUCQFNOGKSAMDOCUEFGMAJMQELFLEQEGOMETNULHFSCUGU:
cv≔GetCanvas⁡url:
seq⁡elemtype,elem=GetElements⁡cv
seq⁡elemtype,elem=GetElements⁡cv,keepempty
seq⁡`if`⁡elemtype=math,elemmath,elemtext,elem=GetElements⁡cv,math,text
seq⁡elemmath,elem=GetElements⁡cv,math,inert
Process an Active Canvas
In this section we create and show a canvas, then use the global variable _canvas to access the state.
cv≔NewCanvas⁡Another GetElements Example,ScriptButton⁡Check Your Page,DoNothing,position=500,50:
ShowCanvas⁡cv,input=`%+`⁡1,1,x2
av≔_canvas:
seq⁡elemtype,elem=GetElements⁡av
seq⁡elemmath,elem=GetElements⁡av,math,keepempty
seq⁡`if`⁡elemtype=math,elemmath,elemtext,elem=GetElements⁡av,math,text
seq⁡elemmath,elem=GetElements⁡av,math,inert
The DocumentTools[Canvas][GetElements] command was introduced in Maple 2022.
For more information on Maple 2022 changes, see Updates in Maple 2022.
The textconvert option was introduced in Maple 2023.
For more information on Maple 2023 changes, see Updates in Maple 2023.
See Also
Annotate
GetCanvas
Math
NewCanvas
Script
ShareCanvas
Text
Download Help Document