\input blue.tex
\loadindexmacros
\report
\font\grkop=cmr12 scaled\magstep3
\bluechapter Mathematics

\beginsummary
On top of plain \TeX{} \bluetex{} provides facilities for:
automatic numbering,
cross-referencing for formulas,
matrix icons,
multi-alignment points in eqalign,
primed summation symbols,
arrows for commutative diagrams, and
some special symbols.
Examples borrowed from literature are incfluded to illustrate 
how \TeX{} can be used to mark up mathematics.
This anthology shows that many details have to be prescribed.
To give a math manuscript to a keyboarder without markup guidance
is doomed to yield mediocre results.
\endsummary

\noindent^{Swanson} {\oldstyle1986} is a good source for what math should 
look like in print. 
Very nice is also `^{Mathematical Writing},' a report from 
a Stanford Workshop organized by Knuth.
\TeX{} is already very rich for math markup, 
because in his Preface to \TB{} Knuth states
\beginquote
\noindent\llap`\dots \TeX, a new typesetting system intended for the
creation of beautiful books\Dash and especially
for books that contain a lot of mathematics.'
\endquote

\bluehead What's the problem, Doc?

If we assume that mathematicians write math manuscripts
in the classical sense, then there is a problem when those mathematicians
wish to have their work formatted via computer-assisted 
document-preparation tools like \TeX. 
What has to be keyboarded looks much different from the manuscript.
Examples of this phenomenon are omni-present in this work.

\blueexample Disparity math notation and markup notation

\thisverbatim{\catcode`!=12
   \catcode`~=0 }
\begindemo
x=1+\left({y^2\over k+1}
      \right)^{\!\!1/3}
~yields
$$x=1+\left({y^2\over k+1}\right)^
                       {\!\!1/3}$$
\enddemo
Because of this disparity, the problem is how to get a correct\ftn{Not
   only in the sense that the \TeX{} formatter does not complain, 
   no, correct in the sense of complying with tradition of mathematical 
   typesetting.} 
\TeX script, starting from a mathscript.
This is difficult\ftn{In the example at hand the keyboarder has to be 
  aware of \cs{over} and $/$ respectively, and when to use which. 
  Moreover, the correct size of the parentheses must be supplied, and 
  some kernings have to be inserted!}
due to the inherent complexity of math typesetting, and due to
the unusual nature of \TeX, if not because of the bewildering and
confusing flavours of \TeX-based products.
Even a fancy and friendly, {\smc wysiwyg} user-interface is not enough.
Optical scanners of math\Dash or systems which understand
  spoken mathematics\Dash are still science fiction.

\bluehead The extras

\bluetex{} provides as extras to plain {\TeX} facilities for:
automatic numbering,
cross-referencing for (display) formulas,
macros for ^{matrix icons},
an extension of ^|\eqalign| with respect to multi-alignment points,
primed summation symbols,
arrows for commutative diagrams, 
^|\beginmathdemo| and |\endmathdemo| from manmac, and
poor man's ^{blackboard bold} and some other special symbols.
These extras are introduced via examples.

\blueexample Automatic numbering and cross-referencing

^^{formula,\ cross-referencing}
^^{formula,\ automatic numbering}
^^{formula,\ labeled}
This is a compatible extension.
For the markup of math ^{cross-referencing} insert 
instead of plain's explicit (reference) number

\bitem \noindent^|\ref|, for creation of the number, and 
       \thisverbatim{\emc}|\ref\<name>|, for attaching
       a name to the automatically generated number, and
\bitem ^|\crsref||\<name>|, for cross-referencing.
\smallbreak

\begindemo
%Automatic numbering
$$a+b\eqno\ref$$
!yields
$$a+b\eqno\ref$$
\enddemo


\begindemo
%Automatic numbering, and 
%symbolic cross-referencing
$$c*d\eqno\ref\cgl$$
Text, \crsref\cgl
!yields
$$c*d\eqno\ref\cgl$$
Text, \crsref\cgl
\par\noindent
\enddemo
\exercise And what about forward referencing?
\answer This is not possible in a one-pass job. Therefore a note
        is printed in the margin while proofing. The correct
        number has to be filled in ultimately.

%end answer
Handy token variables are ^|\prenum|
and ^|\postnum|.\ftn{Courtesy Michael Spivak.} 
Their contents is inserted before, respectively 
after, the automatically generated number in \cs{ref} and \cs{crsref}. 
Because of this one can get labels and crossrefs like {\oldstyle13}a, 
or enclosing numbers by parenthesis. 
The latter are the defaults of these token variables. 
If in such a case the formula counter must keep its value, provide
|\advancefalse|. 
\exercise How can we  retain the number, and suffix a letter, as
          label of a formula to come?
\answer Provide \cs{advancefalse}, and |\postnum{a)}|.

\blueexample Matrix icons

Useful icons concern the matrices: 
rectangular, via ^|\icmat|, 
triangular (lower left and upper right), 
via ^|\icllt| or ^|\icurt|, and
upper Hessenberg, via ^|\icuh|.
The arguments are dimensionless numbers. 
The first argument reflects the vertical size, and 
the second the horizontal size. 
In case of \cs{icuh} the second argument is the Hessenberg bandwidth
and the third is the difference between the first and the second.
        

