% $Id: arbor.tex 1.12 1993/09/23 19:12:51 dnc Exp $

%***************************************************************************
% Useful TeX macros for ArborText's equation 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.
%***************************************************************************
\catcode`\@=11


%*****************************************************************************
% ALIGNMENT
%	for left, center, or right alignment of just about anything.
%*****************************************************************************
% *** The ALIGN attribute is used in many elements
\makeattr{ALIGN}

% *** \EBTarboralign assumes that a value ALIGNis has been defined to (l | c | r).
%	an attribute 'align=' would cause this to happen.
\def\EBTarboralign#1{%
	\ifundefined{ALIGNis} 
		#1
	\else
     		\csname EBTalign\ALIGNis\endcsname{#1}
	\fi
}

% left alignment
\def\EBTarboralignl#1{#1\hfill}

% center alignment
\def\EBTarboralignc#1{\hfill #1\hfill}

% right alignment
\def\EBTarboralignr#1{\hfill #1}

%*****************************************************************************
% FORMULAS
%	For in-line formulas
%*****************************************************************************
% *** \F just puts the formula in math mode
\def\F/#1{%
$#1$%
}

%*****************************************************************************
% DISPLAYED FORMULAS
%	For formulas on their own lines
%*****************************************************************************
\def\FD/#1{%
$\EBTalign{#1}$%
}

% *** A formula line
% Many <fl>s can be in a <fd>.  Each belong on its own line,
% centered with respec to the others.  We currently fail to center them, they
% are right justified instead.
\def\FL/#1{%
	#1\cr%
}

%*****************************************************************************
% FRACTIONS
%*****************************************************************************
\def\FR#1/#2{{%					** localize for nested fractions
	\def\ALIGNis{c}%			** default alignment
	\makeattrdefault{STYLE}{s}%		% not used
	\makeattrdefault{SHAPE}{built}%		% not used
	#1%					** read attributes
	\makechild{NU} \makechild{DE}%		** numerator, denominator
	#2%					** read NUis and DEis
	\EBTarboralign{\NUis}\over\EBTarboralign{\DEis}%
}}

%*****************************************************************************
% LIMITS
%	Summation, products, integrals, any operator
%*****************************************************************************
% *** the children of the limit elements are:

% ** OP is the operator
\makechild{OP}
% ** LL is the lower limit
\makechild{LL}	
% ** UL is upper limit
\makechild{UL}	
% ** OPD is operand
\makechild{OPD}

% *** \LIM handles any operator which takes limits
\def\LIM#1/#2{{%				** 2 {s for nesting
	\def\ALIGNis{c}%			** default limit alignment
	#1%					** read attributes (ALIGNis)
	#2%					** read children
%	** display operator and limits
	\csname ALIGNLIM\ALIGNis\endcsname{\mathop{\OPis}}{\LLis}{\ULis}
	\OPDis%					** display operand
}}

% ***
% 	The next 3 macros are identical, except for the operators which
%	they put limits around.
% ***

% *** \SUM for summation.  uses a sigma (\sum in TeX)
\def\SUM#1/#2{{%
	\def\ALIGNis{c}%
	#1%
	#2%
	\csname ALIGNLIM\ALIGNis\endcsname{\sum}{\LLis}{\ULis}%
	\OPDis%
}}

\newbox\EBTtempbox
\newbox\EBTtmpbox
\newdimen\EBTtempdimen

% *** \IN for integrals.  Uses \EBTint
\def\IN#1/#2{{%
	\def\ALIGNis{c}%
	#1%
	#2%
	\setbox\EBTtempbox=\hbox{$\displaystyle \OPDis$}
	\EBTtempdimen=2\ifdim\ht\EBTtempbox>\dp\EBTtempbox
		\ht\else\dp\fi\EBTtempbox
	\ifdim\EBTtempdimen<30pt
		\csname ALIGNLIM\ALIGNis\endcsname{\int}{\LLis}{\ULis}{\OPDis}%
	\else
	     \csname ALIGNLIM\ALIGNis\endcsname{\bigint}{\LLis}{\ULis}{\OPDis}%
	\fi
}}

% *** \PR for products.  Uses capital Pi (\mathchar"1351 in TeX)
\def\PR#1/#2{{%
	\makeattrdefault{ALIGN}{c}%
	#1%
	#2%
	\csname ALIGNLIM\ALIGNis\endcsname{\mathchar"1351}{\LLis}{\ULis}%%
	\OPDis%
}}


%*** These macros put limits around an operator.  In one case the 
%	limits are centered above and below the operator (using
%	TeX's \limits).  In the other they are left of the operator
%	(\nolimits)

\def\ALIGNLIMc#1#2#3{%
	\def\TU/{\atop \scriptstyle}%
	#1\limits_{\scriptstyle #2}^{\scriptstyle #3}%
}	
\def\ALIGNLIMr#1#2#3{%
	\def\TU/{\atop \scriptstyle}%
	#1\nolimits_{\scriptstyle #2}^{\scriptstyle #3}%
}


%*****************************************************************************
% FENCES 
%	Put fences (parentheses, etc...) around portions of a formula.
% These are complicated because (1) begin and end fences need not match
% each other in shape or in number (in TeX they must match in number), 
% and (2) there may be middle fences which
% should be the same size as the end braces (TeX has no support for middle
% braces)

% These are the most complicated macros in this file.  Here's the basic
% strategy. When opening a fence, simply put the left delimeters there.  When
% closing, put the right delimeters there.  If more rights are required than
% lefts (as can be the case with this dtd), use left delimeters that look like
% rights.  Those delimeters will be closed later on.  Middle delimeters are
% handled the same way.  I know this is cryptic, so here come some examples.
% 'THIS' is the thing to be fenced.
% ')' denotes a right delimeter, even though it may look like a left delimeter
% to the viewer, or it may be invisible.
% '(' denotes a left delimeter, with the same caveat.
% examples:
% How it looks	How it is represented in TeX
% (THIS)	(THIS)				simplest case
% (THIS))	(THIS(())		single opener, 2 closes
% (THIS|THIS)	(THIS)THIS()		single opener, middle, and close
% (THIS||this)	(THIS((this)))		single opener, 2 middles, 1 close
% Note this last case, it exposes a bug.  The closing and middle parens may not
% appear as large as the first, because they are not matching it.  I'm not sure
% how to solve that, yet.

% Note that ArborText generates only the simplest case, so the others will only
% be encountered by someone hand tagging with the AAP dtd.

% The examples could go on forever, and probably not make this any easier to
% understand.  Note that this method uses many less parens than the method
% used in version 2.1.  This is because TeX's memory was easily filled up
% by those macros, which used 3 parens for every fence.  Keep in mind when
% making future improvements, that the level of nestedness should be minimized.

% This does not handle dotted, dashed, or bold fences.		qq
%*****************************************************************************

% *** variables used in the FENCE macros:
% the following info is kept locally within each <fence>
\newcount\FENneeded%	** how many fences need to be drawn
\newcount\FENdepth%	** how deep we already are in fences
\newcount\temp%		** temporary count used in calculations
% the following variables are set globally to communicate the above info
% between the nested levels of fences.
\newcount\TEMP%		** global temporary variable
\newcount\DEPTH
\newcount\NEEDED

% *** defines a left, middle and right brace
\def\FENCETYPE#1#2#3{%
	\def\OPENis{#1}%
	\def\MIDDLEis{#2}%
	\def\CLOSEis{#3}%
}

% *** types of fences.
%	These routines declare what to draw for left, middle and right
%	braces based on the value of lp or post attributes.
\def\FENCETYPEpar{\FENCETYPE(|)}%	      ** left = (, center = |, right = )
\def\FENCETYPEang{\FENCETYPE<|>}%	      ** left = <, center = |, right = >
\def\FENCETYPEsqb{\FENCETYPE[|]}
\def\FENCETYPEvb{\FENCETYPE|||}
\def\FENCETYPEceil{\FENCETYPE\lceil|\rceil}
\def\FENCETYPEfl{\FENCETYPE\lfloor|\rfloor}
\def\FENCETYPEcub{\FENCETYPE\{|\}}
\def\FENCETYPEsol{FENCETYPE///}
\def\FENCETYPEn{\FENCETYPE...}%			** . = invisible brace

% *** attributes of fences

% ** style is single, double, triple, or other values  which are not handled
\makeattrdefault{STYLE}{s}

% ** left post for <fen>
\makeattrdefault{LP}{vb}

% ** post for <cp> and <rp>
\makeattrdefault{POST}{vb}

% *** main fence macro
\def\FEN#1/#2{{%				** 2 {s so all \defs are local
	#1%					** read attrs
	\csname FENCETYPE\LPis \endcsname%	** declare types of braces
	\FENCEopen%				** write open braces
	#2%					** write contents of fence
	\FENCEclose%			** write close fence
%	** here we turn off the fence macros, then fake draw the object
%	** being fenced, this forces close parens to be the same height
%	** as the open parens (in most cases, this is sufficient)
	\let\FEN=\EBTnothing \let\CP=\EBTnothing \let\RP=\EBTnothing
	\vphantom{#2}%			** ensures that fances are large enough
	\FENCEbalance%			** ensures that opened fences are closed
}}

%*** middle fences.  Handles <cp>
\def\CP#1/#2{%
	#1%					** read attributes
	\csname FENCETYPE\POSTis\endcsname%	** declare type of braces
	\FENCEmiddle%			** write braces
}	

%*** right fence.  Handles <rp>
\def\RP#1/#2{%
	%\debug{in RP}
	#1%					** read attrs (style and post)
	\csname FENCETYPE\POSTis\endcsname%	** declare type of braces
	\FENCEclose%			** write close braces
}

% the styles for fences.  These are needed for comparisons in \EBTnumfromstyle
\let\STYLEsingle=s
\let\STYLEdouble=d
\let\STYLEtriple=t
\let\STYLEclosed=x

% turns a style into a number for single, double or triple, any other value
% yeilds 0
\def\EBTnumfromstyle#1{
	0%
	\if#1\STYLEsingle1\fi%
	\if#1\STYLEdouble2\fi%
	\if#1\STYLEtriple3\fi%
}

% draw the opening fence(s)
\def\FENCEopen{%
	\xdef\theFENCE{\OPENis}%		**store fence to draw in global
	\FENneeded=\EBTnumfromstyle{\STYLEis}% ** how many fences to draw
	\FENdepth=0%			** 0 depth because this is first
	\FENCES%				** draw em
}

% draw the close fence(s)
\def\FENCEclose{%
	\xdef\theFENCE{\CLOSEis}%
	\FENneeded=\EBTnumfromstyle{\STYLEis}%
	\FENCES
	\def\STYLEis{\STYLEclosed}%%	** so an RP will not make us close twice
}

% draw a fence in the middle
\def\FENCEmiddle{%
	\xdef\theFENCE{\MIDDLEis}%
	\FENneeded=\EBTnumfromstyle{\STYLEis}%
	\FENCES
}


% note how globals are used to communicate info from one layer of fences to the
% next. 

% when this macro is reached, 
% \theFENCE = character to use in fences
% \FENdepth is the current depth of parens
% \FENneeded is the amount of fences to draw
\def\FENCES{%
	\temp=\FENneeded%
	\advance\temp by -\FENdepth%
	\global\DEPTH=\FENdepth
	\global\NEEDED=\FENneeded
	\ifnum\temp>0 \FENCESleft \else \FENCESright \fi%
	\FENneeded=0%
	\FENdepth=\DEPTH
	\advance\FENdepth by \NEEDED%
}

% draws from 0 to 3 left fences.  They are left to TeX, but they may appear as
% right to the viewer.  For example, the way \left) works.
\def\FENCESleft{%
	\ifcase\NEEDED \or
		\left\theFENCE\or
		\left\theFENCE\left\theFENCE\or
		\left\theFENCE\left\theFENCE\left\theFENCE
	\fi
}

% because of the way the nesting works, we may need to do more than 3 right
% fences at a time.  again, they could appear as left, right, or middle
% delimeters to the viewer.
\def\FENCESright{%
	\EBTrecurse{\the\NEEDED}{\right\theFENCE}
	\global\NEEDED=-\NEEDED
}

% stores the width of a nulldelimeter
%\newdimen\delspace

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


% this draws nothing visible, but inserts \right. until the depth of fences is 0
\def\FENCEbalance{%
	\xdef\theFENCE{.}%			** make fences invisible
	\FENneeded=\ifnum0>\FENdepth
				-\FENdepth
			 \else
				\FENdepth
			 \fi
	\FENCES
%	\delspace=\nulldelimiterspace%		
%	\multiply\delspace by -\FENneeded%
%	\hskip\delspace%			** for some reason, these
%							extra invisible braces
%							take up space.
}


%****************************************************************************
% Special Delimeters
%	ArborText allows for delimeters without matches.  Proper practice
% would be to use a fence element, with a blank delimeter on one side.
% instead ArborText defines entities.  Thus the need for these.
%	The trick is to make the symbols appear the right size.
%***************************************************************************
%\def\EBTlfloor{%
%	\left\lfloor\vphantom{}\right.%
%}
%\def\EBTrfloor{%
%	\left.\vphantom{}\right\rfloor%
%}
%\def\EBTparl{%
%	\left(\vphantom{}\right.%
%}
%\def\EBTparr{%
%	\left.\vphantom{}\right)%
%%}


%*****************************************************************************
% ROOT
%*****************************************************************************

% *** \RAD handles radicals
\def\RAD/#1{%
	\makechild{RCD}%			** radicand
	\makechild{RDX}%			** radix
	#1%					** read radicand and radix
	\root{\RDXis}\of{\RCDis}%		** write root symbol
}

%*****************************************************************************
% ARRAYS

% These rely heavily on TeX's \matrix macro.  Therefore, the important
% things are to seperate each row with a \cr, and each cell in a row
% with a &.  Not too difficult.

% These do r|c|l alignment of individual cells, but the alignment of
% all columns set at the beginning does not work.  I think that would
% require some changes to the c code.
% I don't think they will ever align by
% decimal or exponent, which the arbortext dtd calls for.
% Also, column and row seperators would be very difficult.
%*****************************************************************************

% *** The following 3 attributes are not used.  They could be implemented
%	in c.  Perhaps for a final version.			qq
%	For now, they will write a warning.
\def\CS=#1 {\EBTattrwarning{cs}{ar}}%		column seperators
\def\RS=#1 {\EBTattrwarning{rs}{ar}}%		row seperators
\def\CA=#1 {\EBTattrwarning{ca}{ar}}%		column alignment

% *** main array macro
\def\AR#1/#2{%
	#1%
	\def\ALIGNis{c}%			** for array cells
	\matrix{#2}%
}

% ** array row.  We must put \cr after each row.
\def\ARR/#1{%
	\def\CellSeperator{}% 			** no '&' before first cell
	#1\cr%
}

% ** array cell.  We must put a & between cells.  we do this by
% 	putting a & before each cell except the first.
\def\ARC#1/#2{%
	\CellSeperator%				** write cell seperator
	\def\CellSeperator{&}% 			** '&' before next cell
	#1%					** set alignment
	\ifmmode%
		\EBTarboralign{#2}%
	\else%
		$\displaystyle\EBTarboralign{#2}$%
	\fi%
	\def\ALIGNis{c}%			reset default before next cell
}

%*****************************************************************************
% CASES
% makes use of \ARR and \ARC above
%*****************************************************************************
\def\CASES/#1{%
	\def\ALIGNis{l}%
	\cases{\displaystyle #1}%
}

%*****************************************************************************
% EQALN
%*****************************************************************************
\def\EQALN#1/#2{%
	\EBTalign{#2}%
}

\def\EQLINE#1/#2{%
	&#2\cr%
}

%*****************************************************************************
% STACKS
%*****************************************************************************
% *** a stack is just an array with one column
\def\STK/#1{%
	\matrix{#1}%
}

% ** each layer is a row in an array
\def\LYR#1/#2{%
	\makeattrdefault{ALIGN}{c}%
	#1%
	\EBTarboralign{#2}\cr%
}

%*****************************************************************************
% ATOM CHANGE
%	Used to change the spacing which TeX puts around symbols.
%*****************************************************************************
\makeattrdefault{atom}{ord}

% *** Luckily, the names AAP uses for different atoms are exactly those
%	that TeX uses.  So, for example, to make the object an operator
%	atom (which AAP calls op), we just have to call TeX's \mathop
\def\ACH#1/#2{%
	#1%
	\csname math\ATOMis\endcsname{#2}%
}

%*****************************************************************************
% SCRIPTS
%	Sub/superscript tags are not translated into TeX the way all the
% others are.  If the SGML reads:
%	<foo>...</foo><inf ...> ... </inf><sup ...> ...</sup>
% The TeX macros will read
%	\EBTsubscripts{\SCRIPT{\FOO/{...}}\INF.../{...}\SUP.../{...}}

% This makes it much easier to show subscripts which come BEFORE their
% objects.  The idea is to read all the \INFs and \SUPs, then, when
% they are all known, write the scripts with loc=pre, then the
% contents of \SCRIPT, and then the loc=post scripts.
%*****************************************************************************
% *** loc = (pre | post)
\makeattr{LOC}

% *** main script routine.
%	The idea is to read the script info, defining the following:
%		\SCRIPTis 		the thing that has subscripts
%		\INFpre			the preceeding subscript
%		\INFpost		the subscript
%		\SUPpre and \SUPpost	the superscripts
%	Once these are all know, they are easy to display.

% this is the current way.
\def\EBTsubscripts#1{%
	\def\INFpost{}%					** defaults are empty
	\def\INFpre{}%
	\def\SUPpost{}%
	\def\SUPpre{}%
	#1%						** read the scripts
	{\vphantom{\SCRIPTis}}_{\INFpre}^{\SUPpre}%	** display pre scripts
	{\SCRIPTis}_{\INFpost}^{\SUPpost}%		** display others
}

% this is the new way (this will be used if the c code changes for mkbook v2.5)
\def\beginEBTscripts{
        \begingroup
        \def\INFpost{}%                                 ** defaults are empty
        \def\INFpre{}%
        \def\SUPpost{}%
        \def\SUPpre{}%
        \def\SCRIPTis##1{\def\SCRIPTis{##1}}
}
\def\endEBTscripts{
        {\vphantom{\SCRIPTis}}_{\INFpre}^{\SUPpre}%     ** display pre scripts
        {\SCRIPTis}_{\INFpost}^{\SUPpost}%              ** display others
        \endgroup
}

% ** defines \SCRIPTis
\def\SCRIPT#1{\def\SCRIPTis{#1}}

% ** defines \INFpre and \INFpost
\def\INF#1/#2{%
	\def\LOCis{post}%
	#1%
	\expandafter\def\csname INF\LOCis\endcsname{#2}%
}

% ** defines \SUPpre and \SUPpost
\def\SUP#1/#2{%
	\def\LOCis{post}%
	#1%
	\expandafter\def\csname SUP\LOCis\endcsname{#2}%
}


% *** the AAP dtd provides a zerowidth character for making tensor notation.
%	Luckily, TeX provides a similar macro.
\def\ZW/#1{\mathstrut}%				** zerowidth character


%*****************************************************************************
% BOXES, LINES
%*****************************************************************************
% *** the STYLE attribute was made earlier.  While it is used by these
%	macros, it would be redundant to redefine it here.
%\makeattr{STYLE}

% *** Underlining and overlining are easy because TeX has macros for it.
%	The only trick is making the lines mathch the style.
\def\UNL#1/#2{%
	\def\STYLEis{s}%				*** default style
	#1%
	\csname UNL\STYLEis\endcsname{#2}%		** branch based on style
}

% ** draw a single line
\def\UNLs#1{\underline{#1}}

% ** double line
\def\UNLd#1{\EBTdouble{\underline}{#1}}

% ** triple line
\def\UNLt#1{\EBTtriple{\underline}{#1}}

% *** Overlines are almost identical to underlines
\def\OVL#1/#2{%
	\def\STYLEis{s}%
	#1%
	\csname OVL\STYLEis\endcsname{#2}%
}
\def\OVLs#1{\overline{#1}}
\def\OVLd#1{\EBTdouble{\overline}{#1}}
\def\OVLt#1{\EBTtriple{\overline}{#1}}

% *** Boxes ar similar
\def\BOX#1/#2{%
	\def\STYLEis{s}%			** default is single
	#1%					** read style
	\csname BOX\STYLEis\endcsname{#2}%	** branch based on style
}

% *** the boxing routines used here are defined in ebt.tex
\def\BOXs#1{\EBTboxSingle{#1}}
\def\BOXd#1{\EBTboxDouble{#1}}
\def\BOXt#1{\EBTboxTriple{#1}}
\def\BOXb#1{\EBTboxBold{#1}}

% *** over and under braces
\def\OVB#1/#2{\overbrace {#2}}
\def\UNB#1/#2{\underbrace {#2}}

%*****************************************************************************
% ACCENTS
%	These are tough.  It is generally done by stacking boxes, the accent
%upon the accented.  Several special cases are made, however, which complicates
%things a bit.
%*****************************************************************************
\makeattr{VALIGN}

%**** for custom (makeshift) accents
\newbox\AccentBox
\newbox\AccentedBox
\newbox\TmpBox

\def\A#1/#2{{%
	\def\VALIGNis{u}% 	** up middle, or down
	#1%
 	\getcomponents#2%	** read in accent and object of accent
	\ifundefined{ACCENT\VALIGNis\ACCENTis}%
	      \csname DefaultAccent\VALIGNis\endcsname{{\ACCENTed}}{\ACCENTis}%
	\else%
		\csname ACCENT\VALIGNis\ACCENTis\endcsname{\ACCENTed}%
	\fi%
}}

\def\getcomponents\AC/#1\AC/#2{%
	\def\ACCENTed{#1}%
	\specialSDATA%		** ignore leading \ in sdata
	\edef\ACCENTis{#2}%
	\normalSDATA%		** read leading \ in sdata
}

\def\DefaultAccentu#1#2{%
	\ifundefined{\ACCENTis}%
		%** if no macro for this accent
		\mathchoice{\let\cstyle=\displaystyle \Au{#1}{#2}}%
			   {\let\cstyle=\textstyle \Au{#1}{#2}}%
			   {\let\cstyle=\scriptstyle \Au{#1}{#2}}%
			   {\let\cstyle=\scriptscriptstyle \Au{#1}{#2}}%
	\else%
		%** use macro for this accent
		\csname \ACCENTis\endcsname{\ACCENTed}%%
	\fi%
}

%***	Generic Accent Up (stack boxes)
\def\Au#1#2{%
	\setbox\AccentedBox=\hbox{$\cstyle {#1}$}%
	\setbox\AccentBox=\hbox{$\cstyle {#2}$}%
	\setbox\TmpBox=\vbox {\offinterlineskip%
			\box\AccentBox\kern 1pt \box\AccentedBox}%%
	\dp2 = 3.8 pt \box\TmpBox%
}

%*** underneath accents
\def\DefaultAccentd#1#2{%
	\mathchoice{\let\cstyle=\displaystyle \Ad{#1}{#2}}%
		   {\let\cstyle=\textstyle \Ad{#1}{#2}}%
		   {\let\cstyle=\scriptstyle \Ad{#1}{#2}}%
		   {\let\cstyle=\scriptscriptstyle \Ad{#1}{#2}}%
}

\def\Ad#1#2{%
		\setbox\AccentedBox=\hbox{$\cstyle #1$}%
		\ifundefined{\ACCENTis}%
			\setbox\AccentBox=\hbox{$\cstyle #2$}%
		\else%
			\setbox\AccentBox=\hbox{$\cstyle%
				\csname \ACCENTis\endcsname%
					{\phantom{\copy\AccentedBox}}$}%
		\fi%
		\setbox\TmpBox=\vtop {\offinterlineskip%
				\box\AccentedBox\kern 1pt \box\AccentBox}%
		\dp2 = 3.8 pt \box\TmpBox%
}

%**** if an accent has a special definition, it should be called
%	ACCENT[umd]_name_, where [umd] specifies up middle or down,
%	and _name_ is the name of the accent contained in <ac> </ac>

%\let\ACCENTd@b=\overbar
%\let\ACCENTud@b=\ACCENTd@b

%\let\ACCENTd@c=\dot
%\let\ACCENTud@c=\dot

%\let\ACCENTd@d=\ddot
%\let\ACCENTud@d=\ddot

%\let\ACCENTd@e=\widehat
%\let\ACCENTud@e=\widehat

%\let\ACCENTd@f=\widetilde
%\let\ACCENTud@f=\ACCENTd@f

% These next two come out really bad.  Will fix if someone needs it.
% * triple dot
%\def\ACCENTd@h{...}
% * four dots
%\def\ACCENTd@i#1{....}

%\let\ACCENTd@j=\check
%\let\ACCENTud@j=\check

%\let\ACCENTd@ba=\circ

%\let\ACCENTd@bb=\breve
%\let\ACCENTud@bb=\breve

%\let\ACCENTuar=\overrightarrow
%\let\ACCENTar=\overrightarrow



%*****************************************************************************
% PHRASES (roman text)
%*****************************************************************************
\def\PHR/#1{{
		\mathchoice
		{\hbox{\tenrm{#1}}}
		{\hbox{\tenrm{#1}}}
		{\hbox{\sevenrm{#1}}}
		{\hbox{\fiverm{#1}}}
}}
%\def\PHR{\RM}	*** this does not work because spaces are removed.

%*****************************************************************************
% GREEK 
%*****************************************************************************

\def\G/#1{{\beginGREEK #1\endGREEK}}
\def\BG/#1{\EBTwarning{BG}
	\beginGREEK#1\endGREEK}%		*** bold greek does not work qqq

%*****************************************************************************
% ROMAN, BOLD, and ITALICS
%*****************************************************************************
% ** roman
%\def\RM#1/#2{\beginRM #2\endRM}
\def\RM#1/#2{{\EBTdefaultCharset \fam0 #2}}

% ** these do not work
%\def\IT#1/#2{\fam\mathfont=\fam1 \beginFONT#2 \endFONT}
\def\IT#1/#2{{\mathfont=1 \EBTdefaultCharset\mit #2}}
\def\B#1/#2{{\mathfont=\the\bffam \EBTdefaultCharset\fam\bffam #2}}

%****************************************************************************
% Funky TeX fonts.  These can't work unless we ship the fonts.
%****************************************************************************
\def\BLKBD#1/#2{\EBTwarning{BLKDB} #2}
\def\IG#1/#2{\EBTwarning{IG} \RM/{#2}}
\def\SC#1/#2{\EBTwarning{SC} \RM/{#2}}
\def\GE#1/#2{\EBTwarning{GE} \RM/{#2}}
\def\TY#1/#2{\EBTwarning{TY} \RM/{#2}}
\def\MIT#1/#2{\EBTwarning{MIT} \RM/{#2}}


%*****************************************************************************
% SPACING
%*****************************************************************************
\makeattr{SP}

\def\HSP#1/{%
	\def\SPis{0}%
	#1%
	\hskip\SPis em%
}

\def\VSP#1/{\EBTwarning{vsp}}
%\def\VSP#1/#2{%
%	\def\SPis{0}%
%	#1%
%	\vskip\SPis em%
%}


%*****************************************************************************
% Special Characters/strings
%*****************************************************************************
%vectors
\def\V/#1{\vec{#1}}

%dyadics
\def\DY/#1{\PHR/{\bf #1}}

%fields
\def\FI/#1{{\cal #1}}

%increments ??qq
\def\INC/#1{#1}

%roman functions
\def\RF/#1{{\rm #1}}

%*****************************************************************************
% Things that don't quite work
%*****************************************************************************
\def\VMK#1/{&}
\def\VMKR#1/{&}


%*****************************************************************************
% FONTS FOR USE IN MATH MODE
%*****************************************************************************

% *** ROMAN CHARACTERS
\newfam\mathrm
\textfont\mathrm=\tenrm \scriptfont\mathrm=\sevenrm 
\scriptscriptfont\mathrm=\fiverm
\def\mrm{\fam\mathrm }

\def\beginRM{%
	\begingroup
	\mathcode`a="7\the\mathrm61
	\mathcode`b="7\the\mathrm62
	\mathcode`c="7\the\mathrm63
	\mathcode`d="7\the\mathrm64
	\mathcode`e="7\the\mathrm65
	\mathcode`f="7\the\mathrm66
	\mathcode`g="7\the\mathrm67
	\mathcode`h="7\the\mathrm68
	\mathcode`i="7\the\mathrm69
	\mathcode`j="7\the\mathrm6A
	\mathcode`k="7\the\mathrm6B
	\mathcode`l="7\the\mathrm6C
	\mathcode`m="7\the\mathrm6D
	\mathcode`n="7\the\mathrm6E
	\mathcode`o="7\the\mathrm6F
	\mathcode`p="7\the\mathrm70
	\mathcode`q="7\the\mathrm71
	\mathcode`r="7\the\mathrm72
	\mathcode`s="7\the\mathrm73
	\mathcode`t="7\the\mathrm74
	\mathcode`u="7\the\mathrm75
	\mathcode`v="7\the\mathrm76
	\mathcode`w="7\the\mathrm77
	\mathcode`x="7\the\mathrm78
	\mathcode`y="7\the\mathrm79
	\mathcode`z="7\the\mathrm7A
	\mathcode`A="7\the\mathrm41
	\mathcode`B="7\the\mathrm42
	\mathcode`C="7\the\mathrm43
	\mathcode`D="7\the\mathrm44
	\mathcode`E="7\the\mathrm45
	\mathcode`F="7\the\mathrm46
	\mathcode`G="7\the\mathrm47
	\mathcode`H="7\the\mathrm48
	\mathcode`I="7\the\mathrm49
	\mathcode`J="7\the\mathrm4A
	\mathcode`K="7\the\mathrm4B
	\mathcode`L="7\the\mathrm4C
	\mathcode`M="7\the\mathrm4D
	\mathcode`N="7\the\mathrm4E
	\mathcode`O="7\the\mathrm4F
	\mathcode`P="7\the\mathrm50
	\mathcode`Q="7\the\mathrm51
	\mathcode`R="7\the\mathrm52
	\mathcode`S="7\the\mathrm53
	\mathcode`T="7\the\mathrm54
	\mathcode`U="7\the\mathrm55
	\mathcode`V="7\the\mathrm56
	\mathcode`W="7\the\mathrm57
	\mathcode`X="7\the\mathrm58
	\mathcode`Y="7\the\mathrm59
	\mathcode`Z="7\the\mathrm5A
}

\def\endRM{\endgroup}

% *** greek letters

\def\beginGREEK{%
	\begingroup%
	\mathcode`\a=\alpha
	\mathcode`\b=\beta
	\mathcode`\g=\gamma
	\mathcode`\d=\delta
	\mathcode`\6=\partial
	\mathcode`\e=\epsilon
	\mathcode`\3=\varepsilon
