Advice: Worksheets and Command-line Maple

Worksheets (.mws files) are intended for use in Maple's worksheet (graphical) interface, not in the command-line (text) version of Maple. However, in Maple 6 the makehelp command allows .mws files to be displayed in command-line Maple. Using this and a bit of system-level programming, we can take a .mws file and extract its input regions (commands) into a text file, or run those commands directly in command-line Maple. Once it is set up, the DOS or Unix command

execmws myfile.mws

will run command-line Maple on the commands in the worksheet file "myfile.mws" and show the commands and their outputs. If you use

execmws myfile.mws -q

you will see only the outputs, omitting the commands, Maple's startup
message, etc. If you use

execmws myfile.mws outfile.txt

the commands will be placed into the file "outfile.txt" rather than being run.

There is no way (as far as I know) to create a worksheet file with command-line Maple. However, that should not be necessary: you can work with text files instead.

Unix setup

In Unix, put the script file " execmws" into a directory on your command path, with "execute" permission set. This script uses the "awk" programming language, which is included in most Unix installations. It assumes that the command you use for command-line Maple is "maple".

If the command name is different, you can edit the script to change it.

For convenience, the following Maple code will produce the script file, and set its execute permission. It will be written into the current directory: if that is not where you want it, you can insert the directory name before execmws in the next command. Of course, you must have write permission in this directory.

> fname:= "execmws";

fname :=

> fprintf(fname,"#!/bin/sh\n# Save this file as text, using the name execmws,\n# in a directory on your command path. Set the \n# file's permissions so you can execute it.\n#\n# This finds the path to command-line Maple. \n# If the path below is not right, edit it\nMaple=/usr/local/maple/bin/maple\n#\nif [ -x $Maple ]\nthen \n# found it successfully\n :\nelif [ `type -type maple` ]\n# this will work if it's on the path \nthen\n Maple=`type -path maple`\nelif [ -x /usr/bin/maple ]\n# try some other possibilities\nthen\n Maple=/usr/bin/maple\nelif [ -x /usr/local/bin/maple ]\nthen\n Maple=/usr/local/bin/maple\nelif [ -x ~/bin/maple ]\nthen\n Maple=~/bin/maple\nelse\n echo Where is maple? Edit the file execmws to supply the path.\n exit\nfi\n\ncase \"z$2\" in\n z-q)\n echo 'readlib(makehelp)(foo,`'$1'`);' | $Maple -q | \n awk '/^>/ {print substr($0,2)}' | $Maple $2\n ;;\n z)\n echo 'readlib(makehelp)(foo,`'$1'`);' | $Maple -q | \n awk '/^>/ {print substr($0,2)}' | $Maple $2\n ;;\n * )\n echo 'readlib(makehelp)(foo,`'$1'`);' | $Maple -q | \n awk '/^>/ {print substr($0,2)}' > $2\n ;;\nesac\n\n");
fclose(fname);
system("chmod 755 "||fname);

1064

0

Windows setup

In Windows, use the file " execmws.bat", and run it in a DOS window. You will also need the "awk" programming language. Shareware versions of awk for DOS are available at http://www.simtel.net. Execmws.bat assumes that the command you use for command-line Maple is "cmaple", and for awk is "awk". If these are not right, or if the files cmaple.exe and awk.exe are not on the command path, you'll need to edit the file execmws.bat and insert the appropriate path before each cmaple and awk.

If you are not sure what your command path is, the following Maple code will display it.

> S:= ssystem("path")[2]:
printf(S);

For convenience, the following Maple code will produce the script file, and set its execute permission. It will be written into the current directory: if that is not where you want it, you can insert the directory name before execmws in the next command. Be sure to use "/" or "\\" rather than "\" in directory names.

> fname:= "execmws.bat";

fname :=

> fprintf(fname,"%s","@echo off\nif \"%2\"==\"-q\" goto one\nif \"%2\"==\"\" goto one\necho readlib(makehelp)(foo,`%1`); |cmaple -q | awk \"/^>/ {print substr($0,2)}\" > %2\ngoto end\n:one \necho readlib(makehelp)(foo,`%1`); |cmaple -q | awk \"/^>/ {print substr($0,2)}\" | cmaple %2\n:end");
fclose(fname);

248

See also: makehelp , Maple

Maple Advisor Database, R. Israel 1999