13
An Introduction to Latex Anton Betten Department of Mathematics Colorado State University August 2008 What is Latex? Latex is a text processing system for scientists. It was started as Tex by Donald Knuth. Latex is a derivative of Tex produced by Leslie Lamport. Why Latex? It is very good for mathematical formulas, it supports citations, people can work together on one document by sharing pieces of it (this is impossible in Word, for instance). As opposed to Word, say, we have to program the text in a new language, the laguage is Latex. We can use it for presentations (like this one!), for papers, for theses etc. We can even write books. Hello World Here is a very simple example: Suppose we wish to write a document that says ‘hello world’: Hello World Hello World This is what we have to write: \documentclass[12pt]{article} \begin{document} hello world! \end{document} Hello World We also have to “compile” the file. This is done by using the pdflatex command (in an unix environment). The pdflatex command applied to our input file <name>.tex produces a file <name>.pdf which can be viewed. In Windows, there are latex environments where we simply push buttons.

An Introduction to Latex - Colorado State Universitybetten/talks/talk_latex_intro_6...An Introduction to Late x Anton Betten Depar tment of Mathematics Color ado State Univ ersity

Embed Size (px)

Citation preview

Page 1: An Introduction to Latex - Colorado State Universitybetten/talks/talk_latex_intro_6...An Introduction to Late x Anton Betten Depar tment of Mathematics Color ado State Univ ersity

An Introduction to Latex

Anton Betten

Department of MathematicsColorado State University

August 2008

What is Latex?

Latex is a text processing system for scientists.

It was started as Tex by Donald Knuth. Latex is a derivative ofTex produced by Leslie Lamport.

Why Latex?

It is very good for mathematical formulas, it supports citations,people can work together on one document by sharing piecesof it (this is impossible in Word, for instance).

As opposed to Word, say, we have to program the text in a newlanguage, the laguage is Latex.

We can use it for presentations (like this one!), for papers, fortheses etc. We can even write books.

Hello World

Here is a very simple example:

Suppose we wish to write a document that says ‘hello world’:

Hello World

Hello World

This is what we have to write:\documentclass[12pt]{article}

\begin{document}

hello world!

\end{document}

Hello World

We also have to “compile” the file.

This is done by using the pdflatex command (in an unixenvironment).

The pdflatex command applied to our input file <name>.texproduces a file <name>.pdf which can be viewed.

In Windows, there are latex environments where we simplypush buttons.

Page 2: An Introduction to Latex - Colorado State Universitybetten/talks/talk_latex_intro_6...An Introduction to Late x Anton Betten Depar tment of Mathematics Color ado State Univ ersity

Hello World, biggerWe can make the text larger (and smaller)

\documentclass[12pt]{article}

\begin{document}

hello world!{\large hello world!}{\Large hello world!}{\LARGE hello world!}{\huge hello world!}{\Huge hello world!}{\small hello world!}{\scriptsize hello world!}{\tiny hello world!}

\end{document}

And we get:

Hello World

Hello World, again

Notice that the text does not come aligned in a column, as wemight have expected.

The formatting of our text does not imply anything about theformatting of the output.

We need to use a command to break a line. That command isthe double backslash.

Hello World, again\documentclass[12pt]{article}

\begin{document}

hello world! \\{\large hello world!} \\{\Large hello world!}\\{\LARGE hello world!}\\{\huge hello world!}\\{\Huge hello world!}\\{\small hello world!} \\{\scriptsize hello world!} \\{\tiny hello world!} \\

\end{document}

And we get:

Hello World FormulaeLet’s try something fancy: formulae.

Here we go:

Page 3: An Introduction to Latex - Colorado State Universitybetten/talks/talk_latex_intro_6...An Introduction to Late x Anton Betten Depar tment of Mathematics Color ado State Univ ersity

Formulae

We have typed:

\documentclass[12pt]{article}

\begin{document}

Today we will prove the important formula$$1+1=2$$(that is to say, unless thecharacteristic is 2, in which case$1+1=0$, but let«s omitthis case for now).

\end{document}

FormulaeCompare:

\documentclass[12pt]{article}

\begin{document}

$$1+1=2$$

\[1+1=2\]

\begin{equation}1+1=2\end{equation}

\end{document}

Formulae Formulae with Reference

The last form had one advantage: it gave a number to theequation.

The idea is to refer to previous equations as needed.

We use the label and commands as in the following example.

Note: We have to run latex twice on this file. This is to allowlatex to handle the references.

Formulae Formulae with Reference

\documentclass[12pt]{article}\begin{document}Assume that\begin{equation}\label{assumption1}1+1=2\end{equation}and that\begin{equation}\label{assumption2}2+1=3\end{equation}Then using (\ref{assumption1})and (\ref{assumption2})it follows that\begin{equation}1+1+1=(1+1)+1=2+1=3.\end{equation}\end{document}

Page 4: An Introduction to Latex - Colorado State Universitybetten/talks/talk_latex_intro_6...An Introduction to Late x Anton Betten Depar tment of Mathematics Color ado State Univ ersity

Page-Numbering

In fact, the output shown was not the whole truth.

In all cases, there was an additional page number at thebottom.

Like this (can you see the little one down at the bottom of thepage?):

Page-NumberingSince page numbers make no sense on single pagedocuments, let’s get rid of them altogether, using the pagestylecommand.

\documentclass[12pt]{article}\pagestyle{empty}\begin{document}Assume that\begin{equation}\label{assumption1}1+1=2\end{equation}and that\begin{equation}\label{assumption2}2+1=3\end{equation}Then using (\ref{assumption1})and (\ref{assumption2})it follows that\begin{equation}1+1+1=(1+1)+1=2+1=3.\end{equation}\end{document}

Formulae

The Preamble

Notice the unusual place for putting the pagestyle command:before the “begin document”.

This is called the preamble.

Other stuff that could go in there is the title and author of thedocument, using title and author commands.

We will also use the date command. The date command usedwith today fills in the current date.

Here we go...

Page 5: An Introduction to Latex - Colorado State Universitybetten/talks/talk_latex_intro_6...An Introduction to Late x Anton Betten Depar tment of Mathematics Color ado State Univ ersity

The Preamble

\documentclass[12pt]{article}\pagestyle{empty}\title{My great thesis}\author{Myself}\date{\today}\begin{document}\maketitleIn this thesis, we will prove theimportant theorem ....\end{document}

The Documentclass

So far, we have used the documentclass article.

This is for articles that are submitted.

An article also has an abstract.

An article can have several sections, using the sectioncommand.

The Documentclass

\documentclass[12pt]{article}\pagestyle{empty}\title{My great thesis}\author{Myself}\date{\today}\begin{document}\maketitle\begin{abstract}In this paper, we will prove that ...\end{abstract}\section{Introduction}A group is affine if its socle iselementary abelian.

\section{Acknowledgement}The author thanks ...

\end{document}

More Math

Lets do greek:

More Math\documentclass[12pt]{article}\pagestyle{empty}\begin{document}$$\alpha,\beta,\gamma,\delta,\epsilon,\zeta,\eta,\theta,\iota,\kappa,\lambda,\mu,\nu,\xi,\pi,\rho,\sigma,\tau,\upsilon,\phi,\chi,\psi,\omega$$and$$\varepsilon,\vartheta,\varsigma,\varphi,\varrho,\varpi$$and capitals$$\Gamma, \Delta, \Theta, \Lambda, \Xi, \Pi,\Sigma, \Upsilon, \Phi, \Psi$$\end{document}

Page 6: An Introduction to Latex - Colorado State Universitybetten/talks/talk_latex_intro_6...An Introduction to Late x Anton Betten Depar tment of Mathematics Color ado State Univ ersity

More Math

Lets do symbols:

More Math\documentclass[12pt]{article}\pagestyle{empty}\begin{document}symbols:$$\pm,\mp,\times,\cap,\cup,\vee,\wedge,\setminus,\wr,\diamond,\ast,\div,\star,\circ,\bullet,\cdot,\ldots,\cdots,\oplus,\ominus,\otimes,\oslash,\odot,$$relational symbols:$$\le,\ge,\equiv,\models,\prec,\succ,\sim,\simeq,\prec,\preceq,\succeq,\mid,\ll,\gg,\parallel,\subset,\supset,\subseteq,\supseteq,\cong,\approx,=,\neq,\in,\ni,\vdash,\dashv,<,>$$\end{document}

Matrices

Lets do a matrix:

Matrices\documentclass[12pt]{article}\pagestyle{empty}\begin{document}Lets make a matrix:

$$\begin{array}{cc}a & b \\c & d\\\end{array}$$

\end{document}

OK, one by one: the cc tells him that there are two columns,both centered(left-aligned would be l, right-aligned would be r).The entries are separated by a &, lines are terminated by adouble backslash.

Matrices

If we want to make it look like a matrix, we need to putparenthesis around, like this:

Matrices

\documentclass[12pt]{article}\pagestyle{empty}\begin{document}Lets make a matrix:$$\left(\begin{array}{cc}a & b \\c & d\\\end{array}\right)$$

\end{document}

Page 7: An Introduction to Latex - Colorado State Universitybetten/talks/talk_latex_intro_6...An Introduction to Late x Anton Betten Depar tment of Mathematics Color ado State Univ ersity

Matrices

The left - right commands must always be matched.

If you don’t want the matching one, put an empty match like“right.”

The benefit of the left..right commands is that they adjust thesize of the parenthesis to the object which is in-between.

There are several versions (the “\;” is for adding space)

Matrices

Matrices\documentclass[12pt]{article}\pagestyle{empty}\begin{document}$$\left|\begin{array}{cc}a & b \\c & d\\\end{array}\right|,\;\left[\begin{array}{cc}a & b \\c & d\\\end{array}\right],\;\left(\begin{array}{cc}a & b \\c & d\\\end{array}\right)$$\end{document}

Matrices

Lets make a big and fancy matrix (this one is from my ownthesis).

Matrices\documentclass[12pt]{article}\pagestyle{empty}\begin{document}The Stirling numbers of the second kind are\[\begin{array}{r|*{7}{r}|r}& \multicolumn{7}{l}{S_2(n,r), r=} \\n & 0 & 1 & 2 & 3 & 4 & 5 & 6 & B(n) \\\hline0 & 1& 0& 0& 0& 0& 0& 0& 1\\1 & 0& 1& 0& 0& 0& 0& 0& 1\\2 & 0& 1& 1& 0& 0& 0& 0& 2\\3 & 0& 1& 3& 1& 0& 0& 0& 5\\4 & 0& 1& 7& 6& 1& 0& 0& 15 \\5 & 0& 1& 15& 25& 10& 1& 0& 52 \\6 & 0& 1& 31& 90& 65& 15& 1& 203 \\\end{array}\]The last column are the Bell numbers.

\end{document}

Matrices

Sometimes people make fancy tables by using double bars likethis:

Page 8: An Introduction to Latex - Colorado State Universitybetten/talks/talk_latex_intro_6...An Introduction to Late x Anton Betten Depar tment of Mathematics Color ado State Univ ersity

Matrices

\documentclass[12pt]{article}\pagestyle{empty}\begin{document}$$\begin{array}{|c||c|c|c|}\hline+ & 0 & 1 & 2 \\\hline\hline0 & 0 & 1 & 2\\\hline1 & 1 & 2 & 0\\\hline2 & 2 & 0 & 1\\\hline\end{array}$$Did you notice, this was a group table...\end{document}

Tables

Strictly speaking, everything so far was an array and not a table.

The difference is that an array is within math-mode.

A table can be done using the tabular command.

Tables

\documentclass[12pt]{article}\pagestyle{empty}\begin{document}Our current sale prices after discountare as follows:\\\begin{tabular}{c|c|c}Price & Discount & Sales price \\\hline100 & 10\% & 90\\200 & 5\% & 190\\\end{tabular}\end{document}

Tables

To make this more fancy, you should put it centered using thebegin center command

You did not need to do that in math-mode.

Tables

\documentclass[12pt]{article}\pagestyle{empty}\begin{document}Our current sale prices after discountare as follows:\begin{center}\begin{tabular}{c|c|c}Price & Discount & Sales price \\\hline100 & 10\% & 90\\200 & 5\% & 190\\\end{tabular}\end{center}\end{document}

Lists

Often one needs lists.

There are essentially two kinds: bulleted items or numbereditems.

They are made using the itemize and enumerate commands

The items are indicated using the item command.

Page 9: An Introduction to Latex - Colorado State Universitybetten/talks/talk_latex_intro_6...An Introduction to Late x Anton Betten Depar tment of Mathematics Color ado State Univ ersity

Lists Lists\documentclass[12pt]{article}\pagestyle{empty}\begin{document}\begin{itemize}\itembullet item no 1\itembullet item no 2\itembullet item no 3\end{itemize}\begin{enumerate}\itemitem no 1\itemitem no 2\itemitem no 3\end{enumerate}\end{document}

Lists

Lists can be nested:

Lists

\documentclass[12pt]{article}\pagestyle{empty}\begin{document}\begin{enumerate}\item item no 1\begin{enumerate}\item subitem no a\item subitem no b\item\begin{enumerate}\item subsubitem no a\item subsubitem no b\item subsubitem no c\end{enumerate}\end{enumerate}\item item no 2\item item no 3\end{enumerate}\end{document}

The AMS-Package

The AMS provides an add-on package that can be used tomake more fancy formulas.

We need to load the two packages in the preamble.

Now, equations can be stacked and aligned:

More Math

\documentclass[12pt]{article}\usepackage{amsmath}\usepackage{amssymb}\pagestyle{empty}\begin{document}\begin{align*}\sum_{j=i}^m \binom{j}{i} \alpha_j&= \binom{m}{i} \lambda_i \\\Rightarrow \quad\alpha_t&=\binom{m}{t} \lambda_t -\sum_{h=0}^{m-t-1} \binom{t+h-t}{h}\binom{t+h+1}{t} \alpha_{t+h+1},\end{align*}\end{document}

Page 10: An Introduction to Latex - Colorado State Universitybetten/talks/talk_latex_intro_6...An Introduction to Late x Anton Betten Depar tment of Mathematics Color ado State Univ ersity

Floating Objects

In real typesetting, tables and figures are not placed where theyare used.

They are moved to the top or bottom of the page (or a nearbypage, when space is tight).

Float objects exist in latex, too. We use table for floating tablesand figure for figures.

Floating Objects

\documentclass[12pt]{article}\pagestyle{empty}\begin{document}Allright, lets see an example. InTab.~\ref{tableC3}, we display theCayley table of the group $C_3$.\begin{table}$$\begin{array}{|c||c|c|c|}\hline+ & 0 & 1 & 2 \\\hline\hline0 & 0 & 1 & 2\\\hline1 & 1 & 2 & 0\\\hline2 & 2 & 0 & 1\\\hline\end{array}$$\caption{\label{tableC3}TheGroup Table of $C_3$}\end{table}\end{document}

Including Pictures

Here is how we include pictures using the figure environment.

Including PicturesThe following commands need a file entropy.png in the currentdirectory:

\documentclass[12pt]{article}\usepackage{graphicx}\pagestyle{empty}\begin{document}The entropy is defined as$$H(x) = -x \log(x) - (1-x) \log(1-x) ,\quad 0 \le x \le 1.$$Fig.~\ref{entropy} shows a plot of the function.\begin{figure}\begin{center}\includegraphics[width=70mm]{entropy}\end{center}\caption{\label{entropy}The Entropyfunction $H(x)$}\end{figure}\end{document}

Page 11: An Introduction to Latex - Colorado State Universitybetten/talks/talk_latex_intro_6...An Introduction to Late x Anton Betten Depar tment of Mathematics Color ado State Univ ersity

Making New Commands

In a recent paper, I had to typeset a nasty matrix:

Making New Commands

Typing all matrix entries into an array would likely have lead todesaster.

The trick was to use newcommand to have each matrix entrydefined separately.

newcommand defines a new latex command that can be usedanywhere in the document.

For instance, it can be used to make a matrix entry.

Here we go

Making New Commands

\documentclass[12pt]{article}\pagestyle{empty}\newcommand{\rraa}{d^{2q+2}}\newcommand{\rrab}{c^{q+1}d^{q+1}}\newcommand{\rrac}{c^{2q+2}}\newcommand{\rrad}{c^qd^{q+2}}...\begin{document}$$\left(\begin{array}{c|c|c|c|c}\rraa &\rrab &\rrac &\rrad &\rrae \\ \hline\rrba &\rrbb &\rrbc &\rrbd &\rrbe \\ \hline\rrca &\rrcb &\rrcc &\rrcd &\rrce \\ \hline\rrda &\rrdb &\rrdc &\rrdd &\rrde \\ \hline\rrea &\rreb &\rrec &\rred &\rree \\\end{array}\right)$$\end{document}

Graphics

Sometimes, we do fun stuff.

The following Domino Portrait is taken from the 2007dissertation of Bader Al-Shamarey

Title of the dissertation: Two Topics in CombinatorialOptimization.

In a Domino Portrait, we approximate an image using a fixednumber of complete sets of Dominoes (here, double-9)

Graphics

This graphics was produced in the Metapost language.

The Metapost input file was generated by Bader’s computerprogram.

Metapost is a language for graphics. Documentation can befound on the Web.

Page 12: An Introduction to Latex - Colorado State Universitybetten/talks/talk_latex_intro_6...An Introduction to Late x Anton Betten Depar tment of Mathematics Color ado State Univ ersity

Metapost

Consider an example for a Metapost graphics:

This graphic was created using the following piece of Metapostcode:

input boxes

verbatimtex\documentclass[10pt]{article}\begin{document}etex;u=0.100000mm;beginfig(1);path p[];draw (0u,150u)--(250u,0u);draw (156u,93u)--(31u,18u) dashed evenlyscaled 0.5;path pp;pp = (67u,37u) .. (62u,42u) .. (57u,37u) ..(62u,32u) .. (67u,37u) .. cycle;fill pp withcolor 1 white;path pp;pp = (67u,37u) .. (62u,42u) .. (57u,37u) ..(62u,32u) .. (67u,37u) .. cycle;draw pp;path pp;pp = (130u,75u) .. (125u,80u) .. (120u,75u) ..(125u,70u) .. (130u,75u) .. cycle;fill pp withcolor 1 white;path pp;pp = (130u,75u) .. (125u,80u) .. (120u,75u) ..(125u,70u) .. (130u,75u) .. cycle;draw pp;endfig;

end

Making Presentations with Latex / Beamer

This presentation is made using the Beamer package of Latex.

\documentclass{beamer}\mode<presentation>{\usetheme{Singapore}\setbeamercovered{transparent}}\title{An Introduction to Latex}\author{Anton~Betten}\institute[Colorado State University]{Department of Mathematics\\Colorado State University}\date[GTA training]{August 2008}\setbeamertemplate{blocks}[rounded][shadow=true]\begin{document}\begin{frame}

\titlepage\end{frame}\begin{frame}

\frametitle{What is Latex?}\framesubtitle{What is Latex, really?}

This is a presentation made using the\alert{beamer} package and Latex.\end{frame}\end{document}

Making Presentations with Latex / BeamerOne more slide:

\documentclass{beamer}\mode<presentation>{\usetheme{Singapore}\setbeamercovered{transparent}}\title{An Introduction to Latex}\author{Anton~Betten}\institute[Colorado State University]{Department of Mathematics\\Colorado State University}\date[GTA training]{August 2008}\setbeamertemplate{blocks}[rounded][shadow=true]\newcommand{\PG}{{\rm PG}}\newcommand{\PGL}{{\rm PGL}}\newcommand{\PGammaL}{{\rm P}\Gamma{\rm L}}\begin{document}

\begin{frame}\frametitle{The Fundamental Theoremof Projective Geometry}Together they generate the\alert{semilinear group}$$\PGammaL(n+1,q) =\PGL(n+1,q) \ltimes \langle \phi \rangle.$$\bigskip\bigskip\bigskip\begin{block}{THEOREM (well known)}For $n \ge 2,$ the automorphism groupof $\PG(n,q)$ is $\PGammaL(n+1,q).$\end{block}\end{frame}\end{document}

Page 13: An Introduction to Latex - Colorado State Universitybetten/talks/talk_latex_intro_6...An Introduction to Late x Anton Betten Depar tment of Mathematics Color ado State Univ ersity

Making A Web-Site Using Latex

Latex can be used to make a web-site, too.

For this, you can use the (unix) program tth (tex-to-html)

Simply create your future web-site using Latex, and thentranslate it into html format using tth.

In my case, my homepage is defined in the file index.tex

I convert it using the command

tth -e2 index.tex

The -e2 is so that the picture is embedded into the web site.

Making A Web-Site Using Latex

...

\documentclass[12pt]{article}\begin{document}\parindent 0pt\section*{Anton Betten}\begin{tabular}{*{4}{c}}\includegraphics*[width=50mm]{anton_ow.eps} & & &

\begin{tabular}{l}Dr. Anton Betten\\Department of Mathematics\\Colorado State University\\Fort Collins, CO 80523\\USA.\\phone: (970) 491 1865\\fax: (970) 491 2161\\betten at math dot colostate dot edu\\\end{tabular}\\\end{tabular}\section*{Welcome and Brief Bio}Bla,bla...\section*{Teaching\label{teaching}}In Fall 2008, I am teachingMATH501 Combinatorics I,%%tth: \begin{html} <a href="http://www.math.colo

state.edu/~betten/courses/MATH501/FA08/501_syllabus.html"> MATH501 Combinatorics I </a> \end{html}

\end{document}