\input texinfo
@setfilename tex-mma.info
@settitle Interactive @TeX{}/@i{Mathematica} documents

@c The Texinfo documentation format was invented for the GNU project.  The
@c texinfo.tex file that implements it is included in the
@c TeX/Mathematica distribution.

@c To produce a DVI file, make sure texindex.tex, mathematoca12pt.tex,
@c mathematica.tex and PSTeX.m are where TeX looks for macro files and then do:
@c
@c % tex tex-mma.texinfo;texindex tex-mma.??;tex tex-mma.texinfo
@c
@c (The texindex program is part of the Emacs distribution.)

@c To produce an Info file, use M-x texinfo-format-buffer in Emacs.

@ifinfo
This file documents tex-mma.el

Copyright (C) 1991 Dan Dill.

Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.

@ignore
Permission is granted to process this file through TeX and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).
@end ignore

Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that the
section entitled ``GNU General Public License'' is included exactly as
in the original, and provided that the entire resulting derived work is
distributed under the terms of a permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that the section entitled ``GNU General Public License'' may be
included in a translation approved by the author instead of in the
original English.
@end ifinfo

@titlepage
@title Interactive @TeX{}/Mathematica documents
@subtitle 26 April 1991
@subtitle For version 1.3
@author Dan Dill
@page
@vskip 0pt plus 1filll
Copyright @copyright{} 1991 Dan Dill

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that the
section entitled ``GNU General Public License'' is included exactly in
the original, and provided that the entire resulting derived work is
distributed under the terms of a permission notice identical to this
one.

Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that the section entitled ``GNU General Public License'' may be
included in a translation approved by the author instead of in the
original English.
@end titlepage

@iftex
@headings double
@end iftex

