DocumentTools/Canvas/Script/Annotate - Maple Help

DocumentTools[Canvas][Script]

 Annotate
 script action to annotate math on a canvas

 Calling Sequence Annotate(script,caption) Annotate(script,caption,source)

Parameters

 script - DocumentTools:-Canvas:-Script object caption - string source - (optional) Math record

Description

 • The Annotate command adds message text next to math on a canvas.
 • 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.
 • The source option is an element of the array returned by GetMath.  It can be omitted if SetActive is used to specify the active math container prior to calling Annotate.

Examples

Demonstration Example

 • In this example, we will insert a canvas, get the math from the canvas, and manually add annotations to the math input.
 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Canvas}\right):$
 • create the canvas:
 > $\mathrm{cv}≔\mathrm{NewCanvas}\left(\left["Sample Canvas",x+y\right]\right):$
 > $\mathrm{ShowCanvas}\left(\mathrm{cv},'\mathrm{input}'=\left[\mathrm{box}\left[A\right],\mathrm{box}\left[B\right]\right]\right)$
 • get references to the math data in the canvas:
 > $\mathrm{data}≔\mathrm{GetMath}\left(\right):$
 • look at the math property of the first element:
 > $\mathrm{data}\left[1\right]:-\mathrm{math}$
 • create a script object and add some annotations
 > $\mathrm{sc}≔\mathrm{Script}\left(\right):$
 > $\mathrm{Annotate}\left(\mathrm{sc},"this is a sum",\mathrm{data}\left[1\right]\right)$
 > $\mathrm{Annotate}\left(\mathrm{sc},"this is box A",\mathrm{data}\left[2\right]\right)$
 • loop through all of the math and annotate each element with its type
 > $\mathbf{for}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{elem}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{data}\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}}\mathrm{Annotate}\left(\mathrm{sc},\left["This contains something of type",\mathrm{whattype}\left(\mathrm{elem}\left[\mathrm{math}\right]\right)\right],\mathrm{elem}\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}:$

Button Example

 • In this example, we will define an application that allows user input and provides feedback.  The FindPrimes procedure will run when a button is pressed.  It will find all the math in the canvas area, and add annotations to the inputs.
 > FindPrimes := proc( canvas )    uses DC=DocumentTools:-Canvas;    local script := DC:-Script();    for local m in DC:-GetMath(canvas) do  # get all the math in the canvas        SetActive(script,m);    # set the location of the annotation        if m:-math::integer and isprime(m:-math) then            Annotate(script,"Good job, this is prime");   # annotate based on the given math       else            Annotate(script,"This is not prime");       end if;   end do;   ToString(script); end proc:
 • Generate the canvas
 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Canvas}\right):$
 > $\mathrm{cv}≔\mathrm{NewCanvas}\left(\left["Write Some Prime Numbers Anywhere",\mathrm{ScriptButton}\left("Check Your Page",\mathrm{FindPrimes},\mathrm{position}=\left[500,50\right]\right)\right]\right):$
 • To test this within Maple, run:
 > $\mathrm{ShowCanvas}\left(\mathrm{cv}\right)$
 • To try this on the web using Maple Learn, execute:
 > $\mathrm{ShareCanvas}\left(\mathrm{cv}\right)$

Compatibility

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