#! /bin/sh

# TeX/Mathematica installation shell script
# 12/23/1991 Dan Dill dan@chem.bu.edu

# Adapt the following definitions to your system, as described.



# === BEGINNING OF CONFIGURATION SECTION ===


# Edit the following directory names for your system.
# For the installation, you need write access to each of these directories.
#
# Where GNU Emacs looks for elisp files
#LISPDIR=/usr/local/emacs/lisp-local
LISPDIR=/usr8/dan/test/emacs/lisp
#
# Where GNU Emacs looks for Info files
#INFODIR=/usr/local/emacs/info
INFODIR=/usr8/dan/test/emacs/info
#
# Where TeX looks for files
#TEXDIR=/usr/local/lib/tex/inputs
TEXDIR=/usr8/dan/test/tex/inputs
#
# Where Mathematica looks for files
#PKGDIR=/usr/local/Mathematica-Packages
PKGDIR=/usr8/dan/test/math/Packages
#
# Where GNU Emacs can store temporary Mathematica files
PKGTMPDIR=/tmp
#
# Where UNIX looks for executable files (should be a part of your path)
#BINDIR=/usr/local/bin
BINDIR=/usr8/dan/test/bin


# Edit the following file names for your system
#
# Fully specified path to the shell script, typcially called `math', that
# the Mathematica install scripts install to startup Mathematica
#MATHFILE=/usr/local/bin/math
MATHFILE=/usr8/dan/test/bin/math
#
# Which awk to use in addBBox
#AWKFILE=awk
AWKFILE=gawk


# LaTeX version
#
NEWLATEX=yes
# Uncomment the following line if your LaTeX is dated *earlier* than 2 May 90.
#NEWLATEX=no


# Byte-compilation
#
BYTECOMPILE=yes
# Uncomment the following line if you do *not* want to byte-ecompile the
# TeX/Mathematica Emacs lisp files as part of the installation.  It is
# recommended that you *do* byte-compile the files.
#BYTECOMPILE=no


# Edit the read and execute protection masks for the TeX/Mathematica files
#
RMASK="ugo+r"
XMASK="ugo+rx"


# Various programs used by this script.  Modify, if necessary.
#
SED='/bin/sed'
CP='/bin/cp'
CHMOD='/bin/chmod'
EMACS='/usr/local/bin/emacs'
RM='/bin/rm'
#
LN='/bin/ln -s'
# Uncomment the following line if your system doesn't support symbolic links
#LN='/bin/cp'
#
# This assumes Bourne SHell builtin; might want to change to '/bin/echo'
ECHO='echo'


# After you have edited the definitions above for your system, save this file
# and execute it with
#
#       sh ./tex-mma-install 
#
# or
#
#	chmod +x tex-mma-install
#	./tex-mma-install


# === END OF CONFIGURATION SECTION ===



# You should not need to change things below this point.  Contact the
# author with any comments/questions/suggestions.


$ECHO "
Starting the TeX/Mathematica installation"


# Construct sed-sanitized versions of variables
SANITIZE="-e s/\//\\\\\//g"
BINDIRsed=`$ECHO $BINDIR | $SED $SANITIZE`
TEXDIRsed=`$ECHO $TEXDIR | $SED $SANITIZE`
LISPDIRsed=`$ECHO $LISPDIR | $SED $SANITIZE`
INFODIRsed=`$ECHO $INFODIR | $SED $SANITIZE`
PKGTMPDIRsed=`$ECHO $PKGTMPDIR | $SED $SANITIZE`
MATHFILEsed=`$ECHO $MATHFILE | $SED $SANITIZE`


# GNU Emacs files
$ECHO "
Installing files in $LISPDIR..."
# icky hack to make things look pretty later.. ;-}  (not really that bad)
files="\
	unix-tex-mma.el \
	tex-mma.el \
	math.el"
for file in $files
do
	$CP $file $LISPDIR/$file
	$CHMOD $RMASK $LISPDIR/$file
done
$SED -e "s/LISPDIR/$LISPDIRsed/g" tex-mma-compile.tmplt \
	> $LISPDIR/tex-mma-compile.el
# safety percaution
if [ "x$BYTECOMPILE" = "xyes" ]
then
	$ECHO "
Byte-compiling files in $LISPDIR.
This will take a few moments..."
	$EMACS -batch -l "$LISPDIR/tex-mma-compile.el" -f tex-mma-compile -kill
	$CHMOD $RMASK \
		$LISPDIR/unix-tex-mma.elc \
		$LISPDIR/tex-mma.elc \
		$LISPDIR/math.elc
else
	$ECHO "
The files

$files