\begindemo
\unitlength1ex
$$\icmat44\kern\unitlength\icllt44=
    \icllt44\icuh413\qquad 
    \hbox{AL}=\hbox{LH}$$
!yields
\unitlength1ex
$$\icmat44\kern\unitlength\icllt44=
    \icllt44\icuh413\qquad 
    \hbox{AL}=\hbox{LH}$$
\enddemo

\exercise Another matrix factorization reads
\begincenterverbatim
$$\icmat63=\icmat63\kern\unitlength
  \icurt63\qquad\hbox{A}=\hbox{QR}$$
!endcenterverbatim
When used together with the example above, 
align on the =-signs, that is, on the =-sign in the icons and on the
=-sign in the formulas.
\answer Use \cs{eqalign} as follows.
\beginverbatim
$$\unitlength1ex
  \eqalign{
   \icmat44\kern\unitlength\icllt44={}&
      \icllt44\icuh413&
      \qquad \hbox{AL${}={}$LH}\cr
   \icmat63={}&
      \icmat63\kern\unitlength\icurt63&
      \qquad \hbox{\phantom{A}A${}={}$QR}}
$$
!endverbatim

\blueexample Compatible extension of eqalign %
             with multiple alignment points

^^|\eqalign|
\begindemo
$$\eqalign{
\cos(z\sin\theta)={}&
  J_0(z)&
  {}+2\sum_{n=1}^\infty 
    J_{2n}(z)\cos2n\theta\cr
  \sin(z\sin\theta)={}&      
        &
  {}+2\sum_{n=1}^\infty
J_{2n+1}(z)\sin(2n+1)\theta\cr
}$$
!yields
$$\eqalign{
\cos(z\sin\theta)={}&J_0(z)&
  {}+2\sum_{n=1}^\infty J_{2n}(z)\cos2n\theta\cr
\sin(z\sin\theta)={}&      &
  {}+2\sum_{n=1}^\infty
J_{2n+1}(z)\sin(2n+1)\theta\cr
}$$
\enddemo
\exercise Why is the empty formula used in the markup?
\answer The empty formula $\{\}$ is used to coerce the + to behave
        as a dyadic operator, and the = to behave similarly.
        In other words to yield the correct spacing.

\blueexample Macros for showing math markup and the result

^|\beginmathdemo| (and variants) and |\endmathdemo|, 
are used in the \TB{} script, {\oldstyle444}--{\oldstyle466}, 
for indented display Math,  see \TB{} chapters 
{\oldstyle16}--{\oldstyle19}.\ftn{There 
   is only one second part macro for all these cases. 
   Its replacement text is modified into \cs{crcr}\cs{egroup}\$\$.}
^^|\begindemo|^^|\yields|
They are used to typeset the marked up copy and the
typeset result side-by-side. 
The user does not have to bother about the template for the 
alignment display used.  
The functionality provided is similar, but a little restricted, 
to the (\LaTeX) styles for switching from 
one-column to two-column format and vice versa. 
But, \dots\thinspace it is much simpler and more efficient\Dash 
IMHO with all respect\Dash
because it does not entail OTR processing.

\thisverbatim{\catcode`\|=12 }
\begindemo
%TeXbook 128
\beginmathdemo
   \it Input&\it Output\cr
   \noalign{\vskip2pt}
   |$x^2$|&x^2\cr
\endmathdemo
!yields
\beginmathdemo
   \it Input&\it Output\cr
   \noalign{\vskip2pt}
   |$x^2$|&x^2\cr
\endmathdemo
\enddemo

\thisverbatim{\catcode`\|=12 }
\begindemo
%TeXbook 139
\begindisplaymathdemo
   |$$x+y^2\over k+1$$|&
            x+y^2\over k+1\cr
   \noalign{\vskip2pt}
   |$${x+y^2\over k}+1$$|&
            {x+y^2\over k}+1\cr
\endmathdemo
!yields
\begindisplaymathdemo
  |$$x+y^2\over k+1$$|&
            x+y^2\over k+1\cr
   \noalign{\vskip2pt}
   |$${x+y^2\over k}+1$$|&
            {x+y^2\over k}+1\cr
   \noalign{\vskip-1pt}
\endmathdemo
\enddemo
Remark. Note that we have to supply the input and the output, 
due the \TeX's rigidness of the category codes once assigned.

\blueexample Poor man's blackboard bold and some special symbols

^^{blackboard bold}
Now and then other symbols than those provided in the font tables 
of Appendix~F of \TB{} are needed.\ftn{Generally, non-standard fonts are 
    already available somewhere. For math consult AMS.}
These can be constructed approximately.

{\gutter4em
\def\boxit#1{\vbox{\hrule\hbox{\vrule
             #1\vrule}\hrule}}
\begindemo
$$\halign{#\hfil\quad&
              \hfil#\hfil\cr
 natural numbers    &$\IN$ \cr
 integers           &$\Z$ \cr
 rational numbers   &$\Q$ \cr
 reel numbers       &$\R$ \cr
 and complex numbers&$\C$ \cr
 next to\cr
 greater or less &$\gtrless$\cr
 external tensor product&
               $\boxtimes$\cr}$$
!yields
$$\def\IN{{\rm I\kern-.5ex N}}
\halign{#\hfil\quad&\hfil#\hfil\cr
 natural numbers    &$\IN$ \cr
 integers           &$\Z$ \cr
 rational numbers   &$\Q$ \cr
 reel numbers       &$\R$ \cr
 and complex numbers&$\C$ \cr
 next to\cr
 greater or less &$\gtrless$\cr
 external tensor product&
               $\boxtimes$\cr}$$
\enddemo}
\cs{IN}, \cs{Z}, et cetera are incorporated in \bluetex.
\exercise On the \TeX-NL network there was a request for the pro mille
          token. How to get it?
