%% $Source: /u/maple/research/tex/inputs/RCS/mapleenv.sty,v $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\typeout%
{Maple Latex Environment Definitions -- $Revision: 3.7 $, February, 1994}
%
% Copyright (c) 1994 by Waterloo Maple Software, all rights reserved.
%
% Permission is granted to use this style without charge. It may
% also be redistributed providing that they are distributed as is
% and without charge.  You may modify these macros for your own use,
% and redistributed subject to the following condition:
%
% 1. The style name used for any modified version of this file is 
%    different from mapleenv.sty. 
%
% 2. You acknowledge this file as the source.
%
% 3. It is redistributed under the same terms and conditions 
%    as indicated here.
%
% Please send recommendations or requests for changes to:
%
% 	support@maplesoft.on.ca
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This latex style file defines environments suitable for 
% processing the latex documents exported from Maple worksheets.
% In particular, it defines each of:
%
%   maple commands,   \begin{mapleinput}...\end{mapleinput}, 
%
%   maple text output, \begin{maplettyout}...\end{maplettyout}, 
%
%   maple generated latex, \begin{maplelatex}...\end{maplelatex}
% 
%   maple separator lines, \maplesepline
%
%   maple plots , \mapleplot{filename}
%
% The mapleinput, and maplettyout environments are similar to 
% \begin{verbatim}...\end{verbatim} in effect.  
% but there are several important differences.
%
% - the spacing relative to the surrounding environment is different.
%
% - page breaks are encourages before commands, or after results.
%
% - 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.
%
% - the  indentation of the environments can be indented by setting 
% the value of \LeftMapleSkip  .
%
% The current definition of \mapleplot is appropriate for use with 
% the psfig macros and has been tested with psfig Version 1.9. It
% assumes that the plot is in landscape mode, but parameters can be
% changed to deal with rotation, etc.
%%
% J. S. Devitt,  February, 1994.
%
% The User Definable parameters are
% \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
% \AboveMapleSkip	- space above an environment
% \BelowMapleSkip	- space below an environment
% \LeftMapleSkip 	- the amount of left indentation
% \MapleFont 		- The Maple font 
% \MapleSize 		- The size of the Maple font 
% \MapleFirstLine	- controls ingoring first line feed
% \MaplePrompttrue 	- controls insertion of prompt char
% \MaplePromptString	- defines the prompt character
% \MapleSkip		- amount of glue before and after
%			displayed text
% \MapleTab		- number of spaces per tab (8)
% \MapleParCount	- counter used to detect adjacent Maple
%			regions.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Definitions of dimensions, etc.  Those which can be reset are "set" to 
% specific values in the following section.  CHANGE THEIR VALUES THERE.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newskip\AboveMaplePlot
\newskip\BelowMaplePlot
\newskip\AboveMapleSkip
\newskip\BelowMapleSkip
\newdimen\LeftMapleSkip 
\newdimen\MaplePlotHeight 
\newdimen\MaplePlotWidth 
% \newcount\MaplePlotAngle 
\newdimen\MapleSepLineWidth 
\newdimen\MapleSepLineHeight \MapleSepLineHeight = 0.01in
\newif\ifMaple		\Maplefalse
\newif\ifMapleFirstLine
\newif\ifMaplePrompt
\newcount\MapleTab	\MapleTab = 8
\newcount\MapleParCount   \MapleParCount=0 
\newtoks\MaplePromptString \MaplePromptString = {}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set All User-Setable Parameters in this section 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\MaplePromptString = {\raise 1pt \hbox{$\scriptstyle>$\space}}
%
%  output environment spacing
\AboveMapleSkip = 1ex plus 2 pt minus 1 pt
\BelowMapleSkip = \AboveMapleSkip
\LeftMapleSkip  = 5ex		  % environment spacing
%
%  plot parameters
\AboveMaplePlot = 2\AboveMapleSkip
\BelowMaplePlot = 2\AboveMapleSkip
\MaplePlotHeight = 40ex 
\MaplePlotWidth = 60ex
\edef\MaplePlotAngle{270}		  % plots in landscape mode
%
% separator line parameters
\let\MapleSepLineWidth\linewidth  % \let so it will be redefined 
				  % properly for narrow environments.
\MapleSepLineHeight = 1pt
\let\MapleFont\tt
\let\MapleSize\small
\MapleFirstLinefalse  % Ignore first \cr after \begin{mapleinput}  
\MaplePrompttrue      % Include the prompt string for each input line.
\MapleTab = 8
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Utilities used to define the main environments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\makeatletter
% Utilities for changing character codes
\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}}
% Flag to control treatment of first new line char in maple envs
\newif\if@IgnoreNewLine
\@IgnoreNewLinetrue
%
% 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}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Characters requiring special treatment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Spaces
%%%%%%%%%%%%%%%%%%%%%%%
\def\MapleSpace{\ }
\def\@ObeySpaces{\MakeActive{\ }\@@ObeySpaces\relax}
{%
\MakeActive{\ }\gdef\@@ObeySpaces{\edef {\MapleSpace}}%
}%
%%%%%%%%%%%%%%%%%%%%%%%
% 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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Macro for setting up the verbatim like environents
% This is executed in the preamble to the corresp latex environment.
% The spacing above and below the environment is done in the
% preamble instead of here to enable this to be used in a variety
% of such environments.
\def\@SetupMapleTty#1{%
\begingroup
  %%%  Compute and set tab positions
  \setbox 0 = \hbox{\MapleSize\MapleFont X}
  \@MapleTabSize = \wd0
  \multiply\@MapleTabSize by \MapleTab
  \setbox0 = \hbox{\relax}  % Clearing \box 0
  %
  %%% set paragraph dimensions and line spacing
  \rightskip = 0pt 
  \parindent=0pt
  \parskip = 0pt 
  \leftskip=\LeftMapleSkip
  \parfillskip = 0pt plus 1fil
  %
  %%%  The next two parameters could have been changed 
  %%%  by a \raggedright so they are reset here.
  \spaceskip = 0pt   \xspaceskip = 0pt
  %
