Question

Currently I use the math-software "Maple" from the command line, basically as a powerful calculator. I've written a simple maple "library" that contains my helper functions. I want to load it at maple startup time. (This task is almost equivalent to loading a .bashrc or .bash_profile file at startup of a shell).

How to do this in Maple? It is more complicated than expected, and poorly documented.

What I have right now is a compiled Maple lib in a Maple dir in my home directory.

On a maple shell/REPL I do this to load this file (and then the std lib):

libname := "/home/knut/.maple/12/mylibs", "/opt/maple12/lib";
with(knb_ee);

[argumentd, hz2rad, listPhasors, phase, phased, phasorTheta, phasorThetaSum, polard, proc1, proc2, rad2hz]

I want the two commands above executed at maple startup. HOw to do this? There is a .maple/12/ dir in my home dir, and there I find a file "maplerc" (this is not a dotfile). Is this the way to go?

Update: This description from vendor Maplesoft seems misleading to me, because there are no such directories as mentioned below:

UNIX and Linux

Under UNIX and Linux, the personal initialization file is called .mapleinit, and the global initialization file is called init. The commands in the initialization file will be executed by all users on the network by placing the file in the Maple lib directory, for example, $MAPLE/lib/init.

To execute a user's personal set of commands, the initialization file should be placed in the user's home directory under UNIX, for example, $HOME/.mapleinit.

Maple reads and executes the network initialization file before the personal initialization file.

http://www.maplesoft.com/support/help/Maple/view.aspx?path=worksheet/reference/initialization

Was it helpful?

Solution

Try creating /home/knut/.mapleinit as a new file, containing the commands you want executed.

You ought to already have a home directory for your Linux user account. You should be able to change directory to that location with a command such as,

cd ~

or,

cd $HOME

The last one uses the environment variable HOME, whose assigned value you might also check by issuing the command echo $HOME. From your post it seems that your home directory is /home/knut.

Anyway, the simplest way is to create a new file .mapleinit in your home directory, and place within that plaintext file the Maple commands you want executed automatically at start up.

That is why the documentation mentions it as $HOME/.mapleinit since that file would normally go in your home directory. That file will not exist until you create it manually. That is normal (for Maple).

Even when such an initialization file as ~/.mapleinit exists, you can still launch without it being utilized by passing the -s option to the maple script.

Or you can point to any other file of your choice as the initialization file by using the -i option. Eg,

maple -i somedirectory/somefile

Yet another way (slightly trickier if you have to escape quotes) is to use one of more instance of the -c option when calling the maple script. This is yet another way for you to issue several distinct commands at start up. In fact there are quite a few ways to accomplish your goals.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top