DocumentTools/Canvas/Script/SetText - Maple Help

# Online Help

###### All Products    Maple    MapleSim

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

DocumentTools[Canvas][Script]

 SetText
 set the contents of a text canvas element

 Calling Sequence SetText(script,ex,options)

Parameters

 script - DocumentTools:-Canvas:-Script object text - a string or Canvas:-Text element insert - (optional) truefalse; default is false container - (optional) "group" or "textbox"; default is "group" where - (optional) "below", "right", "newgroup", or [nonnegint,nonnegint]

Description

 • The SetText command sets the contents of a text canvas element.  By default it will set the contents of the active container, or, when the where option is specified, a container at absolute coordinates or relative to the active container.
 • There are two kinds of components that can contain text as denoted by the container option.  A "group" is a collection of math and/or text in a column block.  A "textbox" is an element that can contain only text.  In Maple Learn a "textbox" does not have a visible group label, but it does take up a content id.
 • When the where option is set to "below", and the current active position is a group, the text 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 textbox, a new group will be created below before inserting the text.
 • 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 text will be inserted.  Note that currently only "group" style containers can be inserted to the "right".
 • The where="newgroup" option is similar to where="below" except the text will always be inserted into a new group created below the current group or text box.
 • The insert setting is described above and only applies to the situation where text 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.
 • Formatted text can be inserted by using the Canvas:-Text command.
 • 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 text 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 text
 > $\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{SetText}\left(\mathrm{sc},"Some text",'\mathrm{where}'="below"\right)$
 • change the text
 > $\mathrm{SetText}\left(\mathrm{sc},"revised text"\right)$
 • create a new group to the right
 > $\mathrm{SetText}\left(\mathrm{sc},"column 2",'\mathrm{where}'="right"\right)$
 • create a new row in the current group
 > $\mathrm{SetText}\left(\mathrm{sc},"more text",'\mathrm{where}'="below"\right)$
 • create a new group below
 > $\mathrm{SetText}\left(\mathrm{sc},"new group",'\mathrm{where}'="newgroup"\right)$
 • create a new textbox
 > $\mathrm{SetText}\left(\mathrm{sc},"textbox container",'\mathrm{where}'="below",\mathrm{container}="textbox"\right)$
 • set the active component back to the top of the column, and revise the next two captions
 > $\mathrm{SetActive}\left(\mathrm{sc},"2:0"\right)$
 > $\mathrm{SetText}\left(\mathrm{sc},"revised column 2"\right)$
 > $\mathrm{SetText}\left(\mathrm{sc},"revised more text",'\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)$

Mixed Math and Text

 • In this example, we will display paragraphs or titles that mix text and 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):$
 > $\mathrm{SetActive}\left(\mathrm{sc},"0:0"\right)$
 > $\mathrm{SetText}\left(\mathrm{sc},\mathrm{Text}\left("Mix %1 and %2",{x}^{2},{y}^{2}\right),'\mathrm{where}'="below"\right)$
 > $\mathrm{SetText}\left(\mathrm{sc},\mathrm{Text}\left("Apply %1 formatting",\mathrm{_BOLD}\left("bold"\right)\right),'\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)$

Compatibility

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

 See Also