have been placed in $LISPDIR but have not been byte-compiled.
Byte-compiling these files will improve the performance of TeX/Mathematica.
You can do so from within GNU Emacs with the command

	M-x byte-compile-file

for each each file, or for all all three files at once from the shell with the
commands

	cd $LISPDIR
	$EMACS -batch -l \"tex-mma-compile.el\" -f tex-mma-compile -kill
"
fi
#
#
$ECHO "
Installing file in $INFODIR..."
$CP tex-mma.info $INFODIR
$CHMOD $RMASK $INFODIR/tex-mma.info


# TeX files
$ECHO "
Installing files in $TEXDIR..."
$SED -e "s/TEXDIR/$TEXDIRsed/g" mathematica.tex.tmplt > $TEXDIR/mathematica.tex
$SED -e "s/TEXDIR/$TEXDIRsed/g" mathematicag.tex.tmplt > $TEXDIR/mathematicag.tex
$CHMOD $RMASK $TEXDIR/mathematica.tex $TEXDIR/mathematicag.tex
# Make local link here and then do a generic copy below
$RM mathematica.sty mathematicag.sty
if [ "x$NEWLATEX" = "xyes" ]
then
	$LN `pwd`/mathematica.sty.newlatex mathematica.sty
	$LN `pwd`/mathematicag.sty.newlatex mathematicag.sty
else
	$LN `pwd`/mathematica.sty.oldlatex mathematica.sty
	$LN `pwd`/mathematicag.sty.oldlatex mathematicag.sty
fi
files="\
	mathematica.sty \
	mathematica10pt.tex \
	mathematica12pt.tex \
	mathematicag.sty \
	mma-tex-mma.tex \
	mma.pro-2.0 \
	psfig.tex \
	unix-tex-mma.tex"
for file in $files
do
	$CP $file $TEXDIR/$file
	$CHMOD $RMASK $TEXDIR/$file
done
$RM $TEXDIR/psfig.sty
$LN $TEXDIR/psfig.tex $TEXDIR/psfig.sty


# Mathematica files
$ECHO "
Installing files in $PKGDIR..."
files="\
	PSFile.m \
	PSTeX.m \
	PSTeXpro.m"
for file in $files
do
        $CP $file $PKGDIR/$file
        $CHMOD $RMASK $PKGDIR/$file
done


# Scripts
#
# Package scripts
$ECHO "
Installing files in $BINDIR..."
$SED -e "s/BINDIR/$BINDIRsed/g" -e "s/LISPDIR/$LISPDIRsed/g" \
	tex-mma-assemble-package.tmplt > $BINDIR/tex-mma-assemble-package
$CHMOD $XMASK $BINDIR/tex-mma-assemble-package
$CP tex-mma-assemble-package.el.tmplt $BINDIR
$CHMOD $RMASK $BINDIR/tex-mma-assemble-package.el.tmplt
#
# Graphics scripts
$SED -e "s/AWKFILE/$AWKFILE/g" -e "s/BINDIR/$BINDIRsed/g" addBBoxpro.tmplt \
	> $BINDIR/addBBoxpro
$CHMOD $XMASK $BINDIR/addBBoxpro
$CP addBBox $BINDIR
$CHMOD $XMASK $BINDIR/addBBox
$CP addBBoxpro.awk $BINDIR
$CHMOD $RMASK $BINDIR/addBBoxpro.awk
#
# Graphics utilities
$SED -e "s/BINDIR/$BINDIRsed/g" tex-mma-convert.tmplt > $BINDIR/tex-mma-convert
$CP tex-mma-convert.sed $BINDIR
$CP tex-mma-compress $BINDIR
$CHMOD $XMASK \
	$BINDIR/tex-mma-compress \
	$BINDIR/tex-mma-convert \
	$BINDIR/tex-mma-convert.sed



# GNU Emacs initialization code
#$ECHO "
#Creating Emacs initialization code in tex-mma.emacs..."
$SED -e "s/INFODIR/$INFODIRsed/g" -e "s/PKGTMPDIR/$PKGTMPDIRsed/g" \
	-e "s/MATHFILE/$MATHFILEsed/g" tex-mma.emacs.tmplt > tex-mma.emacs


# Wrapup
$ECHO "

The TeX/Mathematica files have been installed.  To complete the installation,
you need to hand-edit two files, as follows:

	Place the contents of tex-mma.emacs in your Emacs default.el or init file.
	Place the contents of tex-mma.m in your Mathematica init.m file.

Once you have done this, TeX/Mathematica is ready to use: Startup Emacs,
run the command

	M-x latex-mathematica

(for example) and have fun!

Dan Dill
dan@chem.bu.edu
"
