451 lines
16 KiB
HTML
451 lines
16 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
|
|
<TITLE>The teTeX HOWTO: The Linux-teTeX Local Guide: LaTeX commands. </TITLE>
|
|
<LINK HREF="TeTeX-HOWTO-5.html" REL=next>
|
|
<LINK HREF="TeTeX-HOWTO-3.html" REL=previous>
|
|
<LINK HREF="TeTeX-HOWTO.html#toc4" REL=contents>
|
|
</HEAD>
|
|
<BODY>
|
|
<A HREF="TeTeX-HOWTO-5.html">Next</A>
|
|
<A HREF="TeTeX-HOWTO-3.html">Previous</A>
|
|
<A HREF="TeTeX-HOWTO.html#toc4">Contents</A>
|
|
<HR>
|
|
<H2><A NAME="print-your-own"></A> <A NAME="s4">4. LaTeX commands. </A></H2>
|
|
|
|
<P>
|
|
<H2><A NAME="ss4.1">4.1 Document structure.</A>
|
|
</H2>
|
|
|
|
<P>Documents formatted for LaTeX have a few more rules, but with complex
|
|
documents, LaTeX can greatly simplify the formatting process.
|
|
<P>Essentially, LaTeX is a document markup language which tries to
|
|
separate the output style from the document's logical content. For
|
|
example, formatting a section heading with TeX would require
|
|
specifying 36 points of white space above the heading, then the
|
|
heading itself set in bold, 24-point type, then copying the heading
|
|
text and page number to the Table of Contents, then leaving 24 points
|
|
of white space after the heading. By contrast, LaTeX has the
|
|
<CODE>\section{}</CODE> command, which does all of the work for you.
|
|
If you need to change the format of the section headings throughout
|
|
your document, you can change the definition of
|
|
<CODE>\section{}</CODE> instead of the text in the document. You can
|
|
see where this would save hours of reformatting for documents of more
|
|
than a dozen pages in length.
|
|
<P>All LaTeX documents have three sections: a <EM>preamble,</EM> the
|
|
<EM>body</EM> text, and a <EM>postamble</EM>. These terms are
|
|
standard jargon and are widely used by TeXperts.
|
|
<P>The preamble, at a minimum, specifies the type of document to be
|
|
produced---the <EM>document class</EM>---and a statement which signals
|
|
the beginning of the document's body text. For example:
|
|
<PRE>
|
|
\documentclass{article}
|
|
\begin{document}
|
|
</PRE>
|
|
|
|
The document's postamble is usually very simple. Except in
|
|
specialized cases, it contains only the statement:
|
|
<PRE>
|
|
\end{document}
|
|
</PRE>
|
|
|
|
Note the <CODE>\begin{document}</CODE> and
|
|
<CODE>\end{document}</CODE> pairing. In LaTeX, this is called an
|
|
<EM>environment</EM>. All text must appear within an environment, and
|
|
many commands are effective only in the environments in which they're
|
|
called. The <CODE>document</CODE> environment is the only instance where
|
|
LaTeX enforces this convention, however. That is, it's the only
|
|
environment that is required in a document. (An exception is
|
|
<CODE>letter</CODE> class, which also requires you to declare
|
|
<CODE>\begin{letter}</CODE> and <CODE> \end{letter}</CODE>. See the
|
|
section
|
|
<A HREF="#letter-class">Letters</A>.) However, many
|
|
formatting features are specified as environments. They're described
|
|
in the following sections.
|
|
<P>The document classes can be called with arguments. For example,
|
|
instead of the default, 10-point type used as the base point size, as
|
|
in the previous example, we could have specified
|
|
<PRE>
|
|
\documentclass[12pt]{article}
|
|
</PRE>
|
|
|
|
to produce the document using 12 points as the base point size. The
|
|
document class, <EM>article,</EM> makes the necessary adjustments.
|
|
<P>There are a few document classes which are commonly used. They're
|
|
described below. The <EM>report</EM> class is similar to
|
|
<EM>article</EM> class, but produces a title page and starts each
|
|
section on a new page. The <EM>letter</EM> class includes special
|
|
definitions for addresses, salutations, and closings, a few of which
|
|
are described below.
|
|
<P>You can include canned LaTeX code, commonly known as a
|
|
<EM>package,</EM> with the <CODE>\usepackage{}</CODE> command.
|
|
<PRE>
|
|
\usepackage{fancyhdr}
|
|
</PRE>
|
|
|
|
The command above would include the LaTeX style file
|
|
<CODE>fancyhdr.sty</CODE> from one of the <CODE>TEXINPUTS</CODE> directories,
|
|
which you and teTeX specified during installation and setup processes.
|
|
<P>
|
|
<PRE>
|
|
\documentclass{article}
|
|
\usepackage{fancyhdr}
|
|
\begin{document}
|
|
</PRE>
|
|
<P>Note that the <CODE>\usepackage{}</CODE> declarations are given
|
|
before the <CODE>\begin{document}</CODE> statement; that is, in the
|
|
document preamble.
|
|
<P><CODE>fancyhdr.sty</CODE> extends the <CODE>\pagestyle{}</CODE> command
|
|
so that you can create custom headers and footers. Most LaTeX
|
|
document classes provide headers and footers of the following standard
|
|
page styles:
|
|
<PRE>
|
|
\pagestyle{plain} % default pages style -- page number centered at
|
|
% the bottom of the page.
|
|
\pagestyle{empty} % no headers or footers
|
|
\pagestyle{headings} % print section number and page number at the
|
|
% top of the page.
|
|
\pagestyle{myheadings} % print custom information in the page heading.
|
|
</PRE>
|
|
|
|
Everything on a line to the right of the percent sign is a comment.
|
|
<P>The <CODE>\pagestyle{}</CODE> command doesn't take effect until the
|
|
following page. To change the headers and footers on the current page, use
|
|
the command
|
|
<PRE>
|
|
\thispagestyle{the_pagestyle}
|
|
</PRE>
|
|
<H2><A NAME="characters"></A> <A NAME="ss4.2">4.2 Characters and type styles. </A>
|
|
</H2>
|
|
|
|
<P>Character styles are partially a function of the fonts specified in
|
|
the document. However, bold and italic character emphasis should be
|
|
available for every font present on the system. Underlining, too, can
|
|
be used, though its formatting presents special problems. See section
|
|
<A HREF="TeTeX-HOWTO-5.html#latex-packages">LaTeX extension packages and other resources</A>, below.
|
|
<P>You can specify text to be emphasized in several ways. The most
|
|
portable is the <CODE>\em</CODE> command. All text within its scope
|
|
is italicized by default. For example:
|
|
<PRE>
|
|
This word will be {\em emphasized.}
|
|
</PRE>
|
|
|
|
If you have italicized text that runs into text which is not
|
|
italicized, you can specify an italic correction factor to be used.
|
|
The command for this is <CODE>\/</CODE>; that is, a backslash and a
|
|
forward slash.
|
|
<PRE>
|
|
This example {\em will\/} print correctly.
|
|
|
|
This example will {\em not} print correctly.
|
|
</PRE>
|
|
|
|
Slightly less portable, but still acceptable in situations where
|
|
they're used singly, are the commands <CODE>\it</CODE>,
|
|
<CODE>\bf</CODE>, and <CODE>\tt</CODE>, which specify that the
|
|
characters within their scope be printed using italic, bold, and
|
|
monospaced (teletype) typefaces, respectively.
|
|
<PRE>
|
|
{\tt This text will be printed monospaced,}
|
|
{\it this text will be italic,} and
|
|
{\bf this text will be bold\dots} all in one paragraph.
|
|
</PRE>
|
|
|
|
The command <CODE>\dots</CODE> prints a series of three periods for
|
|
ellipses, which will not break across a line.
|
|
<P>The most recent version of LaTeX, which is what you have, includes
|
|
commands which account for instances where one emphasis command would
|
|
supersede another.
|
|
<PRE>
|
|
This is {\it not {\bf bold italic!}}
|
|
</PRE>
|
|
|
|
What happens is that teTeX formats the text with the italic typeface
|
|
until it encounters the <CODE>\bf</CODE> command, at which point it
|
|
switches to boldface type.
|
|
<P>To get around this, the NFSS scheme of selecting font shapes requires
|
|
three parameters for each typeface: shape, series, and family. Not all
|
|
font sets will include all of these styles. LaTeX will print a
|
|
warning, however, if it needs to substitute another font.
|
|
<P>You can specify the following font shapes:
|
|
<PRE>
|
|
\textup{text} % upright shape (the default)
|
|
\textit{text} % italic
|
|
\textsl{text} % slanted
|
|
\textsc{text} % small caps
|
|
</PRE>
|
|
|
|
These are the two series that most fonts have:
|
|
<PRE>
|
|
\textmd{text} % medium series (the default)
|
|
\textbf{text} % boldface series.
|
|
</PRE>
|
|
|
|
There are generally three families of type available.
|
|
<PRE>
|
|
\textrm{text} % Roman (the default)
|
|
\textsf{text} % sans serif
|
|
\texttt{text} % typewriter (monospaced, Courier-like)
|
|
</PRE>
|
|
|
|
Setting font styles using these parameters, you can combine effects.
|
|
<PRE>
|
|
\texttt{\textit{This example likely will result in a font
|
|
substitution, because many fonts don't include a typewriter italic
|
|
typeface.}}
|
|
</PRE>
|
|
|
|
The font family defaults to Computer Modern, which is a bit-mapped
|
|
font. Other font families are usually Postscript-format Type 1 fonts.
|
|
See section
|
|
<A HREF="TeTeX-HOWTO-7.html#postscript-fonts">Using PostScript fonts</A>
|
|
for details on how to specify them.
|
|
<P>There are also many forms of accents and special characters which are
|
|
available for typesetting. This is only a few of them. (Try
|
|
typesetting these on your own printer.)
|
|
<PRE>
|
|
\'{o} \`{e} \^{o} \"{u} \={o} \c{c} `? `!
|
|
\copyright \pounds \dag
|
|
</PRE>
|
|
|
|
Finally, there are characters which are used as meta- or escape
|
|
characters in TeX and LaTeX. One of them, the dollar sign, is
|
|
mentioned above. The complete set of meta characters, which need to be
|
|
escaped with a backslash to be used literally, is:
|
|
<PRE>
|
|
# $ % & _ { }
|
|
</PRE>
|
|
<P>There are also different alphabets available, like Greek and Cyrillic.
|
|
LaTeX provides many facilities for setting non-English text, which are
|
|
covered by some of the other references mentioned here
|
|
<P>
|
|
<H2><A NAME="ss4.3">4.3 Margins and line spacing. </A>
|
|
</H2>
|
|
|
|
<P>
|
|
Changing margins in a TeX or LaTeX document is not a straightforward
|
|
task. A lot depends on the relative indent of the text you're trying
|
|
to adjust the margin for. The placement of the margin-changing
|
|
command is also significant.
|
|
<P>For document-wide changes to LaTeX documents, the
|
|
<CODE>\evensidemargin</CODE> and <CODE>\oddsidemargin</CODE>
|
|
commands are available. They affect the left-hand margins of the
|
|
even-numbered and odd-numbered pages, respectively. For example,
|
|
<PRE>
|
|
\evensidemargin=1in
|
|
\oddsidemargin=1in
|
|
</PRE>
|
|
|
|
adds on inch to the left-hand margin of the even and odd pages <EM>in
|
|
addition</EM> to the standard one-inch, left-hand margin. These
|
|
commands affect the entire document and will shift the entire body of
|
|
the text right and left across a page, regardless of any local indent,
|
|
so they're safe to use with LaTeX environments like
|
|
<CODE>verse</CODE> and <CODE>list</CODE>.
|
|
<P>Below is a set of margin-changing macros which I wrote. They have a
|
|
different effect than the commands mentioned above. Because they use
|
|
plain TeX commands, they're not guaranteed to honor the margins of any
|
|
LaTeX environments which may be in effect, but you can place them
|
|
anywhere in a document and change the margins from that point on.
|
|
<PRE>
|
|
%% margins.sty -- v. 0.1 by Robert Kiesling
|
|
%% Copies of this code may be freely distributed in verbatim form.
|
|
%%
|
|
%% Some elementary plain TeX margin-changing commands. Lengths are
|
|
%% in inches:
|
|
%% \leftmargin{1} %% sets the document's left margin in 1 inch.
|
|
%% \leftindent{1} %% sets the following paragraphs' indent in
|
|
%% 1 inch.
|
|
%% \rightindent{1} %% sets the following paragraphs' right margins
|
|
%% %% in 1 inch.
|
|
%% \llength{3} %% sets the following lines' lengths to 3 inches.
|
|
%%
|
|
\message{Margins macros...}
|
|
\def\lmargin#1{\hoffset = #1 in}
|
|
\def\lindent#1{\leftskip = #1 in}
|
|
\def\rindent#1{\rightskip = #1 in}
|
|
\def\llength#1{\hsize = #1 in}
|
|
%%
|
|
%% (End of margins macros.}
|
|
</PRE>
|
|
|
|
Place this code in a file called <CODE>margins.sty</CODE> in your local
|
|
<CODE>$TEXINPUTS</CODE> directory. The commands are explained in
|
|
the commented section of the file. To include them in a document, use
|
|
the command
|
|
<PRE>
|
|
\usepackage{margins}
|
|
</PRE>
|
|
|
|
in the document preamble.
|
|
<P>While we're on the subject, if you don't want the right margin to be
|
|
justified, which is the default, you can tell LaTeX to use ragged
|
|
right margins by giving the command:
|
|
<PRE>
|
|
\raggedright
|
|
</PRE>
|
|
<P>Setting line spacing also has its complexities.
|
|
<P>The <EM>baselineskip</EM> measurement is the distance between lines of
|
|
text. It is given as an absolute measurement. For example,
|
|
<PRE>
|
|
\baselineskip=24pt
|
|
</PRE>
|
|
|
|
or even better:
|
|
<PRE>
|
|
\setlength{\baselineskip}{24pt}
|
|
</PRE>
|
|
|
|
The difference between the two forms is that <EM>setlength</EM> will
|
|
respect any scoping rules that may be in effect when you use the
|
|
command.
|
|
<P>The problem with using baselineskip is that it also affects the
|
|
distance between section headings, footnotes, and the like. You need
|
|
to take care that baselineskip is correct for whatever text elements
|
|
you're formatting. There are, however, LaTeX macro packages, like
|
|
<CODE>setspace.sty,</CODE> which will help you in these circumstances.
|
|
See section
|
|
<A HREF="TeTeX-HOWTO-5.html#latex-packages">LaTeX extension packages and other resources</A>.
|
|
<P>
|
|
<H2><A NAME="ss4.4">4.4 Document classes.</A>
|
|
</H2>
|
|
|
|
<P>LaTeX provides document classes which provide standardized formats for
|
|
documents. They provide environments to format lists, quotations,
|
|
footnotes, and other text elements. Commonly used document classes
|
|
are covered in the following sections.
|
|
<P>
|
|
<H3>Articles and reports.</H3>
|
|
|
|
<P>As mentioned above, the <CODE>article</CODE> class and the <CODE>report</CODE>
|
|
class are similar. The main differences are that the report class
|
|
creates a title page by default and begins each section on a new page.
|
|
Mostly, though, the two document classes are similar.
|
|
<P>To create titles, abstracts, and bylines in these document classes,
|
|
you can type, for example,
|
|
<PRE>
|
|
\title{The Breeding Habits of Cacti}
|
|
\author{John Q. Public}
|
|
\abstract{Description of how common desert cacti search
|
|
for appropriate watering holes to perform their breeding
|
|
rituals.}
|
|
</PRE>
|
|
|
|
in the document preamble. Then, the command
|
|
<PRE>
|
|
\maketitle
|
|
</PRE>
|
|
|
|
given at the start of the text, will generate either a title page in
|
|
the report class, or the title and abstract at the top of the first
|
|
page, in the article class.
|
|
<P>Sections can be defined with commands that include the following:
|
|
<PRE>
|
|
\section
|
|
\subsection
|
|
\subsubsection
|
|
</PRE>
|
|
|
|
These commands will produce the standard, numbered sections used in
|
|
technical documents. For unnumbered sections, use
|
|
<PRE>
|
|
\section*
|
|
\subsection*
|
|
\subsubsection*
|
|
</PRE>
|
|
|
|
and so on.
|
|
<P>LaTeX provides many environments for formatting displayed material.
|
|
You can include quoted text with the <CODE>quotation</CODE> environment.
|
|
<PRE>
|
|
\begin{quotation}
|
|
Start of paragraph to be quoted...
|
|
|
|
... end of paragraph.
|
|
\end{quotation}
|
|
</PRE>
|
|
|
|
For shorter quotes, you can use the <CODE>quote</CODE> environment.
|
|
<P>To format verse, use the <CODE>verse</CODE> environment.
|
|
<PRE>
|
|
\begin{verse}
|
|
Because I could not stop for death\\
|
|
He kindly stopped for me
|
|
\end{verse}
|
|
</PRE>
|
|
|
|
Notice that you must use the double backslashes to break lines in the
|
|
correct places. Otherwise, LaTeX fills the lines in a verse
|
|
environment, just like any other environment.
|
|
<P>Lists come in several flavors. To format a bulleted list, the
|
|
<CODE>list</CODE> environment is used:
|
|
<PRE>
|
|
\begin{list}
|
|
\item
|
|
This is the first item of the list.
|
|
\item
|
|
This is the second item of the list...
|
|
\item
|
|
... and so on.
|
|
\end{list}
|
|
</PRE>
|
|
<P>A numbered list uses the <CODE>enumerate</CODE> environment:
|
|
<PRE>
|
|
\begin{enumerate}
|
|
\item
|
|
Item No. 1.
|
|
\item
|
|
Item No. 2.
|
|
\item
|
|
\dots
|
|
\end{enumerate}
|
|
</PRE>
|
|
<P>A descriptive list uses the <CODE>description</CODE> environment.
|
|
<PRE>
|
|
\begin{description}
|
|
\item{Oven} Dirty, needs new burner.
|
|
\item{Refrigerator} Dirty. Sorry.
|
|
\item{Sink and drainboard} Stained, drippy, cold water faucet.
|
|
\end{description}
|
|
</PRE>
|
|
<P>
|
|
<H3><A NAME="letter-class"></A> Letters. </H3>
|
|
|
|
<P>The <CODE>letter</CODE> class uses special definitions to format business
|
|
letters.
|
|
<P>The <CODE>letter</CODE> environment takes one argument, the address of the
|
|
letter's addressee. The <CODE>address</CODE> command, which must appear
|
|
in the document preamble, defines the return address. The
|
|
<CODE>signature</CODE> command defines the sender's name as it appears
|
|
after the closing.
|
|
<P>The LaTeX source of a simple business letter might look like this.
|
|
<PRE>
|
|
\documentclass[12pt]{letter}
|
|
\signature{John Q. Public}
|
|
\address{123 Main St.\\Los Angeles, CA. 96005\\Tel: 123/456-7890}
|
|
\begin{document}
|
|
\begin{letter}{ACME Brick Co.\\100 Ash St.\\San Diego, CA 96403}
|
|
\opening{Dear Sir/Madam:}
|
|
|
|
With regard to one of your bricks that I found on my living room
|
|
carpet surrounded by shards of my broken front window...
|
|
|
|
(Remainder of the body of the letter.)
|
|
|
|
\closing{Sincerely,}
|
|
|
|
\end{letter}
|
|
\end{document}
|
|
</PRE>
|
|
|
|
Note that the addresses include double backslashes, which specify
|
|
where the line breaks should occur.
|
|
<P>
|
|
<HR>
|
|
<A HREF="TeTeX-HOWTO-5.html">Next</A>
|
|
<A HREF="TeTeX-HOWTO-3.html">Previous</A>
|
|
<A HREF="TeTeX-HOWTO.html#toc4">Contents</A>
|
|
</BODY>
|
|
</HTML>
|