 DocumentTools/Canvas/GetMath - Maple Help

DocumentTools[Canvas]

 GetMath
 extract math from a canvas Calling Sequence GetMath(canvas) GetMath(canvas, options) Parameters

 canvas - XML canvas string, or table Description

 • 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 like 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. Examples 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.
 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Canvas}\right):$
 > $\mathrm{url}≔"https://learn.maplesoft.com/beta/index.html#/?d=OULPGFDHIFNKDLJJGGMKJKNOARBJLHGRPOOKHKCQHPMFKMOTBFEHCUBUCQFNOGKSAMDOCUEFGMAJMQELFLEQEGOMETNULHFSCUGU":$
 > $\mathrm{cv}≔\mathrm{GetCanvas}\left(\mathrm{url}\right):$
 > $\mathrm{seq}\left(\mathrm{elem}\left[\mathrm{math}\right],\mathrm{elem}=\mathrm{GetMath}\left(\mathrm{cv}\right)\right)$
 > $\mathrm{seq}\left(\left[\mathrm{elem}\left[\mathrm{math}\right]\right],\mathrm{elem}=\mathrm{GetMath}\left(\mathrm{cv},'\mathrm{keepempty}'\right)\right)$
 > $\mathrm{seq}\left(\mathrm{if}\left(\mathrm{elem}\left[\mathrm{type}\right]="math",\mathrm{elem}\left[\mathrm{math}\right],\mathrm{elem}\left[\mathrm{text}\right]\right),\mathrm{elem}=\mathrm{GetMath}\left(\mathrm{cv},'\mathrm{keeptext}'\right)\right)$
 > $\mathrm{seq}\left(\mathrm{elem}\left[\mathrm{math}\right],\mathrm{elem}=\mathrm{GetMath}\left(\mathrm{cv},'\mathrm{inert}'\right)\right)$ Process an Active Canvas

 • In this section we create and show a canvas, then use the global variable, canvas to access the state.
 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Canvas}\right):$
 > $\mathrm{cv}≔\mathrm{NewCanvas}\left(\left["Another GetMath Example",\mathrm{ScriptButton}\left("Check Your Page",\mathrm{DoNothing},\mathrm{position}=\left[500,50\right]\right)\right]\right):$
 > $\mathrm{ShowCanvas}\left(\mathrm{cv},\mathrm{input}=\left[\mathrm{%+}\left(1,1\right),{x}^{2}\right]\right)$
 > $\mathrm{av}≔\mathrm{_canvas}:$
 > $\mathrm{seq}\left(\mathrm{elem}\left[\mathrm{math}\right],\mathrm{elem}=\mathrm{GetMath}\left(\mathrm{av}\right)\right)$
 > $\mathrm{seq}\left(\left[\mathrm{elem}\left[\mathrm{math}\right]\right],\mathrm{elem}=\mathrm{GetMath}\left(\mathrm{av},'\mathrm{keepempty}'\right)\right)$
 > $\mathrm{seq}\left(\mathrm{if}\left(\mathrm{elem}\left[\mathrm{type}\right]="math",\mathrm{elem}\left[\mathrm{math}\right],\mathrm{elem}\left[\mathrm{text}\right]\right),\mathrm{elem}=\mathrm{GetMath}\left(\mathrm{av},'\mathrm{keeptext}'\right)\right)$
 > $\mathrm{seq}\left(\mathrm{elem}\left[\mathrm{math}\right],\mathrm{elem}=\mathrm{GetMath}\left(\mathrm{av},'\mathrm{inert}'\right)\right)$ Compatibility

 • The DocumentTools[Canvas][GetMath] command was introduced in Maple 2021.