Fourth Class (Wednesday 20 September 1995)

Today's tip

Did you know that you can use your Web browser as a graphical interface to view your directories and files? From Netscape, type Alt+O and then click on OK to get a listing of the files and subdirectories in your home directory. From Mosaic, type Alt+L and click on OK.

Goals to accomplish during class

  1. Know how to include graphics in LaTeX files.
  2. Know how to include images in World-Wide Web pages.
  3. Know how to convert from Maple to LaTeX.

Activities to do during class

What we have learned so far about LaTeX, Maple, and HTML is pretty much independent of the computer system. A LaTeX file, for example, is portable: it is easy to transfer to another computer system, and it will produce just about the same printed output on different machines.

Today we are going to work with graphics, and unfortunately there is no standard format for graphics. Therefore, some of what you do today will not transfer automatically to other computers. You may not be able to get the same results on your home PC, for example.

Graphics in LaTeX

LaTeX has a built-in picture environment that is machine-independent, but it is suitable only for simple pictures made of lines, circles, and spline curves. For more sophisticated graphics, you need to use the add-on graphics package by putting the command \usepackage{graphics} in the preamble of your LaTeX document.

The effects you can achieve with the graphics package depend on your printer. Today we are going to see what you can do with a PostScript printer. (The TAMU UNIX machines and the Mathematics Department machines all output to PostScript printers.) Therefore we are going to use the graphics package with the dvips option, like this: \usepackage[dvips]{graphics}.

Cut out the following lines with the mouse and use a text editor to change the information to apply to yourself. Then save the file as test.tex, open a terminal window, run latex test and dvips test. Then start the PostScript screen previewer via ghostview test.ps &. What do the LaTeX commands \rotatebox and \reflectbox do?


\documentclass[12pt]{article}
\usepackage[dvips]{graphics}

\begin{document}
This is a test of the graphics package.

What does \rotatebox{30}{my name} do?

What does \reflectbox{a secret message} do?
\end{document}

Rotating text is a special effect that should be used sparingly. More useful is the capability to include graphics that some other program has created. For example, you can include a Maple plot in a LaTeX file. Here is an example.

By default, Maple saves plots as full-page images in landscape mode. That is the reason in the above example for rotating and scaling the included graphic. It is possible to coax Maple into rotating and scaling the image before saving it to a PostScript file. If you give Maple the command plotsetup(postscript, plotoutput=`myplot.ps`, plotoptions=`portrait,noborder,height=200,width=200`); for example, and then re-execute the plot command, Maple will directly save the plot (without opening a plot window) to a PostScript file named myplot.ps in portrait orientation, with no border, and with height and width of 200 points (where 1 inch is 72 points). Then in your LaTeX file, you could just put the command \includegraphics{myplot.ps} without using the \scalebox and \rotatebox commands.

Here is another example. Let's capture some graphics off the World-Wide Web to include in a LaTeX document. Click on one of the following links to art works on the Web and find a picture that interests you. (Netscape is better than Mosaic for this exercise.)

The Web Museum
A collection of famous paintings from around the world.
World Art Treasures
Includes a special program on art from Egypt, China, Japan, India, Myanmar/Burma, Laos, Cambodia and Thailand.
The Nightmare Gallery
You won't sleep well tonight.
Works of Dali
Works of Vermeer
Images from the Sistine Chapel
America's Cup On Line Photo Exhibition
Photo Perspectives
A high class photography exhibition.
Posters from the Census Bureau
The list from Yahoo where I found the above links.

One of two situations will occur. Either you will get a fairly small image that appears inside your Web browser, or you will get a large image that shows up in its own window under the control of the graphics program xv. In both cases, you want to capture the image and save it to a file.

If the image is in its own xv window, skip this paragraph and the next one. If the image is inside the Netscape window, use the mouse to move the cursor over the image, and hold down the right mouse button. A pop-up menu should appear that has as an option "Save this Image As...". Select this option, make a note of the filename, and click on OK. You have just captured that image to a file.

Probably the image is in either gif or jpeg graphics format. We need to convert it to a PostScript file to make it easy for LaTeX to handle. To do this, we are going to open the graphics file with the graphics program xv and then save the file in a different format. Open a terminal window and execute the command xv filename & where filename is the name that you just noted above.

You should have your image on screen inside an xv window. The xv program has a control panel that is hidden by default. To access the control panel, click the right mouse button in the window. Now click on "Save". A new window pops up that prompts you to save the file in one of a list of different formats. Depending on the version of xv, there is either a drop-down Format menu or a list of radio buttons. Select PostScript, type in a file name ending with the extension .ps and then click on OK. Another window pops up that offers options to adjust the size and resolution of the image. You can ignore this and click on OK again. You have just saved the graphics file in PostScript format. Now click Quit on the xv control panel.

Now open your test.tex file in a text editor and add the line \includegraphics{name.ps} where name.ps is the name you just saved the graphics file under. Save your test.tex and run through the latex, dvips, ghostview cycle again to see if your new image shows up properly in the processed LaTeX file.

Of course, when you print the result on paper, you will not get color output unless you can get your hands on a color printer.

