MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Shell script for editing mathematica input on Unix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13837] Shell script for editing mathematica input on Unix
  • From: Tobias Oed <tobias at physics.odu.edu>
  • Date: Sat, 29 Aug 1998 04:41:15 -0400
  • Organization: Old Dominion University
  • Sender: owner-wri-mathgroup at wolfram.com

Hello all,
	This is for those of you who do not like notebooks and run mathematica
in a terminal window. On the Unix machine I use,  it is impossible to
edit the input you type using the arrow keys  which is pretty anoying,
so I wrote this little shell script (bash) which you may like.

Some comments first:
-) on your system the bash code probably resides in another place than 
/opt/hppd/bin/bash, so you may have to edit the first line.

-) the input to mathematica goes through the named pipe
$HOME/Tmp/PipeToMath,
so you need the right to create named pipes (as far as I know, anybody
can do
this on HP and DEC Alpha machines) and create the Tmp directory. The
reason for 
this state of affairs is that in this way you can SEND STUFF TO
MATHEMATICA 
either by TYPING IN THE TERMINAL WINDOW (with editing possibilities -
arrow 
keys only, no history yet...) OR FROM SOMEWHERE ELSE, for example NEDIT
via 
KEY SHORT-CUTS.

-) The file .inputrc.math contains one single line to switch off the
completion 
feature of read -er (bind "set disable-completion on" does not work in
the script). 
This is it: 
set disable-completion on

-) mathematica runs in a loop so you can restart the kernel in a sane 
state by typing Quit. To exit the whole thing send an <EOF> character.
(Ctrl-D for standard terminal settings).

-) When you change the size of the window mathematica automatically
knows it.

-) I had to cheat a little around the input querry of mathematica, and
it's 
identation; it is not perfect and you will see the problem if you type
multiline
input... (starting mathematica with the option -batchoutup may be a walk
arround but then it complains on startup:" Cannot initialize Motif
graphics ",
but I don't know what this means ) 

Here is the shell anyway:

#!/opt/hppd/bin/bash
# Tobias Oed and Old Dominion University 1998  if [ ! -p
$HOME/Tmp/PipeToMath ]; then	
	mknod $HOME/Tmp/PipeToMath p
	while [ -p $HOME/Tmp/PipeToMath ]; do 
		 math -runfirst '$BatchInput=False;
			Unprotect[In]; 
			HoldPattern[Format[In[l_]]]:= ColumnForm[{
"=:======================",
			    StringForm["In[``]:=\n",l]}];
			Protect[In];
			SetOptions["stdout",PageWidth->'$(($COLUMNS-1))']'
<$HOME/Tmp/PipeToMath 
	done &
	echo $(tty) >$HOME/Tmp/PipeToMathTty
	(
		# Ignore ^C
		trap "" SIGINT
		# Let Mathematica know when the window size changes
		trap 'echo SetOptions[\"stdout\",PageWidth-\>$(($COLUMNS-1))]\;'
SIGWINCH
		# Disable Completion 
		INPUTRC=$HOME/.inputrc.math
		while read -er ; do
			echo "$REPLY"
		done
		rm $HOME/Tmp/PipeToMath
		rm $HOME/Tmp/PipeToMathTty
	) > $HOME/Tmp/PipeToMath
else
	echo "Another mathpipe is already running starting standard
mathematica"
	echo ""
	math
fi

hope some of you will enjoy it, Tobias


  • Prev by Date: Re: Animations on mathematica
  • Next by Date: C++ Builder for MathLink Programs
  • Previous by thread: Lissajous W (was Re: Looking for Contractor)
  • Next by thread: C++ Builder for MathLink Programs