DocumentTools/Canvas/Script/SetMath - Maple Help

# Online Help

###### All Products    Maple    MapleSim

Home : Support : Online Help : DocumentTools/Canvas/Script/SetMath

DocumentTools[Canvas][Script]

 SetMath
 set the contents of a math canvas element

 Calling Sequence SetMath(script,ex,options)

Parameters

 script - DocumentTools:-Canvas:-Script object ex - any math expression keepannotation - (optional) truefalse; default is true insert - (optional) truefalse; default is false where - "below", "right", or "newgroup"

Description

 • The SetMath command sets the contents of a math canvas element.  By default it will set the contents of the active container, or, when the where option is specified, a container relative to the active container.
 • When the where option is set to "below", and the current active position is a group, the math will be set at the next position within the group.  If something already occupies the next spot, it will be overwritten, unless the insert option is set to true, in which case the group contents will be bumped down to make room for the new expression.  If the active position is at the end of a group, a new area will be added to the group regardless of the insert option setting.  When the current position is a text area, a new group will be created below before inserting the math.
 • When the where option is set to "right", a new group will be created to the right of the active element, into which the given expression, ex will be inserted.
 • The where="newgroup" option is similar to where="below" except the math will always be inserted into a new group created below the current group or text area.
 • The keepannotation option controls whether or not an existing annotation in the current active component should be cleared when the math expression is set.
 • The insert setting is described above and only applies to the situation where math is being set "below" the active position of a group, and content already exists in the same group after that position.  When insert = true, room will be made to insert the new expression, as opposed to insert = false, where the behavior is to overwrite the expression that follows.
 Note: insert=true is not currently supported for script actions within a Maple worksheet, but does apply to Maple Learn deployed scripts.
 • 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.
 Note: the initial canvas in a Maple worksheet is created with a fixed size.  Inserting math may exceed that size, which will result in an error.  The ShowCanvas command has a size option that will let you create a size that will better fit your example.

Examples

One Command at a Time

 • In this example, we will insert a canvas and manually add math
 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Canvas}\right):$
 > $\mathrm{cv}≔\mathrm{NewCanvas}\left(\left["Blank Canvas"\right]\right):$
 > $\mathrm{ShowCanvas}\left(\mathrm{cv}\right)$
 > $\mathrm{sc}≔\mathrm{Script}\left(\right):$
 • make the title the active element
 > $\mathrm{SetActive}\left(\mathrm{sc},"0:0"\right)$
 • create a new group below
 > $\mathrm{SetMath}\left(\mathrm{sc},1,'\mathrm{where}'="below"\right)$
 • change the math in the active area
 > $\mathrm{SetMath}\left(\mathrm{sc},11\right)$
 • create a new group to the right
 > $\mathrm{SetMath}\left(\mathrm{sc},2,'\mathrm{where}'="right"\right)$
 • create a new row in the current group
 > $\mathrm{SetMath}\left(\mathrm{sc},3,'\mathrm{where}'="below"\right)$
 • create a new group below
 > $\mathrm{SetMath}\left(\mathrm{sc},4,'\mathrm{where}'="newgroup"\right)$
 • create a blank entry
 > $\mathrm{SetMath}\left(\mathrm{sc},"",'\mathrm{where}'="below"\right)$
 > $\mathrm{SetMath}\left(\mathrm{sc},6,'\mathrm{where}'="below"\right)$
 • recreate the whole example with all of the script steps attached so that it can be played back in Maple Learn
 > $\mathrm{cv2}≔\mathrm{NewCanvas}\left(\left["SetMath Example"\right],\mathrm{sc}\right):$
 > $\mathrm{ShareCanvas}\left(\mathrm{cv2}\right)$

Loop Example

 • In this example, we will display the Fibonacci sequence up to the value specified in the canvas.   This will be done using only 9 display areas, wrapping around to the beginning when the 9th box has been displayed.
 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Canvas}\right):$
 > $\mathrm{cv}≔\mathrm{NewCanvas}\left(\left[\left["Fibonacci Sequence to:",5000\right]\right]\right):$
 > $\mathrm{ShowCanvas}\left(\mathrm{cv}\right)$
 > $\mathrm{sc}≔\mathrm{Script}\left(\right):$
 > $\mathrm{data}≔\mathrm{GetMath}\left(\right):$
 • the starting point is the title text
 > $\mathrm{SetActive}\left(\mathrm{sc},"0:0"\right)$
 > $\mathbf{for}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}i\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{while}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\left(\mathrm{fib}≔\mathrm{combinat}:-\mathrm{fibonacci}\left(i\right)\right)<\mathrm{data}\left[1\right]:-\mathrm{math}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathbf{if}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}i<10\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{then}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{SetMath}\left(\mathrm{sc},\mathrm{fib},'\mathrm{where}'="below"\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathbf{else}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{SetActive}\left(\mathrm{sc},2,i\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}9\right);\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{SetMath}\left(\mathrm{sc},\mathrm{fib}\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{if};\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{Annotate}\left(\mathrm{sc},i\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}$
 • recreate the whole example with all of the script steps attached so that it can be played back in Maple Learn
 > $\mathrm{cv2}≔\mathrm{NewCanvas}\left(\left[\left["Fibonacci Sequence to",5000\right]\right],\mathrm{sc}\right):$
 > $\mathrm{ShareCanvas}\left(\mathrm{cv2}\right)$

Compatibility

 • The DocumentTools[Canvas][Script][SetMath] command was introduced in Maple 2021.
 • For more information on Maple 2021 changes, see Updates in Maple 2021.

 See Also