Up: Class 9, Math 696
Next: Homework
Previous: Goals

Activities for Class 9

Classroom discussion

Computer activities

Customizing LaTeX page styles

Now that you have some experience with LaTeX, you may be wishing that you could overrule some of LaTeX's default design decisions. Perhaps you would like to change the size of the margins, for example. In principle, you have complete control in LaTeX over the appearance of the page. Before you get carried away with customizing the visual design, read Leslie Lamport's warning from the LaTeX manual, page 91:

Before changing your document's style, remember that many authors make elementary errors when they try to design their own documents. The only way to avoid these errors is by consulting a trained typographic designer or reading about typographic design. All I can do here is warn you against the very common mistake of making lines that are too wide to read easily---a mistake you won't make if you follow this suggestion: Use lines that contain no more than 75 characters, including punctuation and spaces.

(Imagine how hard it would be to read a newspaper if the lines of text stretched across the whole page!)

LaTeX page style parameters

In order to change the page layout, you need to know how LaTeX views the printed page. For historical reasons, LaTeX considers the upper left-hand corner of the printed material on the page to be one inch over from the left-hand edge of the physical page and one inch down from the top edge of the physical page. There is a header (possibly empty) across the top of the printed page, a footer (possibly empty) across the bottom of the printed page, and the body of the text in between.

To change a LaTeX page-style parameter, you use the \setlength command in the preamble of your LaTeX source file. For example, if you want the body of the text to be 15 centimeters wide, you type \setlength{\textwidth}{15cm} in the preamble of your LaTeX source file. To get a feel for how this works, cut the following example out with your mouse, paste it into a text editor, save it as a file named alice.tex, and execute latex alice and xdvi alice & in a terminal window.

\documentclass[11pt]{article}

\setlength{\textwidth}{3in}

\begin{document}
Alice was beginning to get very tired of
sitting by her sister on the bank, and of
having nothing to do: once or twice she had
peeped into the book her sister was reading,
but it had no pictures or conversations in
it, ``and what is the use of a book,''
thought Alice ``without pictures or
conversation?''

So she was considering in her own mind (as
well as she could, for the hot day made her
feel very sleepy and stupid), whether the
pleasure of making a daisy-chain would be
worth the trouble of getting up and picking
the daisies, when suddenly a White Rabbit
with pink eyes ran close by her.

There was nothing so \emph{very} remarkable
in that; nor did Alice think it so
\emph{very} much out of the way to hear the
Rabbit say to itself, ``Oh dear! Oh dear! I
shall be late!'' (when she thought it over
afterwards, it occurred to her that she ought
to have wondered at this, but at the time it
all seemed quite natural); but when the
Rabbit actually \emph{took a watch out of its
waistcoat-pocket}, and looked at it, and
then hurried on, Alice started to her feet,
for it flashed across her mind that she had
never before seen a rabbit with either a
waistcoat-pocket, or a watch to take out of
it, and burning with curiosity, she ran
across the field after it, and fortunately
was just in time to see it pop down a large
rabbit-hole under the hedge.

\end{document}

If you make the text width negative via \setlength{\textwidth}{-3in} what do you think will happen? Try it and see. What happens if you make the text width ridiculously big via \setlength{\textwidth}{100cm}?

Here are some other common LaTeX page-style parameters that you can adjust by using the \setlength command in the preamble of your source file.

\textheight
This sets the height of the body (not including the header and footer).
\topmargin
\headheight
\headsep
These are respectively the amount of space at the top of the page (in addition to the default one inch) before the header; the height of the header; and the vertical distance between the header and the body. You can reduce the default one inch top margin by setting \topmargin to be negative.
\footskip
This is the distance between the bottom of the body and the bottom of the footer.
\oddsidemargin
This is the extra space (in addition to the default one inch) at the left-hand edge of the page. Setting it to be negative reduces the default one inch left margin. The reason for the funny name of this parameter is that LaTeX can optionally use a different page style for even-numbered and odd-numbered pages (commonly done in books). To accommodate this option, there is also an \evensidemargin parameter.

