MathGroup Archive 1998

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

Search the Archive

Shell script for editing mathematica input on Unix

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

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
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
either by TYPING IN THE TERMINAL WINDOW (with editing possibilities -
keys only, no history yet...) OR FROM SOMEWHERE ELSE, for example NEDIT

-) The file .inputrc.math contains one single line to switch off the
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
identation; it is not perfect and you will see the problem if you type
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:

# 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;
			HoldPattern[Format[In[l_]]]:= ColumnForm[{
	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))]\;'
		# Disable Completion 
		while read -er ; do
			echo "$REPLY"
		rm $HOME/Tmp/PipeToMath
		rm $HOME/Tmp/PipeToMathTty
	) > $HOME/Tmp/PipeToMath
	echo "Another mathpipe is already running starting standard
	echo ""

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