#! /bin/sh
######################################
##### Model Transformation Tools #####
######################################
# Bourne shell script: latex_tidy
# Tidies up LaTex format files
# P.J.Gawthrop 12 June 1990, Dec 1994
# Copyright (c) P.J.Gawthrop, 1990, 1994
###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.14 1998/02/25 22:12:07 peterg
## Added , to regexp for subscripts
##
## Revision 1.13 1998/02/18 09:06:07 peterg
## Added dX0
##
## Revision 1.12 1998/02/09 14:11:08 peterg
## Added ctf --> D(s)
##
## Revision 1.11 1998/01/30 15:15:14 peterg
## Sorted out superscript problem
##
# Revision 1.10 1997/08/19 10:38:26 peterg
# Added pi to the list
#
## Revision 1.9 1997/02/24 13:02:17 peterg
## Added gamma and delta transformations
##
## Revision 1.8 1996/12/31 16:14:53 peterg
## Now handles multi-character subscripts.
##
## Revision 1.7 1996/12/19 10:24:29 peterg
## Uniform conversion of mttxi --> x_{i} for x,u,y and z
## Convert ???mttx to mtt x for x,u,y and z
##
## Revision 1.6 1996/12/12 16:03:19 peterg
## Removed global argument stuff for y - its already done in the
## translation.
##
## Revision 1.5 1996/12/12 15:59:06 peterg
## Generic handling of subscript for y,u,ui
##
## Revision 1.4 1996/12/12 15:54:20 peterg
## Saved it.
##
## Revision 1.3 1996/08/30 14:36:46 peter
## Added some more subscripts.
## -- its high time this was rewritten in awk or perl!!!
##
## Revision 1.2 1996/08/19 14:35:51 peter
## Prettyfied z dot.
##
## Revision 1.1 1996/08/18 20:03:12 peter
## Initial revision
##
###############################################################
cat $1 | \
tr "[A-Z]" "[a-z]" | \
sed \
-e "s/_\([a-z0-9,]*\)/_{\1}/g" \
-e "s/\// \\\over /g" \
-e "s/[0-9a-z_]*mtty/mtty/g" \
-e "s/[0-9a-z_]*mttu/mttu/g" \
-e "s/mttx\([0-9]*\)/x_{\1}/g" \
-e "s/mttex\([0-9]*\)/\\\chi_{\1}/g" \
-e "s/mttui\([0-9]*\)/v_{\1}/g" \
-e "s/mttu\([0-9]*\)/u_{\1}/g" \
-e "s/mtty\([0-9]*\)/y_{\1}/g" \
-e "s/mttz\([0-9]*\)/z_{\1}/g" \
-e "s/mttdx0/\\\dot x_0/g" \
-e "s/mttdx/\\\dot x/g" \
-e "s/mttdz/\\\dot z_/g" \
-e "s/mttdu/\\\dot u_/g" \
-e "s/dot_/ \\\dot /g" \
-e "s/mtttf/G(s)/g" \
-e "s/mttctf/D(s)/g" \
-e "s/mtta/A/g" \
-e "s/mttb/B/g" \
-e "s/mttc/C/g" \
-e "s/mttd/D/g" \
-e "s/mtte/E/g" \
-e "s/mttg/G/g" \
-e "s/mtti/I/g" \
-e "s/mttk/K/g" \
-e "s/mttl/L/g" \
-e "s/mttm/M/g" \
-e "s/mtto/O/g" \
-e "s/mttv/V/g" \
-e "s/mtty0/y_0/g" \
-e "s/mttu0/u_0/g" \
-e "s/mttx/x/g" \
-e "s/mttz/z/g" \
-e "s/mttyy/Y/g" \
-e "s/mttw/w/g" \
-e "s/mttt/T/g" \
-e "s/mttpar//g" \
-e "s/!/\\\/g" \
-e "s/\\$//g" \
-e "s/(/{(/g" \
-e "s/\*\*/^/g" \
-e "s/\*/ /g" \
-e "s/)/)}/g" \
-e "s/\left/\left (/g" \
-e "s/\right/\right )/g" \
-e "s/sqrt/\\\sqrt/g" \
-e "s/theta/\\\theta/g" \
-e "s/tau/\\\tau/g" \
-e "s/alpha/\\\alpha/g" \
-e "s/beta/\\\beta/g" \
-e "s/gamma/\\\gamma/g" \
-e "s/delta/\\\delta/g" \
-e "s/epsilon/\\\epsilon/g" \
-e "s/lambd/\\lambda/g" \
-e "s/lambda/\\\lambda/g" \
-e "s/mu/\\\mu/g" \
-e "s/phi/\\\phi/g" \
-e "s/pi/\\\pi/g" \
-e "s/rho/\\\rho/g" \
-e "s/sigma/\\\sigma/g" \
-e "s/omega/\\\omega/g" \
-e "s/zeta/\\\zeta/g" \
-e "s/infty/\\\infty/g" \
-e "s/sin/\\\sin/g" \
-e "s/cos/\\\cos/g" \
-e "s/23/{23}/g" \
-e "s/+-/ -/g" \
| cat -s | \
sed -e "s/ $//g" | \
tr -s '\012' '\012' \
>junk
mv junk $1