Here are three exercises to test your understanding of LaTeX's page-style parameters.

  1. Typeset the above passage from the beginning of Alice's Adventures in Wonderland so that the width of the text is 3 inches, and the text is centered horizontally on the (8 and 1/2 inch) page.

  2. If you type \setlength{\textwidth}{3in} \setlength{\textheight}{\textwidth} what happens? What if you type \setlength{\textheight}{\textwidth} \setlength{\textwidth}{3in} in the other order?

  3. If you type \setlength{\textwidth}{7.5cm} \setlength{\oddsidemargin}{8.5in} \addtolength{\oddsidemargin}{-7.5cm} \addtolength{\oddsidemargin}{-0.5\oddsidemargin} \addtolength{\oddsidemargin}{-1in} what is the result?

Introduction to LaTeX packages

One of the advantages of LaTeX as a document-preparation system is that users have contributed numerous add-on packages to simplify many formatting tasks. We have already had occasion to use the amsmath package that is maintained by the American Mathematical Society.

A number of packages are described in The LaTeX Companion, and there is a comprehensive on-line list.

For example, most word-processing programs have a facility for making three-part headers and footers. LaTeX has a \pagestyle declaration that you can read about on page 89 of Lamport's manual, but it is not very flexible. Piet van Oostrum has written a package fancyhdr that makes it easy to customize page headers and footers. For practice, let's try grabbing this package off the net and using it to make fancy page headers and footers.

First go to The TeX and LaTeX Catalogue. Then scroll down to fancyhdr and click on the link. You should see a directory listing of about half a dozen files. Grab at least the ones with extension .sty. You can probably do this in your Web browser by holding down the Shift key while you click the mouse on a highlighted file name. You may want also to grab the documentation files fancyhdr.tex (the LaTeX source) and fancyhdr.dvi (the ready-to-preview documentation).

Now you've got a copy of the fancyhdr package. Let's try using it. Take the above example from Alice's Adventures in Wonderland and put the following code in the preamble. (Here \thepage makes LaTeX print the current page number, and \today makes LaTeX print today's date.)

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{Your favorite color}
\chead{Your name}
\rhead{Your favorite dessert}
\lfoot{\bfseries An example}
\cfoot{\thepage}
\rfoot{\today}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\setlength{\headheight}{15pt}

As you will see when you run latex alice and xdvi alice &, the fancyhdr package makes three-part headers and footers. Any of the parts can be left empty. The thickness of the horizontal rules is adjustable; if you set the thickness to 0pt then the rule will not appear.

The fancyhdr package has some still fancier options which you can read about in the documentation.

Making Maple talk to LaTeX: Part I

We have been learning about several computer tools: Maple, LaTeX, HTML. Wouldn't it be nice if they could all communicate? In fact, there are various ways for these tools to interact. Today we will consider one simple way for Maple to communicate with LaTeX.

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}^{{\frac {\pi }{4}}}\!\sin(x){dx}, which LaTeX typesets as in the figure. Notice that Maple-generated LaTeX code may not be optimally pretty; I would type instead \int_0^{\pi/4}\sin x\,dx.

The upshot is that if you can display it in Maple, then you can typeset it in LaTeX with no more effort. For example, the Maple command linalg[hilbert](4); produces a 4x4 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 matrix. Hint: make Maple do (most of) the work. The (i,j) entry of the matrix is the anti-derivative of the fraction (x^2+i)/(x^2+j). Read the Maple help on matrix to learn how to map a function onto a matrix.


Up: Class 9, Math 696
Next: Homework
Previous: Goals

Created Oct 13, 1996. Last modified Oct 30, 1996 by boas@tamu.edu.
URL: /~harold.boas/courses/696-96c/class9/activities.html
Copyright © 1996 by Harold P. Boas. All rights reserved.