 %% mpicp-comm-latex.tex
%% mathsPIC manual

\documentclass[mathsPICmanual.tex]{subfiles}
\begin{document}
%%=============================

%%-----------------------------------------
\chapter{\TeX\ and \LaTeX\ commands}
\label{chap:texcommands}

A \mathsPIC\ file (script)  can contain any appropriate \TeX\ and \LaTeX\ commands, and  most of these commands are for use in the preamble (e.g.,~headers and footers).

%----------------------------------
\section{Headers and footers}

It is particularly useful to include in the
{\mathsPIC} file any \TeX\ or \LaTeX\ headers and footers
which would otherwise have to be
added manually to the output file before {\LaTeX}ing the file.
Note that the \LaTeX\ command \verb!\thispagestyle{empty}! is included  for convenience in  \texttt{mathspic.sty} in order to stop a page number appearing in a figure (see Section~\ref{sec:sty} for details).

   For example, when using  \LaTeX\  a typical
   format for a {\mathsPIC} file might be as follows 
(for use with plain \TeX\ see Section~\ref{sec:headfoot}).

\begin{verbatim}
\documentclass[a4paper]{article}
\usepackage{mathspic, color}
\begin{document}
%---------------
\beginpicture
...
...
\endpicture
%---------------
\end{document}
\end{verbatim}



Note that when using \TeX\ or \LaTeX\ commands \textit{within} the {\PiCTeX}
picture environment, it is very important
to include the  comment \verb!%! symbol at the end of such lines, to prevent
{\PiCTeX} accumulating  additional \verb!<space>! characters from the ends of non-\PiCTeX\ commands,  since otherwise {\PiCTeX}
incorporates such spaces into the horizontal  distance used for  representing $x$-coordinates,  with the effect
that all subsequent picture elements will be displaced slightly to the right.


 If it is necessary (or simply convenient) to extent a \TeX\ or \LaTeX\ command across several lines, then each additional line must be protected  by using  a leading $\backslash\textvisiblespace$ (a backslash followed by one or more spaces) unless the line  actually starts with  a \TeX\ or \LaTeX\ command. 
A typical example is in the following macro (used in Figure~7.6) which defines a `display' maths formula. The macro is split  across several lines as follows:

\begin{Verbatim}
\newcommand{\formula}{%
\     $\displaystyle \sum_{p\ge0} \Delta_{jp} z^{(p+1)}$%
\     }%
text(\formula){B}
\end{Verbatim}


%%---------------------------
\section[\texttt{thispagestyle\{\}}]{The $\backslash$\texttt{thispagestyle\{empty\}} command}



This is an important command to include in the preamble, since this disables page numbering on the same page as the diagram, and for this reason this command is included in \texttt{mathspic.sty} (see Section~\ref{sec:sty}). 

If you intend to crop the image automatically using the \verb!-E! option with  \textsc{dvips} command to make an EPS and PDF image, for example,
\begin{Verbatim}
dvips -E myfigure.dvi -o myfigure.eps 
epstopdf myfigure.eps
\end{Verbatim}
then if a page number has been typeset then the rest of the page including the pagenumber will be included in the cropping. 

Of course, if you intend to use \mathsPIC\ commands in the main \texttt{.tex} document (as opposed to simply using the EPS or PDF image) then this command can be edited out of the file \texttt{mathspic.sty} as described in Section~\ref{sec:pictexfigs}.



%%---------------------------
\section[\texttt{typeout\{\}}]{The $\backslash$\texttt{typeout\{\}} command}

This is a very useful command which makes \TeX\ print comments 
to the screen while the
output-file is being processed.
For example, the following commands in the {\mathsPIC} file
will print a message to the
screen just before processing a data-file for a curve.
\begin{verbatim}
\typeout{processing the data-file now}%
inputfile*(curve.dat)
\end{verbatim}
This command is also useful when a file is
\verb!input! several times in a loop using the
{\mathsPIC} \verb!inputFile{..}[]!
command. In such cases it is quite useful to include
the line \verb!\typeout{...}%! at the beginning of the file
being input, as this results in \TeX\ printing \verb!...!
to the screen each time the file is input.

Note the importance of including the  comment \verb!%! symbol
at the end of the line when the \verb!\typeout{}%! command
is used \textbf{within} the {\PiCTeX} picture environment---this applies mainly to  lines ending with the right brace \} of a  \TeX\ or \LaTeX\  command (see Section~\ref{sec:headfoot}).


%--------------------------------
\section{The Color package}
\label{sec:color}

The standard \LaTeX\  Color package can be used  to draw parts of  a diagram in
colour, in much the same way one would when dealing with text (note that the color package must be installed \textit{after} mathspic).
One simply inserts the the usual \LaTeX\  `color' commands between
\mathsPIC\ commands (preferably on a separate line). 

Since the \verb!\color{}! command is a \LaTeX\ command, it is important to  include the  comment \verb!%! symbol at the end of the command when it is used \textbf{within} the {\PiCTeX} picture environment.
 For example, the following code will draw the line $PQ$ in blue. 
\begin{verbatim}
\usepackage{mathspic, color}
%---------------------------
\beginpicture
....
....
\color{blue}%
\drawline(PQ)
\color{black}%
....
....
\endpicture
\end{verbatim}
Note however, that while all PS and PDF viewers show colours, there are  some DVI-viewers which  do not currently show colour.



\textbf{Colour spilling (old \TeX\ systems only)}: \ 
If you  find that colour is spilling into unexpected zones (say, into ordinary text following a figure), then this can be fixed by using the \LaTeX\ command  \verb!\normalcolor%! immediately before the \verb!\endpicture! command.



%%-------------------------------
\section{Other useful \LaTeX\ commands}


For more details of these useful commands see Knuth (1990) p~272--279; Eijkhout (1992); Salomon (1995).
See also Chapter~\ref{ch:texparameters} for details of using \LaTeX\ commands for accessing parameter values.
 Note, finally, that it is important to put a \% on the end of these \LaTeX\ commands in order to prevent \PiCTeX\ from adding spaces to the end.
\begin{verbatim}
\typeout{....}
\thispagestyle{empty}
\scrollmode  %(forces TeX to display errors but not to stop)
\nonstopmode
\batchmode
\newlength{}
\newcommand{}
\color{..}
\normalcolor
\settowidth{}
\settolength{}
\settodepth{}
\write
\newwrite
\immediate\write18{...}
\openout
\closeout
\the
\number
\showthe
\jobname
\end{verbatim}




\end{document}