\answer It is in the wasy font. A poor man's version is an open problem
        as yet, because the lower 0 is neither 5pt, nor 6pt, and therefore
        the symbol can't be built from \% and an appropriate sized 0.
        A very, very poor man's version reads |\%\lower.2ex\hbox{\fiverm 0}|,
        in fact unacceptible.
        Building it from \cs{frac}, |\frac0/{00}|, is different from \%.

\bluehead Use

Many ingredients are supplied by plain. 
It is just a matter of what-and-how, what to use from the wealth offered.
It has all to do with what the script should look like in print
{\em within the context}.
In the sequel some more math markup will be shown, not restricted to
markup tags from \bluetex{}.
A classical example is the markup for the various uses of O.

Noteworthy is further that
punctuation symbols are also used with spacing before them, 
ditto for the vertical bars and the backslash.
The size of delimiters is dependent on the context,
which can't be completely automated.
The variants can be obtained via special markup, for example via 

\bitem ^{coercion macro}s 
   (to guide \TeX{} with respect to spacing before and after,
    for example via \cs{mathdelimiter},
    or to positioning of embellishments below and on top,
    for example via  \cs{mathop})
\bitem the use of the ^{empty formula}, $\{\}$, 
       to coerce binary behaviour of the operator 
\bitem macros to impose the size of delimiters 
   (\cs{biggl} et cetera)
\bitem special control sequences
   (like \cs{colon}).
\smallbreak
    
\bluesubhead Plain's display maths

Most displays belong to one of the categories given below.

\blueexample A labeled formula in display

Spaces are neglected in math mode. ^^{formula,\ labeled}
The kern |\,| is needed to coerce the correct spacing.
\begindemo
$$\sin2x=2\sin x\,\cos x
     \eqno({\rm TB186})$$
!yields
$$\sin2x=2\sin x\,\cos x
     \eqno({\rm TB186})$$
\enddemo

\blueexample Formula hyphenation; shifting of lines

A hyphenated formula via \cs{displaylines}. ^^{formula,\ hyphenation}
With the use of \cs{hfill} we can shift lines to the
left or right.
\begindemo
$$\displaylines{F(z)=
a_0+{a_1\over z}+{a_2\over z^2}
  +\cdots+{a_{n-1}\over z^{n-1}}
  +R_n(z),\hfill\cr
\hfill n=0,1,2,\dots\,,\cr
F(z)\sim\sum_{n=0}^\infty 
  a_nz^{-n},\quad z\to\infty
  \hfill\llap{(TB ex19.16)}}$$
!yields
$$\displaylines{F(z)=
a_0+{a_1\over z}+{a_2\over z^2}
  +\cdots+{a_{n-1}\over z^{n-1}}
  +R_n(z),\hfill\cr
\hfill n=0,1,2,\dots\,,\cr
F(z)\sim\sum_{n=0}^\infty 
  a_nz^{-n},\quad z\to\infty
  \hfill\llap{(TB ex19.16)}}$$
\enddemo

\blueexample Alignment and centered labeling

\begindemo
$$\eqalign{\cos2x
      &=2\cos^2x-1\cr
      &=\cos^2x-\sin^2x}
  \eqno({\rm TB193})$$
!yields
$$\eqalign{\cos2x
      &=2\cos^2x-1\cr
      &=\cos^2x-\sin^2x}
  \eqno({\rm TB193})$$
\enddemo

\blueexample Alignment and labels per line

\begindemo
$$\eqalignno{\cosh2x
     &=2\cosh^2x-1&({\rm TB192})\cr
     &=\cosh^2x+\sinh^2x}$$
!yields
$$\eqalignno{\cosh2x
     &=2\cosh^2x-1&({\rm TB192})\cr
     &=\cosh^2x+\sinh^2x}$$
\enddemo

Remark. %In not too narrow columns the last formulas 
        %are both centered.
If one wants \cs{eqalignno} to behave like 
\cs{displaylines}\Dash that is, left-justified\Dash
then modify in \cs{eqalignno} the first
\cs{tabskip}=\cs{centering} assignation into 
\cs{tabskip}= \cs{z@skip}.

\blueexample Subscripts

The depth of a ^{subscript} depends on whether there is
a superscript. With a superscript a subscript sinks a little. 
In order to obtain uniformly placed subscripts
the solution is to adjust the following font dimension 
parameters, see \TB{} {\oldstyle179}.
\begindemo
\fontdimen16\textfont2=2.7pt
\fontdimen17\textfont2=2.7pt
$$X_1+Y_1^2=1$$
!yields
\fontdimen16\textfont2=2.7pt
\fontdimen17\textfont2=2.7pt
$$X_1+Y_1^2=1$$
\enddemo

