%% $Id: maple2e.sty,v 1.5 1995/12/15 20:34:29 kmheal Exp kmheal $
% $Revision: 1.5 $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\fileversion{4.1}
\def\filedate{95/12/04}
\ProvidesPackage{maple2e}[\filedate\space\fileversion
Maple Latex Environment Definitions -- \filedate\space\fileversion]
%%%%
\typeout{Package: mapleenv\space\filedate\space v\fileversion}
\typeout{... Maple Latex Environment Definitions}
% 
% Copyright (c) 1994,1995 by Waterloo Maple Inc., all rights reserved.
%
% Permission is granted to use this package without charge. It may
% be redistributed providing that it is distributed as is
% and without charge.  You may modify these macros for your own use,
% and redistribute them, subject to the following conditions.
%
% 1. The package name used for any modified version of this file is 
%    different from maple2e and the file name used is different from
%    maple2e.sty
%
% 2. You acknowledge this copyright notice and this file as the source.
%
% 3. It is redistributed under the same terms and conditions 
%    as indicated here, including this notice.
%
% Please send recommendations or requests for changes to:
%
% 	doc@maplesoft.com
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% The following flags are set by options to the package.
%
% Depending on the settings graphics is set up for use with dvips
% or OzTeX (version 1.7 or newer)
%
% Maple ordinarily generates its postscript graphics in landscape
% mode sized for an 8.5 by 11 page.  This behavior can be controlled by
% Maple's interface() command.  The command:
% 
%	interface( plotoptions=`portrait,height=40,width=60`);
%
% See help info ?plot,device  for more detail.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% Package Options
%
\newif\ifnoplots\noplotsfalse
\DeclareOption{noplots}{
    % \PassOptionsToPackage{dvips}{epsfig}
    \noplotstrue
}
\DeclareOption{dvips}{
    % \PassOptionsToPackage{dvips}{epsfig}
    \edef\Driver{dvips}
    \AtEndOfPackage{
      \typeout{... configuring graphics for dvips driver}
      \usepackage[dvips]{epsfig}
      \let\mapleplot\epsfigmapleplot
      \let\imapleplot\mapleplot
    }
}
\DeclareOption{dvi2ps}{
    \edef\Driver{dvi2ps}
    \AtEndOfPackage{
      \typeout{... configuring graphics for dvips driver}
      \usepackage[dvi2ps]{epsfig}
      \let\mapleplot\epsfigmapleplot
      \let\imapleplot\mapleplot
    }
}
\DeclareOption{dvilaser}{
    \edef\Driver{dvilaser}
    \AtEndOfPackage{
      \typeout{... configuring graphics for dvilaser driver}
      \usepackage[dvilaser]{epsfig}
      \let\mapleplot\epsfigmapleplot
      \let\imapleplot\mapleplot
    }
}
\DeclareOption{dvipsone}{
    \edef\Driver{dvipsone}
    \AtEndOfPackage{
      \typeout{... configuring graphics for dvipsone driver}
      \usepackage[dvipsone]{epsfig}
      \let\mapleplot\epsfigmapleplot
      \let\imapleplot\mapleplot
    }
}
\DeclareOption{dvitops}{
    \edef\Driver{dvitops}
    \AtEndOfPackage{
      \typeout{... configuring graphics for dvitops driver}
      \usepackage[dvitops]{epsfig}
      \let\mapleplot\epsfigmapleplot
      \let\imapleplot\mapleplot
    }
}
\DeclareOption{dviwindo}{
    \edef\Driver{dviwindo}
    \AtEndOfPackage{
      \typeout{... configuring graphics for dviwindo driver}
      \usepackage[dviwindo]{epsfig}
      \let\mapleplot\epsfigmapleplot
      \let\imapleplot\mapleplot
    }
}
\DeclareOption{emtex}{
    \edef\Driver{emtex}
    \AtEndOfPackage{
      \typeout{... configuring graphics for emtex driver}
      \usepackage[emtex]{epsfig}
      \let\mapleplot\epsfigmapleplot
      \let\imapleplot\mapleplot
    }
}
\DeclareOption{pubps}{
    \edef\Driver{pubps}
    \AtEndOfPackage{
      \typeout{... configuring graphics for pubps driver}
      \usepackage[pubps]{epsfig}
      \let\mapleplot\epsfigmapleplot
      \let\imapleplot\mapleplot
    }
}
\DeclareOption{textures}{
    \edef\Driver{textures}
    \AtEndOfPackage{
      \typeout{... configuring graphics for textures driver}
      \usepackage[textures]{epsfig}
      \let\mapleplot\epsfigmapleplot
      \let\imapleplot\mapleplot
    }
}
\DeclareOption{xdvi}{
    \edef\Driver{xdvi}
    \AtEndOfPackage{
      \typeout{... configuring graphics for xdvi driver}
      \usepackage[xdvi]{epsfig}
      \let\mapleplot\epsfigmapleplot
      \let\imapleplot\mapleplot
    }
}
\DeclareOption{dvitps}{
    \edef\Driver{dvitps}
    \AtEndOfPackage{
      \typeout{... configuring graphics for dvitps driver}
      \usepackage[dvitps]{epsfig}
      \let\mapleplot\epsfigmapleplot
      \let\imapleplot\mapleplot
    }
}
\DeclareOption{dviwin}{
    \edef\Driver{dviwin}
    \AtEndOfPackage{
      \typeout{... configuring graphics for dviwin driver}
      \usepackage[dviwin]{epsfig}
      \let\mapleplot\epsfigmapleplot
      \let\imapleplot\mapleplot
    }
}
\DeclareOption{oztex}{
    \edef\Driver{oztex}
    \AtEndOfPackage{
      \typeout{... Configuring graphics for OzTex, rotation not supported}
      \usepackage[oztex]{epsfig}
      \let\mapleplot\oztexmapleplot
      \let\imapleplot\mapleplot
    }%
}
\DeclareOption{SWP}{
    \edef\Driver{SWP}
    \AtEndOfPackage{
      \typeout{... Configuring graphics for Scientific Work Place}
      \let\mapleplot\swpmapleplot
      \let\imapleplot\mapleplot
    }
}
% \ExecuteOptions{dvips}  % default's to dvips driver
\ProcessOptions*
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ----------------------------------------------
% Environments for Export to LaTeX
% ----------------------------------------------
%
% This package defines the environments used by Maple V Release 4's
% "Export to Latex" facility.  In addition, each of the environments 
% accepts an optional parameter.  For example, for example,
% Maple Input lines accept any of:
%
%      \begin{mapleinput}...\end{mapleinput},   (default)
%
% The contents of such an environment are in terms of mapleinline.
%
% The "Export to LaTeX" facility of the Maple worksheet does not use any
% of the optional parameters.  They exist to provide the additional
% control needed for reprocessing long LaTeX manuscripts and which is
% carried out by a special "Maple Filter".
% 
% Maple output can occur in several forms.  Maple's "prettyprint" output,
% as well as error messages and warnings, is encapsulated as
%
% 	        \begin{maplettyout}...\end{maplettyout} 
%
% "Export to Latex" generates LaTeX code for the entire worksheet. 
%  The displayed mathematics output is controlled to fit a
%  user specified line width and appears inside the environment
%
% 	\begin{maplelatex}...\end{maplelatex}
%
% Maple generated plots are exported as postscript files.
% The resulting files are included in the LaTeX document 
% by using the macro call
%
%  	\mapleplot{filename}
%
% On processing by LaTeX, the postscript code from the 
% indicated file is read into "dvi" file and a display is 
% generated at that point in the document.  The plot dimensions 
% are specified as \MaplePlotHeight and \MaplePlotWidth.
%
% The actual embedding is accomplished using the LaTeX2e graphics 
% package.  This style file has been tested with the dvi to 
% poscript conversion programs:
%
%     dvips 
%     dvipsone
%
% ----------------------------------------------
% Environments that ignored by the Maple Filter
% ----------------------------------------------
% The Maple Filter is a special version of Maple that can read
% and update latex files which have been developed using these
% macros.  There is a need, in such tex files, to display information
% in the same manner as the preceding manner and yet guarantee that
% the information is not changed by the Maple Filter.
% The macros are identical to those describe above, but with each 
% name preceded by an "i".
%
%   \begin{imapleinput}...\end{imapleinput}  like mapleinput
%   \begin{mapleinput}[p]...\end{imapleinput} as above, default case
%   \begin{imaplelatex}...\end{imaplelatex} like maplelatex
%   \imapleplot{filename}   like mapleplot
%   \imaplesepline	  like \maplesepline, but ignored by the filter.
%
% ----------------------------------------------
% Implementation Details
% ----------------------------------------------
% The mapleinput, and maplettyout environments are similar to 
% \begin{verbatim}...\end{verbatim} but with several 
% important differences.
%
% - The spacing relative to the surrounding environment is different.
%
% - Page breaks are encourages before commands, or after results,
%   and discouraged inbetween.
%
% - maplettyout and maplelatex environments are assumed to follow
%   mapleinput regions and so have less space above.  This allows us to
%   reduce the space between adjacent Maple regions without any
%   elaborate mechanism to detect when there have been intervening
%   paragraphs of text.
%
% - the size of the font for text regions is definable.  Use \MapleFont
%   to reset the font.
%
% - the  indentation of the environments can be indented by setting 
%   the value of \LeftMapleSkip  .
%
% - a prompt is automatically generated at the start of each line in
%   the case of the input environments.
%
% Much of the spacing and sizing information is parameterized.
% The following Macros control most of the spacing for the the 
% Maple environments.  They are all resettable in the preamble of 
% your document. 
% 
% \AboveMapleSkip	- space above an environment
% \BelowMapleSkip	- space below an environment
% \AboveMaplePlot	- space above a Maple Plot 
% \BelowMaplePlot	- space below a Maple Plot
% \MaplePlotHeight	- vertical space reserved for a plot
% \MaplePlotWidth	- width reserved for a plot
% \MaplePlotAngle	- angle of rotatation
% \LeftMapleSkip 	- the amount of left indentation
% \MapleFont 		- The Maple font 
% \MapleSize 		- The size of the Maple font in mapleinput and 
%                          maplettyout
% \MapleLatexSize	- The size of the Maple fonts in maplelatex
% \MapleFirstLine	- controls ingoring first line feed
% \MaplePrompttrue 	- controls insertion of prompt char
% \MaplePromptString	- defines the prompt string
% \MaplePromptSecondary	- defines the secondary prompt string
% \MapleSkip		- amount of glue before and after
%			displayed text
% \MapleTab		- number of spaces per tab (8)
%
% Spacing, dimensions, etc.  
%
\newskip\AboveMapleSkip		% space above the maple environments.
\newskip\BelowMapleSkip		% space below the maple environments.
\newdimen\LeftMapleSkip 	% indentation for the maple commands.
\newskip\AboveMaplePlot		% spacing above and below maple plots.
\newskip\BelowMaplePlot
\newdimen\MaplePlotHeight 	% size of the maple plot.
\newdimen\MaplePlotWidth 
\newdimen\MapleSepLineWidth 
\newif\ifMapleFirstLine		% flag to control printing of first CR
\newif\ifMaplePrompt		% flag to control prompting
\newcount\MapleTab	
\newtoks\MaplePromptString 
\newtoks\MaplePromptSecondary 
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set the Default Values  (Some are reset later in response to package
% options.)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Environment spacing
%
\AboveMapleSkip = 1.5ex plus 3 pt minus 0 pt
\BelowMapleSkip = \AboveMapleSkip
\LeftMapleSkip  = 1.5em		  
\AboveMaplePlot = 1.5\AboveMapleSkip
\BelowMaplePlot = 1.5\AboveMapleSkip
\MaplePlotHeight = 40ex 
\MaplePlotWidth = 60ex
\edef\MaplePlotAngle{270}	  % assumes Maple plots are in landscape 
                                  % mode
