Converting Maple code into LaTeX markup |

There are two ways to get
LaTeX code out of Maple. First of all, you can convert an
entire Maple worksheet into a LaTeX file by using the
`LaTeX`

option on the `Export As`

feature on the
Maple `File`

menu. If your system has the file
*maple2e.sty* installed in the LaTeX search path, then
you should be able to run the resulting LaTeX file through
`latex` with no further tinkering. The file *maple2e.sty*
defines certain LaTeX environments, similar to the
`verbatim`

environment, that disable LaTeX
processing on Maple input and output regions, while letting
LaTeX do its formatting magic on textual regions.

Of course, you can print a Maple worksheet directly from the
`File`

menu, so you will not need the `Export As`

feature for everyday use. However, LaTeX is more powerful
than Maple for text processing, so you might sometime want to
use LaTeX to massage a file originally written as a Maple worksheet; or you might want to include a Maple worksheet as a
section of a longer LaTeX document. (The commercial product
Scientific Workplace attempts to
combine Maple and LaTeX directly in a unified program.)

Instead of converting an entire Maple worksheet, you can convert snippets of Maple code into their
LaTeX equivalents. Maple has a command `latex` that
translates a mathematical expression into LaTeX code. For
example, the Maple command `latex(sin(x));`

returns the
result `\sin(x)`

.

The Maple command `latex(Int(sin(x),x=0..Pi/4));`

returns the result
`\int _{0}^{1/4\,\pi }\!\sin(x){dx}`

, which LaTeX
typesets as in the first figure.

Notice that Maple-generated LaTeX code may not be optimally
pretty; you might type instead `\int_0^{\pi/4}\sin x\,dx`

,
which LaTeX typesets as in the second
figure.

The upshot is that if you can display
a formula in Maple, then you can typeset the formula in
LaTeX with no more effort. For example, the Maple command
`linalg[hilbert](4);`

produces a *4×4* Hilbert
matrix,
and `latex(linalg[hilbert](4));`

spawns the
LaTeX code

\left [\begin {array}{cccc} 1&1/2&1/3&1/4\\ \noalign{\medskip}1/2&1/3&1 /4&1/5\\ \noalign{\medskip}1/3&1/4&1/5&1/6\\ \noalign{\medskip}1/4&1/5&1 /6&1/7 \end {array}\right ]

which typesets as in the figure.

**Exercise**

Typeset the following matrices with LaTeX. Hint: make Maple do (most of) the work. The *(i,j)* entry of the first matrix
is the derivative of the exponential of *i sin(jx)*, and the
second matrix is a block matrix composed of Hilbert matrices.
Read the Maple help on `matrix`

to learn how to map a
function onto a matrix.

The Math 696 course pages were last modified April 5, 2005.

These pages are copyright © 1995-2005 by Harold P. Boas. All rights reserved.

Converting Maple code into LaTeX markup |