\thissubhead{\runintrue}
\bluesubhead A snapshot of examples\par borrowed from \TB, 
to illustrate the need for extra markup. 
\TB{} chapters {\oldstyle16}\dash{\oldstyle19} contain many examples, 
well-ordered and appropriately explained.   

\blueexample Dots and the comma after

^^{dots and the comma after}
\begindemo
$${\bf S^{\rm-1}TS=dg}(\lambda_1,
   \ldots\,,\lambda_n)=\bf\Lambda$$
!yields
$${\bf S^{\rm-1}TS=dg}(\lambda_1,
   \ldots\,,\lambda_n)=\bf\Lambda$$
\enddemo

\blueexample Summation with limits

\begindemo
$$\sum_{k=1}^\infty{1\over2^k}=1$$
!yields
$$\sum_{k=1}^\infty{1\over2^k}=1$$
\enddemo
\exercise In line we usually have subscripts and superscripts.
          How can we get those?
\answer Automatically! \TB{} 144: ` A displayed sum usually occurs 
        with `limits,' i.e., with subformulas that are to appear above
        and below it. \dots\thinspace According to the normal conventions 
        of mathematical typesetting, \TeX{} will change this to 
        `$\sum_{k=1}^\infty{1\over2^k}=1$' (i.e., without limits) if it
        occurs in text style rather than in displaystyle.' Explicit control
        is possible via the control sequences \cs{limits}, respectively
        \cs{nolimits}.

%end answer

\blueexample Overlining; accents

If there is an example with various markup possibilities, this is the one,
although the various O-s comes close. ^^{overlining}^^{accents in math}
\begindemo
$$\bar z,\ \overline z,\
\bar P,\ \overline P,\
\bar h,\ \hbar,\
\overline{AB}$$
!yields
$$\bar z,\ \overline z,\
\bar P,\ \overline P,\
\bar h,\ \hbar,\
\overline{AB}$$
\enddemo

\blueexample Square roots

\begindemo
$$\sqrt{1+\sqrt{1+\sqrt{1+x}}}$$
!yields
$$\sqrt{1+\sqrt{1+\sqrt{1+x}}}$$
\enddemo

\blueexample Roman texts in math, \TB~{\oldstyle163}; accents

^^{roman texts in math}
\begindemo
$${f(x+\Delta x)-f(x)\over
     \Delta x}\to f'(x)\quad
  {\rm as}\quad\Delta x\to0$$
!yields
$${f(x+\Delta x)-f(x)\over
     \Delta x}\to f'(x)\quad
  {\rm as}\quad\Delta x\to0$$
\enddemo
Remark. \TeX{} uses special conventions for accents in formulas, so the 
accents in ordinary text and the ^{accents in math} have different markup, 
\TB~{\oldstyle135}.


\blueexample Kerning; positive and negative

^^{kerning; positive and negative}
\thisverbatim{\catcode`\!=12
              \catcode`\~=0 }
\begindemo
$$       \int\!f(x)\,dx,   \quad
 \Gamma_{\!2}+\Delta^{\!2},\quad
 \sum^\infty_{n=-\infty}\!
                \!\!\cos nt$$
~yields
$$         \int\!f(x)\,dx,        \quad
 \Gamma_{\!2}+\Delta^{\!2},       \quad
\sum^\infty_{n=-\infty}\!\!\!\cos nt$$
\enddemo

\blueexample Empty formula and subscripting

^^{empty formula and subscripting}
\begindemo
(\lambda)_2\,{}_2F_1 
!yields
$$(\lambda)_2\,{}_2F_1$$ 
\enddemo

\blueexample Math operator

^^{math\ operator}
\begindemo
$$\mathop{\hbox{\rm Res}}_
  {s=e^{i\pi}}f(s)=-e^{i\pi z}$$
!yields
$$\mathop{\hbox{\rm Res}}_
  {s=e^{i\pi}}f(s)=-e^{i\pi z}$$
\enddemo

\blueexample Colon markup; punctuation vs.\ operator

^^{colon markup}
\begindemo
$$f\colon A\to B,\quad \{x:x>5\}$$
!yields
$$f\colon A\to B,\quad \{x:x>5\}$$
\enddemo

\blueexample Context-dependent size

\begindemo
$$\bigl\!vrt\,\alpha(\sqrt
   {\mathstrut a}+\sqrt
   {\mathstrut b}\,)\,
  \bigr\!vrt
\leq!vrt\alpha!vrt\,
  \bigl\!vrt\sqrt
   {\mathstrut a}+\sqrt
   {\mathstrut b}\,
  \bigr\!vrt$$
!yields
$$\bigl\Vert\,\alpha(\sqrt{\mathstrut a}+
       \sqrt{\mathstrut b}\,)\,\bigr\Vert
  \leq\vert\alpha\vert\,
  \bigl\Vert\sqrt{\mathstrut a}+
   \sqrt{\mathstrut b}\,\bigr\Vert$$
\enddemo
It is tempting to insert a multiplication dot. Don't!

\blueexample Vertical bars, \TB{} {\oldstyle146}, {\oldstyle147},
             ex{\oldstyle18}.{\oldstyle21}

\begindemo
$$\big\{\,x^3\bigm\vert h(x)\in
       \{-1,0,+1\}\,\bigr\}$$
!yields
$$\bigl\{\,x^3\,\bigm\vert\,h(x)\in
       \{-1,0,+1\}\,\bigr\}$$
\enddemo

\blueexample Halves variety \TB{} ex{\oldstyle11}.{\oldstyle6}, ex{\oldstyle19}.{\oldstyle2}

Essential is the use of \cs{textstyle}.
\begindemo
$$D^\lambda_0(z)=
  4a_\lambda\, z\,{}_2F_1(%
  \textstyle
  \lambda+{1\over2},{1\over2};
  {3\over2};z)$$
%Typographer's 1/2
Typographer's $\fracdek1/2$,
(recipes), which works better 
than a mathematician's $1\over2$
!yields
$$D^\lambda_0(z)=
4a_\lambda\, z\,{}_2F_1(\textstyle\lambda+{1\over2},{1\over2};
{3\over2};z)$$
Typographer's $\fracdek1/2$,
(recipes), which works better 
than a mathematician's $1\over2$
\enddemo

\blueexample Under and overbraces

Subtle use of fonts, and \cs{mathstrut} to enforce size.
For under and over parentheses see TTN 3.4. ^^{underbraces}^^{overbraces}
\begindemo
$$\{\underbrace{\overbrace
 {\mathstrut a,\ldots,a}^
     {k\;a\mathchar`'\rm s},
 \overbrace{\mathstrut b,\ldots
    ,b}^{l\;b\mathchar`'\rm s}}
      _{k+l\rm\;elements}\}$$
!yields
$$\{\underbrace{\overbrace{\mathstrut 
  a, \ldots,a}^{k\;a\mathchar`'\rm s},
    \overbrace{\mathstrut b,\ldots,b}
      ^{l\;b\mathchar`'\rm s}}
      _{k+l\rm\;elements}\}$$
\enddemo

\blueexample Diagonal dots, coercions, \TB{} ex{\oldstyle18}.{\oldstyle45}

^^{diagonal dots}
\begindemo
$$2\uparrow\uparrow k
   \mathrel{\mathop=^{\rm def}}
   2^{2^{2^{\cdot^{\cdot^
            {\cdot^2}}}}}\vbox
  {\hbox{$\Big\}\scriptstyle k$}
   \kern0pt}$$
!yields
$$2\uparrow\uparrow k\mathrel{\mathop=
  ^{\rm def}}
  2^{2^{2^{\cdot^{\cdot^{\cdot^2}}}}}
  \vbox{\hbox{$\Big\}\scriptstyle k$}
  \kern0pt}$$
\enddemo

\exercise What is the function of the \cs{kern}0pt?
\answer To set the curly brace on the baseline.

\exercise Can the \cs{cdot} be replaced by just a period?
\answer It looks like it. Used within the picture environment
        I stumbled on lack of scaling invariance for the latter case?!?
        As far as I see it now the \cs{cdot} yields nicer result anyway.
        Because of the explicit \cs{Big} the above markup is not
        scaling invariant.

\blueexample Undoing mathsurround space

\begindemo
$2{\times}3$-matrix
!yields
\hfil$2{\times}3$-matrix
\enddemo

\blueexample All those O-s

\begindemo
$\emptyset$, (the empty set)
$f\circ g\colon
  x\mapsto f\bigl(g(x)\bigr)$,
  (composition), and 
   order symbols
$o(h^2)$,
$O(h^2)$.
!yields
\par $\emptyset$, {(the empty set)},
\par $f\circ g\colon x\mapsto f\bigl(g(x)\bigr)$
(composition),
\par and the order symbols $o(h^2)$ and $O(h^2)$
\enddemo

\blueexample Set difference vs.\ cosets

^^{set difference}^^{cosets}
\begindemo
$A\setminus A=\emptyset,
 \hbox{and the cosets of $G$ 
 by $H$:\ }G\backslash H$
!yields
$A\setminus A=\emptyset,
\hbox{and the cosets of $G$ by $H$:\ }
  G\backslash H$
\enddemo

\blueexample The Cardano solution to third-order equation

\begindemo
%x^3+px=q, p,q\ge0
$$\root3\of{\sqrt{p^3/27-q^2/4}+
  q/2}-\root3\of{\sqrt{p^3/27+
  q^2/4}-q/2}$$
!yields
$$\root3\of{\sqrt{p^3/27-q^2/4}+q/2}-
 \root3\of{\sqrt{p^3/27+q^2/4}-q/2}$$
\enddemo

\blueexample Derivatives

The problem is the three dotted derivative, ^^{derivatives}
\TB~{\oldstyle136}.
\begindemo
$$\dot y\,\ddot y\, 
  \skew3\dot{\ddot y}\quad
  y'\,y''\,y'''        \quad
\partial_xy\,\partial_x^2y\,
\partial_x^3y$$
!yields
$$\dot y\,\ddot y\, 
  \dot{\ddot y\kern2pt}\quad
  y'\,y''\,y'''        \quad
\partial_xy\,\partial_x^2y\,
\partial_x^3y$$
\enddemo

\blueexample Bessel equation

^^{Bessel equation}
\begindemo
$$z^2w''+zw'+(z^2-\nu^2)w=0$$
solutions:
$J_{\pm\nu}(z)$, 
$Y_{\pm\nu}(z)$, 
$H_\nu^{(1)}(z)$,  
$H_\nu^{(2)}(z)$
!yields
$$z^2w''+zw'+(z^2-\nu^2)w=0$$
solutions:
$J_{\pm\nu}(z)$, 
$Y_{\pm\nu}(z)$, 
$H_\nu^{(1)}(z)$, 
$H_\nu^{(2)}(z)$
\enddemo

\blueexample Primed summation symbols and split formula

Subtle use of the prime and the right font. 
Nice is the nested use of the coercions \cs{mathop} and 
\cs{mathrel}. A minor detail is to preserve the dyadic 
character of the + in the last term. \cs{acclap} is
incorporated in \bluetex. See \TB{} ex{\oldstyle18}.{\oldstyle44}.
\begindemo
$$\displaylines{
  \mathop{{\sum}\acclap'}_{k=0}^n
  a_kT_k(x)
  \mathrel{\mathop=^{\rm def}}
 .5\kern1pt a_0+a_1 x+a_2T_2(x)+
  \cdots                  \hss\cr
  \hfill{}+a_nT_n(x)}$$
!yields
$$\displaylines{
     \mathop{{\sum}\acclap'}_{k=0}^n
 a_kT_k(x)\mathrel{\mathop=^{\rm def}}
 .5\kern1pt a_0+a_1 x+a_2T_2(x)+\cdots
                               \hss\cr
                \hfill{}+a_nT_n(x)}$$
\enddemo
\exercise How can we prevent the line distance from growing larger 
          than the regular value?
\answer Give the summation symbol depth 0.

\blueexample Hypergeometric function

^^{hypergeometric function}
Subtle subscripting, size of parentheses, and positioning of arguments. 
\begindemo
$$M_n(z)={}_{n+1}F_n\Bigl({k+a_0,
   \atop\phantom{kc_1}}
   {k+a_1,\dots,k+a_n
   \atop k+c_1,\dots,k+c_n};z\Bigr)
$$
!yields
$$M_n(z)={}_{n+1}F_n\Bigl({k+a_0,
   \atop\phantom{kc_1}}
   {k+a_1,\dots,k+a_n
   \atop k+c_1,\dots,k+c_n};z\Bigr)
$$
\enddemo
\exercise Why has the \cs{phantom} argument |kc_1|?
\answer   It could have been anything representative for the lower part.
          With the k and the subscript in the \cs{phantom} we are sure
          that the vertical positioning will be OK.

%end answer
\blueexample From \TB{} {\oldstyle177}, (p)matrix as formula part. % 
             proclaim is used too

\begindemo
\proclaim Definition. $x$ is called 
an eigenvector with 
eigenvalue $\lambda$ of the matrix
$$A=\pmatrix{
    a_{11}&a_{12}&\ldots&a_{1n}\cr
    a_{21}&a_{22}&\ldots&a_{2n}\cr
    \vdots&\vdots&\ddots&\vdots\cr
    a_{n1}&a_{n2}&\ldots&a_{nn}\cr}$$
if $Ax=\lambda x$.
\par
!yields
\proclaim Definition. $x$ is called 
an eigenvector with 
eigenvalue $\lambda$  
of the matrix
$$A=\pmatrix{
    a_{11}&a_{12}&\ldots&a_{1n}\cr
    a_{21}&a_{22}&\ldots&a_{2n}\cr
    \vdots&\vdots&\ddots&\vdots\cr
    a_{n1}&a_{n2}&\ldots&a_{nn}\cr}$$
if $Ax=\lambda x$.

\enddemo%blank line is necessary

\blueexample Split equation and context-sized delimiters

\begindemo
From Swanson (1986, Section 3.3
              Math in Display)
Because it is a large formula
I used \displaylines. 
For the integral we need \nolimits
to inactivate the default placement
of limits.
Furthermore, there is subtle use of
subscripting and delimiters of
varying sizes.
Finally the shifting of parts
has to handled corrrectly.
See the script for the details.
!yields
$$\displaylines{
  \int\nolimits_U\delta(I)\mu(I)
                   \leq{}\hfill\cr
  \quad{}\sum_{{\cal D}}
         \sum_{{\cal D}_{I'}}
  \biggl[\int\nolimits_J
  \alpha(J')\mu(J')-\alpha(J)\mu(J)
                         \hfill\cr
  \hfill    {}-\int\nolimits_J
    [\{s(\alpha\eta)(J')\}
       /\eta(J')]\mu(J')\biggr]\cr
  \quad{}+\biggl[
       \sum_{{\cal D}}
       \sum_{{\cal D}_{I'}}
   |\alpha(J)-[\{s(\alpha\eta)(J)\}
   /\eta(J)]|\mu(J)\biggr]\hfill\cr
  \hfill
   {}\times\biggl[
       \sum_{{\cal D}}
       \sum_{{\cal D}_{I'}}
   |\alpha(J)-[\{s(\alpha\eta)(J)\}
   /\eta(J)]|\eta(J)\biggr] \cr} $$
\enddemo

\blueexample Rhombus scheme

^^{rhombus\ scheme}
\begindemo
The idea is to align vertically.
Pseudo markup reads
\setbox\ru={</ line>}
\setbox\rl={<\ line>}
$$\halign{<template>\cr
1st &   &e...\cr
    &\ru&    &\rl&    \cr
q...&   &    &   &q...\cr
    &\rl&    &\ru&    \cr
    &   &e...&\omit...
              \hidewidth\cr}$$
For the details consult the script.
!yields
{\hfuzz=30pt
\newbox\ru %
\newbox\rl %
\setbox\ru=\hbox{\unitlength=1ex
   \xdim{4}\ydim{2}
   \beginpicture
     \put(0,0){\line(2,1){4}}
   \endpicture}
%\diagline . 4ex wd +2ex ht\relax}%
\setbox\rl=\hbox{\unitlength=1ex
   \xdim{4}\ydim{2}
   \beginpicture
     \put(0,2){\line(2,-1){4}}
   \endpicture}
%\diagline . 4ex wd -2ex ht\relax}%
$$\quad\vbox{\offinterlineskip
\halign to\displaywidth
{\tabskip=0pt   \hfil$#$%left element
&\hfil$\vcenter{#}$\hfil%left lines
&\hfil$#$\hfil          %middle elements
&\hfil$\vcenter{#}$\hfil%right lines
&$#$\hfil               %right elements
\tabskip=\centering\cr  %end template
1^{st}\/{\rm RS}\hfill
         & &e^{(s)}_k&&     \cr
&\copy\ru& &\copy\rl&       \cr
q^{(s+1)}_k&&&&q^{(s)}_{k+1}\cr
&\copy\rl& &\copy\ru&       \cr
&     &e^{(s+1)}_k
   &\omit$={q^{(s)}_{k+1}\over q^{(s
+1)}_k}\,e^{(s)}_k$\hfil\hidewidth\cr
\noalign{\vskip1ex}
2^{nd}\/{\rm RS}\hfill
         & &q^{(s)}_k&&     \cr
&\copy\ru& &\copy\rl&       \cr
e^{(s+1)}_{k+1}&&&&e^{(s)}_k\cr
&\copy\rl& &\copy\ru&       \cr
&     &q^{(s+1)}_k
   &\omit$=q^{(s)}_k+(e^{(s)}_k-
    e^{(s+1)}_{k+1})$\hfil\hidewidth
                    \cr}%end halign
}% end vbox element
$$}
\enddemo

\blueexample Commutative diagram, confer \TB{} ex{\oldstyle18}.{\oldstyle46}

Nice use of two-sided \cs{hidewidth}, ^^{commutative diagram}
and the subtle \cs{strut} to place the superscript of {$\cal F$}.
There is no strict alignment. The elements at the nodes overflow
into the space of the arrows. As a consequence we need arrows of
various lengths.
\begindemo
\let\normalbaselines
    \adaptedbaselines
$$\matrix{
  f&\lmapright\otimes&a_f\cr
  \mapdown{{\cal F}}&&\mapup{%
           {\cal F}\strut^{-}}\cr
  \hidewidth{\cal F}(f)\hidewidth
    &\mapright\times\hfil&
    \hidewidth\bigl({\cal F}(f)
         \bigr)^2\hidewidth\cr}$$
!yields
\let\normalbaselines\adaptedbaselines
$$%Diagram
\matrix{f&\lmapright\otimes&a_f\cr
    \mapdown{{\cal F}}&&\mapup{%
            {\cal F}\strut^{-}}\cr
    \hidewidth{\cal F}(f)\hidewidth
    &\mapright\times\hfil&
    \hidewidth\bigl({\cal F}(f)
          \bigr)^2\hidewidth\cr}$$
\enddemo

\blueexample Partitioning

^^{partitioning}
\begindemo
$$\def\data{$I_{n-r}$\cs 0       \rs
                0\cs $I-2v_rv_r^T$}
P_r=\left(\vcenter{\ruled
          \btable\data}\right)$$
!yields
$$\def\lft{\hfil$}\def\rgt{$\hfil}
\def\data{I_{n-r}\cs 0       \rs
                0\cs I-2v_rv_r^T}
P_r=\left(\vcenter{\ruled
          \btable\data}\right)$$
\enddemo
\exercise How can we avoid \$-s in the  markup of the data?
\answer Define \cs{lft} and \cs{rgt} equal to \$ with
        \cs{hfil} added left, respectively right, for centering.

\exercise How can we construct partitioned matrices in general?
\answer Make use of nested tables. Consider the partitioned matrix,
        a \cs{ruled}\cs{btable}, to be built from blocks  
        with each block a non-ruled matrix.

%end answer

\blueexample Continued fractions with alignment on =, and interruption

^^{continued fraction}
\begindemo
Many details come together in
this markup. Not in the least
the alignment on = where one is
an =-def. Also the space
saving variants, borrowed from
literature are relevant.
The special `\over'-line is a 
poor man's use of \atop and 
\over, because \over is a
primitive.
Peruse the script. 
!yields
\def\cfsym{\mathop{\grkop \Phi}}
$$\eqalignno{
1+\cfsym_{k=1}^n{a_k\over b_k}
&{}\buildrel{\rm def}\over=
 1+{a_1\over\displaystyle b_1+
   {\strut a_2\over\strut
    \vrule height3ex width0pt\relax
    \displaystyle b_2 +
     \lower2.0ex\hbox{$\ddots\,
      \lower1.25ex\hbox{$+
      {\displaystyle a_{n-1}\over
        \displaystyle b_{n-1}+
                 {\strut a_n\over
           \displaystyle b_n}}$}
                        $}
    }
   }\cr
\noalign{%\noindent %not necessary
with (space saving)
         variant notations}
&{}\buildrel{\rm\phantom{def}}\over=
1+\cf{a_1}{b_1}+\cf{a_2}{b_2}+\cdots+\cf{a_n}{b_n}\cr
%
&{}\buildrel{\rm\phantom{def}}\over=
1+
{a_1\over\textstyle\strut
    \vrule height2.5ex width0pt
    b_1\,+\,}
{a_2\over\textstyle\strut
    \vrule height2.5ex width0pt
    b_2\,+\,}
    \cdots
{a_n\over\textstyle\strut
    \vrule height2.5ex width0pt
    b_n}
\cr}%end\eqalignno
$$
\enddemo
\exercise How can we  replace the division line by $\cf{}{}$ \ ?
\answer This is an open problem. If you have an elegant solution,
        let me know.

%end answer
\blueexample Context sensitivity

Certain accents can grow a little with what has to be accented, \TB~{\oldstyle136}. 
^^{context sensitivity}^^{accents in math}
\begindemo
$$\widehat{xy},
 \widetilde{xyz}$$
!yields
$$\widehat{xy},
  \widetilde{xyz}$$
\enddemo

\blueexample Matrix equation

^^{matrix equation}
\begindemo
$$\displaylines{\indent
\bordermatrix{
   &      &\rm A &      \cr
   &\times&\times&\times\cr
   &\times&\times&\times\cr
   &\times&\times&\times}
\bordermatrix{
   & &\rm N & \cr
   &1&      & \cr
   &0&1     & \cr
   &0&\times&1}
\hfill\cr\hfill=
\bordermatrix{& &\rm N & \cr
              &1&      & \cr
              &0&1     & \cr
              &0&\times&1}
\bordermatrix{
   &      &\rm H &      \cr
   &\times&\times&\times\cr
   &\times&\times&\times\cr
   &0     &\times&\times}
}$$
!yields
$$\displaylines{\indent
\bordermatrix{&      &\rm A &      \cr
              &\times&\times&\times\cr
              &\times&\times&\times\cr
              &\times&\times&\times\cr}
\bordermatrix{& &\rm N & \cr
              &1&      & \cr
              &0&1     & \cr
              &0&\times&1\cr}\hfill\cr
\hfill=
\bordermatrix{& &\rm N & \cr
              &1&      & \cr
              &0&1     & \cr
              &0&\times&1\cr}
\bordermatrix{&      &\rm H &      \cr
              &\times&\times&\times\cr
              &\times&\times&\times\cr
              &0     &\times&\times\cr}
}$$
\enddemo


\blueexample Braces and matrices

^^{braces and matrices}
\begindemo
This is a complex problem, with a lot 
of fine-tuning. However, it is 
possible to systemize much. 
The approach is to look at it as
a bordered table with a 
parenthesized matrix as data.
The handling of the row stub and
the header are separated from
the data (the pmatrix). 
The pseudo code reads as follows.
\setbox1=\hbox{$\pmatrix{<data>}$}
Define header and row stub list, and
switch off defaults of btable, 
especially the separators. 
Finally invoke
$$\btable{$\vcenter{\copy1}$}$$.
Alignment left braces courtesy 
Alan Jeffrey communicated by
J\"org Knappen.
For the details see the script.
!yields
\def\fatlbrace{\delimiter"4000338 }
%Set the block
\setbox1=\hbox{$\pmatrix{%
\times&\times&\times&\times&\times&\times&\times\cr
0     &\times&\times&\times&\times&\times&\times\cr
0     &0     &\times&\times&\times&\times&\times\cr
0     &0     &0     &\times&\times&\times&\times\cr
0     &0     &0     &0     &\times&\times&\times\cr
0     &0     &0     &0     &\times&\times&\times\cr
0     &0     &0     &0     &\times&\times&\times}$}
%Define header and row stub list (each one element)
\def\header{\hbox to\wd1{\hfil
$\overbrace{\vrule height0pt width.4\wd1  depth0pt}^p$\hfil
$\overbrace{\vrule height0pt width.3\wd1 depth0pt}^{n-p}$\hfil}}
\tvsize=\ht1\advance\tvsize\dp1
\def\rowstblst{{$\vcenter to\tvsize{\vss
  \hbox{${\scriptstyle\phantom{n{-}}p}
    \left\fatlbrace\vrule height.55\ht1 width0pt depth 0pt\right.$}\vss
  \hbox{${\scriptstyle n{-}p}
    \left\fatlbrace\vrule height.15\ht1 width0pt depth 0pt\right.$}\vss}$}}
%
\def\data{$\vcenter{\copy1}$}
%Switch off defaults in btable
\let\rowstbsep\relax%kind of row stub separator
\let\headersep\relax%kind of header separator
\let\colsepsurround\relax%space around column separator
\def\hs{\cr\nxtrs}%function of header separator: yield next row stub
$$\vcenter{\btable\data}$$
\enddemo

\exercise Add partitioning to the braces and matrices example.
\answer In pic.dat a trial-and-error solution is included.
        Not elegant. Improve, enjoy, and let me know!

\endinput
\bye