 Math - Maple Help

DocumentTools[Canvas]

 Math
 create a math structure with metadata Calling Sequence Math(expression) Math(expression, options) Parameters

 expression - anything Description

 • The Math command is used by GetMath when extracting math from a canvas.  It packages a math expression up into a record where it can be saved alongside other information relevant to the context of the canvas application, such as the id, position, and annotation.
 • It can also be useful to use the Math command when constructing a canvas that will later be deployed to Maple Learn, especially when a non-default property is needed to change the behavior and/or look of the math in the Maple Learn canvas.
 • When the position option is given, the math will be located at those [x,y] pixel coordinates on the canvas.
 • When the annotation option is given, the math will have a text message beside it on the canvas.
 • When the attributes option is used, those attributes will be added to the MathML [itex] tag.  Some such attributes can control the behavior and/or display of the expression when dispatched to Maple Learn via the ShareCanvas command.  Most often these attributes are ignored by ShowCanvas.  See the examples section for some examples of properties that are recognized.
 • When unwrap=true it is expected that the given input expression is a list, and should be extracted as the contents of the list.  This allows the math to be extracted to a sequence.
 • The background option can be set to a string or ColorTools:-Color object, and specifies the background color of the given math.
 • The color option can be set to a string or ColorTools:-Color object, and specifies the color of the given math.
 • The border option can be set to true in order for ShowCanvas to put a box border around the given expression.
 • The custom option puts a custom attribute on the math expression that is useful when using GetMath in a script to find a particular math expression.
 • The istext option indicates that this math expression should be considered as text (it will still render as Math, but the Maple Learn interface will put it in a group-text box).
 • Setting readonly=true option will prevent editing this expression in the Maple Learn interface.
 • Setting result=false will prevent display and calculation of the result value in the Maple Learn interface.
 • Setting slider=false will prevent display of a slider when the given expression is an assignment of the form &coloneq(name,value)
 • Setting plot=false will exclude this expression from the shared plot in the Maple Learn interface. Examples

 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Canvas}\right):$

The Math command simply returns a record detailing properties of the given expression.  A significant property is called "math", and can be accessed via the colon-dash syntax.

 > $m≔\mathrm{Math}\left(x+y\right)$
 ${m}{≔}{\mathrm{Record}}{}\left({\mathrm{position}}{=}{\mathrm{undefined}}{,}{\mathrm{mathml}}{=}{"x+y\left[/itex\right]"}{,}{\mathrm{border}}{=}{\mathrm{false}}{,}{\mathrm{math}}{=}{x}{+}{y}{,}{\mathrm{dependency}}{=}\left(\right){,}{\mathrm{box}}{=}{""}{,}{\mathrm{custom}}{=}{""}{,}{\mathrm{container}}{=}{"group"}{,}{\mathrm{gridpos}}{=}\left(\right){,}{\mathrm{readonly}}{=}{\mathrm{false}}{,}{\mathrm{result}}{=}{\mathrm{true}}{,}{\mathrm{plot}}{=}{\mathrm{true}}{,}{\mathrm{id}}{=}{36893628171580983388}{,}{\mathrm{xmlns}}{=}{"http://www.w3.org/1998/Math/MathML"}{,}{\mathrm{hascursor}}{=}{\mathrm{false}}{,}{\mathrm{istext}}{=}{\mathrm{false}}{,}{\mathrm{annotation}}{=}{""}{,}{\mathrm{groupnum}}{=}{-1}{,}{\mathrm{type}}{=}{"math"}\right)$ (1)
 > $m:-\mathrm{math}$
 ${x}{+}{y}$ (2)
 > $m:-\mathrm{mathml}$
 ${"x+y\left[/itex\right]"}$ (3)

The ShowCanvas command respects some of the properties, such as annotation and position:

 > $\mathrm{m2}≔\mathrm{Math}\left({x}_{2}+{y}_{2},\mathrm{position}=\left[600,100\right]\right):$
 > $\mathrm{ShowCanvas}\left(\mathrm{NewCanvas}\left(\left[\mathrm{m2}\right]\right)\right)$
 > $\mathrm{m3}≔\mathrm{Math}\left({x}_{3}+{y}_{3},\mathrm{annotation}="Example 3"\right):$
 > $\mathrm{ShowCanvas}\left(\mathrm{NewCanvas}\left(\left[\mathrm{m3}\right]\right)\right)$

Some tricks can be used to format the math, such as using InertForm to prevent automatic simplification.  Here Typesetting:-mspace() is also used to create a blank:

 > $\mathrm{m4}≔\mathrm{Math}\left(\mathrm{%+}\left(1,1\right)=\mathrm{Typesetting}:-\mathrm{mspace}\left(\right),\mathrm{readonly}=\mathrm{true}\right):$
 > $\mathrm{ShowCanvas}\left(\mathrm{NewCanvas}\left(\left[\mathrm{m4}\right]\right)\right)$

Incomplete expressions that cannot be represented as a Maple data structure can be written directly in MathML.  Here is an example that leaves the numerator of a fraction blank.

 > $\mathrm{m5}≔\mathrm{Math}\left("\left[itex\right]2\left[/itex\right]"\right):$
 > $\mathrm{ShowCanvas}\left(\mathrm{NewCanvas}\left(\left[\mathrm{m5}\right]\right)\right)$

Here are some other options, of which some of these control behavior that may only apply to the Maple Learn environment.

 > $\mathrm{cv6}≔\mathrm{NewCanvas}\left(\left[\mathrm{Group}\left(\left[\mathrm{Text}\left("Math Attributes:"\right),\mathrm{Math}\left(\mathrm{%+}\left(x,1,1\right)\right),\mathrm{Math}\left(\mathrm{%+}\left(x,1,1\right),\mathrm{readonly}=\mathrm{true},\mathrm{annotation}="Read-only"\right),\mathrm{Math}\left(\mathrm{%+}\left(x,1,1\right),\mathrm{result}=\mathrm{false},\mathrm{annotation}="Turn off computation result"\right),\mathrm{Math}\left(\mathrm{%+}\left(x,1\right),\mathrm{plot}=\mathrm{false},\mathrm{annotation}="Don\text{'}t plot"\right),\mathrm{Math}\left(\mathrm{%+}\left(x,1\right),\mathrm{istext}=\mathrm{true},\mathrm{annotation}="Text"\right),\mathrm{Math}\left(\mathrm{%+}\left(x,1\right),\mathrm{background}="red",\mathrm{annotation}="Background color"\right),\mathrm{Math}\left(\mathrm{%+}\left(x,1\right),\mathrm{color}="green",\mathrm{annotation}="Font color"\right)\right]\right)\right]\right):$
 > $\mathrm{ShareCanvas}\left(\mathrm{cv6}\right)$

When fetching a canvas from Maple Learn, the GetMath command calls Math(...) to create record structures.

 > $\mathrm{url}≔"https://learn.maplesoft.com/#/?d=OULPGFDHIFNKDLJJGGMKJKNOARBJLHGRPOOKHKCQHPMFKMOTBFEHCUBUCQFNOGKSAMDOCUEFGMAJMQELFLEQEGOMETNULHFSCUGU":$
 > $\mathrm{cv}≔\mathrm{GetCanvas}\left(\mathrm{url}\right):$
 > $M≔\mathrm{GetMath}\left(\mathrm{cv}\right):$
 > ${M}_{3}:-\mathrm{math}$
 > ${M}_{3}:-\mathrm{id}$
 > ${M}_{3}:-\mathrm{annotation}$
 > ${M}_{3}:-\mathrm{position}$ Compatibility

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