% $Id: iso.tex 1.11 1993/01/13 15:12:38 dnc Exp $

%***************************************************************************
% TeX macros for SGML equations (ISO math dtd)
%***************************************************************************

%***************************************************************************
% Copyright 1990-1992, Electronic Book Technologies, Inc.
% All Rights Reserved.
% E.B.T. retains all right, title, and interest in and to this
% source code and all copies thereof.  Any unauthorized copying or
% use of this source code is a violation of the United States 
% copyright laws.
%***************************************************************************


%*****************************************************************************
% ALIGNMENT
%*****************************************************************************

\def\ALIGNleft#1{{#1}\hfill}
\def\ALIGNcenter#1{\hfill{#1}\hfill}
\def\ALIGNright#1{\hfill{#1}}
\def\ALIGN=#1 {
	\def\ALIGNit##1{\csname ALIGN#1\endcsname{##1}}}
\def\ALIGNinit{
	\def\ALIGNit##1{\ALIGNcenter{##1}} %default, without this I think it would inherit
}

%*****************************************************************************
% STYLES
%*****************************************************************************
\def\EBTdouble#1#2{#1{{#1{#2}}}}
\def\EBTtriple#1#2{#1{{\EBTdouble{#1}{#2}}}}

\def\STYLEinit{\def\STYLEis{single}}
\def\STYLE=#1 {
	\def\STYLEis{#1}
}

%*****************************************************************************
% FORMULAS
%*****************************************************************************
% *** just put it in math mode.
\def\F/#1{$\mathstrut #1$}

%*****************************************************************************
% DISPLAYED FORMULAS
%*****************************************************************************
\makeattr{ID}
\makeattr{NUM}
\makeattr{HMOVE}

% *** displaystyle math mode
\def\DF#1/#2{$\EBTalign{#2}$}
%*****************************************************************************
% DISPLAYED FORMULA GROUPS
%*****************************************************************************
\def\DFG#1/#2{%
	\let\DF=\DFinsideDFG%
	$\EBTalign{#2}$%
}

\def\DFinsideDFG#1/#2{%
	#2\cr%			
}

%*****************************************************************************
% BOXES
%*****************************************************************************
\def\BOX#1/#2{
	\STYLEinit%	sets defaults
	#1
	\csname BOX\STYLEis\endcsname{#2}
}

