% $Id: ebt.tex 1.15 1993/09/23 20:09:58 dnc Exp $

%***************************************************************************
% Useful TeX macros for all equation DTDs
%***************************************************************************

%***************************************************************************
% 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.
%***************************************************************************

% so that errors do not stop TeX.  No user interaction.
\nonstopmode

% for some reason, box0 is sometimes corrupted.  This fixes.
\setbox0=\hbox{\relax}

% useful in some comparisons
\def\empty{\relax}

% very useful
\def\ifundefined#1{\expandafter\ifx\csname#1\endcsname\relax}

% makes attribute.  Example: \makeattr{FOO} will define a macro
% such that \FOO=bar will define \FOOis to be bar.
\def\makeattr#1{%
%	\expandafter\def\csname #1is\endcsname{\empty}% default is empty
	\expandafter\def\csname #1\endcsname=##1 {
	\expandafter\def\csname #1is\endcsname{##1}
}}

\def\makeattrdefault#1#2{%
	\expandafter\def\csname #1is\endcsname{#2}% default is #2
	\expandafter\def\csname #1\endcsname=##1 {
	\expandafter\def\csname #1is\endcsname{##1}
}}


% makes child.  A lot like \makeattr, but defines a macro such
% that \FOO{bar} will define \FOOis to be bar.
\def\makechild#1{%
	\expandafter\def\csname #1is\endcsname{\empty}% default is empty
	\expandafter\def\csname #1\endcsname/##1{
	\expandafter\def\csname #1is\endcsname{##1}
}}

% a dummy macro, useful when we want to turn off the behavior of a certain tag
\def\EBTnothing#1/{}

% performs #2, #1 times!
% uses globals, because #2 could be {\right)}, or something like that.
\newcount\EBTtemp
\def\EBTrecurse#1#2{
	\global\EBTtemp=#1
	\global\advance\EBTtemp by -1
	\ifnum-1<\EBTtemp
		#2
		\EBTrecurse{\the\EBTtemp}{#2}
	\fi
}

