Application Center - Maplesoft

App Preview:

Using Embedded Components in Maple 11

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application



Using Embedded Components in Maple 11

Copyright Maplesoft, a division of Waterloo Maple Inc., 2007 


In Maple 11, Embedded Components have been updated and are easier to use.  This Tips and Techniques will introduce you to the new DocumentTools[Do] command, which  allows more user-friendly access to Embedded Components.   


Embedded Components are graphical interface components, such as clickable buttons, check boxes, and movable sliders. These are all available from the Components palette on the left side of the Maple 11 window. You can specify actions to be performed when a component is selected or changed; for example, moving a slider might update a plot.   


This Tips and Techniques assumes some familiarity with the basic concepts related to Embedded Components.  For a more general introduction, please read the previous Embedded Components Tips and Techniques. 


What is the Do Command? 

Previously, when using Embedded Components, the DocumentTools[GetProperty]and DocumentTools[SetProperty] commands were used to pass information between components.  For most intents these have been replaced by the DocumentTools[Do] command in Maple 11. 


For example, using the Do command you can create a Button component which when clicked will take information from one or more components, like an expression in a Mathematical Expression box; perform some operation such as plotting the expression or calculating its derivative; and display the result in another component like a Plot or Mathematical Expression, all in a single line. 


Inside a call to the Do command, you can extract information from, or store information to, an Embedded Component, simply by referring to that component's name. The component name is one of the component's properties, which you can set when you first insert the component into your document. Component values are accessed using  %name, which automatically refers to the value attribute of that component.  For instance, here is the code for a Button component which creates a plot when clicked: 


The code to perform these actions goes in the Action When Clicked section of the Button properties (or similar, for Slider components etc.). 


Alternate attributes can be specified using %name(attr). The following line of code assigns a list of 3 colors to the attribute itemList for a ComboBox component:
Embedded component


Tip: Some embedded components, like the Label, do not have a value attribute. To retrieve or set attributes on such components, an explicit attribute needs to be specified, e.g. %MyLabel(caption). 

Tip: When accessing Mathematical Expression components using the Do command, you no longer need to parse information using MathML commands; it is done for you automatically. 

Tip: Maple worksheets that use embedded components can also be used in slideshow mode.   


By default, when used to extract values, the Do command requires that the result is a valid Maple expression. It is possible to apply automatic type-checking to the result. It is also possible to avoid parsing the expression entirely, which is useful when the result is not expected to be a valid Maple expression (for example, a full file name).  


The help page for the Do command contains more detailed information. 


This is a live example.  Type in any mathematical expression into the box, and click the "Plot Expression" button.  Clicking the check box will also plot the derivative.  If you drag the slider back and forth, you will move the graph up and down. 


Embedded component 

Embedded component 


Plot ExpressionPlot DerivativeEmbedded component 

How does it work? 

The components used in this example are: 


  • Plot component - "PlotExpressions"

  • Button component

  • CheckBox component - "PlotDerivative"

  • Slider component - "ShiftExpression"

  • Mathematical Expression component - "MathExpression"


Tip:  Give meaningful names to components you will be referring to programmatically. Keep default names for those you won?t be referring to. 


You can right-click to look inside each component and find out how it works.  The "Plot Expression" button takes the value from the Mathematical Expression component and plots it.  

Do( %PlotExpressions = plot( %MathExpression, x=-5..5, y=-10..10 )); 


The command inside the Slider component simply adds the current value of the Slider component to the function being plotted. 

Do( %PlotExpressions = plot( %MathExpression + %ShiftExpression, x=-5..5, y=-10..10 )); 


Both of these components use an if statement, to decide whether to plot the derivative as well as the original component. 


plotA:= plot( Do(%MathExpression), x=-5..5, y=-10..10 );plotB:= plot( diff(Do(%MathExpression), x), x=-5..5, y=-10..10, color=blue );if (Do(%PlotDerivative) = false) 

 then  (Do( %PlotExpressions = plotA))  else  (Do( %PlotExpressions = plots[display](plotA, plotB) ))end if; 

Tip:  When entering component commands, some people prefer to delete all the comments at the top of the component code, to make their code easier to read. Be careful - don't delete the 1st and last lines:  "use DocumentTools in" and "end use;", as these lines tell the component that the commands between them are part of the DocumentTools package. 


Legal Notice: The copyright for this application is owned by Maplesoft. The application is intended to demonstrate the use of Maple to solve a particular problem. It has been made available for product evaluation purposes only and may not be used in any other context without the express permission of Maplesoft.