introduction to latex by lindash

VIEWS: 24 PAGES: 6

									                                        Lecture 3


                              Defining New Environments

In a previous section, we learned how to use theorem-like environments. Notice that text
in those environments is automatically slanted by LaTeX. But perhaps you don’t want
the text of your theorems to be slanted. Perhaps you want your theorems automatically
centered. Perhaps you want a period appearing after each theorem’s number. You can
tailor theorem-like environments (and other environments) to suit your needs using the
\newenvironment and \renewenvironment commands. You use the \newenvironment
command when defining a new environment, and the \renewenvironment command when
redefining an existing environment. These commands go in the preamble of your
document, and the basic syntax is as follows:

\newenvironment{env_name}[narg]{beg_def}{end_def}
\renewenvironment{env_name}[narg]{beg_def}{end_def}

The argument env_name is the name of your environment, the beg_def argument is the
initial text to be inserted when \begin{env_name} is called, and the end_def argument is
the final text to be inserted right before \end{env_name} is called. The optional argument
narg is a number between 1 and 9 that states how many arguments the environment is to
have. (There is also an optional argument opt, but we will not go into that here.)

What happens if I put the following commands in the preamble of my document,

\newtheorem{mythm}{Theorem}

\newenvironment{thm}
{\begin{mythm}\begin{upshape}}
{\end{upshape}\end{mythm}}

and then write the following theorem:

\begin{thm}If $G$ is a group with prime order, then $G$ is cyclic. \end{thm}

What if I instead define my thm environment as follows?

\newenvironment{thm}
{\begin{mythm}{\bf .}}{\end{mythm}}

How can we make the period appear closer to the theorem number? Use the \hspace
command, with a negative length measurement!
                                                                                 Lecture 3: 01/26/07

\newenvironment{thm}
{\begin{mythm}\hspace{-5pt}{\bf .}}{\end{mythm}}

Here is an example of a new environment defined with an argument:

\newenvironment{thm}[1]
{\begin{mythm}\label{#1}}{\end{mythm}}

What then will this text do?

\begin{thm}{silly.thm}
Here is a nonsense theorem.
\end{thm}


                                               Graphics

Sometimes you may want to include graphics in your DVI or PDF. The way you do this
may depend on the nature of the picture you want to include. Perhaps you want a
directed graph in your document; perhaps instead you want a Maple plot, or a screenshot.
You can create some pictures within LaTeX itself, using regular LaTeX code or packages;
others pictures you’ll want to include in your document as files created using another
application. Here, we discuss two particular ways of putting pictures in LaTeX:
    1) Including pictures that were created using another application (e.g., Maple);
    2) Using the package \xypic to create (directed) graphs in LaTeX.
There are other ways to deal with graphics in LaTeX, but these will give you a good start.

Including pictures that were created using another application:

The first thing you will need to do is create and save the image you want to put in your
document. I have had the most success including images on both Macs and PCs as PDFs,
or, if I’m using a PC, as EPS files. I’ve heard that you can, however, include other types
of images, such as JPEGs and GIFs.

If you, for instance, use Maple 10, you can right-click on the image you want (if you’re
using a PC) or CTRL-click on the image (if you’re using a Mac), select “Export”, and
choose “Encapsulated Postscript (EPS);” then save the file in the same folder as your .tex
document. Let’s say you call your file mypic.eps.

If you are using a Mac, double-click to open your .eps file; then you can (hopefully) save
the opened file as a PDF, called mypic (the Mac will omit the .pdf extension when it
displays this PDF’s filename). On a PC, you can convert it to a PDF using the application
GSView*, or you can keep it as an EPS.

*
  To convert an EPS to a PDF in GSView, open your .eps file in GSView, and select Convert… from the
file menu; select pdfwrite and 600 for your Device and Resolution; click OK; and then save your file as
type .pdf. In our example, we save our file as mypic.pdf.
                                                                      Lecture 3: 01/26/07

You then include your image in your .tex document in the following way. First, call on
the package graphicx: that is, put the command

\usepackage{graphicx}

in your preamble.Then put the code

\includegraphics[scale change]{mypic}

where you want your image to appear. You do not need to put the extension in your
filename.

1. On a Mac: TeXShop can now compile your .tex file as usual.
2. On a PC:
      a. If you’ve converted your EPS to a PDF, you can now use the PDFLaTeX
         button in MiKTeX to compile your .tex file to a PDF. Note: you cannot
         create a DVI file using the LaTeX button if your image is in a PDF.
      b. If your image in still in EPS format, the PDFLaTeX button in MiKTeX cannot
         be used to convert this .tex file to a PDF. Instead, to get a PDF, first click on
         the LaTeX button to create a DVI, and then convert your DVI to a PDF using
         the button dvi->pdf.

PROF’S ADMISSION: All of this is terribly complicated, no? There are almost
certainly better ways of including graphics, but yours truly is ignorant. If you learn of
better ways to do this, she’d love it if you’d share your knowledge!