%*****************************************************************************
% ALIGNMENT
%	This is much like plain.tex's eqalign, but allows for more
%	tabs, and it does not center the equations.
%	The first portion is right justified, the rest are left justified.
%*****************************************************************************
\def\EBTalign#1{\null\vcenter{\openup\jot \mathsurround=0pt
  \ialign{\strut\hfil$\displaystyle{##}$&$\displaystyle{{}##}$\hfil
	&$\displaystyle{{}##}$\hfil&$\displaystyle{{}##}$\hfil
	&$\displaystyle{{}##}$\hfil&$\displaystyle{{}##}$\hfil
      \crcr#1\crcr}}}

\def\EBTcenter#1{\null\vcenter{\openup\jot \mathsurround=0pt
  \ialign{\strut\hfil$\displaystyle{##}$\hfil
      \crcr#1\crcr}}}

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

%*****************************************************************************
% SDATA
%	This relies heavily on the way in which the c code converts SDATA
% to TeX.  Currently, we assume part of the SDATA has the form `\TeX=_macro_'
% the c code will write \SDATA{_macro_} to the TeX file.  
%	If there is no TeX macro in the SDATA, the c code will generate
% a warning.  and write nothing to the TeX file
%*****************************************************************************

\def\SDATA{\SDATAnormal}
\def\specialSDATA{\let\SDATA=\SDATAspecial}
\def\normalSDATA{\let\SDATA=\SDATAnormal}

%*** throw away the next character ***
\def\gobble#1{}

%*** use the TeX macro provided ***
\def\SDATAnormal#1{\ifmmode #1\else\SDATAmath{#1}\fi}

%*** always be in math mode for sdata
\def\SDATAmath#1{\hbox{$#1$}}

%*** cut the '\' off the tex macro***
\def\SDATAspecial#1{\expandafter\gobble\string#1}

%*****************************************************************************
% BOXES
%*****************************************************************************
% a simple box
\def\EBTboxSingle#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}}
}

% a bold box
\def\EBTboxBold#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
}

\def\EBTboxDouble#1{\EBTdouble{\EBTboxSingle}{#1}}
\def\EBTboxTriple#1{\EBTtriple{\EBTboxSingle}{#1}}


%*****************************************************************************
% WARNING MESSAGES
%*****************************************************************************

\def\EBTwarning#1{\immediate\write16{WARNING: the SGML tag <#1> not implemented.}}

\def\EBTattrwarning#1#2{\immediate\write16{
WARNING: the attribute '#1' of <#2> yeilds unpredictable results.}}

\def\EBTsdatawarning#1{\immediate\write16{
WARNING: I don't know what to do with entity '#1'
}}

\def\debug#1{\immediate\write16{#1}}

%*****************************************************************************
% So TeX adds no unnecessary blank space to pages
%*****************************************************************************

%*** here, we put the entire contents of the file into a box.
%	This way, we can set the page hieght and width to match the box.
%	This info is stored in the DVI file, so we can tell it to the
%	renderer.

\newbox\EBTbox

\def\EBTbegin{%
	\setbox\EBTbox=\hbox\bgroup%
}

\def\EBTend{%
	\egroup
	x%			*** bogus text to trigger \box255
}

%*** This tells TeX to write only those dvi instructions necessary to display
%	the equations.  No margins or space at bottom of page.
\output={\setbox0=\box255 \count0=\dp\EBTbox \shipout\box\EBTbox}


% the following are macros for large integer signs which were posted
% to comp.text.tex by Donald Arseneau.

%  bigint.sty (or bigint.tex)   -- Donald Arseneau
% 
%  Make a big integral sign using the extensible \lmoustache
%  with balls on the tips.  This will *only* work for the cmex10
%  math extension font (possibly scaled to some other size).
%  The size of the integral depends on the integrand (argument)
%  with a minimum of approximately the size of the normal \int.
%  Note that the integral sign is vertically centered; the integrand
%  need not be.
%
%  The syntax is:
%
%  \bigint [ <overlap> ] <limits> { <integrand> }
%
%  - The integrand is what is being integrated.  Unlike the normal
%  \int syntax, the braces are necessary for \bigint.
%  - The limits are the integration limits expressed in the normal
%  way, with _{ }, ^{ }, \limits, \nolimits, and/or \displaylimits.
%  Any, none, or even all of these may be used.
%  - The optional argument gives a character to overlap with the 
%  integral sign.  This is for making a big \oint or others.
%  (\bigoint is defined as \bigint[\bigcirc])
%  - The \bigint command itself may be repeated to produce multiple
%  integral signs at the same size, but only the last copy takes 
%  parameters:  \bigint\bigint_0^1{...}  is correct. 
%  \bigint_0^1 \bigint_{-1}^0{...} will give an error.  For multiple
%  integrals with separate limits use \bigint_0^1 {\bigint _{-1}^1 {...}}. 
%
%  Examples (alternately written for LaTeX and plain TeX):
%
%  \bigint {\frac{\displaystyle 1 - \frac{1}{x^2}}{\sqrt{\displaystyle
%            x + \frac{1}{x} }}\,\,dx} = 2\sqrt{\displaystyle x+\frac{1}{x}}
%  \bigint_0^1{dx \over \sqrt{\displaystyle \log{\left( 1 \over x \right) }}}
%                 = \sqrt{\pi}
%  \bigint\bigint\bigint\limits_{-\infty}{+\infty} {\left( \begin{array}{c} 
%           a\\b\\c\\d\\e \end{array} \right)\,dx\,dy\,dz}
%  \bigint[-]_{-\infty}^{+\infty} { {e^{iwt}\over \sqrt{w^2 + w + 1}}\;dw}

\edef\BIcatz{\the\catcode`\@}
\catcode`\@=11

\newtoks\supsubtoks

\def\bigint{\begingroup \displaystyle
 \edef\@bi@fam{\fam\the\fam\relax}%
 \supsubtoks{}\def\@bi@lap{}\count@\@ne \bi@gint}

\def\bi@gint{\futurelet\@bi@next\@bi@gint}

\def\@bi@gint{% parse limits and options
\ifcase 0%
  \ifx\@bi@next\limits1\fi \ifx\@bi@next\nolimits1\fi 
  \ifx\@bi@next\displaylimits1\fi 
  \if\noexpand\@bi@next\space2\fi
  \ifcat\noexpand\@bi@next\sp3\fi
  \ifcat\noexpand\@bi@next\sb3\fi
  \ifx\@bi@next[4\fi
  \ifx\@bi@next\bigint 5\fi
 \relax \expandafter \bi@@gint
 \or \expandafter\@bi@applim
 \or \expandafter\@bi@eatspa\expandafter\\%
 \or \expandafter\@bi@appscr
 \or \expandafter\@bi@intopt
 \or \expandafter\@bi@multii
 \fi}

\def\@bi@intopt[#1]{\def\@bi@lap{#1}\bi@gint}
\def\@bi@applim#1{\supsubtoks\expandafter{\the\supsubtoks#1}\bi@gint}
\def\@bi@appscr#1#2{\supsubtoks\expandafter{\the\supsubtoks
   #1{\ifcat#1\sb \mkern-9mu\relax\fi#2}}\bi@gint}
\def\@bi@eatspa\\ {\bi@gint}
\def\@bi@multii#1{\if @\the\supsubtoks \ifx\@bi@lap\empty @\else.\fi
    \advance\count@\@ne \expandafter \bi@gint \else
    \expandafter \bi@@gint \fi}

\def\bi@@gint#1{\setbox\z@\hbox{$\m@th \@bi@fam \displaystyle {#1}$}%
   \dimen@2\ifdim\ht\z@>\dp\z@\ht\else\dp\fi\z@ % figure it out!
   \mathop{\@big@int}\nolimits
   \the\supsubtoks \box\z@ \mskip\medmuskip \endgroup}

% use vert. center, left edge for ref. point on -
% use center-center for ref. point on bullet
%
% character positioning parameters:
% {whole_top_horiz.}{wt_vertical}{top_ball_h}{tb_v}
%    {whole_bottom_horiz.}{wb_vertical}{bottom_ball_h}{bb_v}
\def\@big@Int#1#2#3#4#5#6#7#8#9{%
 \ifx\@bi@lap\empty \else 
  \rlap{{\the\textfont3 \kern #9em}\hbox to\z@
   {\hss$\m@th \@bi@fam \@bi@lap$\hss}}\fi
 \vcenter
 to\ifdim\dimen@<20pt 20pt \else\dimen@\fi
 {\the\textfont3 \m@th % do \lmoustache in a vbox.
  \hbox{8\smash{\kern-#1em\lower#2ex\hbox{%
     $\vcenter{\rlap{\the\scriptscriptfont0 -}}$%
     \kern#3em
     $\vcenter{\kern#4ex\hbox to\z@{\hss \the\scriptscriptfont2 ^^O\hss}}$%
     \kern#3em\kern1pt}}}\nointerlineskip\kern-3pt
  \cleaders\hbox{>}\vfil
  \kern-3pt\hbox{;}\nointerlineskip 
  \smash{\kern#5em\lower#6ex\hbox{%
     $\vcenter{\rlap{\the\scriptscriptfont0 -}}$%
     \kern#7em
     $\vcenter{\kern-#8ex\hbox to\z@{\hss \the\scriptscriptfont2 ^^O\hss}}$%
  }}\kern\z@
 }\ifnum\count@>\@ne
   \advance\count@\m@ne \mskip-5mu \relax \expandafter \@big@int\fi 
}

% Here are the parameters for piecing the integral together.  Even though
% I tried to use stable reference points on the characters, there is still
% quite a bit of variation when size changes so these can be varied.  

\def\@big@int{%
 \@big@Int{.2315}{.6455}{.1768}{.4673}{.0395}{.5116}{.0282}{.504}{0.4472}}

\def\bigoint{\bigint[\bigcirc]}

\catcode`@=\BIcatz \let\BIcatz\underfined

\let\EBTint=\bigint

\endinput