%	\mathcode`\5=\		**** should be digamma
	\mathcode`\z=\zeta
	\mathcode`\h=\eta
	\mathcode`\q=\theta
	\mathcode`\j=\vartheta
	\mathcode`\i=\iota
	\mathcode`\k=\kappa
	\mathcode`\8=\kappa%	**** should be cursive (not available)
	\mathcode`\l=\lambda
	\mathcode`\m=\mu
	\mathcode`\n=\nu
	\mathcode`\x=\xi
%				**** omicron is same as o
	\mathcode`\p=\pi
	\mathcode`\2=\varpi
	\mathcode`\r=\rho
	\mathcode`\9=\varrho
	\mathcode`\s=\sigma
	\mathcode`\v=\varsigma
	\mathcode`\t=\tau
	\mathcode`\u=\upsilon
	\mathcode`\f=\phi
	\mathcode`\4=\varphi
	\mathcode`\c=\chi
	\mathcode`\y=\psi
	\mathcode`\w=\omega
%
%	**** several letters should be bound to roman characters qqq
	\mathcode`\A="7041%	*** roman A
	\mathcode`\B="7042%	*** roman B
	\mathcode`\G=\Gamma
	\mathcode`\D=\Delta
	\mathcode`\1=\nabla
	\mathcode`\E="7045%	*** roman E
	\mathcode`\Z="7060%	*** roman Z
	\mathcode`\H="7048%	*** roman H
	\mathcode`\Q=\Theta
