% File tex-mma-tex.tex -- TeX example of TeX/Mathematica
% Written 2/8/1991 by Dan Dill dan@chem.bu.edu


% Copyright (C) 1991 Dan Dill
% This is part of TeX/Mathematica
%
% TeX/Mathematica is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility to
% anyone for the consequences of using it or for whether it serves any
% particular purpose or works at all, unless he says so in writing.
%
% Everyone is granted permission to copy, modify and redistribute this
% file, provided:
%  1.  All copies contain this copyright notice.
%  2.  All modified copies shall carry a prominant notice stating who
%      made the last modification and the date of such modification.
%  3.  No charge is made for this software or works derived from it.  
%      This clause shall not be construed as constraining other software
%      distributed on the same medium as this software, nor is a
%      distribution fee considered a charge.
%
% The right to distribute this file for profit or as part of any commercial
% product is specifically reserved for the author.



% This file is simple example of how TeX/Mathematica can be used in a TeX.
% The LaTeX document tex-mma-j.tex is a fuller example, because it takes
% advantage of the document structuring commands of LaTeX.

\input mathematica10pt	% Get the tex-mma macros.  Use ...12pt for 12 pt dcouments
\input psfig		% Get the psfig macros
\psfiginit  		% .. and initialize them

% Here is a macro to place figures and give them a caption
%   #1 is the file
%   #2 is figure height in the printed document
%   #3 is the figure caption
\def\insertfig#1#2#3{\midinsert\centerline{\psfig{figure=#1,height=#2}}
\global\advance\figno by1 % \global so new \figno carried over to next call
\setbox0=\vbox{\noindent\leftskip=.2\hsize\rightskip=.2\hsize
    {\bf Figure \the\figno}. #3}
\vskip 18pt
\centerline{\box0\hss}
\vskip 24pt
\endinsert}

\newcount\figno \figno=0 % Initialize figure number

