Programmatic Content Generation - Maple Programming Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : System : Information : Updates : Maple 2015 : updates/Maple2015/ContentGeneration

Programmatic Content Generation

New subpackages and commands within the DocumentTools package now allow fully programmatic functionality to create and make use of Worksheet and Document content, including:


Customized Tables


Applications containing Embedded Components and Code Edit Regions


Sections and subsections, Document Blocks and Execution Groups, customized text, and input and output


Insertion into the current document, and launching or saving as a new document


This functionality is already in use by several other Maple commands, including Explore, ImageTools:-Embed, and the new Tabulate command.



Layout elements

Embedded Components and application authoring

The Tabulate command

Layout elements


The DocumentTools:-Layout subpackage contains commands for constructing basic elements of a Document or Worksheet.


Commands currently available and documented are as indicated by the following command to load the subpackage:






These commands can be used to construct a structure of nested Maple function calls which comprise an XML format representation of a complete Document or Worksheet. The resulting document content can be inserted, launched, or saved.


The following is a simple example of construction and insertion of such content. This example uses the constructor commands Worksheet, Table, Row, Textfield, and Equation.

E1:=Equation'i=1ni',style=TwoDimInput:E2Equationfactori=1ni,style=TwoDimInput,typesetting=extended:TTextfieldThe sum of the first n positive integers ,E1, is equal to ,E2,alignment=centered:xmlWorksheetTableRowT,alignment=center,width=50:


The InsertContent command can be used to insert this content directly into the current document.



The sum of the first n positive integers i=1ni is equal to nn+12

Embedded Components and application authoring


The DocumentTools:-Components subpackage contains commands for constructing Embedded Components as content.






An interactive application can be completely programmatically constructed as content.

The following example consists of constructing a Plot and a Button component, each with their own action code. Each time the mouse cursor is clicked within the Plot component a new data point is added to the list assigned to the global name L, and a least squares linear fit of this data is plotted. Clicking on the Button clears the plot.

The application is inserted into the current document for this first example. This example uses the commands Plot and Button to construct the components' contents.

This example also uses two procedures, update and clear, which must be defined (and left as defined) for the inserted application to function. These procedures are called whenever the respective components are clicked.


update:=proccomp     local cx,cy,v;     global L;         use DocumentTools, plots, CurveFitting incx,cy:=Docompclickx,Docompclicky;iftypeL,listlistthenL:=L,cx,cyelseL:=cx,cyend if;Docomp=displayplotL,style=point,symbol=solidcircle,symbolsize=15,color=blue,axes=normal,plotLeastSquaresL,v,v=0..10,view=0..10,0..10;         end use:end proc:

clear:=proccomp     DocumentTools:-Docomp=plot0,0,color=white,axes=normal,view=0..10,0..10end proc:


Next, the two components are constructed. Their respective action code, executed whenever the components are clicked upon, call the aforementioned procedures.

P:=Plotplot0,0,color=white,axes=normal,view=0..10,0..10,identity=Plot0,clickdefault,clickaction=update(%Plot0);:B:=ButtonClear,identity=Button0,action=unassign(':-L'); clear(%Plot0);:


The content construction is then completed, forming a full worksheet in XML representation. Next, this is inserted into the current worksheet.



In the second example, the same application is regenerated, but now the defining of the supporting procedures update and clear is done within the constructed application itself. This allows the application to function even if it is launched or saved as a new worksheet.


In the following revision, the procedure definitions are part of the action code of the two components. An alternative approach is to put those procedure definitions into a Code Edit Region constructed as an additional part of the content.


P2:=Plotplot0,0,color=white,axes=normal,view=0..10,0..10,                       identity=Plot0,clickdefault,                       clickaction=catsprintfupdate:=%a;,evalupdate,update(%Plot0);:

B2ButtonClear,identity=Button0,                               action=catsprintfclear:=%a;,evalclear,unassign(':-L'); clear(%Plot0);:



The ContentToString command is used to create a text string of an actual worksheet. This string can be launched directly in a new window, or saved as a worksheet file.




This worksheet string can be launched directly in a new window using the Display command from the Worksheet package. In such a new window,the application functions independently of any definitions inside the current worksheet.

The following invocation uses the global name syntax :-Worksheet in order to reference the package by that name rather than the export by that same name in the previously loaded Layout package.




The test string of the worksheet can also be saved as a worksheet file.



The saved file is an application that functions independently of any definitions made in the current worksheet.


The Tabulate command


The Tabulate command allows indexed structures, such as lists, Vectors, Matrices, or Arrays to be formatted with their elements becoming the entries in the cells of an inserted Table GUI element.