%
% separator line parameters (obsolete)
%
\newdimen\MapleSepLineHeight \MapleSepLineHeight = 0.01in
\let\MapleSepLineWidth\linewidth  % use \let for automatic scaling
\MapleSepLineHeight = 1pt
%
% Font characteristics and other controls 
% for inside Maple's special verbatim environments.
%
\def\MapleSize{\small}
\def\MapleFont{\tt}
\def\@MapleFont{\MapleFont\MapleSize\@noligs}  % used in mapletty envs.
\def\MapleLatexSize{\normalsize} % change this to change maplelatex size
\MapleFirstLinefalse  % Ignore first \cr after \begin{mapleinput}  
\MaplePrompttrue      % Include the prompt string for each input line.
\MapleTab = 8
\MaplePromptString = {\raise 1pt \hbox{$\scriptstyle>$\space}}
\MaplePromptSecondary = \MaplePromptString % prompts  on every line
% \MaplePromptSecondary = {\space\space} % no prompts after first line
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Utilities used to define the main environments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Utilities for changing character codes
%
\def\MakeTab#1{\catcode `#1 = 4 }      		% &
\def\MakeParameter#1{\catcode `#1 = 6 }		% #
\def\MakeSuperScript#1{\catcode `#1 = 7 }	% ^
\def\MakeSubScript#1{\catcode `#1 = 8 }		% _
\def\MakeLetter#1{\catcode `#1 = 11 }
\def\MakeOther#1{\catcode `#1 = 12 }
\def\MakeActive#1{\catcode `#1 = \active\relax }
\def\MakeTabActive{\MakeActive{\^^I}}
\def\MakeEolActive{\MakeActive{\^^M}}
%
\@ifundefined{dospecials}{
\gdef\dospecials{\do\ \do\\\do\{\do\}\do\$\do\&%
  \do\#\do\^\do\_\do\%\do\~}
}{\relax}
\@ifundefined{postdospecials}{
\gdef\postdospecials{%
  \catcode`\\\z@
  \catcode`\{\@ne
  \catcode`\}\tw@
  \catcode`\ 10
  \catcode`\&11}
}{\relax}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% In a Maple tty environment every line is treated as a paragraph.
% The behavior at the end of every Maple paragraph (line) is given
% by, thereby inhibiting page breaks in such environments.
\def\@MaplePar{\nopagebreak[3]\par\@@par}%
% \def\@MaplePar{\nopagebreak[3]\EveryParZ\@@par}%
%
\newif\if@IgnoreNewLine
\@IgnoreNewLinetrue
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Characters requiring special treatment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%-- Spaces

\def\MapleSpace{\ }
\def\@ObeySpaces{\MakeActive{\ }\@@ObeySpaces\relax}
{\MakeActive{\ }\gdef\@@ObeySpaces{\edef {\MapleSpace}}}

%-- BackSlashes

{\catcode`| = 0 |catcode`\\ = 12 |gdef|BackSlash{\}}

%-- Tabs

\newdimen\@MapleTabSize
\def\@ObeyTabs{\MakeTabActive\@@ObeyTabs\relax}
{\MakeTabActive\gdef\@@ObeyTabs{\def^^I{\@MapleTab}}}
\def\@MapleTab{%
  \leavevmode   % ensure that we are in horizontal mode
  \egroup      % Terminate box register 0
  \dimen0=\wd0 % store its length and round up to next stop
  \divide\dimen0 by \@MapleTabSize
  \advance\dimen0 by 1sp
  \multiply \dimen0 by \@MapleTabSize
  \wd0 = \dimen0
  \box0
  \setbox0 = \hbox\bgroup
}

%-- End of Line Character

\def\@ObeyEol{\MakeEolActive\@@ObeyEol\relax}%
{\MakeEolActive\gdef\@@ObeyEol{\let^^M=\@MapleEol}}
\def\@MapleEol{%
  \if@IgnoreNewLine
  \else
    \leavevmode%
    \egroup%
    \box 0%
    \@MaplePar%
  \fi
  \@IgnoreNewLinefalse
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Definitions of Utilities for the Main Environments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% These Macros are the common elements of the verbatim like environents.
% The spacing above and below the environment should is done in the 
% environment preamble instead of here to enable this to be used in a 
% variety of such environments.

% \newtoks\MapleIOType \MapleIOType = {a}
\edef\@MapleQuiet{q}      % indicates a silent command or result
\edef\@MapleVerbose{a}    % The standard behavior in which
                          % results are generated and displayed.
\edef\@MapleNoPrompt{np}  % specify no prompts in environment
\edef\@MaplePrompt{p}     % specify prompts for this environment
\edef\@MapleNoInput{ni}   % No input appears in output stream.
\edef\@MapleNoOutput{no}  % No output appears in outputstream.

% The next macro is used by the verbatim like environments to
% reset character codes, and change the treatment of new lines, etc.
% Actions  can be made conditional on the value of \@MapleIOType which
% is always set to 'a' , or to 'q' as in the value of the 
% optional parameter used in \begin{mapleinput}[q]

\newtoks\MapleListCorrection  \MapleListCorrection={}
\def\@SetupMapleTty#1{%
\par\@endpefalse   %% to clear the \@endpetrue done in \mapleinput
\begingroup  %% this is the real start of the special environment. 
  %%%  Compute and set tab positions
  \setbox 0 = \hbox{\@MapleFont X}
  \@MapleTabSize = \wd0
  \multiply\@MapleTabSize by \MapleTab
  \setbox0 = \hbox{\relax}  % Clearing \box 0
  %%% paragraph dimensions and line spacing
  \rightskip = 0pt 
  \parindent = 0pt
  \parskip = 0pt 
  \ifnum\@listdepth>0%
        \MapleListCorrection={\hskip-\@totalleftmargin\relax }
        \LeftMapleSkip= 0em 
  \else
        \MapleListCorrection={\hskip 0ex\relax }
  \fi
  \setlength{\leftskip}{\LeftMapleSkip}
  \addtolength{\leftskip}{\@totalleftmargin}
  \parfillskip = 0pt plus 1fil
  %
  %%%  The next two parameters may have been changed 
  %%%  by a \raggedright so they are reset here.
  \spaceskip = 0pt   \xspaceskip = 0pt
  %
  %%%  Set this flag to 0 if the \begin{...} is to appear on a
  %%%  separate line of the source file.
  \ifnum #1 = 0 \@IgnoreNewLinetrue\else\@IgnoreNewLinefalse\fi%
  %
  %%% Describe how to handle every paragraph (recall paragraph == line )
  %% \@MapleFont%
  \everypar = {\EveryParZ}%
  \def\EveryParZ{%
    \ifMaplePrompt
    \the\MapleListCorrection
    \the\MaplePromptString
    \MaplePromptString = \MaplePromptSecondary
    \MapleListCorrection = {\hskip 0pt\relax}
    \fi
    \setbox0 = \hbox \bgroup
  }%
%
%%%  Choose the type size and font -  The order of these commands
%%%  may be important.
\@MapleFont%
\lineskiplimit=0\normalbaselineskip
\baselineskip=0.85\normalbaselineskip
\@noligs%
\let\do\@makeother \dospecials
\catcode ``=\active%
\frenchspacing%
\@ObeySpaces% 
\@ObeyTabs%
\@ObeyEol%
}

% Exit the special tty environments
\def\@EndMapleTty{%
\endgroup%% matches the \begingroup inside of @SetupMapleTty
}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% The following Macros start the various Verbatim like environments
% for special Maple regions.  These calls set up the 
% scanning for the environment terminator.
%
% A conditional parameter as in \begin{...}[q] etc. denotes a
% special class of Maple Regions.

\begingroup
  \catcode`| = 0  % becomes the escape character
  \catcode`( = 1  % becomes a begin group
  \catcode`) = 2  % becomes an end group
  \catcode`@ = 11 % becomes a regular character (for macro names)
  \catcode`\{ = 12 % becomes an other character
  \catcode`\} = 12 % becomes a other character
  \catcode`\\ = 12 % becomes a other character
%
%  type a   standard (verbose) usage
%  type q   quiet command
%  type np  no prompt  (imapleinput only at this time...)
%  type ni  no input  
%  type no  no output  
%
% -- Maple Inert Input  
|gdef|@BeginIMapleInput#1\end{imapleinput}(%
|MaplePrompttrue%
#1%
|end(imapleinput))%
%
% -- Inert TTY Output
|gdef|@BeginIMapleTtyout#1\end{imaplettyout}(%
|vskip|AboveMapleSkip%  extra vspace is needed here
|MaplePromptfalse
#1%
|end(imaplettyout))%
%
% -- Fixed Width
|gdef|@BeginFixedWidth#1\end{FixedWidth}(%
|vskip|AboveMapleSkip%  extra vspace is needed here
|MaplePromptfalse
#1%
|end(FixedWidth))%
% -- TTY Input 
|gdef|@BeginMapleInput[#1]#2\end{mapleinput}(%
|edef|@MapleIOType(#1)%
|gdef|MapleIOType(#1)%
|ifx|@MapleIOType|@MapleNoPrompt|MaplePromptfalse|fi%
|ifx|@MapleIOType|@MapleNoInput|edef|@MapleIOType(q)|fi%
|ifx|@MapleIOType|@MapleQuiet%
|typeout(.............Quiet Maple Command #1)%
|removelastskip%
|else%
%|typeout(.............Verbose Maple Command)%
#2%
|fi%
|end(mapleinput))%
%
% -- TTY Output
|gdef|@BeginMapleTtyout[#1]#2\end{maplettyout}(%
%%|typeout(TTYout Environment of type #1)%
|edef|@MapleIOType(#1)%
|gdef|MapleIOType(#1)%
|ifx|@MapleIOType|@MaplePrompt|MaplePromptfalse|fi%
|ifx|@MapleIOType|@MapleNoOutput|edef|@MapleIOType(q)|fi%
|ifx|@MapleIOType|@MapleQuiet%
|typeout(.............Quiet Maple Tty Out)%
|else%
#2%
|fi%
|end(maplettyout))%
%
% -- Suppressed Latex Output
|gdef|@GobbleMapleLatex#1\end{maplelatex}(%
|end(maplelatex))%
|endgroup
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Page breaks are inhibited immediately following the input
% environment.  This assumes that no extra space is 
% required below the region as it is followed by some
% form of Maple output region.
%
% Latex environments can be defined by newenvironment, or by
% defining two macros   \newmacro   and \endnewmacro
% 
% This code handles the recognition and the processing of 
% the optional parameter  by mapping the case of no parameter
% onto the case \begin{...}[a].
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Definition of a Maple environments that are ignored by
% the Maple Filter.  
% 
% \begin{imapleinput} ...\end{imapleinput}
% \begin{imaplettyout} ...\end{imaplettyout}
% \begin{imaplelatex} ...\end{imaplelatex}
% \imaplesepline
% \imapleplot
%
% These environments are ignored by the Maple Filter.
%
% -- imapleinput
%
\def\imapleinput{
\removelastskip%
\MaplePrompttrue% prompt is required in this environment.
\if@minipage\removelastskip\vskip-1.3ex
\else\vskip\AboveMapleSkip\fi%
\@SetupMapleTty{0}% The 0 indicates ignore first new line
\@BeginIMapleInput% 
}
%
\def\endimapleinput{%
  \@EndMapleTty%
  \removelastskip%
  \edef\@MapleIOType{\MapleIOType}
  \ifx\@MapleIOType\@MapleQuiet%
    \typeout{.............Quiet Maple Command finished}
  \else
    \vskip\BelowMapleSkip% not usually followed by output...
  \fi%
  \@endpetrue
  \ignorespaces
}
%
% -- imaplettyout
%
\def\imaplettyout{
  \removelastskip%
  \nopagebreak[3]% 
  \MaplePromptfalse	  % No prompt is required in this environment.
  \@SetupMapleTty{1}   % The 1 indicates "respect first new line"
  \@BeginIMapleTtyout  % np indicates omit prompt
}
%
\def\endimaplettyout{%
  \@EndMapleTty%
  \removelastskip
  \vskip\BelowMapleSkip%
  \pagebreak[3]%
  \@endpetrue
  \ignorespaces
}%
%
% -- imaplelatex
%
%  an inert maple latex environment  (ignored by the filter)
%
\newenvironment{imaplelatex}%
{\vskip.5\AboveMapleSkip\vskip\z@\begin{maplelatex}}{\end{maplelatex}}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Definition of actual mapleinput environments.
% 
% \begin{mapleinput} ...\end{mapleinput}
% \begin{maplettyout} ...\end{maplettyout}
% \begin{maplelatex} ...\end{maplelatex}
% 
% These parameterized environments are intended for reprocessing 
% by the Maple Filter.
%
% The [a] case is used by default.  
% The [q] is the quiet (suppressed)  mode.
% The [ni] (no input) behaves the same as [q]
% The [no] behaves the same as [a]
%
% -- mapleinput
%
\newenvironment{mapleinput}{%
\def\@gobblefirst##1{\relax\egroup\par}
\def\@gobblesecond##1##2{##1\egroup\par}
\def\@gobblesemicolons##1{##1}
\setlength{\parskip}{\z@}
\setlength{\leftskip}{\LeftMapleSkip}
\addtolength{\leftskip}{\@totalleftmargin}
\removelastskip
\vskip\AboveMapleSkip
\par\@endpefalse
\everypar{\the\MaplePromptString\MaplePromptString=\MaplePromptSecondary\ }
\parindent=\z@
\parfillskip=0pt plus 1fil
\lineskiplimit=0\normalbaselineskip
\baselineskip=.85\normalbaselineskip
}{\par\everypar{}\vskip\BelowMapleSkip\@endpetrue\ignorespaces}
%
% -- maplettyout
%
\def\maplettyout{
  \removelastskip%
  \vskip 0pt plus 0pt minus 3pt%  
  \nopagebreak[3]% 
  \MaplePromptfalse	  % No prompt is required in this environment.
  \@SetupMapleTty{1}   % The 1 indicates "respect first new line"
  \@ifnextchar [{\@BeginMapleTtyout}{\@BeginMapleTtyout[a]}%
}
% 
\def\endmaplettyout{%
  \@EndMapleTty%
  \edef\@MapleIOType{\MapleIOType}
  \ifx\@MapleIOType\@MapleQuiet%
     \typeout{.............Quiet Maple TTY finished}
  \else
    \vskip\BelowMapleSkip%
    \pagebreak[3]%
    \@endpetrue
    \ignorespaces
  \fi
}
% -- maplelatex 
%
% This is basically a wrapper around a display math environment
% but it does gobble the display if the [q] or [no] options are in
% effect.
%
\newbox\maplebox
\newdimen\mapleboxwidth
\def\maplelatex{%
\removelastskip%
\vskip .5\AboveMapleSkip%
\nopagebreak[3]%
\leftskip=\LeftMapleSkip
\@ifnextchar [{\@maplelatex}{\@maplelatex[a]}}
%
\def\@maplelatex[#1]{%
  \MakeSuperScript{^}%  Ensure these have normal interpretation
  \MakeSubScript{_}%
  \MakeTab{&}%
  \let\StartMapleLatex\relax  % default case is \@MapleVerbose
  \edef\@MapleIOType{#1}  %% for \ifx test%
  \ifx\@MapleIOType\@MapleNoOutput
    \typeout{.............No Output Option [no]}%
    \edef\@MapleIOType{q}   %%  handle same as \@MapleQuiet  
    % \relax%
  \fi %
  \gdef\MapleIOType{\@MapleIOType}   %% for consultation by exit routine
  %
  \ifx\@MapleIOType\@MapleQuiet% 
    \typeout{.............Quiet Maple Latex }%
    \@SetupMapleTty{0}%
    \let\StartMapleLatex\@GobbleMapleLatex%   similar to a quiet tty region.
    \relax%
  \else
    % Default case \@MapleVerbose
    \def\arraystretch{1.5}%
  \fi%
  \MapleLatexSize%
  % \parindent=0pt%
  \parskip = 0pt plus 1pt minus 0pt%
  \topskip = 0pt plus 1pt minus 0pt%
  \parfillskip = 0pt plus 1fil%
  \lineskiplimit=0\normalbaselineskip%
  \baselineskip=0.8\normalbaselineskip%
  \abovedisplayskip=0pt plus 1pt minus 2pt%
  \abovedisplayshortskip=0pt plus 1pt minus 2pt%
  \belowdisplayskip=0pt plus 3pt minus 0pt%
  \belowdisplayshortskip=0pt plus 3pt minus 0pt%
  \StartMapleLatex%
}%
%
\def\endmaplelatex{%
\edef\@MapleIOType{\MapleIOType}%
\ifx\@MapleIOType\@MapleQuiet%   End the same as the verbatim's
    \typeout{.............Quiet Maple Latex finished}%
    \let\FinishMapleLatex\@EndMapleTty %
\else%
    \let\FinishMapleLatex\relax%
    \vskip\BelowMapleSkip%
    \pagebreak[3]%
    \@endpetrue
    \ignorespaces
\fi%
\FinishMapleLatex%
}%
% -- maplesepline
%
\newcommand{\maplesepline}{\vskip \parskip%
\hrule\@height\MapleSepLineHeight\@width\MapleSepLineWidth%
\vskip \parskip\relax}
%
% -- imaplesepline ( the inert form )
%
\let\imaplesepline\maplesepline
%
% - Special Indentation used to format procedures
%
\newdimen\Tab
\Tab=3ex
\def\mapleIndent#1{\hbox{\hskip#1\Tab\relax}}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  Special environments for in-line maple commands.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  \begin{maplegroup}				- maple exchange group
%  ...
%  ... and \mexpr{sin(x^2)} ...			- inline maple code
%  ...
%  \mapleinline{Inert}{TwoD}{int(sin(x^2),x);}{%	- for maple filter
%  {mapletex}{$\int{ .... }$}		        - for latex
%  ...
%  ...
%  \mapleresult					- location of inline results
%  \begin{maplelatex}				- actual displayed results
%  ...
%  \end{maplelatex}
%  \end{maplegroup}
% 
% Note: { and } do not display inside of \mexpr, use \{ and \} instead.
%
%  \@domexpr          completes the following inline math
%  \@gobblefirst      absorbs the inline math (not displaying it)
%  \@gobblesecond     absorbs the second following argument.
%  \@gobblesemicolons      absorbs semi-colons inside of the 1d mode.
%
\def\@domexpr#1{#1\egroup}
\def\@gobblefirst#1{\relax\egroup}
\def\@gobblesecond#1#2{#1\egroup\ignorespaces}
\def\@gobblesemicolons{\MakeActive{;}\@@gobblesemicolons}
{\MakeActive{;}\gdef\@@gobblesemicolons{\edef;{\relax}}}
\def\dosetup{\let\do\@makeother  \dospecials  \postdospecials}
%
% \mexpr{int(sin(x^2),x)} --- \mapleexpr{int(sin(x^2),x)}
%
% To make { and } visible in this verbatim environment, use \{ and \}
% Also, to show \, use \\. 
%
\def\mexpr{\bgroup\ttfamily\dosetup\let\\\BackSlash\@domexpr}
\def\mapleexpr{\bgroup\ttfamily\dosetup\let\\\BackSlash\@domexpr}
%
% \mapleinline{Inert}{2D}{int(sin(x^2),x)}{ % used to generate display
% $\int{\sin(x^2),dx}$}	                    % updated by the filter
%
% \@bsphack ... \@esphack   for absorbing unwanted space not currently used.
% but spacing inside this macro definition is important.

\edef\OneD{1d} \edef\TwoD{2d}
\newif\ifDisplay\Displayfalse

\def\mapleinline#1#2{%
\edef\DisplayType{#2}%
\ifx\DisplayType\TwoD%
\let\Display\@gobblefirst	% display the 2-D representation
\global\Displaytrue
\else%
\let\Display\@gobblesecond	% display the 1-D representation
\global\Displayfalse
\fi%
\bgroup\ttfamily\dosetup%
\@gobblesemicolons%		% absorb semi-colons
\let\\\BackSlash%		% make backslash available
\Display}%
%
% - mapleresult  
%
\let\mapleresult\relax   % marker indicating location to place maple
			 % generated results.
%
% -- mapletex    (a Maple specific wrapper for inline 2-d math)
%
\def\mapletex#1{#1}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Various Plot Configurations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% -- noplots  -- No Driver Available ?
%
\def\mapleplotname#1{
	\typeout{...using Plot file #1}%
	\vskip.5\MaplePlotHeight
        \centerline{\Large \bfseries Plot:  #1}
        \vskip.5\MaplePlotHeight
}
%
% -- epsfig.sty (used by dvips, etc)
%
\def\epsfigmapleplot#1{
        \removelastskip\par
	%\vskip.5\AboveMaplePlot
	\vskip -.5\AboveMaplePlot
	\IfFileExists{#1}{%
		\typeout{...including Plot file #1}%
		% \hskip 12ex%
		\vbox{%
		    \hfil%
		    \epsfig{figure=#1,%
		        height=\MaplePlotWidth,%
		        width=\MaplePlotHeight,%
		        angle=\MaplePlotAngle}%
		    \hfil%
		}%
		\vskip\BelowMaplePlot%
	    }%
	    {%
	    \typeout{...Missing Plot File  #1}
	    \vbox{\mapleplotname{#1} }%
	    }%
}% end of mapleplot def
%
% -- Oztex postscript driver
%
% Rotation is not supported.  so use Maple's commands to rotate.
% This can be done using the Maple command 
%
%	interface(plotoptions=`portrait,height=200,width=300`); 
%
% This is the same as mapleespfig, but with no rotation expected.
%
\def\oztexmapleplot#1{
    \vskip\AboveMaplePlot%
    \vskip\MaplePlotHeight%
    \IfFileExists{#1}{%
	\typeout{...including Plot file #1}
	\hskip 8em\hbox{%
	    \epsfig{figure=#1,%
	       height=\MaplePlotHeight,%
	       width=\MaplePlotWidth,%
	       % angle=\MaplePlotAngle
	       }%
	} % end of hbox
	\vskip\BelowMaplePlot%
	}% end of first case
	{% second case 
	    %\typeout{...Missing Plot File  #1}
	    { %
		\vskip.5\MaplePlotHeight%
		\centerline{\Large \bfseries Plot File = #1}
		\vskip.5\MaplePlotHeight %
		}% end of vbox
	}% end of second case
} % end of oztexmapleplot

%%%%%%%%%%%%%%%%%%%%%%%%%
% Install the Driver.
%%%%%%%%%%%%%%%%%%%%%%%%%
\@ifundefined{Driver}{%
      \ifnoplots
	     \let\mapleplot\mapleplotname
	     \let\imapleplot\mapleplot
      \else
      \IfFileExists{epsfig.sty}{% Default to dvips
             \typeout{ ... Defaults to "dvips" Driver }
             \usepackage[dvips]{epsfig}
             \let\mapleplot\epsfigmapleplot
             \let\imapleplot\mapleplot
             \edef\Driver{dvips}}{%  no driver 
	     % generate vertical space containing file name
	     \let\mapleplot\mapleplotname
	     \let\imapleplot\mapleplot
	}
      \fi
}{\usepackage[\Driver]{epsfig}}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%
%--  Maple Worksheet Default Paragraph and Character Styles definitions
%
%   Character styles are handled as in {\textbf ... }
%
%   Paragraph styles are handled by environments as in
%   \begin{flushleft} ... \end{flushleft}
%
%--------------------------------------------------
% - Routine for Handling Undefined Character Styles
%
\newif\if@def\@deffalse
\def\DefineCharStyle#1{
  \@ifundefined{#1}{\@deftrue}{\@deffalse}
  \if@def
    \typeout{Defining a new character style: #1}
    \expandafter\def\csname #1\endcsname##1{\relax}
  \fi}
%
%--------------------------------------------------
% - Routine for Handling Undefined Paragraph Styles  
%
% These are handled as environments.  Blank spaces are allowed in 
% the environment names.
\def\DefineParaStyle#1{
\@ifundefined{#1}{\@deftrue}{\@deffalse}
\if@def
  \typeout{Defining new paragraph style: #1}
  \expandafter\newcommand \csname #1\endcsname[0]{\relax}%
  \expandafter\long\expandafter\def\csname end#1\endcsname{\relax}
\fi
}

%--------------------------------------------------
% - Routine for Handling Undefined Paragraph Styles  
%
\@ifundefined{QTR}{%	(borrowed from TCI Research)
  \gdef\QTR#1#2{{\csname#1\endcsname#2}}}{\relax} %  compatibility with TCI
\@ifundefined{TEXTsymbol}{%
  \gdef\TEXTsymbol#1{\mbox{$#1$}}}{\relax}%

%--------------------------------------------------
%
% - The Known Maple Paragraph Styles
%
\newenvironment{maplegroup}{}{}
\newenvironment{Author}{\begin{center}\large\itshape\mdseries}{\end{center}}
\newenvironment{subtitle}{\begin{center}\normalsize\upshape\mdseries}{\end{cente
r}}
\newenvironment{Bullet Item}{%
\renewcommand{\labelitemi}{$\bullet$}
\begin{itemize}\item\null}{\end{itemize}}
\newenvironment{Dash Item}{%
\begin{itemize}\item\null}{\end{itemize}}
\newenvironment{Diagnostic}{\bfseries}{}
\newenvironment{Error}{\bfseries}{}
%
\newenvironment{Heading 1}%
{\par\noindent\sffamily\Large\bfseries\upshape}%
{\par}
\newenvironment{Heading 2}%
{\par\noindent\sffamily\large\bfseries\upshape}%
{\par}
\newenvironment{Heading 3}%
{\par\noindent\sffamily\large\bfseries\itshape}%
{\par}
\newenvironment{Heading 4}%
{\par\noindent\sffamily\normalsize\bfseries\itshape}%
{\par}
%
\newenvironment{Normal}{\normalsize\rmfamily\mdseries}{}
\newenvironment{Text Output}{\normalsize\ttfamily\mdseries}{}
\newenvironment{Title}{\begin{center}\rmfamily\LARGE\upshape}%
{\end{center}}
\newenvironment{Warning}{\ttfamily}{}

% -- To be defined
% 
% \newenvironment{FixedWidth}{%
% \bgroup\@SetupMapleTty{0}}{\egroup}
% \newenvironment{Fixed Width}{%
% \bgroup\@SetupMapleTty{0}}{\egroup}
% \newenvironment{HyperLink}{\normalsize\rmfamily\itshape}{}

% -- Regular Known Character styles

\def\HyperLink#1{\normalsize\rmfamily\itshape #1}
\expandafter\def\csname 2D Math\endcsname#1{{\rmfamily\upshape #1}}
\expandafter\def\csname Help Heading\endcsname#1{%
{\large\bfseries\sffamily\upshape #1}}
\expandafter\def\csname Maple Input\endcsname#1{%
{\ttfamily\upshape #1}}
%
\newbox\maplettybox%
\setbox\maplettybox=\hbox{}
%
% -- Fixed Width is like a verbatim Version
%
\expandafter\def\csname FixedWidth\endcsname{
  \removelastskip%
  \nopagebreak[3]% 
  \MaplePromptfalse	  % No prompt is required in this environment.
  \@SetupMapleTty{1}   % The 1 indicates "respect first new line"
  \@BeginFixedWidth  % np indicates omit prompt
}
%
\expandafter\def\csname endFixedWidth\endcsname{%
  \@EndMapleTty%
  \removelastskip
  \vskip\BelowMapleSkip%
  \pagebreak[3]%
  \@endpetrue
  \ignorespaces
}%
%
\endinput %%%% The End %%%%%