A word of caution: graphics files are big. If you save a few large images on the calclab machines, you might get the message "Disc quota exceeded." It is therefore useful to know how to cut out a small piece of an image, say just a face, and save that. Open the image in xv, bring up the xv control panel, and click on the "Grab" button. If you move the mouse into the image and hold down the middle mouse button, you can draw a cropping rectangle. When you let the button up, xv will grab the region inside the rectangle and load it into a window. You can then save the cropped region into a new file.

Converting Maple to LaTeX

Suppose that you need to typeset the formula for the derivative of the inverse tangent of 1 plus the exponential of the square of x. You could work this out by hand and code it into LaTeX, but why not make use of that wonderful tool Maple? At least Maple can compute the derivative for you:

> Diff(arctan(1+exp(x^2)),x)=simplify(diff(arctan(1+exp(x^2)),x));


                                                 2
       d                  2               x exp(x )
     ---- arctan(1 + exp(x )) = 2 -------------------------
      dx                                     2           2
                                  2 + 2 exp(x ) + exp(2 x )

(Here Diff is the inert form of diff.)

Wouldn't it be wonderful if Maple could also translate this into LaTeX code for you? Well, Maple can! Maple has a command latex that does a pretty good job of converting its argument into LaTeX code. Here's what it does in the above example:

> latex(Diff(arctan(1+exp(x^2)),x)=simplify(diff(arctan(1+exp(x^2)),x)));

{\frac {d}{dx}}\arctan(1+{e^{{x}^{2}}})={\frac {2\,x{e^
{{x}^{2}}}}{2+2\,{e^{{x}^{2}}}+{e^{2\,{x}^{2}}}}}

You can cut this result out with the mouse, paste it into a LaTeX document between \begin{equation} and \end{equation}, and voilà:

Maple does not produce the most elegant LaTeX code, but it does a serviceable job. (Maple puts in more braces than may be required, and it is over-fond of "thin spaces", which is what those backslash commas are above.) You may need to do some fine-tuning by hand.

We have just seen that Maple can be used to help format LaTeX documents. What about the other direction? Can we use LaTeX to help format Maple documents?

Some of you have noticed that when you send a Maple session to the printer, the text regions do not get justified. It is possible to use LaTeX to format the text regions of a Maple worksheet while leaving the input and output regions alone. This is what the "Export as LaTeX" feature on the Maple "File" menu is for.

If you save a Maple worksheet via "Export as LaTeX", then you can process the resulting file in a terminal window via latex, xdvi, dvips, and lpr as usual, but LaTeX will basically leave alone the Maple input lines and output formulas. LaTeX will just do its formatting on any text regions in your Maple worksheet. A few notes about this:

An in-class project

To demonstrate that you can apply the above techniques, your assignment to hand in by the end of class today is to write a paper in LaTeX, addressed to high school students or first-year college students, explaining the concepts of shifting and scaling functions and their graphs. For example, you could explain the relation between sin(x), sin(2x), sin(x+3), 5sin(x), and 5sin(2x+3). Your paper should include several graphs as illustrations.

In this connection, you might enjoy playing with the on-line drill on shifting and scaling described on pages 199-200 of the CalcLabs with Maple V manual. The associated interactive Maple worksheet is /courses/math151/Drills/shift/shift.ms.

Including graphics in Web pages

Have you still got a graphics file lying around? Let's see how to embed it in your home page.

Open a terminal window and execute the command ls to list your files. Pick one with extension .gif or .jpeg. You need to move or copy the file to your public_html directory so that Web browsers can find it. You can do this via cp filename ~/public_html/ (to copy the file) or mv filename ~/public_html/ (to move the file). Then do cd ~/public_html/ and chmod 644 filename to set the file permissions to world readable.

Now open your home page in a text editor and add a line like

<p> <img src="./filename">

Save your home page and then bring it up inside your Web browser. Your graphics file should show up.

Comments on previous assignments

There were several popular solutions to the problem about a special polynomial taking integer values. Recall the problem:

   > p:=unapply(interp([1,2,3,4],[2,3,5,9],n),n);

                                    3        2
                     p := n -> 1/6 n  - 1/2 n  + 4/3 n + 1

   Show that p(n) is an integer when n is.

Concerning the exercise on completing the square, I thought that the best papers were the ones that gave some motivation or application. For example, people mentioned that completing the square is a way to solve quadratic equations or to derive the quadratic formula, and it is a useful technique to know when integrating rational functions.

Here are some more pointers about LaTeX: common features that I marked on many papers.

Finished?

If you have done all the above activities, and there is still time left, here are some other activities you can do.

Homework for after class

Of course, you may start on the homework during class if you have time!

  1. Work through chapters 5 and 6 of the CalcLabs with Maple V manual.
  2. Your calclab account will go away at the end of the semester. Move your home page to some other computer where you have a more permanent account.

    To make it easy for people to find you, make yourself a very simple calclab home page that links to your real home page. For example, my calclab home page looks like this:

    <html> <head>
    <title>Harold Boas's Calclab home page</title> </head>
    <body>
    <h1>Harold P. Boas</h1>
    <p> My home page is located <a href="../..">elsewhere</a>.
    <p> You can also visit the home page for <a href="..">Math 689-604</a>.
    </body> </html>

    Notice how links are accomplished in HTML. The tag for a link has the form
    <A href="web_address">highlighted text</A>.


/ Home / Contents /


Harold P. Boas
Last modified: Sat Jul 30 10:08:59 EDT 2022