@c We use the program index for file extensions.  (We want them to come out
@c in typewriter, but saying `@cindex @t{.aux} file', say, doesn't work.)
@synindex pg fn


@node Top, Copying, (dir), (dir)

@ifinfo
@TeX{}/@i{Mathematica} is a set of tools that provide facilities of
@i{Mathematica} Notebooks in a UNIX environment, under GNU Emacs.  They
permit interaction between a text and a @i{Mathematica} buffer and, if
desired, the use of @TeX{}/La@TeX{} to annotate @i{Mathematica}-based
explorations and programs.  Inclusion of @i{Mathematica}-generated
graphics in @TeX{}/La@TeX{} documents printed using PostScript is
supported.  The tools also support the automatic generation of
@i{Mathematica} packages from @i{Mathematica} documents.

With these tools one can interactively develop and refine teaching and
research documents. The interactive nature of the tools encourages
@i{Mathematica}-based exploration as a natural part of the writing
process.
@end ifinfo

@menu
* Copying::               	How you can copy and share TeX/Mathematica
* Intro::	                The purpose of TeX/Mathematica.
* Using tex-math::		Describes the TeX/Mathematica major mode
* Packages::			How to make Mathematica packages
* Formatting::			Including Mathematica code in TeX/LaTeX
* Graphics::			Including Mathematica graphics in TeX/LaTeX
* Help::			Getting help from Emacs and Mathematica
* Changing things::		How to customize TeX/Mathematica
* Extending tex-math::		How to add new cell types to TeX/Mathematica
* Getting tex-math::		How to get and install TeX/Mathematica
* Related programs::		Programs used by TeX/Mathematica
* Index::
@end menu


@node Copying, Intro, Top, Top
@unnumbered GNU GENERAL PUBLIC LICENSE
@center Version 1, February 1989

@display
Copyright @copyright{} 1989 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA

Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@end display

@unnumberedsec Preamble

  The license agreements of most software companies try to keep users
at the mercy of those companies.  By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software---to make sure the software is free for all its users.  The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

  For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must tell them their rights.

  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

  The precise terms and conditions for copying, distribution and
modification follow.

@iftex
@unnumberedsec TERMS AND CONDITIONS
@end iftex
@ifinfo
@center TERMS AND CONDITIONS
@end ifinfo

@enumerate
@item
This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License.  The
``Program'', below, refers to any such program or work, and a ``work based
on the Program'' means either the Program or any work containing the
Program or a portion of it, either verbatim or with modifications.  Each
licensee is addressed as ``you''.

@item
You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program.  You may charge a fee for the physical act of
transferring a copy.

@item
You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:

@itemize @bullet
@item
cause the modified files to carry prominent notices stating that
you changed the files and the date of any change; and

@item
cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).

@item
If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.

@item
You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
@end itemize

Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.

@item
You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:

@itemize @bullet
@item
accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,

@item
accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal charge
for the cost of distribution) a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of
Paragraphs 1 and 2 above; or,

@item
accompany it with the information you received as to where the
corresponding source code may be obtained.  (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
@end itemize

Source code for a work means the preferred form of the work for making
modifications to it.  For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.

@item
You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License.  However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.

@item
By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.

@item
Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions.  You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.

@item
The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of the license which applies to it and ``any
later version'', you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.

@item
If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

@iftex
@heading NO WARRANTY
@end iftex
@ifinfo
@center NO WARRANTY
@end ifinfo

@item
BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

@item
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
@end enumerate


@iftex
@unnumbered ABSTRACT

@TeX{}/@i{Mathematica} is a set of tools that provide facilities of
@i{Mathematica} Notebooks in a UNIX environment, under GNU Emacs.  They
permit interaction between a text and a @i{Mathematica} buffer and, if
desired, the use of @TeX{}/La@TeX{} to annotate @i{Mathematica}-based
explorations and programs.  Inclusion of @i{Mathematica}-generated
graphics in @TeX{}/La@TeX{} documents printed using PostScript is
supported.  The tools also support the automatic generation of
@i{Mathematica} packages from @i{Mathematica} documents.

With these tools one can interactively develop and refine teaching and
research documents. The interactive nature of the tools encourages
@i{Mathematica}-based exploration as a natural part of the writing
process.
@end iftex

@node Intro, Using tex-math, Copying, Top
@chapter Introduction

@cindex @TeX{}/Mathematica, purpose of

@i{Mathematica} Notebooks, available on several platforms, constitute
an exciting step toward the goal of interactive mathematical
documents, and are a significant factor in the ready acceptance of
@i{Mathematica} by beginning users.  Unfortunately, Notebooks are not
yet available on UNIX systems.  This limitation is an obstacle to new
users, especially students, who may be faced with the need to learn a
new operating system and an editor, in addition to @i{Mathematica}.

Notebooks themselves have shortcomings: although they allow annotation
of @i{Mathematica} sessions, these annotations do not support full
mathematical notation in a system-independent way, as @TeX{}, for
example, does.  This restricts the effective use of Notebooks in the
development of course materials in upper-level mathematics courses and
in courses at all levels in astronomy, chemistry, physics and in all
fields of engineering, for example, since mathematics is central to
their exposition.

To overcome the limitations above, I've developed tools that provide
some of the facilities of Notebooks in a UNIX environment and permit the
full use of @TeX{} in @i{Mathematica} documents (or vice versa).  The
tools also support automatic generation of @i{Mathematica} packages from
@i{Mathematica} documents.  The primary tool is the Emacs package
@kbd{tex-mathematica}, which defines a new mode for interactive exchange
between a @TeX{} document and @i{Mathematica}.  This builds on, and
extends in several ways, David Jacobson's @i{Mathematica} mode for Emacs
(@pxref{math}).  In addition, macro packages are provided to format
@i{Mathematica}-based documents with @TeX{}.

@TeX{}/@i{Mathematica} and @i{Mathematica} modes are in some sense
complementary.  Under the first, the emphasis is on interactive
document preparation, so editing can be done in the text buffer.
Under the second, the emphasis is on the @i{Mathematica} session
itself, so one interacts directly with @i{Mathematica} in the
@i{Mathematica} buffer.  The user can switch back and forth between
the two approaches as appropriate.



@node Using tex-math, Packages, Intro, Top
@chapter Using @TeX{}/@i{Mathematica}

@menu
* Startup::			Getting TeX/Mathematica going
* Cells::			Where to put Mathematica statements
* Input::			How to type Mathematica statements
@end menu


@node Startup, Cells, , Using tex-math
@comment  node-name,  next,  previous,  up
@section Starting @TeX{}/@i{Mathematica}

@iftex
To start up @TeX{}/@i{Mathematica}, use the command @kbd{M-x
tex-mathematica}.  This will set up @kbd{TeX-Mathema@-ti@-ca mode} in
the working buffer.  @i{Mathematica} will be started as a shell process
in @kbd{Mathematica mode} in a second buffer (but not until necessary).
The command @kbd{C-c o} switches to the @i{Mathematica} buffer in
another window.  The command @kbd{C-c l} places the @i{Mathematica}
input prompt at the top of the @i{Mathematica} window.
@end iftex
@ifinfo
To start up @TeX{}/@i{Mathematica}, use the command @kbd{M-x
tex-mathematica}.  This will set up @kbd{TeX-Mathematica mode} in the
working buffer.  @i{Mathematica} will be started as a shell process in
@kbd{Mathematica mode} in a second buffer (but not until necessary).
The command @kbd{C-c o} switches to the @i{Mathematica} buffer in
another window.  The command @kbd{C-c l} places the @i{Mathematica}
input prompt at the top of the @i{Mathematica} window.
@end ifinfo
@cindex starting @TeX{}/Mathematica
@cindex @kbd{tex-mathematica}
@cindex @kbd{Mathematica mode}
@cindex @kbd{TeX/Mathematica mode}

The command @kbd{M-x tex-mathematica} tries to determine whether the
buffer contains @TeX{} or La@TeX{} text, and then sets the mode
accordingly to @kbd{TeX/Mathematica mode} or @kbd{LaTeX/Mathematica
mode}.  For cases where this results in the wrong mode, the commands
@kbd{M-x plain-tex-mathematica} and @kbd{M-x latex-mathematica} are provided
to explicitly select the mode.
@cindex @kbd{latex-mathematica}
@cindex @kbd{plain-tex-mathematica}
@cindex @kbd{LaTeX/Mathematica mode}

Note that @kbd{TeX/Mathematica mode} and @kbd{Mathematica mode} are
complimentary approaches to interacting with @i{Mathematica}.  In
@kbd{TeX/Mathematica mode} the emphasis is on interactive document
preparation and so editing can be done in the @TeX{} buffer.  In
@kbd{Mathematica mode} the emphasis is on the @i{Mathematica} session
itself and so one interacts directly with @i{Mathematica} in the
@i{Mathematica} buffer.  Because @kbd{TeX/Mathematica mode} uses
@kbd{Mathematica mode}, both approaches can be used as appropriate,
simply by changing buffers.
@cindex @kbd{Mathematica mode}
@cindex @kbd{TeX/Mathematica mode}


@node Cells, Input, Startup, Using tex-math    
@comment  node-name,  next,  previous,  up
@section @i{Mathematica} cells

At the simplest level, all text delineated by blank lines can be sent to
the @i{Mathematica} buffer with the command @kbd{C-c RET}.  This command
is convenient for quickly sketching ideas.  However, the bulk of
@TeX{}/@i{Mathematica} depends on its @dfn{cell structure}.

@menu
* Regular cells::		Contain Mathematica statements
* Initialization cells::	Contain statements that should be
				executed to initialize Mathematica
@end menu



@node Regular cells, Initialization cells, , Cells    
@comment  node-name,  next,  previous,  up
@subsection Regular cells

@i{Mathematica} code in a @TeX{} document is contained in @dfn{cells},
@cindex cell, regular
@cindex regular cell
delineated by

@example
\begin@{mathematica@}
...
\end@{mathematica@}
@end example

@noindent
The command @kbd{C-c c} creates an active cell and the commands @kbd{C-c
C-[} and @kbd{C-c C-]} move to preceding and subsequent cells.  Cell
input is sent to @i{Mathematica} with the command @kbd{ESC RET} and the
output of the last @i{Mathematica} command is inserted into the cell
with the command @kbd{C-c r} (replace).  These two operations, send and
replace, are combined with the command @kbd{C-c u} (update).

  For example, here is a @i{Mathematica} cell containing just input:

@example
\begin@{mathematica@}
Apply[Plus, Array[@{@{#,#^3@},@{#^2,1@}@}&, 100]] // MatrixForm
\end@{mathematica@}
@end example

@ifinfo
@noindent
When this cell is formatted by @TeX{} it will be delineated by
horizontal rules.
@end ifinfo
@tex
\noindent
When this cell is formatted by @TeX{} it is delineated by horizontal rules:
\input mathematica12pt
\parskip=0pt
% This suppress texinfo.tex's extra skip so cells are evenly set off from text
\begin{mathematica}
Apply[Plus, Array[{{#,#^3},{#^2,1}}&, 100]] // MatrixForm
\end{mathematica}
\catcode`\@=0
% texinfo.tex uses @ as \escape, whereas mathematica12pt.tex changes it to
% \letter for use in macros and then to \other at exit.
% texinfo-format-buffer looks for `@end tex', so we must change @ to \escape
% so tex will pick up the `\end' command.
@end tex
@noindent
Here is the cell after @kbd{C-c u} (update):
@refill

@example
\begin@{mathematica@}
Apply[Plus, Array[@{@{#,#^3@},@{#^2,1@}@}&, 100]] // MatrixForm

                    5050      25502500
                     
Out[1]//MatrixForm= 338350    100
\end@{mathematica@}
@end example

@noindent
The output is separated from the input by a blank line, and contains the
output marker @kbd{Out[...}, if any.
@tex
Here is how the cell appears formatted by @TeX{}:

\input mathematica12pt
\parskip=0pt
\begin{mathematica}
Apply[Plus, Array[{{#,#^3},{#^2,1}}&, 100]] // MatrixForm

                    5050      25502500
                     
Out[1]//MatrixForm= 338350    100
\end{mathematica}
\catcode`\@=0
@end tex

The commands @kbd{C-c a} and @kbd{C-u C-c a} evaluate @emph{all} cells
in a document (except cells that refer to other cells, @pxref{Packages};
these can be evaluated using @kbd{C-u C-c m}, @pxref{Assembling}).  The
first form lets a cell be bypassed optionally.
@cindex cell, evaluating all

@xref{Initialization cells} for how to mark only certain cells for
evaluation.

@xref{Customization} for information on changing the appearance of
formatted cells.


@node Initialization cells, , Regular cells, Cells    
@comment  node-name,  next,  previous,  up
@subsection Initialization cells

An important feature of @i{Mathematica} Notebook frontends is the
ability to specify that certain cells should be evaluated as
initialization, typically when a document is first opened.  Such
@dfn{initialization cells} are specified in @TeX{}/@i{Mathematica}
documents as
@cindex initialization cell
@cindex cell, initialization

@example
\begin@{mathematica@}[* Initialization Cell *]
...
\end@{mathematica@}
@end example

@noindent
The command @kbd{C-c TAB} toggles the initialization indicator.  The
commands @kbd{C-c i} and @kbd{C-u C-c i} evaluate all initialization
cells in a document (except cells that refer to other cells,
@pxref{Packages}; thses can be evaluated using @kbd{C-u C-c m},
@pxref{Assembling}). The first form lets an initialization cell be
bypassed optionally.  Here is an example of an initialization cell:

@example
\begin@{mathematica@}[* Initialization Cell *]
u[t_] := @{@{Cos[t], -Sin[t]@}, @{Sin[t], Cos[t]@}@}; \
v = @{@{0,I@}, @{-I,0@}@};
\end@{mathematica@}
@end example

@noindent
@ifinfo
Note that these particular commands generate no @i{Mathematica} output
and so there is no output portion to the cell.  In the formatted
document an initialization cell is marked with a boxed @kbd{I} at the
right edge of the cell-start rule.
@end ifinfo
@iftex
Note that these particular commands generate no @i{Mathematica} output
and so there is no output portion to the cell.  In the formatted
document an initialization cell is marked with a boxed @kbd{I} at the
right edge of the cell-start rule:
@tex
\input mathematica12pt
\parskip=0pt
\begin{mathematica}[* Initialization Cell *]
u[t_] := {{Cos[t], -Sin[t]}, {Sin[t], Cos[t]}}; \
v = {{0,I}, {-I,0}};
\end{mathematica}
\catcode`\@=0
@end tex
@end iftex


@node Input, , Cells, Using tex-math
@comment  node-name,  next,  previous,  up
@section Arrangement of @i{Mathematica} statements in cells

Statements may be set off with @kbd{TAB} characters, and these will be
reflected in the formatted document, based on an eight-character tab width.
@cindex @kbd{TAB} in cell input
@cindex cell, using @kbd{TAB} in

Cell input can contain more than one @i{Mathematica} statement, and each
statement can extend across several lines.  Multiple statements must be
separated by @samp{;} and when @i{Mathematica} statements extend over
multiple lines, any lines except the last that could be interpreted by
@i{Mathematica} as a valid end of statement must end with the
continuation character @samp{\}.  The @samp{;} and @samp{\} are
necessary because each line of input is sent separately to
@i{Mathematica}.  For example, consider the cell
@cindex statement termination, @samp{;}
@cindex @samp{;}, statement termination
@cindex statement continuation, @samp{\}
@cindex @samp{\}, statement continuation

@tex
\input mathematica12pt \parskip=0pt \begin{mathematica} y = u[Pi] . v \
	/. 0 -> x

Out[3]= {{x, -I}, {I, x}}
\end{mathematica}
\catcode`\@=0
@end tex
@ifinfo
@example
\begin@{mathematica@}
y = u[Pi] . v \
	/. 0 -> x

Out[3]= @{@{x, -I@}, @{I, x@}@}
\end@{mathematica@}
@end example
@end ifinfo

@noindent
Without the @samp{\}, @i{Mathematica} would process the first line as a
complete statement and then report an error for the next line.  In fact
@kbd{tex-mathematica} will flag such potential problems
(@pxref{Mathematica help}).



@node Packages, Formatting, Using tex-math, Top
@chapter Creating @i{Mathematica} packages
@cindex Mathematica packages
@cindex packages, creating

@iftex
You may want to collect some of the @i{Mathematica} cells of a
@TeX{}/@i{Mathematica} document into a @i{Mathematica} package.  This
chapter describes how to do this automatically.
@end iftex
@ifinfo
You may want to collect some of the @i{Mathematica} cells of a
@TeX{}/@i{Mathematica} document into a @i{Mathematica} package.  This
node describes how to do this automatically.
@end ifinfo

This feature of @TeX{}/@i{Mathematica} is modeled on Knuth's @kbd{WEB}
system of structured documentation.  The basic idea of the @kbd{WEB}
system is to develop code hierarchically in terms of named fragments.
Fragments are introduced as appropriate, in whatever order is convenient
to the description of the program, using @TeX{} for documentation.
Thereby the author is freed from the constraints of the programming
language in the development and description of the code.

In the usual implementation of @kbd{WEB} systems, the source document is
written in @kbd{WEB}, the mixture of code and @TeX{} documentation.  The
@kbd{WEB} document is then alternatively processed by a program
@kbd{WEAVE} into a file which can then be processed by @TeX{} to give
the formatted documentation and code, or by a program @kbd{TANGLE} which
collects together the code fragments into a source file for the
particular language processor (for example, Pascal or C.

Here instead, since @i{Mathematica} code is printed verbatim without
other special formatting, the source @TeX{}/@i{Mathematica} document can
be processed directly by @TeX{} (or La@TeX{}), that is, the @kbd{WEAVE}
step is not needed. The generation of the @i{Mathematica} package code,
the @kbd{TANGLE} step, is done either interactively from within Emacs or
from a UNIX shell.

@menu
* Marking::	How to mark cells as part of a package
* Assembling::	How to assemble a package from the marked cells
* Batch::	How to assemble a package from UNIX, e.g., using make
@end menu

@node Marking, Assembling, , Packages
@section Marking @i{Mathematica} cells as part of a package
@cindex packages, marking cells

A cell is marked as part of a @i{Mathematica} package by appending a
@dfn{cell label} @kbd{<@var{file}:@var{part}>} to the end of the line
starting the @i{Mathematica} cell:
@cindex cell label

@example
\begin@{mathematica@}<@var{file}:@var{part}>
...
\end@{mathematica@}
@end example

@noindent
where @var{file} is the name of the file to contain the text of the
@i{Mathematica} package and @var{part} specifies to what part of the
package the cells belongs.  The order in which parts are assembled into
the package file (@pxref{Assembling}) is determined by package
references contained in @dfn{package cells}, cells marked
@kbd{<@var{file}:>} --- without a part.  Cells referenced in package
cells can also contain cell references and the same cell reference can
be used in multiple cells.  In this way the structure of the package can
be set out hierarchically.
@cindex package cell
@cindex cell, package

@ifinfo
Here is an example of how this works.  Let's say we want to assemble the
package file @file{MatrixMechanics.m}.  The overall structure of the
package might be defined by the package cell
@end ifinfo
@iftex
Here is an example of how this works.  Let's say we want to assemble the
package file @file{Matrix@-Me@-chan@-ics.m}.  The overall structure of the
package might be defined by the package cell
@end iftex

@example
\begin@{mathematica@}<MatrixMechanics.m:>
BeginPackage["MatrixMechanics.m`"]

<MatrixMechanics.m:Usage messages>

Begin["`Private"]

<MatrixMechanics.m:Error messages>

<MatrixMechanics.m:Utility functions>

<MatrixMechanics.m:Function QMmatrix>

End[]; EndPackage[]
\end@{mathematica@}
@end example

@noindent
in terms of parts @kbd{Usage messages}, @kbd{Error messages},
@kbd{Utility functions} and @kbd{Function QMmatrix}.  These parts are
defined in correspondingly marked cells.  For example, part
@kbd{Function QMmatrix} might have the definition

@example
\begin@{mathematica@}<MatrixMechanics.m:Function QMmatrix>
QMmatrix[op_, basis_List] := Block[@{
        <MatrixMechanics.m:QMmatrix local variables>
        @},
    <MatrixMechanics.m:QMmatrix argument checking>
    <MatrixMechanics.m:QMmatrix evaluation>
\end@{mathematica@}
@end example

@noindent
in terms of still other parts.  Cells referenced in package cells can
also contain cell references and the same cell reference can be used in
multiple cells.  This is convenient to control the layout of the
assembled package.

Cells with the same label will be collated together in the order in
which they appear in the document (@pxref{Assembling}). For example, the
part @kbd{Utility functions} could be built up from several cells

@example
\begin@{mathematica@}<MatrixMechanics.m:Utility functions>
...
\end@{mathematica@}
@end example


@ifinfo
When marked cells are formatted by @TeX{}, the package filename and
partname are printed in the cell start rule, separated by a colon.
Package cells are marked @kbd{Definition of package @var{file}}.

@end ifinfo
@tex
When marked cells are formatted by @TeX{}, the package filename and
partname are printed in the cell start rule, separated by a colon, for
example,
\input mathematica12pt
\parskip=0pt
\begin{mathematica}<MatrixMechanics.m:Function QMmatrix>
...
\end{mathematica}
\catcode`\@=0
Package cells are marked @kbd{Definition of package @var{file}}, for
example,
\input mathematica12pt
\parskip=0pt
\begin{mathematica}<MatrixMechanics.m:>
...
\end{mathematica}
\catcode`\@=0
@end tex

@cindex completion, cell names
@cindex @kbd{ESC TAB}
It is useful to make package filenames and, especially, partnames as
descriptive as possible.  This is made easier by name completion and
name abbreviation.  The command @kbd{ESC TAB} will complete filenames
and partnames based on names appearing elsewhere in the document
(@pxref{Mathematica help} for another use of @kbd{ESC TAB}).  The
filename and partname also can be abbreviated by a unique substring
followed by @kbd{...}, for example

@example
\begin@{mathematica@}<Matrix...:U...>
...
\end@{mathematica@}
@end example

@noindent
If only a single package filename or partname appears in the document,
then it may be abbreviated to simply @kbd{...}.  Thus, utility functions
of the package file @file{MatrixMechanics.m} could be specifed in the
same @TeX{}/@i{Mathematica} document as (assuming only the single
package filename @file{MatrixMechanics.m} appears in the document for
cell-type @kbd{mathematica}; documents may contain other cell-types,
@pxref{Extending tex-math}):

@example
\begin@{mathematica@}<...:U...>
...
\end@{mathematica@}
@end example

@noindent
The abbreviation marker @kbd{...} appears in the cell start rule and so can
leave space there for long partnames.





@node Assembling, Batch, Marking, Packages
@section Assembling a package
@cindex packages, assembling using Emacs

The command @kbd{C-c m} (@kbd{M-x tex-mma-assemble-package}) assembles
cells marked as part of a package.  The package is assembled in a buffer
of the same name as the specified filename.  If only a single package
filename is specified in the @TeX{}/@i{Mathematica} document, then it
will be used.  Otherwise the command will prompt for the package
filename.

The assembly of the package proceeds as follows: First, all cells for
each part are collated together in the order they appear in the
document; package cells are also collated together.  Then the combined
text for each part is collated together in the order the references to
it appear in the collated package cell text (@pxref{Marking}).  Finally,
the text for any resulting references is inserted, recursively until all
references have been resolved.

You can also assemble any single marked cell, using the command @kbd{C-u
C-c m} (@kbd{M-x tex-mma-assemble-cell}).  The text is assembled in the
buffer @kbd{@var{file}:@var{part}} corresponding to the cell label.  The
assembly proceeds as for package cells, except that only cells referred
to in the particular cell are collated; other cells with the same cell
label are @emph{not} collated.  Assembly of an individual cell is useful
for checking intermediate phases of package assembly and for preparing a
cell for submission to @i{Mathematica}.

Note the difference between assembling a cell and assembling a package.
If you specify just a single package cell in your document, then you can
assemble the package cell with either @kbd{C-c m} or @kbd{C-u C-c m}.
If your package is specified in several package cells, then you need to
use @kbd{C-c m} so that their text will be collated together in the
package assembly.




@node Batch, , Assembling, Packages
@section Assembling a package from the UNIX shell
@cindex packages, using UNIX

You can create a package file from the UNIX shell, for example in
conjunction with UNIX make to ensure that packages generated from a
@TeX{}/@i{Mathematica} document reflect any changes to the document.
You can do this with the UNIX command @kbd{tex-mma-assemble-package} (a
shell script), which runs the Emacs Lisp function
@kbd{tex-mma-assemble-package} using Emacs batch mode.  The UNIX command
takes three arguments:

@example
tex-mma-assemble-package @var{package-type} @var{package-file} @var{document-file}
@end example

@noindent
the package type (usually @kbd{mathematica}, but other kinds of cells
and so packages are also possible, @pxref{Extending tex-math}), the
package filename, and the @TeX{}/@i{Mathematica} document filename.

For example, let's say you want to create the package file
@kbd{AngularMomentum.m} from marked cells in the La@TeX{} document
@file{am.tex}.  You can do this with the UNIX command

@example
tex-mma-assemble-package mathematica AngularMomentum.m am.tex
@end example

@noindent
This command tells Emacs to visit @file{am.tex}, assemble the package
file @file{AngularMomentum.m} from marked @i{Mathematica} cells and then
exit.  Note that @file{AngularMomentum.m} will be overwritten if
necessary.  The command also creates the file
@file{AngularMomentum.m.log} that contains what would have been printed
in the echo area had the package been assembled interactively from
within Emacs (using @kbd{C-c m}).


@node Formatting, Graphics, Packages, Top
@comment  node-name,  next,  previous,  up
@chapter Formatting @TeX{}/@i{Mathematica} documents

One reason for creating this package was so you can easily edit,
annotate and save work with @i{Mathematica}.  You can do this without
having to use @TeX{} at all, just by using the cell creation, send,
update and replace commands (@pxref{Regular cells}), together with the
help and syntax error facilities (@pxref{Mathematica help}).  If you want to use
@TeX{} to format your document, however, macro packages are provided for
formatting @i{Mathematica} cells.


@menu
* Initialization::	Setting up a document for formatting by TeX/LaTeX
* Customization::	How to change the appearance of formatted cells
* Example::		Text of a TeX example illustrating TeX/Mathematica
* Verbatim::		Including Mathematica (and other) files
@end menu

@node Initialization, Customization, , Formatting    
@comment  node-name,  next,  previous,  up
@section Initialization

In 10 point @TeX{} documents @i{Mathematica} cell formatting is made
available with

@example
\input mathematica10pt
@end example

@noindent
Use @kbd{mathematica12pt} for 12 point @TeX{} documents.  In La@TeX{} use

@example
\documentstyle[mathematica,...
@end example

@noindent
for both 10 and 12 point documents.  With these macro packages
@i{Mathematica} sessions can be neatly integrated into @TeX{} documents.


@node Customization, Example, Initialization, Formatting    
@comment  node-name,  next,  previous,  up
@section Customizing cells
@cindex cell, customizing format of

The type style, type size (for La@TeX{} only), and the indentation of
cell text can be changed.

@menu
* Style::			Changing fixed-width type style
* Size::			Changing type size (LaTeX only)
* Indentation::			Changing cell left margin
@end menu


@node Style, Size, , Customization    
@comment  node-name,  next,  previous,  up
@subsection Type style

Cells are set in a fixed-width typewriter font.  This is necessary to
preserve tabular alignment.  Any fixed-width font can be used.  To
change the font, the macro files need to be changed.  For @TeX{}, in
file @file{mathematica10pt.tex}, change the @kbd{cmtt8<} in the line
@cindex cell, type style of
@cindex font used in cells
@cindex type style used in cells

@example
\font\cellf@@nt=cmtt8 % Font for cell text
@end example

@noindent
or in file @file{mathematica12pt.tex} change the @kbd{cmtt9} in the line

@example
\font\cellf@@nt=cmtt9 % Font for cell text
@end example

@noindent
Make sure that the new font style is the same size (that is, 8 or 9
points) or the tabbing and line spacing will come out wrong.  For
La@TeX{}, in @file{mathematica.sty} change the @kbd{\tt} in the line

@example
\def\v@@rbsize@{\mm@@size\tt@} % Font for cell text
@end example


@node Size, Indentation, Style, Customization
@comment  node-name,  next,  previous,  up
@subsection Type size

For La@TeX{} documents (but not @TeX{} documents) the type size can be
changed with the command
@cindex cell, La@TeX{} type size of
@cindex \mmasize

@example
\mmasize@{<type size specification>@}
@end example

@noindent
The default size is @kbd{\footnotesize}.  Use @kbd{\normalsize} to make cell
text the same size as regular text.  In 12 point documents with narrow
margins @kbd{\scriptsize} might work well,

@example
\mmasize@{\scriptsize@}
@end example


@node Indentation, , Size, Customization    
@comment  node-name,  next,  previous,  up
@subsection Indentation

For both La@TeX{} and @TeX{}, the left margin of cell contents can be
changed with the command
@cindex cell, text indentation of
@cindex indentation of cell text
@cindex \mmaindent

@example
\mmaindent@{<size specification>@}
@end example

@noindent
The default indentation is @kbd{\parindent}.  For example, to set the
cell margin flush left, use

@example
\mmaindent@{0pt@}
@end example


@node Example, Verbatim, Customization, Formatting    
@comment  node-name,  next,  previous,  up
@section Example @TeX{}/@i{Mathematica} text

@ifinfo
The following text, taken from lecture notes on quantum
mechanics, illustrates how @TeX{} and @i{Mathematica} can be combined.

@example
\input mathematica10pt	% Get the tex-mathematica 10 point macros.
\input psfig		% Get the psfig macros
\psfiginit  		% .. and initialize them

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

% 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@}]@}.  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[4]= @{True, True, True, True, True, True@}
\end@{mathematica@}
The second sum rule can be tested in a similar way.
@end example
@end ifinfo
@iftex
The following paragraph, taken from lecture notes on quantum
mechanics, illustrates how @TeX{} and @i{Mathematica} can be combined.
@end iftex

@tex
\input mathematica12pt
\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,
{\parskip=0pt % Disable Texinfo paragraph spacing
\begin{mathematica}[* Initialization Cell *]
<<DiscreteMath/ClebschGordan.m
\end{mathematica}
}defines the function
{\tt Clebsch[{j1,m1},{j2,m2},{j,m}]}.%
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
{\parskip=0pt
\begin{mathematica}
cg[l_, j_] := Clebsch[{l,0},{l,0},{j,0}]
\end{mathematica}
}and the first sum rule can be written 
{\parskip=0pt
\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
{\parskip=0pt
\begin{mathematica}
Table[check[i], {i, 0, 5}]

Out[7]= {True, True, True, True, True, True}
\end{mathematica}
}The second sum rule can be tested in a similar way.
\catcode`\@=0
@end tex

Using @TeX{}/@i{Mathematica} 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.


@node Verbatim, , Example, Formatting    
@comment  node-name,  next,  previous,  up
@section Verbatim listing of @i{Mathematica} (and other) files
@cindex listing files, verbatim
@cindex files, verbatim listing
@cindex verbatim listing of files

You can insert the verbatim listing of @i{Mathematica} file
@kbd{<filename>} (or any text file, for that matter) in your document
with the command

@example
\mathematicafile@{<filename>@}
@end example

@ifinfo
@noindent
For example, to include the file @file{PSTeX.m}, use the command

@example
\mathematicafile@{PSTeX.m@}
@end example

@end ifinfo
@noindent
The file contents will have the same format as cells and the file name
will be included in the cell-start rule.

Caution: If text follows on the next line, then include the file with
the command

@example
\mathematicafile@{<filename>@}%
@end example

@noindent
The trailing @kbd{%} prevents a space before the start of the text on
the next line.  If the next line is empty, then the trailing @kbd{%} is
not needed (but will do no harm).

@iftex
As an example, the command

@example
\mathematicafile@{PSTeX.m@}
@end example

@noindent
inserts the verbatim listing of the file @file{PSTeX.m}, which defines the
command @kbd{PSTeX} (@pxref{Files}):
@cindex PSTeX, listing
@tex
\input mathematica12pt
\mathematicafile{PSTeX.m}
\catcode`\@=0
@end tex
@end iftex

@node Graphics, Help, Formatting, Top
@chapter @i{Mathematica} graphics

Graphics generated by @i{Mathematica} can be incorporated into @TeX{}
documents using Trevor Darrell's @kbd{psfig} @TeX{}/La@TeX{} macros.
These are described fully in the detailed documentation provided as part
of the @kbd{psfig} kit (@pxref{psfig}). (The @kbd{epsf} macros of Tomas
Rokicki's program @kbd{dvips} can be used instead; @xref{dvips}.)
Including graphics in a @TeX{}/@i{Mathematica} document is a three-part
process.  First the @kbd{psfig} macro must be read in, then graphics are
generated to files with appropriate PostScript bounding box information,
and finally files are placed in the document.

@menu
* Setup::			Preparing a document for graphics
* Files::			How to generate Mathematica graphics files
* Placement::			How to place graphics in a document
@end menu


@node Setup, Files, , Graphics    
@comment  node-name,  next,  previous,  up
@section Preparing a document for graphics

Before @i{Mathematica} graphics files can be included in a document, the
@kbd{psfig} macro (@pxref{psfig}) must be read in and initialized.  For
a @TeX{} document use
@cindex psfig
@cindex \psfiginit

@example
\input psfig
...
\psfiginit
@end example

@noindent
For a La@TeX{} document use

@example
\documentstyle[mathematica,psfig,...
...
\begin{document}
...
\psfiginit
@end example

@noindent
The command @kbd{\psfiginit} must come before any use of @kbd{\psfig};
in La@TeX{} documents @kbd{\psfiginit} also must come @emph{after}
the @kbd{\begin@{document@}}.


@node Files, Placement, Setup, Graphics    
@comment  node-name,  next,  previous,  up
@section Generating @i{Mathematica} graphics to a file

Figures are incorporated via PostScript graphics files that contain the
proper bounding box information.  The @i{Mathematica} command
@kbd{PSTeX[-graphics-, "file"]}, defined in @file{PSTeX.m} (@pxref{Tool
kit}), generates these graphics files.
@cindex bounding box in graphics
@cindex graphics, bounding box
@cindex PostScript, bounding box
@cindex graphics, PSTeX
@cindex PSTeX

Note that the @i{Mathematica} PostScript prolog is @emph{not} included
in the file and the prolog must be downloaded to the printer before the
file can be printed.  This is done by the @kbd{dvips} processor
(@pxref{dvips}), using @kbd{\special} commands inserted in the
@file{.dvi} file by @kbd{\psfiginit} (@pxref{Setup}).
@cindex graphics, prolog
@cindex PostScript, prolog

Double quotes are required around the file name and suffix @file{.ps} is
added. Use @kbd{ESC ` "} (@kbd{M-x quoted-insert "}) to insert a double
quote in a @TeX{} buffer.  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 @kbd{PSTeXHeight} or
by using the @kbd{height} variable of @kbd{\psfig}.
@cindex @kbd{quoted-insert}
@cindex @kbd{height}, psfig
@cindex psfig, @kbd{height}
@cindex graphics, height
@cindex @kbd{PSTeXHeight}

@kbd{PSTeX} yields a graphic scaled to height @kbd{PSTeXHeight} and
without centering or margins and hence not generally suitable for
printing.  @kbd{PSFile}, defined in @file{PSFile.m} (@pxref{Tool kit}),
produces a graphic in a file, centered and scaled to fill the whole
page.  The font size is 7 points at the height @kbd{PSTeXHeight}; this
can be changed by changing @kbd{PSTeXFontsize}.  Note that the
@kbd{height} variable of @kbd{psfig} results in the whole graphic being
scaled and so the font size as well.
@cindex graphics, scaling
@cindex scaling graphics
@cindex @kbd{PSTeXFontsize}
@cindex @kbd{PSFile}

If @kbd{PSTeX} is not yet set up (say by the @i{Mathematica} initialization
file @file{init.m}), then it is defined with
@cindex PSTeX, setup

@ifinfo
@example
\begin@{mathematica@}[* Initialization Cell *]
<<PSTeX.m
\end@{mathematica@}
@end example

@end ifinfo
@tex
\input mathematica12pt
\parskip=0pt
\begin{mathematica}[* Initialization Cell *]
<<PSTeX.m
\end{mathematica}
\catcode`\@=0
@end tex
@noindent
Once @kbd{PSTeX} has been set up, a figure is generated to a file with
commands like
@cindex PSTeX, example
@cindex graphics, example
@cindex graphics, file example

@ifinfo
@example
\begin@{mathematica@}
fig = Plot[Sin[x]^3, @{x, 0, 4Pi@}]; \
        PSTeXFontsize = 9; \
        PSTeX[fig, "sin3x"]; 
\end@{mathematica@}
@end example

@end ifinfo
@tex
\input mathematica12pt
\parskip=0pt
\begin{mathematica}
fig = Plot[Sin[x]^3, {x, 0, 4Pi}]; \
        PSTeXFontsize = 9; \
        PSTeX[fig, "sin3x"]; 
\end{mathematica}
\catcode`\@=0
@end tex
@noindent
Note that in this example the the font size has been changed from the
default (7 points) to 9 points.


@node     Placement, , files, Graphics
@comment  node-name,  next,  previous,  up
@section Placing graphics in documents

@menu
* LaTeX::			How to place graphics in LaTeX
* TeX::				How to place graphics in TeX
@end menu

@node LaTeX, TeX, , Placement
@comment  node-name,  next,  previous,  up
@subsection La@TeX{} documents

Figures can be placed in a La@TeX{} document using the @kbd{\figure}
environment.  For example
@cindex graphics, La@TeX{} example

@example
\begin@{figure@}
\centerline@{\psfig@{figure=sin3x.ps@}@}
\caption@{@{\sl Mathematica@} plot of $\sin^3 x$.@}
\end@{figure@}
@end example


@node TeX, , LaTeX, Placement    
@comment  node-name,  next,  previous,  up
@subsection @TeX{} documents


Figures can be placed in a @TeX{} document using the various
@var{insert} commands.  For example, here is a macro using
@kbd{\midinsert} to place figures and give them a caption.
@cindex graphics, @TeX{} example

@example
% #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 \figno incremented
        \setbox0=\vbox@{%
            \noindent
            \leftskip=.2\hsize
            \rightskip=.2\hsize
            @{\bf Figure \the\figno@}. #3@}
        \vskip 18pt
        \centerline@{\box0\hss@}
        \vskip 24pt
    \endinsert
@}

% Define and initialize figure number
\newcount\figno \figno=0
@end example

@noindent
Placing the caption (macro argument 3) in a @kbd{\vbox} allows the caption
to extend over many lines.  Here is an example of how to use this macro:

@example
\insertfig@{sin3x.ps@}@{100pt@}
@{@{\it Mathematica@} plot of $\sin^3x$.@}
@end example



@node Help, Changing things, Graphics, Top
@comment  node-name,  next,  previous,  up
@chapter Getting help

  On-line help is available for both @kbd{Emacs} and @i{Mathematica}.

@menu
* Emacs help::		Getting help on tex-math and math
* Mathematica help::	Getting help on Mathematica
@end menu



@node Emacs help, Mathematica help, , Help    
@comment  node-name,  next,  previous,  up
@section Help on @kbd{tex-mathematica} and @kbd{math}
@cindex help, math
@cindex help, tex-mathematica

This Info description of the facilities of @TeX{}/@i{Mathematica} is
accessed by the command @kbd{C-c h}.  The version of
@TeX{}/@i{Mathematica} that is running is displayed with the command
@kbd{C-c v}.  Help on the commands available in the
@TeX{}/@i{Mathematica} and @i{Mathematica} buffers is given by the
command @kbd{C-h m} in each buffer.



@node Mathematica help, , Emacs help, Help
@comment  node-name,  next,  previous,  up
@section Help on @i{Mathematica}
@cindex help, Mathematica
@cindex completion, Mathematica names
@cindex @kbd{ESC TAB}

David Jacobson's GNU Emacs package @kbd{math} contains several aids that
have been made available in the @TeX{}/@i{Mathematica} buffer: automatic
syntax checking of @i{Mathematica} input, normal and extended help on
@i{Mathematica} symbols (@kbd{C-h e} and @kbd{C-h E}), name completion
(@kbd{ESC TAB}) (@pxref{Marking} for another use of @kbd{ESC TAB}),
and location of syntax errors in @file{.m} files (@kbd{C-c C-e}).  In
particular, the input syntax checking detects the problem in the above
cell caused by omitting the `@kbd{\}' (@pxref{Input}).

Since @TeX{}/@i{Mathematica} uses @kbd{Mathematica mode}, the help, name
completion and @file{.m}-file syntax error location commands also work
directly from the @i{Mathematica} buffer.



@node Changing things, Extending tex-math, Help, Top
@comment  node-name,  next,  previous,  up
@chapter Customizing @TeX{}/@i{Mathematica}

@ifinfo
This node documents the @TeX{}/@i{Mathematica} commands defined in the
@end ifinfo
@iftex
This chapter documents the @TeX{}/@i{Mathematica} commands defined in the
@end iftex
@TeX{}/@i{Mathematica} buffer and how their key bindings can be changed.


@menu
* Bindings:: 		TeX/Mathematica buffer key bindings
* Rebinding::		Changing TeX/Mathematica buffer key bindings
@end menu


@node Bindings, Rebinding,  , Changing things    
@comment  node-name,  next,  previous,  up
@section  @TeX{}/@i{Mathematica} key bindings

Here are all of the commands of @TeX{}/@i{Mathematica} defined in the
@TeX{}/@i{Mathematica} buffer and the Emacs Lisp functions that they invoke.
The bindings are defined in the key map @kbd{TeX-mma-mode-map}.

@example
C-c C-[         tex-mma-backward-cell
C-c C-]         tex-mma-forward-cell
C-c C-b         TeX-buffer
C-c C-e         tex-mma-math-find-error
C-c C-f         TeX-close-LaTeX-block
C-c C-k         TeX-kill-job
C-c C-l         TeX-recenter-output-buffer
C-c C-p         TeX-print
C-c C-q         TeX-show-print-queue
C-c C-r         TeX-region
C-c RET         tex-mma-send
C-c TAB         tex-mma-toggle-init
C-c a           tex-mma-eval-all-ask
C-c c           tex-mma-create-cell
C-c h           tex-mma-info
C-c i           tex-mma-eval-init-ask
C-c l           tex-mma-recenter
C-c m           tex-mma-assemble-package
C-c r           tex-mma-replace
C-c s           tex-mma-show
C-c u           tex-mma-update
C-c v           tex-mma-version

C-h E           math-extra-help
C-h e           math-help

C-u C-c a       tex-mma-eval-all-noask
C-u C-c i       tex-mma-eval-init-noask
C-u C-c m       tex-mma-assemble-cell

ESC RET         tex-mma-send-cell
ESC TAB         tex-mma-do-completion
ESC o           tex-mma-buffer-go
ESC @{           TeX-insert-braces
ESC @}           up-list
@end example

@noindent
The commands beginning @kbd{tex-mma-} are defined in @file{tex-mma.el}
(@pxref{Tool kit}), the commands beginning @kbd{TeX-} are defined in
@file{tex-mode.el} (part of GNU Emacs) and the commands beginning
@kbd{math-} are defined in @file{math.el} (@pxref{Tool kit}).


@node Rebinding,  , Bindings, Changing things    
@comment  node-name,  next,  previous,  up
@section  Changing key bindings

If you want to change some key bindings, add additional key bindings of
your own, or perform any other operations when starting up
@TeX{}/@i{Mathematica}, you can do so by defining the variable
@kbd{TeX-mma-mode-hook} in your initialization file @file{.emacs}.  Here
is an example.  It defines the cell motion commands to be @kbd{C-c [}
and @kbd{C-c ]}.

@example
(setq TeX-mma-mode-hook
      '(lambda ()
         (define-key TeX-mma-mode-map "\C-c[" 'tex-mma-backward-cell)
         (define-key TeX-mma-mode-map "\C-c]" 'tex-mma-forward-cell)
         ))
@end example

@noindent
Commands are defined in the @TeX{}/@i{Mathematica} mode key map
@kbd{TeX-mma-mode-map} (@pxref{Bindings}).


@node Extending tex-math, Getting tex-math, Changing things, Top
@chapter Extending @TeX{}/@i{Mathematica}
@cindex extending TeX/Mathematica
@cindex cell, defining new

@iftex
By default @TeX{}/@i{Mathematica} defines "mathematica" cells as its
single cell type. You can define additional cell types.  This chapter
describes how to do this.
@end iftex
@ifinfo
By default @TeX{}/@i{Mathematica} just defines "mathematica" cells as
its single cell type. You can define additional cell types.  This node
describes how to do this.
@end ifinfo

@menu
* Interface::		Things that must be in the Emacs Lisp file that
			  defines the cell interface.
* Init::		Things that need to be added to your Emacs init file
* Macros::		How to add new cell types to TeX/LaTeX
@end menu

@node Interface, Init, , Extending tex-math
@section Emacs Lisp specification of new cell types

The file @file{unix-tex-mma.el} provided with @TeX{}/@i{Mathematica} is
an example Emacs Lisp implementation of cell type "unix", for
interaction between the @TeX{} buffer and a UNIX shell running in
another buffer.  There are three things that the implementation must
contain:

@enumerate
@item
@iftex
The function @kbd{`type'-tex-mma-hook}, which is used to make "type"
cells part of @TeX{}/@i{Math@-e@-ma@-tica}.  For example,
@end iftex
@ifinfo
The function @kbd{`type'-tex-mma-hook}, which is used to make "type"
cells part of TeX/Mathematica.  For example,
@end ifinfo

@example
(defun unix-tex-mma-hook ()
  "Hook for TeX/Mathematica."
  ; Put any setup processing you need to do here.  You don't have to
  ; do any, but this function must still be defined.
  )
@end example

@noindent
Whether or not you define a body for this function, the function itself
must still be defined.  It will be used by Emacs to make sure the
functions for this cell type are loaded, using the @kbd{autoload}
mechanism (@pxref{Init}).

@item
The string @kbd{`type'-tex-mma-version-string} describing the version of
this cell interface.  For example,

@example
(defconst unix-tex-mma-version-string
  "TeX/Mathematica UNIX shell interface Version 1 <Thur 11 April 1991>"
  "String describing this version of TeX/Mathematica UNIX interface.")
@end example

@noindent
This string will be displayed by @kbd{C-c v} to identify the cell types
supported by the version of @TeX{}/@i{Mathematica} that is running.

@item
The statement (for example)

@example
(defconst unix-tex-mma-cell-alist
  '(
    ("buffer-go" . unix-buffer-go)
    ("recenter" . unix-recenter)
    ("replace" . unix-replace)
    ("send" . unix-send)
    ("send-cell" . unix-send-cell)
    ("show" . unix-show)
    ("update" . unix-update)
    ))
@end example

@noindent
@iftex
to associate the cell type @kbd{unix} with the functions that
communicate with its buffer.  The list entries define the functions that
replace the corresponding functions of @TeX{}/@i{Math@-e@-ma@-tica}.
The statement above includes entries for all @TeX{}/@i{Mathematica}
operations that use the @i{Mathematica} buffer.  There should be an
entry for each function you want defined for your cell type.  If an
entry is absent, the corresponding operation will be ignored for your
cell type.  You can define additional functions for your cell type.
These do not need to be in the list, but their presence will
cause no harm.
@end iftex
@ifinfo
to associate the cell type @kbd{unix} with the functions that
communicate with its buffer.  The association list entries define the
functions that replace the corresponding functions of
@TeX{}/@i{Mathematica}.  The statement above includes entries for all
@TeX{}/@i{Mathematica} operations that use the @i{Mathematica} buffer.
There should be an entry for each function you want defined for your
cell type.  If an entry is absent, the corresponding operation will be
ignored for your cell type.  You can define additional functions for
your cell type.  These do not need to be in the association list, but
their presence will cause no harm.
@end ifinfo

@end enumerate


@node Init, Macros, Interface, Extending tex-math
@section Modifications to the Emacs init file
@cindex cell, hooks for new
@cindex @kbd{tex-mma-hooks}

For each piece you want to add to @TeX{}/@i{Mathematica} you should use
an @kbd{autoload} function in, for example, your Emacs init file to
associate its functions @kbd{`type'-tex-mma-hook} (@pxref{Interface})
with the Emacs Lisp file in which the functions for the type are
defined.  For example, to add cell types "c" and "unix", defined in
(say) @file{c-tex-mma.el} and @file{unix-tex-mma.el}, you need

@example
(autoload 'c-tex-mma-hook "c-tex-mma"
          "Add `c' cells to TeX/Mathematica.")
(autoload 'unix-tex-mma-hook "unix-tex-mma"
          "Add `unix' cells to TeX/Mathematica.")
@end example

@noindent
Then, you must list all of the cell types that you are adding in the
list @kbd{tex-mma-new-types}.  For example,

@example
(defconst tex-mma-new-types '("c" "unix"))
@end example

@noindent
tells @TeX{}/@i{Mathematica} to add cell types "c" and "unix".


@node Macros, , Init, Extending tex-math
@section Modifications to @TeX{}/La@TeX{} macros

You will have to add your new cell type(s) to the @TeX{}/La@TeX{} macros
if you want to format your document.  The file @file{mathematica.tex}
contains code common to @TeX{} and La@TeX{} for the actual formatting of
cell.  The file @file{mathematica.sty} handles the La@TeX{} interface to
@file{mathematica.tex}.  The files @file{mathematica10pt.tex} and
@file{mathematica12pt.tex} provide the @TeX{} interface.  You will have
to adapt the macros in these file to handle your cells.

At a minimum you will have to define your @kbd{\begin@{`type'@}}
@kbd{...} @kbd{\end@{`type'@}} commands.  Then you can format your new
cells in the same way as @i{Mathematica} cells.  You might also want to
define new cell rules to identify your cells, using the @i{Mathematica}
cell rules as a starting point.



@node Getting tex-math, Related programs, Extending tex-math, Top
@chapter Getting @TeX{}/@i{Mathematica}

The @TeX{}/@i{Mathematica} tools are available from Internet host
@kbd{chem.bu.edu} @t{[128.197.30.18]} by anonymous @kbd{ftp} in directory
@kbd{/pub/tex-mathematica}.  The author can be reached at Internet address
@kbd{dan@@chem.bu.edu}.
@cindex @TeX{}/Mathematica, getting
@cindex ftp site, @TeX{}/Mathematica
@cindex Dill, Dan
@cindex mail address, Dan Dill

The @kbd{ftp} directory contains four files

@itemize @bullet
@item
@file{README}, which duplicates the information
@ifinfo
in this node.
@end ifinfo
@iftex
in this chapter.
@end iftex

@item
@file{CHANGES}, which describes changes that have been made.

@item
@file{tex-mma-j.ps.Z}, the compressed PostScript documentation/example.

@item
@file{tex-mma.tar.Z}, the TeX/Mathematica distribution kit (includes the
first three files).
@end itemize
    	    	
@menu
* Documentation::		LaTeX description of TeX/Mathematica
* Tool kit::			Contains the TeX/Mathematica tools
* Install::			Step-by-step installation instructions
@end menu



@node    Documentation, Tool kit, , Getting tex-math
@comment  node-name,  next,  previous,  up
@section La@TeX{} description of @TeX{}/@i{Mathematica}

@iftex
The PostScript document @file{tex-mma-j.ps.Z} is derived from
@file{tex-mma-j.tex}. Transfer the document from the @kbd{ftp} directory
in binary (image) mode and then print it with
@end iftex
@ifinfo
The PostScript document @file{tex-mma-j.ps.Z} is derived from the La@TeX{}
description of @TeX{}/@i{Mathematica}.  Transfer the document from the
@kbd{ftp} directory in binary (image) mode and then print it with
@end ifinfo

@example
zcat tex-mma-j.ps.Z | lpr
@end example

@noindent
The source for this document is the La@TeX{} file @file{tex-mma-j.tex} and
the Bib@TeX{} file @file{tex-mma-j.bib}.  You can use @file{tex-mma-j.tex}
as a La@TeX{} example of a @TeX{}/@i{Mathematica} document.



@node     Tool kit, Install, Documentation, Getting tex-math
@comment  node-name,  next,  previous,  up
@section Files in the distribution kit

The file @file{tex-mma.tar.Z} contains the @TeX{}/@i{Mathematica}
tools.  These consist of the following:

@noindent
Documentation things:

@itemize @bullet

@item
@file{tex-mma.texinfo}, Texinfo documentation of @TeX{}/@i{Mathematica}

@item
@file{tex-mma.ps.Z}, compressed Texinfo document
@iftex
(this document) formatted with @TeX{} into Post@-Script
@end iftex
@ifinfo
formatted with @TeX{} into PostScript
@end ifinfo

@item
@file{tex-mma.info}, Info file
@ifinfo
(this file)
@end ifinfo
for on-line @t{Emacs} documentation

@item
@file{tex-mma-j.tex}, LaTeX description/example of @TeX{}/@i{Mathematica}

@item
@file{tex-mma-j.bib}, Bib@TeX{} file for @file{tex-mma-j.tex}

@item
@file{tex-mma-j.ps.Z}, compressed La@TeX{} documentation formatted in
PostScript

@item
@file{sin3x.ps}, @i{Mathematica}-generated figure included in
@file{tex-mma-j.tex}

@item
@file{tex-mma-tex.tex}, @TeX{} example of @TeX{}/@i{Mathematica}

@item
@file{texinfo.tex}, TeX macros used to format @file{tex-mma.texinfo}
@end itemize


@noindent
GNU Emacs things:

@itemize @bullet
@item
@file{tex-mma.el}, the @kbd{tex-mathematica} package

@item
@file{math.el}, David Jacobson's @i{Mathematica} mode package (@pxref{math})

@item
@file{unix-tex-mma.el}, example implementation of cell-type @kbd{unix}

@end itemize
@cindex Jacobson, David
@cindex math.el

@noindent
@TeX{}/La@TeX{} things:

@itemize @bullet
@item
@file{mathematica10pt.tex}, @TeX{} 10 point @TeX{}/@i{Mathematica} interface

@item
@file{mathematica12pt.tex}, @TeX{} 12 point @TeX{}/@i{Mathematica} interface

@item
@file{mathematica.sty}, La@TeX{} generic @TeX{}/@i{Mathematica} interface

@item
@file{mathematica.tex}, macros for formatting @TeX{}/@i{Mathematica}
documents, used by the preceding files
@end itemize


@noindent
Shell scripts and @i{Mathematica} commands for processing graphics, and
shell script and template file for @i{Mathematica} package assembly:

@itemize @bullet
@item
@file{PSTeX.m}, generates @kbd{psfig}-adapted graphics to a file, without
PostScript prolog

@item
@file{addBBox}, shell script called by @kbd{PSTeX}

@item
@file{PSTeXpro.m}, generates @kbd{psfig}-adapted graphics to a file, with
PostScript prolog

@item
@file{addBBoxpro}, shell script called by @kbd{PSTeXpro}

@item
@file{addBBoxpro.awk}, @kbd{awk} script called by @file{addBBoxpro}

@item
@file{PSFile.m}, generates full-page graphics to a file, with PostScript
prolog

@item
@file{tex-mma-assemble-package}, shell script for @i{Mathematica} package
assembly

@item
@file{tex-mma-assemble-package.tmplt}, Emacs Lisp template for
@file{tex-mma-assemble-package}

@end itemize

@noindent
This is from Cameron Smith (@pxref{addBBox}):
@cindex Smith, Cameron
@cindex mma.pro.1.2

@itemize @bullet
@item
@file{mma.pro.1.2}, @i{Mathematica} Version 1.2 PostScript prolog.  Note
that a different prolog will be needed for @i{Mathematica} Version 2.0.
This will be available from the author (@pxref{Getting tex-math}).
@end itemize

@noindent
These are from Trevor Darrell's @kbd{psfig/tex} distribution (@pxref{psfig}):
@cindex Darrell, Trevor
@cindex psfig

@itemize @bullet
@item
@file{psfig.pro}, @kbd{psfig} PostScript prolog.

@item
@file{psfig.sty}, @kbd{psfig} for La@TeX{}.

@item
@file{psfig.tex}, @kbd{psfig} for @TeX{}.
@end itemize



@node     Install, , Tool kit, Getting tex-math
@comment  node-name,  next,  previous,  up
@section Installation procedure

@enumerate
@item
Transfer @file{tex-mma.tar.Z} in binary (image) mode into an empty
directory, and extract its contents, with (for example)

@example
zcat tex-mma.tar.Z | tar xvf -
@end example

@item
Install the Info on-line documentation file @file{tex-mma.info} where
your Emacs looks for Info file.  If desired, add a pointer to it to your
Info directory file so that it will appear in the Info top-level menu.
The source for @file{tex-mma.info} is @file{tex-mma.texinfo}.  The file
@file{tex-mma.ps.Z} is the compressed @TeX{} formatted version, made
using the @file{texinfo.tex} included in the distribution (see the
beginning of @file{tex-mma.texinfo} for directions).  The formatted
version can be printed with

@example
zcat tex-mma.ps.Z | lpr
@end example

@noindent
It contains complete details of the @TeX{}/@i{Mathematica} tools.

@item
Edit @kbd{tex-mma.el} to

@itemize @bullet
@item
set @kbd{tex-mma-process-string} to the command you use to start
@i{Mathematica} (default is @kbd{math});

@item
set @kbd{tex-mma-info-file} to point to where you put the file
@file{tex-mma.info}
@end itemize

@item
Run @kbd{M-x byte-compile} on @file{tex-mma.el} and store the resulting
@file{tex-mma.elc} wherever your GNU Emacs looks for files.

@item
Add the following to the GNU Emacs initialization file

@example
(autoload 'tex-mathematica "tex-mma"
          "Major-mode for interaction with Mathematica from TeX." t)
(autoload 'plain-tex-mathematica "tex-mma"
          "Major-mode for interaction with Mathematica from TeX." t)
(autoload 'latex-mathematica "tex-mma"
          "Major-mode for interaction with Mathematica from TeX." t)
@end example

@item
If you do not have David Jacobson's @i{Mathematica} mode package
@file{math.el}, install it following the instructions in @file{math.el}.
If you do have @file{math.el}, make sure your version is at least as
current as the one here, which contains changes necessary for use with
@file{tex-mma.el}.  Make sure you place the file @file{math.el} (or,
better, the byte-compiled file @file{math.elc}) where your Emacs looks
for libraries, so that @file{tex-mma.elc} will be able to load it if it
is not already loaded.

@item
Edit @file{mathematica.tex} (at the end) to specify where the PostScript
prolog files @file{psfig.pro} and @file{mma.pro.1.2} will be, and put the
prolog files there.

@item
If you are using a La@TeX{} @emph{earlier} than 2 May 90, edit
@file{mathematica.sty} according to the comments there.

@item
@iftex
Put @file{mathematica.tex}, @file{mathematica.sty}, @file{mathematica12pt.tex},
@file{mathematica10pt.@-tex}, @file{psfig.sty}, and @file{psfig.tex} where your
@TeX{} looks for macro files.
@end iftex
@ifinfo
Put @file{mathematica.tex}, @file{mathematica.sty}, @file{mathematica12pt.tex},
@file{mathematica10pt.tex}, @file{psfig.sty}, and @file{psfig.tex} where your
@TeX{} looks for macro files.
@end ifinfo

@item
Put @file{PSTeX.m}, @file{PSTeXpro.m} and @file{PSFile.m} where your
@i{Mathematica} looks for packages.
   
@item
Edit @file{addBBoxpro} to specify which @kbd{awk} you use (default is GNU
awk, @kbd{gawk}).

@item
Edit @file{tex-mma-assemble-package} to set the variables @kbd{bindir},
@kbd{tmpdir} and @kbd{tmpdirsed} for your system, as described in the
comments there.  Then place @file{tex-mma-assemble-package.tmplt} in
@kbd{bindir}.

@item
Put @file{addBBox}, @file{addBBoxpro}, @file{addBBoxpro.awk} and
@file{tex-mma-assemble-package} on your system's binary search path, make
sure they have execute status, and then execute @kbd{rehash}.

@end enumerate

@noindent
You should be ready to go: Startup emacs, run @kbd{M-x tex-mathematica}
(@pxref{Startup}), and have fun.


@node Related programs, Index, Getting tex-math, Top
@comment  node-name,  next,  previous,  up
@chapter Related programs

@iftex
@TeX{}/@i{Mathematica} uses several other programs.  All except
@kbd{dvips} are included in the @TeX{}/@i{Math@-e@-ma@-ti@-ca}
distribution, and @kbd{dvips} is freely available.  These programs and
where they come from are summarized here.
@end iftex
@ifinfo
@TeX{}/@i{Mathematica} uses several other programs.  All are included
with the @TeX{}/@i{Mathematica} distribution, except @kbd{dvips} which
is freely available.  These programs and where they come from are
summarized here.
@end ifinfo

@menu
* addBBox::		Shell script to set PostScript bounding boxes
* dvips::		TeX dvi-to-PostScript processor
* math::		GNU Emacs package to talk to Mathematica
* psfig::		TeX macros to include PostScript in TeX
@end menu


@node addBBox, dvips, , Related programs    
@comment  node-name,  next,  previous,  up
@section @kbd{addBBox}: PostScript bounding box shell script

@kbd{addBBox} is the UNIX shell script that is called by @kbd{PSTeX} to
adjust the PostScript bounding box in @i{Mathematica} graphics so that
the resulting graphics files can be handled properly by @kbd{psfig}.
@kbd{addBBox} is based on a scheme developed by Cameron Smith.  His
electronic mail address is @kbd{cameron@@midd.cc.middlebury.edu}.
@cindex Smith, Cameron
@cindex mail address, Cameron Smith
@cindex addBBox
@cindex bounding box in graphics
@cindex PostScript, bounding box


@node dvips, math, addBBox, Related programs    
@comment  node-name,  next,  previous,  up
@section @kbd{dvips}: @TeX{}-dvi-to-PostScript processor

@kbd{dvips} is a program that converts @TeX{} @file{.dvi}
(device-independent) files into PostScript.  Several such programs are
available.  @TeX{}/@i{Mathematica} was tested with the @kbd{dvips}
written by Tomas Rokicki.  His electronic mail address is
@kbd{rokicki@@neon.stanford.edu}.  His program is available by anonymous
@kbd{ftp} from @kbd{labrea.stanford.edu} as the files
@file{/pub/dvips*}.  @TeX{}/@i{Mathematica} also works with the
@kbd{dvips} available from ArborText Inc., 535 West William Street,
Suite 300, Ann Arbor, Michigan 48103, telephone (313) 996-3566.
@cindex Rokicki, Tomas
@cindex mail address, Tomas Rokicki
@cindex dvips
@cindex dvips, Rokicki version
@cindex ArborText dvips
@cindex dvips
@cindex dvips, ArborText version
@cindex ftp site, dvips

The @kbd{\special} commands are slightly different for these two
@kbd{dvips} processors.  Both forms are given at the end of the macro
file @file{mathematica.tex} in the @kbd{\psfiginit} macro.  The Rokicki form
is selected in the distribution kit:
@cindex \psfiginit
@cindex mathematica.tex

@example
\def\psfiginit@{%
% ArborText dvips
%\special@{ps: plotfile /usr8/dan/tex/inputs/psfig.pro global@}
%\special@{ps: plotfile /usr8/dan/tex/inputs/mma.pro.1.2 global@}
% Rokicki dvips
\special@{header=/usr8/dan/tex/inputs/psfig.pro@}
\special@{header=/usr8/dan/tex/inputs/mma.pro.1.2@}
@}
@end example

@noindent
If you use the ArborText driver, change these statements to

@example
\def\psfiginit@{%
% ArborText dvips
\special@{ps: plotfile /usr8/dan/tex/inputs/psfig.pro global@}
\special@{ps: plotfile /usr8/dan/tex/inputs/mma.pro.1.2 global@}
% Rokicki dvips
%\special@{header=/usr8/dan/tex/inputs/psfig.pro@}
%\special@{header=/usr8/dan/tex/inputs/mma.pro.1.2@}
@}
@end example

@noindent
Note that in either case the directory @file{/usr8/dan/tex/inputs/} will
be different on your system (@pxref{Install}).

Other @kbd{dvips} processors can be used with @TeX{}/@i{Mathematica} by
adapting the @kbd{\psfiginit} macro in @file{mathematica.tex} to their
@kbd{\special} command syntax.
@cindex dvips
@cindex \psfiginit


@node math, psfig, dvips, Related programs    
@comment  node-name,  next,  previous,  up
@section @kbd{math}: @i{Mathematica} mode Emacs package

@file{math.el} is the Emacs package that communicates with @i{Mathematica}.
It was written by David Jacobson.  @file{math.el} is included in the
@TeX{}/@i{Mathematica} distribution.  It is also available by anonymous
@kbd{ftp} from @kbd{otter.stanford.edu}; see the file @file{README} in the
top-level directory there for more information.  David Jacobson's
electronic mail address is @kbd{jacobson@@cello.hpl.hp.com}.
@cindex Jacobson, David
@cindex mail address, David Jacobson
@cindex math
@cindex ftp site, math.el


@node psfig, , math, Related programs    
@comment  node-name,  next,  previous,  up
@section @kbd{psfig}: @TeX{} PostScript graphics macros

@kbd{psfig} is the @TeX{} macro package that allocates space for
PostScript graphics and adds the appropriate @kbd{\special} commands to
the @file{.dvi} file.  It was written by Trevor Darrell and is available
by anonymous @kbd{ftp} from @kbd{whitechapel.media.mit.edu}.  Trevor
Darrell's electronic mail address is
@kbd{trevor@@brixton.media.mit.edu}.
@cindex Darrell, Trevor
@cindex mail address, Trevor Darrell
@cindex psfig
@cindex \special
@cindex ftp site, psfig


@node Index,  , Related programs, Top
@unnumbered Index

@printindex cp



@contents


@bye

@c 
@c Local variables:
@c page-delimiter: "^@\\(unnumbered\\|chapter\\) "
@c End:
