0% found this document useful (0 votes)
20 views34 pages

Document Structure in L TEX: Simon Eveson

Uploaded by

Bibek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views34 pages

Document Structure in L TEX: Simon Eveson

Uploaded by

Bibek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Document Structure in LATEX

Simon Eveson

Department of Mathematics, University of York

November 2010
Which (free) TEX distribution?

Windows MikTeX or TEX Live.


Linux TEX Live (standard package in Ubuntu, etc.)
Macintosh MacTeX (=TEX Live + some other bits and pieces)
http:
//www.tex.ac.uk/cgi-bin/texfaq2html?label=TeXsystems
http:
//maths.york.ac.uk/compdoc/LaTeX_on_unsupported_PCs
Which (free) TEX editor / IDE?

Windows I texworks (basic, bundled with MikTeX)


I TeXnicCenter (fancier than texworks)
Linux I kile (standard package in Ubuntu etc.)
Macintosh I TeXShop (bundled with MacTeX)
Anything you like!
Which workflow?

I For almost all purposes use pdflatex which generates PDF


directly from LATEX source.
I Use LATEX→.dvi→PS(→PDF) only in rare circumstances:
I You need to include an EPS graphics file.
I You’re using \usepackage{pstricks}.
I You need a DVI or PostScript file.
I If any of the above apply you should preferably:
I Convert the EPS file to PDF (e.g. epstopdf)
I Convert the pstricks file to tikz.
I Ask yourself why!
Source file structure

\documentclass[class options]{class name}


Preamble \usepackage[package options]{package name} . . .
\newcommand{macro name}{macro definition} . . .

\begin{document}

Topmatter \title{document title} . . . \maketitle

Body ..
.

\end{document}
The class declaration
\documentclass[class options]{class name}

I The class determines the appearance of the document (layout


of the title page, size and alignment of section headings,
location of page numbers, . . . ). There are many classes
available! Some useful ones:
I article, report, book: standard LATEX classes for documents
of increasing length.
I amsart, amsbook: originally intended for AMS publications,
but generally useful.
I Class options influence the layout of the text, e.g. size of
type, size of paper, single-sided or double-sided, single-column
or two-column. Some useful class options:
I 10pt, 11pt, 12pt (base font size)
I a4paper
I oneside, twoside, onecolumn, twocolumn
With a few exceptions, the document layout can be changed by
altering the class and options, with no other editing required.
Package declarations
\usepackage[package options]{package name}

I Packages can change document appearance, much like class


options. Some useful layout packages:
I mathptmx (Times/Helvetica/Courier fonts)
I fullpage, a4wide (narrow margins),
I hyperref (creates internal and external hyperlinks)
I More commonly, packages add extra features. Some useful
packages (others mentioned later):
I tikz (line diagrams)
I amsmath, amsfonts, amssymb (mathematical layout and
symbols, automatically loaded by AMS classes)
I Find many more in the LATEX catalogue: http://www.tex.
ac.uk/tex-archive/help/Catalogue/catalogue.html
Most of these come as standard in MikTeX, TEX Live, etc.
I The distinction between class, class option and package is
blurred!
Macro Declarations

\newcommand{macro name}{macro definition}


\DeclareMathOperator{macro name}{operator name}
(from amsmath package, autoloaded by AMS classes)

I Save typing, improve source readability:


I \newcommand{\eps}{\varepsilon} ε
I \newcommand{\C}{\mathbb{C}}  C

x y
I \newcommand{\ip}[1] {\left<#1\right>} ,
kxk ky k
I \DeclareMathOperator{\Si}{Si} Si(x)
I \DeclareMathOperator*{\esup}{ess\,sup} ess sup f (x)
x∈X
I Many more sophisticated uses.
Personal Macro Files
\input{filename}
I Reads the LATEX commands in filename.tex
I Usually looks first the directory / folder containing the master
LATEX file, then in a local inputs directory — the “local tree”
in MiKTeX.
I Can be used to load a personal collection of macro definitions
into a document.
I Advantages: easy maintenance, instant availability of all
personal macros in all documents.
I Disadvantage: other people (collaborators, journals) can’t
build your documents without your personal macro file, either
as a file or pasted into the document in place of \input.
I Potentially useful package on CTAN http://tug.ctan.org/
cgi-bin/ctanPackageInformation.py?id=artex
I Rough and ready alternative: cut and paste macros from file
to file as needed.
Topmatter (I): document information
\author{Simon Eveson \and Henning Bostelmann}
\title{...}
\date{...}
..
.
\begin{abstract}
..
.
\end{abstract}
\maketitle
I \maketitle goes after \begin{document} — other macros
usually record their arguments for \maketitle to typeset
later and can go in the preamble or body.
I Layout depends on document class (e.g. some fields might
appear in footnotes, at the end of the document, . . . )
I Fields available, syntax for multiple authors, addresses, email
addresses, etc. depend on document class.
I Read the document class documentation!
Topmatter (II): contents lists

\tableofcontents
\listoffigures
\listoftables

I Table of contents is built from the sectioning commands


\part, \chapter, \section, \subsection, etc.
I List of figures is built from
\begin{figure}. . . \end{figure} environments.
I List of tables is built from \begin{table}. . . \end{table}
environments.
I Numbers and page numbers of sections, figures and tables are
shown.
I LATEX sometimes has to be run as many as three times before
all page references are correctly resolved. Your IDE will
probably take care of this for you.
Master files and \include
\documentclass{class name}
\includeonly{file1,file2}
\begin{document}
\include{file1}
\include{file2}
..
.
\include{filen}
\end{document}

I Break a large document down into several files.


I The file containing the \documentclass declaration and the
\include and \includeonly commands is the master file.
I Use \includeonly to process only some of the files.
I Omit \includeonly to process all of the files.
I Note that each \include clears pending floats and starts a
new page.
Sectioning (I): section levels
Command might be typset as
\chapter{Introduction} 1. Introduction
\section{Definitions} 1.1 Definitions

I Each documentclass defines a hierarchy of sections.


I Book-type classes usually have \chapter, \section,
\subsection, \subsubsection, \paragraph and
\subparagraph. Article-type classes usually omit \chapter.
I Sections are automatically numbered, as specified by the
documentclass: e.g. sections might be numbered 1, 2, 3, . . . ,
subsections 1.1, 1.2, 1.3 . . . etc. They can be labelled for
cross-referencing.
I Create unnumbered sections with \chapter* etc.
I Google “latex startsection” if you want to tune the way
section headings are displayed (or use a different
documentclass).
Sectioning (II): parts and appendices
\part{Part Title}
\chapter{Chapter Title}
..
.
\part{Part Title}
\chapter{Chapter Title}
..
.
\appendix
\chapter{Appendix Title}
..
.

I Part numbering is usually independent of chapter numbering:


Part 1 might contain Chapters 1–5, Part 2 Chapters 6–10 etc.
I \appendix declares that subsequent sections are appendices.
Commonly \chapter or \section numbering is 1, 2, 3, . . .
before \appendix and A, B, C, . . . after \appendix
Cross-referencing

\label{key}
..
.
\ref{key} \pageref{key} \eqref{key}

I Every automatically generated number (sections, equation


numbers, enumerated lists, . . . ) can be labelled. Put a
\label command immediately after the command generating
the number.
I The label is a private cross-referencing key and is not printed.
I \ref prints the number, \pageref the page.
I \eqref is an AMS macro for referencing equation numbers.
Tips for using cross-references

I Use a tie to stop line breaks: Section~\ref{key}.


I LATEX sometimes needs to be run as many as three times
before cross-references are correctly resolved. Your IDE will
probably take care of this for you.
I Use descriptive names for labels. A systematic scheme of
what the label refers to can be helpful, e.g. sec:hyperbolic,
chap:intro, etc.
I \usepackage{showkeys} prints the keys in the margin of a
draft.
I \usepackage{smartref}, \usepackage{varioref} and
possibly \usepackage{fancyref} do lots of clever things
between them. Look for documentation on the CTAN:
www.tex.ac.uk
HyperTeX

\usepackage{hyperref}
..
.
\url{http://www...}

I For use when creating PDF files. Works best with pdflatex.
I Table of contents appears as a PDF table of contents.
I Table of contents entries, cross-references, index entries, etc.
become clickable links.
I References to websites with \url become clickable links.
I For the \url macro’s formatting features without clickability,
\usepackage{url}.
Enumeration
\usepackage{enumerate}
..
.
\begin{enumerate}[template]
\item . . .
..
.
\end{enumerate}

I \item works with \label and \ref.


I \usepackage{enumerate} allows you to specify the
enumeration labels via the template option, e.g.
I [1] gives 1, 2, 3, . . .
I [a] gives a, b, c, . . .
I [(I):] gives (I):, (II):, (III):, . . .
I [Idea 1] gives Idea 1, IIdeb 2, IIIdec 3, . . . so don’t get carried
away!
I For finer control, Google “latex enumi”
I itemize is similar but uses bullet points, not numbers.
Floats
\begin{float}[options]
..
.
\caption{Caption Text}
\label{float label}
\end{float}

I float can be figure or table


I LATEX moves the float in order to avoid bad page breaks.
I Make sure the \label is after the \caption. The caption
can be at the top or bottom of the float.
I To stop a float floating, \usepackage{float} in the
preamble then \begin{float}[[]H]. Beware of bad page
breaks and floats appearing in a strange order.
I \usepackage{caption} allows you to tune the way the
caption is formatted.
Equations
\usepackage{amsmath} (not needed in AMS classes)
..
.
\begin{equation}
..
.
\end{equation}
I Like $$...$$ or \[...\] but more control over equation
numbers (tags)
I Equations are numbered and work with \label and \ref.
I For an unnumbered equation, use equation* (or just
$$...$$ or \[...\])
I To number equations with sections, put something like
\numberwithin{equation}{section}
in the preamble. Equations in section 1 are now numbered
1.2, 1.2, . . .
I To use your own tags, put e.g. \tag{A} inside the equation
environment.
Aligned Equations

\usepackage{amsmath} (not needed in AMS classes)


..
.
\begin{align}
x &= a + b \\ x =a+b
&= c + d \\ =c +d
..
. ..
\end{align} .

I & is the alignment point. \\ is the end of the line.


I Each line is numbered using the same counter as equation
I For an unnumbered alignment use align*
I To suppress numbering on one line, put \notag before \\
I To use your own tag, put e.g. \tag{A} before \\
More on AMS equation layout

I amsmath has many more equation layout features, e.g.


I splitting an equation across several lines (multline, split)
I Grouping equations together (gather, gathered)
I Alignments within alignments.
Google “amsmath documentation” for the details.
I AMS classes print tags on the left by default. To print them
on the right, use the reqno class option.
I Tags are normally displayed with brackets around them. If you
\ref an equation number, you just get the number. If you
\eqref it, you get the brackets as well, in the way the current
documentclass prints them.
Theorems (I): declaration and use
\usepackage{amsthm} (not needed in AMS classes)
\theoremstyle{style}
\newtheorem{environment name}{theorem name}
..
.
\begin{environment name}[optional title]
..
.
\end{environment name}

I Use \newtheorem in the preamble, once for each theorem


type (lemma, theorem, . . . ) then \begin. . . \end where
required.
I Styles are plain, example and remark. plain style stands
out most from the text, remark style least.
I environment name is used to refer to the theorem type,
theorem name is printed; e.g. \newtheorem{thm}{Theorem}
Theorems (II): numbering
I Theorems are numbered and work with \label and \ref.
I Several theorem types can share the same numbering
sequence, e.g.
\newtheorem{thm}{Theorem}
\newtheorem[thm]{lem}{Lemma}
Now Theorem 1 will be followed by Lemma 2.
I Numbering is normally presented as “Theorem 1”. To change
this to “1. Theorem.” put \swapnumbers in the preamble,
before the \newtheorem declarations.
I To number theorems within sections, use something like
\newtheorem{prop}{Proposition}[chapter]
Now, if chapters are numbered I, II, . . . , propositions in
Chapter I will be numbered I.1, I.2, . . .
I Unnumbered theorems are declared using \newtheorem*, e.g.
\newtheorem*{rem*}{Remark}
\begin{rem*} . . . \end{rem*} is then used as usual.
Proofs

\usepackage{amsthm} (not needed in AMS classes)


..
.
\begin{proof}
..
.
\end{proof}

I Proofs normally begin with the word “Proof.” To change this,


use an optional argument, e.g.
\begin{proof}[Proof of Cauchy’s Theorem]
I End of proof is normally denoted by . To change this,
redefine \qedsymbol in the preamble, e.g.
\renewcommand{\qedsymbol}{$\blacksquare$}
finishes proofs with 
The bibliography (I): simple use, numeric
\cite[extra information]{key1,key2,. . . }
..
.
\begin{thebibliography}{N}
\bibitem{key} publication details
..
.
\end{thebibliography}

I \bibitem is analogous to \label, \cite to \ref. key is a


citation key, like a label. It is not printed.
I N: use 9 for 1–9 bibliography entries, 99 for 10–99 etc.
I The thebibliography environment prints a numbered list of
its contents, much like enumerate
I \cite works in several ways:
I \cite{Eveson2010} [2]
I \cite{Eveson2009,Eveson2010} [1,2]
I \cite[Theorem~1]{Eveson2010} [2, Theorem 1]
The bibliography (II): simple use, author / year
I For author / year citation, \usepackage{natbib} in the
preamble. Examples below from the natbib documentation.
I Bibliography entries now look like
\bibitem[Jones et al.(1990)Jones, Baker, and
Williams] {jon90} . . .
I Jones et al. is the abbreviated citation, 1990 the year and
Jones, Baker, and Williams the full citation.
I Variants of \cite work in several ways:
I \citet{jon90} Jones et al. (1990)
I \citet[chap. 2]{jon90} Jones et al. (1990, chap. 2)
I \citep{jon90} (Jones et al., 1990)
I \citep[chap. 2]{jon90} (Jones et al., 1990, chap. 2)
I \citep[see][]{jon90} (see Jones et al., 1990)
I \citep[see][chap. 2]{jon90} (see Jones et al., 1990,
chap. 2)
I \citet*{jon90} Jones, Baker, and Williams (1990)
I \citep*{jon90} (Jones, Baker, and Williams, 1990)
BibTeX (I): the basics
\bibliographystyle{style name}
\bibliography{database name}

I BibTeX uses a bibliography database file to create a a


bibliography for a particular document, including only the
items cited.
I The bibliography database is a plain text file with extension
.bib containing a sequence of records.
I Advantages: ease of maintenance of a single database file, no
need to cut and paste or retype citation details into each new
document, MathSciNet, SPIRES export in BibTeX format.
I Possible disadvantage: if you’re working on a single large
document like a PhD thesis, it might take longer to create the
database than to create a single bibliography.
I Workflow: run LATEX, then BibTeX, then LATEX once more.
Your IDE will probably take care of this for you.
BibTeX (II): a book in the bibliography database

@book {MR1084815,
AUTHOR = {Horn, Roger A. and Johnson, Charles R.},
TITLE = {Matrix analysis},
NOTE = {Corrected reprint of the 1985 original},
PUBLISHER = {Cambridge University Press},
ADDRESS = {Cambridge},
YEAR = {1990},
PAGES = {xiv+561},
ISBN = {0-521-38632-2},
MRCLASS = {15-01},
MRNUMBER = {1084815 (91i:15001)},
}
BibTeX (III): an article in the bibliography database
@article {MR1333035,
AUTHOR = {Wiles, Andrew},
TITLE = {Modular elliptic curves and {F}ermat’s last
theorem},
JOURNAL = {Ann. of Math. (2)},
FJOURNAL = {Annals of Mathematics. Second Series},
VOLUME = {141},
YEAR = {1995},
NUMBER = {3},
PAGES = {443--551},
ISSN = {0003-486X},
CODEN = {ANMAAH},
MRCLASS = {11G05 (11D41 11F11 11F80 11G18)},
MRNUMBER = {1333035 (96d:11071)},
MRREVIEWER = {Karl Rubin},
DOI = {10.2307/2118559},
URL = {http://dx.doi.org/10.2307/2118559},
BibTeX (IV): styles

I plain: basic numeric style.


I amsplain: AMS numeric style, like plain but with some extra
features.
I plainnat: put \usepackage{natbib} in the preamble, then
use \cite for a numeric style and the variant \cite
commands above for author / year style.
I Many other styles exist — look on the CTAN.
BibTeX (V): miscellanea

I There are tools to manage the bibliography database, e.g.


JabRef is open-source and multi-platform.
I BibTeX reformats citation data, often changing case. To
protect text, e.g. necessary capital letters, LATEX macros,
surround with braces, e.g. {B}anach.
I BibTeX normally puts only the items you cite into the
bibliography. To include an entry without citing it (rarely a
good idea!), put \nocite{key} before the bibliography.
\nocite{*} puts the entire database into the bibliography.
I \usepackage{citeref} creates page references from the
bibliography to the points of citation.
I \usepackage[pagebackref]{hyperref} does the same
thing with hyperlinks.
The index
\usepackage{makeidx} (not in AMS classes)
\makeindex
..
.
\index{topic!subtopic!subsubtopic}
..
.
\printindex
I \usepackage and \makeindex go in the preamble; \index
creates index references from the document body;
\printindex prints the alphabetically sorted index.
I The entry will appear in the index under topic, subtopic,
subsubtopic. Most commonly only topic is used.
I To specify a sorting position, use an index entry like
\index{R@\mathbb{R}} which puts the symbol R in the
index, sorted as if it were an ordinary R.
I Workflow: run LATEX, then makeindex, then LATEX. Your IDE
will probably take care of this for you.
Websites

I The CTAN (Comprehensive TeX Archive Network). The


principal UK node is www.tex.ac.uk.
I The CTAN home page links to the LATEX Catalogue
http://www.tex.ac.uk/tex-archive/help/Catalogue/
catalogue.html — the best place to look for packages.
I It also links to the UK TEX User’s Group (TUG) FAQ
http://www.tex.ac.uk/faq
I It also holds the Comprehensive LATEX Symbol List
http://www.tex.ac.uk/tex-archive/info/symbols/
comprehensive/symbols-a4.pdf
I There is a good LATEX Wikibook
http://en.wikibooks.org/wiki/LaTeX
I The local Mathematics Department page has some useful
information http://maths.york.ac.uk/compdoc/LaTeX

You might also like