%				**** J should be cursive theta
	\mathcode`\I="7049%	*** roman I (Iota)
	\mathcode`\K="704B%	*** roman K (Kappa)
	\mathcode`\L=\Lambda
	\mathcode`\M="704D%	*** roman M (Mu)
	\mathcode`\N="704E%	*** roman N (Nu)
	\mathcode`\X=\Xi
	\mathcode`\O="704F%	*** roman O (Omicron)
	\mathcode`\P=\Pi
	\mathcode`\R="7050%	*** roman P (Rho)
	\mathcode`\S=\Sigma
	\mathcode`\T="7054%	*** roman T (Tau)
	\mathcode`\U=\Upsilon
	\mathcode`\F=\Phi
%				***** C should be Chi (X)
	\mathcode`\C="7058%	*** roman X
	\mathcode`\Y=\Psi
	\mathcode`\W=\Omega
}

\def\endGREEK{
	\endgroup
}

% *** default character set.  This is changed when typing greek.  So,
% *** a \RM or \IT nested within a \G should call this first.
\newcount\mathfont=0
\def\EBTdefaultCharset{\EBTdefaultChars}


\def\EBTdefaultChars{%
	\mathcode`a="7\the\mathfont61
	\mathcode`b="7\the\mathfont62
	\mathcode`c="7\the\mathfont63
	\mathcode`d="7\the\mathfont64
	\mathcode`e="7\the\mathfont65
	\mathcode`f="7\the\mathfont66
	\mathcode`g="7\the\mathfont67
	\mathcode`h="7\the\mathfont68
	\mathcode`i="7\the\mathfont69
	\mathcode`j="7\the\mathfont6A
	\mathcode`k="7\the\mathfont6B
	\mathcode`l="7\the\mathfont6C
	\mathcode`m="7\the\mathfont6D
	\mathcode`n="7\the\mathfont6E
	\mathcode`o="7\the\mathfont6F
	\mathcode`p="7\the\mathfont70
	\mathcode`q="7\the\mathfont71
	\mathcode`r="7\the\mathfont72
	\mathcode`s="7\the\mathfont73
	\mathcode`t="7\the\mathfont74
	\mathcode`u="7\the\mathfont75
	\mathcode`v="7\the\mathfont76
	\mathcode`w="7\the\mathfont77
	\mathcode`x="7\the\mathfont78
	\mathcode`y="7\the\mathfont79
	\mathcode`z="7\the\mathfont7A
	\mathcode`A="7\the\mathfont41
	\mathcode`B="7\the\mathfont42
	\mathcode`C="7\the\mathfont43
	\mathcode`D="7\the\mathfont44
	\mathcode`E="7\the\mathfont45
	\mathcode`F="7\the\mathfont46
	\mathcode`G="7\the\mathfont47
	\mathcode`H="7\the\mathfont48
	\mathcode`I="7\the\mathfont49
	\mathcode`J="7\the\mathfont4A
	\mathcode`K="7\the\mathfont4B
	\mathcode`L="7\the\mathfont4C
	\mathcode`M="7\the\mathfont4D
	\mathcode`N="7\the\mathfont4E
	\mathcode`O="7\the\mathfont4F
	\mathcode`P="7\the\mathfont50
	\mathcode`Q="7\the\mathfont51
	\mathcode`R="7\the\mathfont52
	\mathcode`S="7\the\mathfont53
	\mathcode`T="7\the\mathfont54
	\mathcode`U="7\the\mathfont55
	\mathcode`V="7\the\mathfont56
	\mathcode`W="7\the\mathfont57
	\mathcode`X="7\the\mathfont58
	\mathcode`Y="7\the\mathfont59
	\mathcode`Z="7\the\mathfont5A
}

\def\endFONT{\endgroup}



\endinput

