File mttroot/mtt/bin/trans/latex_tidy artifact 05bdd5ac1d part of check-in dcfb465bef


#! /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.23  2003/08/17 11:35:07  gawthrop
## Fixed problem with parentheses
##
## Revision 1.22  2002/09/26 08:33:54  geraint
## Removed comma from pattern so that braces are places around each argument
## of a function call. Added greek letter nu as a special variable.
##
## Revision 1.21  2002/08/21 18:11:15  geraint
## Replaced |x| with |{x}|. LaTeX now renders abs(fractions) correctly.
##
## Revision 1.20  2002/08/20 19:33:21  geraint
## Minor bug fixes and enhancements (I hope):
##
## Delimited expressions within function calls to prevent denominators from continuing beyond commas.
## Allow latex to adjust size of parentheses according to expression within.
## Replaced ^ with \uparrow (less misleading - latex maths doesn't understand operator precedence or words).
## Replaced abs(x) with |x| when x does not contain brackets.
##
## Revision 1.19  2002/08/19 14:37:05  geraint
## Fixed eta, beta, theta, Theta and zeta.
##
## Revision 1.18  2001/06/11 19:43:50  gawthrop
## MTT is now much more sophisticated in generating lbl files
## Labels can contain maths
## Repetative components are now broken
##
## Revision 1.17  2000/12/28 12:31:15  peterg
## *** empty log message ***
##
## Revision 1.16  2000/10/10 21:03:20  peterg
## *** empty log message ***
##
## Revision 1.15  1998/04/07 08:44:11  peterg
## zapped eta - it messes up theta
##
## 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/mttddui\([0-9]*\)/\\\ddot{v}_{\1}/g" \
    -e "s/mttdui\([0-9]*\)/\\\dot{v}_{\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/mtttheta/\\\Theta/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/abs(\([^()]*\))/|{ \1 }|/g" \
    -e "s/(\([^(),]*\),/( { \1 } ,/g" \
    -e "s/,\([^(),]*\),/, { \1 } ,/g" \
    -e "s/,\([^(),]*\))/, { \1 } )/g" \
    -e "s/(/{\\\\left (/g" \
    -e "s/\*\*/^/g" \
    -e "s/\*/ /g" \
    -e "s/)/\\\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/\([^b(Th)(th)z]\)eta/\1\\\eta/g" \
    -e "s/^eta/\\\eta/g" \
    -e "s/kappa/\\\kappa/g" \
    -e "s/lambd/\\lambda/g" \
    -e "s/lambda/\\\lambda/g" \
    -e "s/mu/\\\mu/g" \
    -e "s/nu/\\\nu/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


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]