% a simple box
\def\BOXsingle#1{\mathchoice
		{\vcenter{\hrule\hbox{\vrule\kern3pt\vbox{
		\kern3pt{\hbox{$\displaystyle #1$}}\kern3pt
		}\kern3pt\vrule}\hrule}
	}
		{\vcenter{\hrule\hbox{\vrule\kern3pt\vbox{
		\kern3pt{\hbox{$\textstyle #1$}}\kern3pt
		}\kern3pt\vrule}\hrule}
	}
		{\vcenter{\hrule\hbox{\vrule\kern1pt\vbox{
		\kern1pt{\hbox{$\scriptstyle #1$}}\kern1pt
		}\kern1pt\vrule}\hrule}
	}
		{\vcenter{\hrule\hbox{\vrule\kern1pt\vbox{
		\kern1pt{\hbox{$\scriptscriptstyle #1$}}\kern1pt
		}\kern1pt\vrule}\hrule}}
}

\def\BOXdouble#1{\EBTdouble{\BOXsingle}{#1}}
\def\BOXtriple#1{\EBTtriple{\BOXsingle}{#1}}

% a bold box
\def\BOXbold#1{\mathchoice
		{\vcenter{\hrule height1pt\hbox{\vrule width1pt\kern3pt\vbox{
		\kern3pt{\hbox{$\displaystyle #1$}}\kern3pt
		}\kern3pt\vrule width1pt}\hrule height1pt}
	}	% end displaystyle
		{\vcenter{\hrule height.8pt\hbox{\vrule width.8pt\kern3pt\vbox{
		\kern3pt{\hbox{$\textstyle #1$}}\kern3pt
		}\kern3pt\vrule width.8pt}\hrule height.8pt}
	}	% end text style
		{\vcenter{\hrule height.6pt\hbox{\vrule width.6pt\kern1pt\vbox{
		\kern1pt{\hbox{$\scriptstyle #1$}}\kern1pt
		}\kern1pt\vrule width.6pt}\hrule height.6pt}
	}	% end script style
		{\vcenter{\hrule height.4pt\hbox{\vrule width.4pt\kern1pt\vbox{
		\kern1pt{\hbox{$\scriptscriptstyle #1$}}\kern1pt
		}\kern1pt\vrule width.4pt}\hrule height.4pt}}	% end script script style
}

%*****************************************************************************
% OVER EMBELLISHMENTS
%*****************************************************************************
\makeattr{TYPE}
\makeattrdefault{POS}{above}
\makeattrdefault{STYLE}{single}

% **** delete this qqqq *******
\def\OVold#1/#2{
	\TYPE=bar %				** defaults
	#1
	\def\POSabove{above} \def\POSbelow{below} \def\STYLEsingle{single}
	\ifx\POSis\POSabove %\ifabove 
		\ifx\STYLEis\STYLEsingle %\ifsingle
			\csname OV\TYPEis\endcsname{#2}
		\else
			\EBTdouble{\csname OV\TYPEis\endcsname}{#2}
		\fi 
	\else {\underline {#2}}
	\fi
}

\def\OV#1/#2{
	\TYPE=bar %				** defaults
	#1
	\csname OV\POSis\endcsname{#2}
}

%**** macros for different styles of embellishments
\def\OVsingle#1#2{#1{#2}}
\def\OVdouble#1#2{\EBTdouble{#1}{#2}}
\def\OVbold#1#2{{\bf \OVsingle{#1}{#2}}}

%*** default for pos 'above'
\def\OVabove#1{
	\mathchoice
	{\rlap{$\displaystyle #1$}}
	{\rlap{$\textstyle #1$}}
	{\rlap{$\scriptstyle #1$}}
	{\rlap{$\scriptscriptstyle #1$}}
	\csname OV\STYLEis\endcsname{\csname OV\TYPEis\endcsname}{\phantom{#1}}
}

\def\OVdefaultbelow#1{
	\mathchoice{\let\cstyle=\displaystyle \doit{#1}}
		   {\let\cstyle=\textstyle \doit{#1}}
		   {\let\cstyle=\scriptstyle \doit{#1}}
		   {\let\cstyle=\scriptscriptstyle \doit{#1}}}
\def\doit#1{
		\setbox0=\hbox{$\cstyle #1$}
		\setbox1=\hbox{$\csname OV\STYLEis\endcsname%
			{\csname OV\TYPEis\endcsname}{\phantom{\copy0}}$}%
		\setbox2=\vtop {\offinterlineskip\box0\kern 1pt \box1}%
		\dp2 = 3.8 pt \box2%
}

\def\OVbelow#1{%
	\ifundefined{OV\TYPEis below}
		\OVdefaultbelow{#1}
	\else
	     \csname OV\STYLEis\endcsname{\csname OV\TYPEis below\endcsname}{#1}
	\fi
}

%**** custom accents ****

\def\OVdot#1{\dot{#1}}	%\def\OVdotbelow{\OVbelow}
\def\OVdotdot#1{\ddot{#1}}

\def\OVtiebrace#1{\overbrace{#1}} \def\OVtiebracebelow#1{\underbrace{#1}}
\def\OVhat#1{\widehat{#1}}

\def\OVacute#1{\acute{#1}}
\def\OVgrave#1{\grave{#1}}

\def\OVtilde#1{\widetilde{#1}}
\def\OVvec#1{\overrightarrow{#1}\!} \def\OVvecbelow#1{\underrightarrow{#1}}

\def\OVbarbelow#1{\underline{#1}}
\def\OVbar#1{\overline{#1}}	

%*****************************************************************************
% SUB and SUPERSCRIPTS  
% these require that special macros have been written the tex file.
% The c code looks ahead of each element to see if it is followed
% by a sub/superscript.  If so, it writes
%	\EBTsubscripts{\SCRIPT{element} all the element's scripts }
% this way, it is possible to handle subscripts which appear before
% what they are scripts of (pos = ``pre'')
%*****************************************************************************
\newif\ifMiddleScripts
\def\testMiddleScripts{
	\MiddleScriptsfalse
	\ifx\SUBmid\empty
	\else
		\MiddleScriptstrue
	\fi
	\ifx\SUPmid\empty
	\else
		\MiddleScriptstrue
	\fi
}

\def\EBTsubscripts#1{
	\def\SUBpost{}
	\def\SUBpre{}
	\def\SUPpost{}
	\def\SUPpre{}
	\def\SUBmid{\relax}
	\def\SUPmid{\relax}
	#1
	{\vphantom{\SCRIPTis}}_{\SUBpre}^{\SUPpre}%	** pre scripts
	\testMiddleScripts
	\ifMiddleScripts
		\mathop{\SCRIPTis}\limits_{\SUBmid}^{\SUPmid}%	** mid scripts
	\else
		\SCRIPTis
	\fi
	{\vphantom{\SCRIPTis}}_{\SUBpost}^{\SUPpost}%	** post scripts
}

\def\SCRIPT#1{\def\SCRIPTis{#1}}

\def\SUB#1/#2{
	\makeattrdefault{POS}{post}
	#1
	\expandafter\def\csname SUB\POSis\endcsname{#2}
}

\def\SUP#1/#2{
	\makeattrdefault{POS}{post}
	#1
	\expandafter\def\csname SUP\POSis\endcsname{#2}
}




%*****************************************************************************
% TENSORS
%*****************************************************************************
% This one requires some special formatting from the c code.
\makeattr{POSF}

\def\TENSORbegin{
	\begingroup
	\let~=\TENSOR
}

\def\TENSORend{
	\endgroup
}

\def\TENSOR#1{
	\def\TENSORis{#1}
	#1
}

\def\SUFFIX#1{
	\csname SUFFIX\POSFis\endcsname{#1}
}

\def\SUFFIXsub#1{
	{\vphantom{\TENSORis}}_{#1}
	\def\POSFis{sup}
}
\def\SUFFIXsup#1{
	{\vphantom{\TENSORis}}^{#1}
	\def\POSFis{sub}
}

%****************************************************************************
% ROMAN TEXT 
%****************************************************************************
\def\ROMAN/#1{
	\mathchoice
		{\hbox{\tenrm{#1}}}
		{\hbox{\tenrm{#1}}}
		{\hbox{\sevenrm{#1}}}
		{\hbox{\fiverm{#1}}}
}

%****************************************************************************
% ITALIC TEXT
%****************************************************************************
\def\ITALIC/#1{
	\mathchoice
		{\hbox{\tenit{#1}}}
		{\hbox{\tenit{#1}}}
		{\hbox{\seveni{#1}}}
		{\hbox{\fivei{#1}}}
}

%*****************************************************************************
% VECTORS
%*****************************************************************************
\def\VEC/#1{\overrightarrow{#1}}

%*****************************************************************************
% Sums, etc...
%*****************************************************************************
%*** These have special behavior (\atop) which makes them more complicated
%*** than other children

\def\FROM/#1{
	\ifx\FROMis\empty
		\def\FROMis{#1}
	\else
		\edef\FROMis{{\FROMis}\atop{#1}}
	\fi
}

\def\TO/#1{
	\ifx\TOis\empty
		\def\TOis{#1}
	\else
		\edef\TOis{{#1}\atop{\TOis}}
	\fi
}

\makechild{OF}
\makechild{OPERATOR}

%**** Special limits *****
\def\SUM/#1{{
	\def\TOis{\relax} \def\FROMis{\relax}
	#1
	\sum_{\FROMis}^{\TOis}{\OFis}
}}

\def\INTEGRAL#1/#2{{
	\def\TOis{\relax} \def\FROMis{\relax}
	#2
	\int_{\FROMis}^{\TOis}{\OFis}
}}

\def\PRODUCT/#1{{
	\def\TOis{\relax} \def\FROMis{\relax}
	#1
	\mathchar"1351_{\FROMis}^{\TOis}{\OFis}
}}

%*** generic limits ***
\def\PLEX/#1{{
	\def\TOis{\relax} \def\FROMis{\relax}
	#1
	\mathop{\OPERATORis}_{\FROMis}^{\TOis}{\OFis}
}}

%*****************************************************************************
% FRACTIONS
%*****************************************************************************
\makechild{NUMER} 
\makechild{OVER}

\def\FRAC#1/#2{{
	\ALIGNinit
	#1
	#2
	\ALIGNit{\NUMERis}\over\ALIGNit{\OVERis}
}}

%*****************************************************************************
% DIFFERENTIALS
%*****************************************************************************
\makechild{DIFFOF}
\makechild{BY}

\def\DIFF#1/#2{{
%	\makeattr{TYPE}%				** already made
	\TYPE=normal % default				** set in dtd
	#1
	#2
	\csname DIFF\TYPEis\endcsname
}}
\def\DIFFnormal{\delta\DIFFOFis\over\delta\BYis}
\def\DIFFordinary{\delta\DIFFOFis\over\delta\BYis}
\def\DIFFpartial{\partial\DIFFOFis\over\partial\BYis}

%*****************************************************************************
% PILES
%*****************************************************************************
\def\PILE#1/#2{
	\ALIGNinit%	to set default
	#1
	\matrix{#2}
}

\def\ABOVE#1/#2{% '#1' here gobbles the unnecessary '1' in 'ABOVE1'
	\ALIGNit{#2}\cr
}

%*****************************************************************************
% MATRICES
%*****************************************************************************
\def\MATRIX/#1{
	#1
}

\def\COL#1/#2{
	\ALIGNinit
	#1
	\matrix{#2}
}

%*****************************************************************************
% ROOT
%*****************************************************************************
\makechild{DEGREE}
%\makechild{OF}%				** already made

\def\ROOT/#1{
	#1
	\root{\DEGREEis}\of{\OFis}
}

\def\SQRT/#1{\sqrt{#1}}

%*****************************************************************************
% POWER
%*****************************************************************************
\def\POWER/#1{
	#1
	{\OFis}\sp{\DEGREEis}
}

\def\SQUARE/#1{{#1}\sp{2}}

%*****************************************************************************
% MATHEMATICAL FUNCTIONS
%*****************************************************************************
\def\FNAME/#1{\def\FNAMEis{#1}}

\def\MFN#1/#2{\mathinner{%	** treat as mathinner for spacing
	\def\TYPE##1=##2 {\def\FNAMEis{##2}}
	#1
	\ifundefined{FNAMEis}
		#2%		*** treat below as mathords for spacing
		\mathord{\ROMAN/\FNAMEis}\mathord{\left({\OFis}\right)}
	\else
		\mathord{\ROMAN/\FNAMEis}\mathord{\left({#2}\right)}
	\fi
}}

%*****************************************************************************
% FENCES
%*****************************************************************************

% ** open attribute
\def\OPENTYPEparen{\def\OPENchar{(}}
\def\OPENTYPEbracket{\def\OPENchar{[}}
\def\OPENTYPEangbrack{\def\OPENchar{<}}
\def\OPENTYPEbrace{\def\OPENchar{\{}}
\def\OPENTYPEbar{\def\OPENchar{|}}
\def\OPENTYPEnone{\def\OPENchar{.}}
\def\OPENTYPEnochange{\relax}

% ** close attribute
\def\CLOSETYPEparen{\def\CLOSEchar{)}}
\def\CLOSETYPEbracket{\def\CLOSEchar{]}}
\def\CLOSETYPEangbrack{\def\CLOSEchar{>}}
\def\CLOSETYPEbrace{\def\CLOSEchar{\}}}
\def\CLOSETYPEbar{\def\CLOSEchar{|}}
\def\CLOSETYPEnone{\def\CLOSEchar{.}}
\def\CLOSETYPEnochange{\relax}

\def\MIDDLETYPEnochange{\relax}

% ** type attribute
\def\FENCETYPE#1#2#3{\def\OPENchar{#1} \def\MIDDLEchar{#2} \def\CLOSEchar{#3}}
\def\FENCETYPEparen{\FENCETYPE(|)}
\def\FENCETYPEbracket{\FENCETYPE[|]}
\def\FENCETYPEangbrack{\FENCETYPE<<>}
\def\FENCETYPEbrace{\FENCETYPE\{|\}}
\def\FENCETYPEbar{\FENCETYPE|||}
\def\FENCETYPEnone{\FENCETYPE...}

%\def\FENCEold#1/#2{{
%	\STYLEinit
%	\FENCETYPEparen%	default
%	\def\TYPE=##1 {\csname FENCETYPE##1\endcsname}
%	#1
%	\csname FENCEit\STYLEis\endcsname\OPENis\CLOSEis{#2}
%}}

% ** write fences
%\def\FENCEitsingle#1#2#3{\left#1#3\right#2}
%\def\FENCEitdouble#1#2#3{\left#1\left#1#3\right#2\right#2}
%\def\FENCEittriple#1#2#3{\left#1\left#1\left#1#3\right#2\right#2\right#2}

%middle fences are too small	qq
\def\MIDDLE#1/#2{
	\STYLEinit
	#1
	\csname MIDDLEit\STYLEis\endcsname{\MIDDLEis}
}
\def\MIDDLEitsingle#1{\left#1\right.}


% *** main fence macro
\def\FENCE#1/#2{{%				** 2 {s so all \defs are local
	\STYLEinit
	\FENCETYPEparen%	default
	\makeattrdefault{TYPE}{paren}
	\makeattrdefault{OPEN}{nochange}
	\makeattrdefault{CLOSE}{nochange}
	\makeattrdefault{MIDDLE}{nochange}
	#1%					** read attrs
	\csname FENCETYPE\TYPEis\endcsname
	\csname OPENTYPE\OPENis\endcsname
	\csname CLOSETYPE\CLOSEis\endcsname
	\FENCEit{open}%				** write open braces
	\makeattr{TYPE}%			** because TYPE was redifined
	#2%		** write contents of fence
	\FENCEit{close}%			** erite close fence
}
}

%*** middle fences.  Handles <cp>
\def\MIDDLE#1/#2{
	#1%					** read attributes
	\FENCEit{middle}%			** write braces
}	

%	\nulldelimeter space =0.0 so invisible fences take no space.
\nulldelimiterspace=0pt

% *** writes either left, center, or right fences, depending on #1
\def\FENCEit#1{
	\csname FENCE#1\STYLEis\endcsname
}


% ** single open fence
\def\FENCEopensingle{
	\left\OPENchar\left.\left.
}

% ** double open fence
\def\FENCEopendouble{
	\xdef\theFENCE{\OPENchar}
	\left\theFENCE\left\theFENCE\left.
}

% ** triple open fence
\def\FENCEopentriple{
	\xdef\theFENCE{\OPENchar}
	\left\theFENCE\left\theFENCE\left\theFENCE
}
%*** these routines are just like the opening brace routines, but they
%	draw closing braces

% ** single closing brace
\def\FENCEclosesingle{
	\xdef\theFENCE{\CLOSEchar}
	\right.\right.\right\theFENCE
}

% ** double
\def\FENCEclosedouble{
	\xdef\theFENCE{\CLOSEchar}
	\right.\right\theFENCE\right\theFENCE
}

% ** triple
\def\FENCEclosetriple{
	\xdef\theFENCE{\CLOSEchar}
	\right\theFENCE\right\theFENCE\right\theFENCE
}

%*** Similar to the preceeding routines, these routines draw middle braces.
%	2 closing and 2 opening.

% ** single
\def\FENCEmiddlesingle{
	\xdef\theFENCE{\MIDDLEchar}
	\hskip1.2pt\right.\right\theFENCE\left.\left.
}

% ** double
\def\FENCEmiddledouble{
	\xdef\theFENCE{\MIDDLEchar}
	\hskip1.2pt\right\theFENCE\right\theFENCE\left.\left.
}

% ** triple
\def\FENCEmiddletriple{
	\xdef\theFENCE{\MIDDLEchar}
	\hskip1.2pt\right\theFENCE\right\theFENCE\left\theFENCE\left.
}


%*****************************************************************************
% MISC			(don't work fully)
%*****************************************************************************
\def\MARK#1/#2{&}
\def\MARKREF#1/#2{&}
\def\BREAK#1/#2{\cr}



\endinput
\end