Now back to our .tex code. The scale change argument in the \includegraphics command
is an optional argument that allows you to change the size of your included image. If you
want the image to be half as big as its default size, put the command

scale = .5

as your optional argument. If you want your image to be 3 times as big as its default size,
what command should you use?

Typically, I center my images by putting them between \begin{center} and \end{center}
commands. You can also have them automatically numbered and put attach captions to
them using the figure environment. Here is an example of how you would put (and
center) a picture in such an environment

\begin{figure}[placement]
\begin{center}
\includegraphics[scale factor]{mypic}
\caption{$x^2$} \label{polydeg2}
\end{center}
                                                                        Lecture 3: 01/26/07

\end{figure}

The optional argument placement allows you to specify where you would like the figure
to appear. The possible arguments are:

   1.   h       (Here) - at the position in the text where the figure environment appears.
   2.   t       (Top) - at the top of a text page.
   3.   b       (Bottom) - at the bottom of a text page.
   4.   p       (Page of floats) - on a separate float page, which is a page containing no
        text, only floats.

I usually use the argument h. The optional argument scale factor allows you to shrink or
expand the figure from its default size. If I want the figure to be half its default size, I’d
use the argument scale=.5. If I wanted it to be three times its size, what argument would
I use?

I can then refer to this figure later in the same way as you refer to theorems or the like:
e.g., I can type

Do you like the graph in Figure \ref{polydeg2}?

Some important notes on using figure environments:

       The order of your \caption and \label commands here is very important: the \label
        command must occur after the \caption command. This is kind of annoying,
        especially since you may not want a caption for your figure! If you don’t want a
        caption, I still recommend putting in a \caption command with an empty argument,
        if you want to be sure your labeling will work.
       If you want to center images and captions within the figure environment, make
        sure that, as in the code above, you put your \begin{center} [\end{center}]
        command immediately after [before] your \begin{figure} [\end{figure}]
        command.
       Finally, as always, if you use labels in these environments, compile twice in order
        to make sure that your references are correct.

There is a lot more to including graphic images in LaTeX, but hopefully this provides
you with a start.

Creating (directed) graphs using \xypic:

I have sent you a handout that will help you make more complicated diagrams using the
package xypic; here I address xypic’s use only briefly. (You can also find the handout at
http://www.ctan.org/tex-archive/macros/generic/diagrams/xypic/xy/doc/xyguide.pdf.) To
use xypic, first put in your preamble the command

\usepackage[all]{xy}
                                                                       Lecture 3: 01/26/07



Note that this looks slightly different from our usual usepackage commands, since it
include the argument [all]. Then to draw a diagram, use the command \xymatrix in math
mode. The syntax for this command mimics that used for LaTeX arrays. For instance,
the command

\xymatrix{A&B&C\\ D&E&}

will create an array with three columns and two rows, with entries A, B, and C in the first
row, and D, E, and a blank entry in the second row. The difference is that with the
\xymatrix command, you can also put arrows from one array entry to any other (including
itself). E.g., what happens if I type

\xymatrix{A\ar[r]\ar[dr]&B&C\ar[l]\\ D\ar[u]&E&}

in my document? Why?

What happens if I enter, instead,

\xymatrix{A\ar[r]^\rho \ar[dr]&B&C\ar[l]^\gamma\\ D\ar[u]_\sigma&E&}

or do that, but change the ^s to _s, and vice versa?

Let’s now give our digraphs some curved arrows, and loops. Take a look at the digraph
produced by

\xymatrix{a\ar@(dl,ul)\ar@/^/[r]&b\ar@/^/[l]\\c\ar[ur]&d\ar@(dl,ul)\ar[u]} .

What made the arrows curve? What made loops?

The handout I sent explains how to make fancier graphs, with different arrowheads
(including no heads), loops, curvatures of arrows, etc.


                                 Presentation Overheads

Though many people use PowerPoint these days for mathematics presentations, it is a
great idea to use LaTeX, instead, if there is any level of typesetting complication to your
mathematics. One way you can easily make transparencies in LaTeX is by using the
document class slides: just put the command

\documentclass{slides}

at the top of your .tex file. (Note that this command goes there instead of commands
declaring your document to be of class, say, book, report, or article.) This class will
                                                                      Lecture 3: 01/26/07

make your default font large enough for transparencies, and will put your title on a page
by itself. It also automatically suppresses page numbers.


                                      Page Layouts

Changing margins and the like in LaTeX can be tricky. I tend to avoid doing so myself,
unless I absolutely cannot avoid it. Rather than discussing my hacks here, I’ll point you
to some sites that might be useful for you when attempting to change the look of your
page layouts (note that these sites may disappear at any time, so I recommend
downloading them and saving them as .html docs, for future reference):

http://www.kronto.org/thesis/tips/custom-geometry.html
http://www.iam.ubc.ca/~newbury/tex/page-set-up.html
http://web.image.ufl.edu/help/latex/margins.shtml



                           Happy LaTeXing!!

								
To top