tex_logos_04.gif (2422 bytes)
TeX and LaTeX resources

img01compressed.jpg (3366 bytes) Including Maple Images in LaTeX files

When the short Maple Worksheet  (test1.mws)

> plot3d(sin(x)*cos(y),x=-3..3,y=-3..3,axes=`normal`);

is executed on a PC it displays a full color 3D graph (usually inline or in a separate window). If we select the menu item  File/Export As/LaTeX then two files are produced: test1.tex and test101.eps. The second file is an encapsulated Postscript file containing the image of our 3D graph. Unfortunately it is gray-scale, has a heavy border and is rotated 90 degrees counter-clockwise (landscape orientation).

The LaTeX file produced (after cleaning up a bit) has the following contents:

\documentclass{article}
\usepackage{maple2e}
\DefineParaStyle{Maple Plot}
\begin{document}

\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}%
{plot3d(sin(x)*cos(y),x=-3..3,y=-3..3,axes=`normal`);}{}
\end{mapleinput}

\mapleresult
\begin{center}
\mapleplot{test101.eps}
\end{center}

\end{maplegroup}
\end{document}

This file can be LaTeX'ed in the usual way to produce a dvi file containing the image. In general our Worksheet will contain other interesting stuff of course! We can then pass the dvi file through dvips to obtain a Postscript image of the entire document. It can easily be converted to pdf, for example, for display on the Web. Note that the \mapleplot() command automatically rotates the image 270 degrees counter-clockwise and re-sizes it. The border remains and color is lacking unfortunately - otherwise the results are nice.

To obtain color is no problem. We can simply replace test101.eps in the \mapleplot() command with a color version. To obtain a color image we replace our Maple Worksheet with the following:

> origdev:=interface(plotdevice):
>
> plotsetup( `ps`,plotoutput=`img01.ps`,plotoptions=`color,noborder`);
> plot3d(sin(x)*cos(y),x=-3..3,y=-3..3,axes=`normal`);
>
> plotsetup(origdev);

When this Worksheet is executed it creates a full color surface plot img01.ps (but no inline image). We can use this plot in place of   test101.eps above.

In practice one can usually omit defining origdev and replace the last command by plotsetup(default) to restore graphical output to inline or window.

This procedure is actually a convenient way to produce all kinds of graphs for various purposes. In the plotsetup command one can replace `ps` by `jpeg` or `gif` to directly produce JPEG or GIF graphics instead. Check Maple help for more information.

Plot Refinement

The \mapleplot() command works fine, but if you include the graphicx package in your LaTeX file you can add some flexibility. For example, if you define the  homebrew command:

\newcommand{\maplepic}[3]{%
\begin{figure}[htb!]\hspace{0.2\textwidth}%
\includegraphics[angle=270,width={#3}]{#1}
\vspace{-3.5\baselineskip}
\caption{#2}
\end{figure}}
%%% #1=filename #2=caption #3=width

and then replace \mapleplot{img01.ps} command above with

\maplepic{img01.ps}{Nice surface}{2.3in}

you obtain a centered image 2.3 inches wide with a caption and the image will be listed in your LaTeX list of figures. Do not forget the \usepackage{graphicx} command in order to load the graphicx package. Many LaTeX refinements now become possible - experiment with creating a mapleplot replacement to satisfy your own needs!

Text Color

If  you are creating a LaTeX document containing portions of Maple Worksheets you may wish to use the default Maple colors for text. It is easy to add text color by incorporating the color package - see color-package.html . The problem is that the maple2e.sty package does not contain color commands. One solution is to hack a copy of  maple2e.sty being sure to give it a new name, perhaps cmaple2e.sty , by adding a \color(blue) command to the \maplettyout command and a \color(red) command to the mapleinput environment.

Then do not forget

\usepackage[usenames]{color}
\usepackage{cmaple2e}  %% hacked maple2e.sty for text color

in your LaTeX file prologue. Have fun!


Last updated Thursday, April 10, 2003
Bent E. Petersen
petersen@math.oregonstate.edu

Back to the TeX index page

HOME