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.
13
Embed
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
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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.
Hello World, biggerWe can make the text larger (and smaller)
Hello World FormulaeLet’s try something fancy: formulae.
Here we go:
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-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...
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.
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}
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).
Sometimes people make fancy tables by using double bars likethis:
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.
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.
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}
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.
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}
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.
\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}