Automatically load my own functions on startup
Modérateur : xcasadmin
Automatically load my own functions on startup
Is it possible to define my own functions in some file, and have it loaded automatically each time 'giac' or 'xcas' start?
Re: Automatically load my own functions on startup
Yes, add your commands in ~/.xcasrc Linux/Mac or in xcas.rc Windows (note that the file will be overwritten if you change and save your setup).
Re: Automatically load my own functions on startup
Thanks for replying.
I checked your solution. It works for 'giac' only (the console app), not for 'xcas' (the GUI app).
For example, I added ";myfunc(x):=x*666;" to ~/.xcasrc. 'giac' then recognizes "myfunc", but 'xcas' doesn't.
Is there a solution that works for 'xcas' as well?
For reference, here's the content of my ~/.xcasrc (note the last line):
(I'm using xcas 1.2.3, which comes with Ubuntu 18.04.)
I checked your solution. It works for 'giac' only (the console app), not for 'xcas' (the GUI app).
For example, I added ";myfunc(x):=x*666;" to ~/.xcasrc. 'giac' then recognizes "myfunc", but 'xcas' doesn't.
Is there a solution that works for 'xcas' as well?
For reference, here's the content of my ~/.xcasrc (note the last line):
Code : Tout sélectionner
widget_size([0,14,40,10],1,25,1278,977,1,2,0,[56,255,60,255,58,255,216,255,56,255,49],"/usr/bin/firefox",0,0,"","");
cas_setup(0,0,0,1,0,[1e-12,1e-15],12,[2,100,0,25],0,1,0,1),xcas_mode(0);
xyztrange([-10.0,10.0,-10.0,10.0,-10.0,10.0,-10.0,10.0,-10.0,10.0,-1.4,1.1,1,0.0,1.0,3]);
autosimplify(regroup);
myfunc(x):=x*666;
Re: Automatically load my own functions on startup
Indeed, the xcasrc file is executed in the null context, not in the session context.
The best is perhaps to run read("script_filename") in the first level of your xcas session when you start a new file. When you load an existing worksheet, all variables are restored, you don't need to re-parse them.
The best is perhaps to run read("script_filename") in the first level of your xcas session when you start a new file. When you load an existing worksheet, all variables are restored, you don't need to re-parse them.
-
- Messages : 145
- Inscription : mer. janv. 13, 2010 3:20 pm
Re: Automatically load my own functions on startup
I did this by using the following:
I modified runxcas.en to:
#! /bin/bash
export LANG=en
export XCAS_ROOT='/cygdrive/C/Programs_OS/xcas'
# export XCAS_HOME='/cygdrive/p'
# export XCAS_AUTOSAVEFOLDER='/cygdrive/p'
export XCAS_LOCALE="$XCAS_ROOT/locale/"
export XCAS_HELP="$XCAS_ROOT/aide_cas"
cp /cygdrive/C/Programs_OS/xcas/eq_funcs_template.xws /cygdrive/C/Programs_OS/xcas/eq_funcs.xws
if [ "$1" == "" ]
then
$XCAS_ROOT/xcas.exe /cygdrive/C/Programs_OS/xcas/eq_funcs.xws
else
$XCAS_ROOT/xcas.exe /cygdrive/C/Programs_OS/xcas/eq_funcs.xws "$1"
fi
Note, I created a template called eq_funcs_template.xws with all my functions loaded in it. That file is in C:\Programs_OS\xcas. That template gets copied into eq_funcs.xws and opened in the last if statement. If I double click a xws file it opens it and the "template file". That way I always have a fresh file to work on that has all my functions.
I also modified xcasen.bat to include C:\Programs_OS\xcas in the PATH:
set PATH=C:\Programs_OS\xcas;%PATH%
bash.exe '/cygdrive/C/Programs_OS/xcas/runxcas.en' %1
hope it works for you. Since you are running Linux, maybe xcasen.bat isn't necessary.
I modified runxcas.en to:
#! /bin/bash
export LANG=en
export XCAS_ROOT='/cygdrive/C/Programs_OS/xcas'
# export XCAS_HOME='/cygdrive/p'
# export XCAS_AUTOSAVEFOLDER='/cygdrive/p'
export XCAS_LOCALE="$XCAS_ROOT/locale/"
export XCAS_HELP="$XCAS_ROOT/aide_cas"
cp /cygdrive/C/Programs_OS/xcas/eq_funcs_template.xws /cygdrive/C/Programs_OS/xcas/eq_funcs.xws
if [ "$1" == "" ]
then
$XCAS_ROOT/xcas.exe /cygdrive/C/Programs_OS/xcas/eq_funcs.xws
else
$XCAS_ROOT/xcas.exe /cygdrive/C/Programs_OS/xcas/eq_funcs.xws "$1"
fi
Note, I created a template called eq_funcs_template.xws with all my functions loaded in it. That file is in C:\Programs_OS\xcas. That template gets copied into eq_funcs.xws and opened in the last if statement. If I double click a xws file it opens it and the "template file". That way I always have a fresh file to work on that has all my functions.
I also modified xcasen.bat to include C:\Programs_OS\xcas in the PATH:
set PATH=C:\Programs_OS\xcas;%PATH%
bash.exe '/cygdrive/C/Programs_OS/xcas/runxcas.en' %1
hope it works for you. Since you are running Linux, maybe xcasen.bat isn't necessary.
Re: Automatically load my own functions on startup
Thanks. I considered this solution, but it's flawed for me: I usually launch xcas from the directory I work in, as I want xcas to save the file to the diretcory I'm in, without me navigating there. But if I load it with a template file, it will default to the template file's direcotry. Besides, I wouldn't be able to save the file just by pressing Control-S but will have to use the mouse (for "save as").XcasEngGuy a écrit : ↑lun. juin 03, 2019 10:41 pmI did this by using the following:
I modified runxcas.en to:
BTW, in your script you can replace the 'if' statement with:
$XCAS_ROOT/xcas.exe /cygdrive/C/Programs_OS/xcas/eq_funcs.xws "$@"
(I.e., use $@ instead of $1 or null).
-
- Messages : 145
- Inscription : mer. janv. 13, 2010 3:20 pm
Re: Automatically load my own functions on startup
add:
cd "$(dirname "$@")"
cp /cygdrive/C/Programs_OS/xcas/eq_funcs_template.xws eq_funcs.xws
$XCAS_ROOT/xcas.exe eq_funcs.xws "$@"
puts the template in the same directory as the file you open.
cd "$(dirname "$@")"
cp /cygdrive/C/Programs_OS/xcas/eq_funcs_template.xws eq_funcs.xws
$XCAS_ROOT/xcas.exe eq_funcs.xws "$@"
puts the template in the same directory as the file you open.