DocumentTools[Canvas]
GetMath
extract math from a canvas
Calling Sequence
Parameters
Description
Examples
Compatibility
GetMath(canvas)
GetMath(canvas, options)
canvas
-
XML canvas string, or table
The GetMath 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 will be 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.
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⁡elemmath,elem=GetMath⁡cv
seq⁡elemmath,elem=GetMath⁡cv,keepempty
seq⁡`if`⁡elemtype=math,elemmath,elemtext,elem=GetMath⁡cv,keeptext
seq⁡elemmath,elem=GetMath⁡cv,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 GetMath Example,ScriptButton⁡Check Your Page,DoNothing,position=500,50:
ShowCanvas⁡cv,input=`%+`⁡1,1,x2
av≔_canvas:
seq⁡elemmath,elem=GetMath⁡av
seq⁡elemmath,elem=GetMath⁡av,keepempty
seq⁡`if`⁡elemtype=math,elemmath,elemtext,elem=GetMath⁡av,keeptext
seq⁡elemmath,elem=GetMath⁡av,inert
The DocumentTools[Canvas][GetMath] command was introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
See Also
Annotate
GetCanvas
Math
NewCanvas
Script
ShareCanvas
Text
Download Help Document