%%%  Should the first new line of the environment
%%%  be ignored?  Allows \begin... to be on a separate line
\ifnum #1 = 0 \@IgnoreNewLinetrue\else\@IgnoreNewLinefalse\fi%
%
%%% Get ready to handle every paragraph (recall paragraph == line )
\everypar = {\EveryParZ}%
\def\EveryParZ{%
  \ifMaplePrompt
    \the\MaplePromptString
  \fi
    \setbox0 = \hbox \bgroup
}%
%
%%%  Choose the type size and font - order is important
\MapleSize\MapleFont%
\lineskiplimit=0\normalbaselineskip
\baselineskip=0.8\normalbaselineskip
\@noligs%
%\MakeAllActive%
\let\do\@makeother \dospecials
\catcode ``=\active
\frenchspacing%
\@ObeySpaces% 
\@ObeyTabs%
\@ObeyEol%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Behavior on exiting of special environments
\def\@EndMapleInput{%
  \endgroup  %% matches the \begingroup inside of @SetupMapleInput
}
%
\let\@EndMapleTtyout\@EndMapleInput
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Macros executed to start Verbatim like environments
% for special Maple regions.  These calls do all the work
% of scanning for the environment terminator.
\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
  |gdef|@BeginMapleInput#1\end{mapleinput}(#1|end(mapleinput))%
  |gdef|@BeginMapleTtyout#1\end{maplettyout}(#1|end(maplettyout))%
|endgroup
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Definition of actual mapleinput environment.
% \begin{mapleinput} ...\end{mapleinput}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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.
%
\def\mapleinput{
%%%  Include Extra Spacing at top of display
\@MaplePar%
\if@minipage\removelastskip\vskip-1.3ex
\else\vskip\AboveMapleSkip\fi%
\@SetupMapleTty{0}% The 0 indicates ignore first new line
\@BeginMapleInput
}
%%%
\def\endmapleinput{
  \@EndMapleInput
  %\vskip\BelowMapleSkip
  \nopagebreak[3]
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Definition of the actual \maplettyout environment
% usage: \begin{maplettyout} ... \end{maplettyout}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This can use almost exactly the same setup and exit as for input. 
% The main difference is the treatment of prompts, and in page breaking
% Page breaks are inhibited before, and encouraged after.
\def\maplettyout{
  \MaplePromptfalse	  % No prompt is required in this environment.
  \nopagebreak[3]\@MaplePar
  \removelastskip
  \@SetupMapleTty{0}   % A 1 would indicate "respect first new line"
  \@BeginMapleTtyout
}
%%%
\def\endmaplettyout{
  \@EndMapleTtyout	
  \vskip\BelowMapleSkip
  \pagebreak[3]
  \par
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Maple Latex Environment
% \begin{maplelatex} ....\end{maplelatex}
% This environment is basically a wrapper around a display
% math environment.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Spacing is slightly different in a minipage, page breaks are
% encourages after the region, and inhibited before.
\newenvironment{maplelatex}{
  % \if@minipage\fi% 
  \parindent=0pt
  \parskip = 0pt 
  \parfillskip = 0pt plus 1fil
  \lineskiplimit=0\normalbaselineskip
  \baselineskip=0.6\normalbaselineskip
  \abovedisplayskip=.4\AboveMapleSkip
  \belowdisplayskip=.4\AboveMapleSkip
  \def\arraystretch{1.5}
  \removelastskip
  \nopagebreak[3]\@@par
}{%
\baselineskip=\normalbaselineskip%
\pagebreak[3]\relax}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Separator Lines
% \maplesepLine
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The %'s at the end of the lines are important here to
% avoid inserting uwanted newlines in the output stream.
\newcommand{\maplesepline}{\vskip \parskip%
\hrule\@height\MapleSepLineHeight\@width\MapleSepLineWidth%
\vskip \parskip\relax}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plots
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following assumes you have already installed the psfig 
% macros on your system.  These are available without charge 
% from:
%
\input psfig.sty
\psrotatefirst
\def\mapleplot#1{
\vskip\AboveMaplePlot
\centerline{\vbox{\psfig{figure=#1,%
height=\MaplePlotHeight,%
width=\MaplePlotWidth,%
angle=\MaplePlotAngle}}}
\vskip\BelowMaplePlot
}
%
\makeatother
%%%%%% The End %%%%%