% Save some typing
\def\Mma{{\sl Mathematica}}
\def\TMma{\TeX/\Mma}
\def\bslash{{\char'134}}
\def\lbr{{\char'173}}
\def\rbr{{\char'175}}

% From eplain.tex
\def\LaTeX{L\kern -.26em
   \raise .6ex \hbox{\fiverm A}\kern -.15em
   \TeX}

\font\title=cmr10 scaled \magstep3
\font\sltitle=cmsl10 scaled \magstep3
\font\name=cmr9 scaled \magstep2

% Narrowed margins look better with 10 point type 
\hoffset=1in \advance\hsize by -2in
\voffset=1in \advance\vsize by -2in

% OK.  Here we go:


{\openup 3pt
\centerline{\title Example \TeX/{\sltitle Mathematica} document}
\vskip 20pt
\centerline{\name\strut Dan Dill}
\centerline{\name\strut Chemistry Department, Boston University}
\centerline{\name\strut Boston, MA 02215}
\vskip 10pt
\centerline{\name February 8, 1991}
\vskip 20pt
}

{\narrower
\centerline{\bf Abstract}
\medskip
This document is an example of how \TMma\ can be used with
\TeX.  See the file {\tt tex-mma-j.tex} for an example using \LaTeX.
\bigskip
}

\beginsection{Clebsch-Gordan coefficients}

The following paragraph, taken
from lecture notes on quantum mechanics, illustrates how \TeX\ and \Mma\ can
be combined.

% The example uses these macros
\def\ket#1{\raise .25ex\hbox{$|$} #1\raise .25ex\hbox{$\rangle$}}
\def\braket#1#2%
{\raise .25ex\hbox{$\langle$} #1 \raise .25ex\hbox{$|$}
	 #2 \raise .25ex\hbox{$\rangle$}}

Clebsch-Gordan coefficients $\braket{j_1 m_1, j_2 m_2}{j m}$ arise in the
quantum theory of angular momentum.  They are elements of unitary
transformation between uncoupled and coupled representations $\ket{j_1 m_1 j_2
m_2}$ and $\ket{j_1 j_2 j m}$.  The unitarity of the transformation implies
the sum rules
$$\eqalign{
\sum_{jm}
	\braket{j_1 m_1, j_2 m_2}{j m}
	\braket{j m}{j_1 m_1, j_2 m_2}
		&= 1, \cr
\sum_{jm}
	\braket{j m}{j_1 m_1, j_2 m_2}
	\braket{j_1 m_1, j_2 m_2}{j m}
		&= 1. \cr
}
$$
The first of these rules can be illustrated explicitly as follows.  First,
\begin{mathematica}[* Initialization Cell *]
<<DiscreteMath/ClebschGordan.m
\end{mathematica}
defines the function {\tt
Clebsch[{j1,m1},{j2,m2},{j,m}]}.\footnote{$^{\rm \dag}$}{The marker
\mmabox{I} at the right edge of the cell rule indicates that this is an
``initialization cell''.} Next, to keep things simple, consider the case $j_1
= j_2 = l$, so that $0 \le j \le 2l$, and $m_1 = m_2 = 0$, so that $m = 0$.
Then the only coefficients needed are
\begin{mathematica}
cg[l_, j_] := Clebsch[{l,0},{l,0},{j,0}]
\end{mathematica}
and the first sum rule can be written 
\begin{mathematica}
check[l_] := 1 == Sum[cg[l,j]^2, {j, 0, 2 l}]
\end{mathematica}
The rule for $l = 0$ to $l = 5$ is then checked with
\begin{mathematica}
Table[check[i], {i, 0, 5}]

Out[55]= {True, True, True, True, True, True}
\end{mathematica}
The second sum rule can be tested in a similar way.

Using \TMma\ in this way, one can interactively develop and refine course and
research documents.  The interactive nature of these tools encourages
exploration as a natural part of the writing process.  At every point a fully
annotated record of the journey so far is at hand.


\beginsection{\Mma\ graphics in \TeX\ documents}

Graphics generated by \Mma\ can be incorporated into \TeX\ documents using
Trevor Darrell's {\tt psfig} \TeX/\LaTeX\ macros.  These are
described fully in the detailed documentation provided as part of the {\tt
psfig} kit.  The following describes how {\tt psfig} is used in \TMma.

The first step is to setup {\tt psfig}.  For a \TeX\ document use.
For a \LaTeX\ document use.
The command {\tt\bslash psfiginit} must come before any use of
{\tt\bslash psfig}; in \LaTeX\ documents {\tt\bslash psfiginit} also
must come {\it after} {\tt\bslash begin{document}}.

Figures are incorporated via disk files and so the second step is to generate
\Mma\ figures in a file.  {\tt PSTeX[-graphics-, "file"]}, defined in {\tt
PSTeX.m}, does this.  Quotes are required around the file name and suffix {\tt
.ps} is added.  The graphic is scaled to height 100 points (72 points equal 1
inch), using a scheme developed by Cameron Smith.  The height can be changed
by adjusting the value of {\tt PSTeXHeight} or by using the {\tt height}
variable of {\tt\bslash psfig}.  The font size is 7 points at the height {\tt
PSTeXHeight}; this can be changed by changing {\tt PSTeXFontsize}.  If {\tt
PSTeX} is not yet set up (say by the \Mma\ initialization file {\tt init.m}),
then it is defined with
\begin{mathematica}[* Initialization Cell *]
<<PSTeX.m
\end{mathematica}

Once {\tt psfig} and {\tt PSTeX} have been set up, figures can be included in
the following way.  A figure is generated to a file with commands like
\begin{mathematica}
fig = Plot[Sin[x]^3, {x, 0, 4Pi}]; \
	PSTeXFontsize = 9; \
	PSTeX[fig, "sin3x"]; 
\end{mathematica}
where the font size has been changed from the default (7 points).

\insertfig{sin3x.ps}{100pt}
{\Mma\ plot of $\sin^3x$.  The plot is reproduced at its natural height (100
points) and the labels are at 9 points.  The {\tt\bslash insertfig} macro
allows the caption to extend over many lines.}

Once the figure has been generated it can be placed in the document with
commands like

\bigskip
\leftline{\tt\hskip\parindent\bslash insertfig\lbr sin3x.ps\rbr}
\leftline{\tt\hskip\parindent\hskip\parindent\lbr 100pt\rbr}
\leftline{\tt\hskip\parindent\hskip\parindent\lbr caption text...\rbr}
\bigskip

\noindent
which produce the figure seen here.

There you go.

\bye

