I'm in the process of manipulating Maple worksheets (both Classic .mws and Standard .mw formats) blindly from the command line. There are a surprising number of stumbling blocks in Maple that make this work difficult. While I've managed to worm my way around them one by one, I thought I'd take some time to just voice my frustration so that others are aware of these pitfalls.
I should note that I am using Maple 10.02 on a Gentoo Linux machine, feeding my commands into Maple through a standard pipe. I would update to Maple 10.04, but the updater program from the website continues to cause problems with Java. Another complaint? That might as well be...
1) "use" apparently does not like "if" statements.
This is what I was using:
use StringTools in
use XMLTools in
if IsElement(child) then
---stuff that uses StringTools commands---
elif IsText(child) then
end use:end use:
And each time Maple would reach the "elif" statement, it would seem to have forgotten that it was using XMLTools and be unable to evaluate the IsText() statement.
2) The Worksheet and XMLTools packages are fundamentally different and do not play well together.
This rather vague complaint has manifested itself in a number of different ways. For example: I open a worksheet and store it in a variable using var:=Worksheet[ReadFile](), then add pieces to the worksheet using var:=XMLTools:-AddChild(), then I want to save the file. I can't save the worksheet data in var by simply using Worksheet[WriteFile](filename,var) because it has been edited using commands from XMLTools. I cannot use Worksheet[ToString](var) to convert the worksheet information in var to a string for the same reason. If I save the file using Worksheet[WriteFile](filename,XMLTools:-ToString(var)), then I receive an error message when I open the file. All my information is there, but Maple still says that the worksheet may be incomplete.
If, instead of Worksheet[WriteFile](), I were to use XMLTools:-PrintToFile(), I get different results. Sometimes the file will be written but will produce an error and fail to open when I try to open it in Maple. Other times, when the file opens successfully, my text has been brutalized: If I have a text field of varying styles, fonts, highlights, and colors, along with 2-D Math markup, the file produced by XMLTools:-PrintToFile() linebreaks between each change in style. For example, if I had the sentence
"I would like to <u>COLOR</u> every integral"
in some text field in a worksheet, XMLTools:-PrintToFile() would produce a worksheet that had the line
"I would like to
I have not yet found any consistent reason as to why XMLTools:-PrintToFile() will write files which will not open.
I believe that the important difference between the Worksheet and XMLTools packages lies in the fact that the elements produced from XMLTools are (apparently) inert, and Worksheet doesn't like that. For an example, find a file that has a blank line of XMLText at the end (any file should do), and do this:
doc:=XMLTools:-AddChild(doc,XMLText(" \n"), XMLTools:-ContentModelCount(doc)):
c1, the line added using XMLTools commands, is inert, whereas c2, the line that was in the file read with Worksheet commands, is not. Since these two packages share so many capabilities, why can they not simply work together without hassle?
To get my worksheets to save correctly, I currently use the command Worksheet[WriteFile](filename, Worksheet[FromString]( XMLTools:-ToString( doc ) ) ):
Before I leave the topic of XMLTools, let me also express my disappointment with the XMLTools:-CleanXML() command. In the situation I described above concerning XMLTools:-PrintToFile(), XMLTools:-CleanXML() will remove the spaces immediately surrounding the different texts. So, the output from XMLTools:-CleanXML() would contain the line "I would like to<u>COLOR</u>every integral." These are not spaces which should be cleaned away.
3) Inconsistancies in storage methods.
2-D Math markup in a worksheet file is stored in a 64 bit encoding of Maple's proprietary .m storage format. If I have a 2-D Math object in a worksheet (e.g. the variable name A_PLACEHOLDER), I can search through all the XML children until I find the string of characters which represents it, decode that string, convert it from Maple's .m storage format, and then I'm stuck. I will have a string with a lot of commands from the Typesetting package. Normally, Maple can parse these commands no sweat; however, Maple's .m storage format makes no distinction between local and global names. The functions in this string are global function names which Maple will not parse. This can be overcome with a massive series of subs() commands to substitute local function names for the global names which are not yet documented in Maple's help files.
I said before that I am editing these files blindly; I do not have the ability to search through each worksheet individually to find the exact location of every placeholder. If I know that there is a name A_PLACEHOLDER in 2-D Math markup in a worksheet, I should be able to take the string "A_PLACEHOLDER," typeset it, convert it to Maple's .m storage format, encode it as base 64, and then match that string to the string in the worksheet which I seek to modify. Unfortunately, the two strings are different. I can only assume this is because of the difference in local and global function names. I do not know if this can be fixed by any number of substitutions, but I do know that this makes editing content in a worksheet almost more trouble than its worth.
I'm probably forgetting a few things, but those are my three biggest problem areas.