LaTeX Part 1

51
An Intro to L A T E XPart I An introduction to creating a L A T E Xdocument Aubry W. Verret Brown Science and Engineering Library Research Computing Lab November 10, 2008

description

This is the first part of a two part tutorial designed to introduce you to LaTeX and show you how to use it.

Transcript of LaTeX Part 1

Page 1: LaTeX Part 1

An Intro to LATEXPart IAn introduction to creating a LATEXdocument

Aubry W. Verret

Brown Science and Engineering Library Research Computing Lab

November 10, 2008

Page 2: LaTeX Part 1

Outline IIntroduction to LATEX

What is LATEX?Why use LATEX?How to Get LATEX

Basic LATEXDocumentExample DocumentMarkup fo Example DocumentBasic LATEXCommands

Special LATEXcharacters

CompilingHow LATEXWorksHow to Compile

FilesCLS filesOutput files

Index and Table of Contents GenerationThe ToC

Page 3: LaTeX Part 1

Outline IIThe Index

Bibliographies.bib filesBibliography StylesCompilingBibliography Assistance

Resources

Preview

Page 4: LaTeX Part 1

What is LATEX?

DefinitionLATEXis a powerful document markup system that uses the TeXtypesetting program.

It is pronounced as ’Lah Tek’ or ’Lay Tek’

Page 5: LaTeX Part 1

Why use LATEX?

I LATEXproduces superior quality documents compared to wordprocessor such as Microsoft Word.

I It offers separation of content and formatting

I Makes it easy to collaborate with others on a document

I Many conferences prefer submissions done in LATEX

Page 6: LaTeX Part 1

How to Get LATEX

There are several distributions of LATEXthat are free to obtain.

I Windows - MikTeX is a common package to use. It is freeand easy to install.Common editors to use are TeXnicCenter, WinShell, and Led.

I Mac - MacTex is the current distribution for Mac users.

I Linux - It is likely that LATEXis already a part of your operatingsystem, but if not you can install Tex live.You can use whatever text editor you would normally prefer touse, Emacs, Vi, etc.

I LATEXis also on all of the Lab computers

Go here for more informationhttp://www.latex-project.org/ftp.html

Page 7: LaTeX Part 1

How to Get LATEX

There are several distributions of LATEXthat are free to obtain.

I Windows - MikTeX is a common package to use. It is freeand easy to install.Common editors to use are TeXnicCenter, WinShell, and Led.

I Mac - MacTex is the current distribution for Mac users.

I Linux - It is likely that LATEXis already a part of your operatingsystem, but if not you can install Tex live.You can use whatever text editor you would normally prefer touse, Emacs, Vi, etc.

I LATEXis also on all of the Lab computers

Go here for more informationhttp://www.latex-project.org/ftp.html

Page 8: LaTeX Part 1

How to Get LATEX

There are several distributions of LATEXthat are free to obtain.

I Windows - MikTeX is a common package to use. It is freeand easy to install.Common editors to use are TeXnicCenter, WinShell, and Led.

I Mac - MacTex is the current distribution for Mac users.

I Linux - It is likely that LATEXis already a part of your operatingsystem, but if not you can install Tex live.You can use whatever text editor you would normally prefer touse, Emacs, Vi, etc.

I LATEXis also on all of the Lab computers

Go here for more informationhttp://www.latex-project.org/ftp.html

Page 9: LaTeX Part 1

How to Get LATEX

There are several distributions of LATEXthat are free to obtain.

I Windows - MikTeX is a common package to use. It is freeand easy to install.Common editors to use are TeXnicCenter, WinShell, and Led.

I Mac - MacTex is the current distribution for Mac users.

I Linux - It is likely that LATEXis already a part of your operatingsystem, but if not you can install Tex live.You can use whatever text editor you would normally prefer touse, Emacs, Vi, etc.

I LATEXis also on all of the Lab computers

Go here for more informationhttp://www.latex-project.org/ftp.html

Page 10: LaTeX Part 1

How to Get LATEX

There are several distributions of LATEXthat are free to obtain.

I Windows - MikTeX is a common package to use. It is freeand easy to install.Common editors to use are TeXnicCenter, WinShell, and Led.

I Mac - MacTex is the current distribution for Mac users.

I Linux - It is likely that LATEXis already a part of your operatingsystem, but if not you can install Tex live.You can use whatever text editor you would normally prefer touse, Emacs, Vi, etc.

I LATEXis also on all of the Lab computers

Go here for more informationhttp://www.latex-project.org/ftp.html

Page 11: LaTeX Part 1

How to Get LATEX

There are several distributions of LATEXthat are free to obtain.

I Windows - MikTeX is a common package to use. It is freeand easy to install.Common editors to use are TeXnicCenter, WinShell, and Led.

I Mac - MacTex is the current distribution for Mac users.

I Linux - It is likely that LATEXis already a part of your operatingsystem, but if not you can install Tex live.You can use whatever text editor you would normally prefer touse, Emacs, Vi, etc.

I LATEXis also on all of the Lab computers

Go here for more informationhttp://www.latex-project.org/ftp.html

Page 12: LaTeX Part 1
Page 13: LaTeX Part 1

Basic LATEXDocument

The basic LATEXdocument consists of a preamble, a body, and anending.

Page 14: LaTeX Part 1

A Basic LATEXDocument

Example Document

Aubry W. Verret

November 7, 2008

Hello World!

1

Page 15: LaTeX Part 1

Markup for a Basic LATEXDocument

\ d o c u m e n t c l a s s { a r t i c l e }\ t i t l e {A B a s i c \LaTeX Document}\ a u t h o r {Aubry W. V e r r e t }\ da te {November 2008}\ b e g i n {document}\ m a k e t i t l e

H e l l o World !

\end{document}

Page 16: LaTeX Part 1

Basic LATEXcommands: Preamble

LATEXdocuments begin with a preamble:

I \documentclass{}

I \title{}

I \author{}

I \date{}

Page 17: LaTeX Part 1

Basic LATEXcommands: Preamble

LATEXdocuments begin with a preamble:

I \documentclass{}

I \title{}

I \author{}

I \date{}

Page 18: LaTeX Part 1

Basic LATEXcommands: Preamble

LATEXdocuments begin with a preamble:

I \documentclass{}

I \title{}

I \author{}

I \date{}

Page 19: LaTeX Part 1

Basic LATEXcommands: Preamble

LATEXdocuments begin with a preamble:

I \documentclass{}

I \title{}

I \author{}

I \date{}

Page 20: LaTeX Part 1

Basic LATEXcommands: Preamble

LATEXdocuments begin with a preamble:

I \documentclass{}

I \title{}

I \author{}

I \date{}

Page 21: LaTeX Part 1

Basic LATEXCommands: Body

The Body of the document:

I \begin{document}

I \maketitleYou can then type the body of your document.No need to indent-this happens automatically.Separate paragraphs by a blank line.The document must end with

I \end{document}

Page 22: LaTeX Part 1

Basic LATEXCommands: Body

The Body of the document:

I \begin{document}

I \maketitleYou can then type the body of your document.No need to indent-this happens automatically.Separate paragraphs by a blank line.The document must end with

I \end{document}

Page 23: LaTeX Part 1

Basic LATEXCommands: Body

The Body of the document:

I \begin{document}

I \maketitle

You can then type the body of your document.No need to indent-this happens automatically.Separate paragraphs by a blank line.The document must end with

I \end{document}

Page 24: LaTeX Part 1

Basic LATEXCommands: Body

The Body of the document:

I \begin{document}

I \maketitleYou can then type the body of your document.No need to indent-this happens automatically.Separate paragraphs by a blank line.

The document must end with

I \end{document}

Page 25: LaTeX Part 1

Basic LATEXCommands: Body

The Body of the document:

I \begin{document}

I \maketitleYou can then type the body of your document.No need to indent-this happens automatically.Separate paragraphs by a blank line.The document must end with

I \end{document}

Page 26: LaTeX Part 1

Other Common Commands

Here are some other commands that you will use often:

I \section

I \subsection

I \chapter

I {\bf text}

I {\it text}

I \smallskip \medskip \bigskip

I \begin{enumerate}...\end{enumerate}

I \begin{itemize}...\end{itemize}

Page 27: LaTeX Part 1

Special Characters

LATEXreserves some characters for special purposes:

\ # $ % & ~ _ ^ { }

These characters cannot be used by themselves in your document.

You can include these characters in your text by using the EscapeCharacter

\

Page 28: LaTeX Part 1

Special Characters

LATEXreserves some characters for special purposes:

\ # $ % & ~ _ ^ { }

These characters cannot be used by themselves in your document.

You can include these characters in your text by using the EscapeCharacter

\

Page 29: LaTeX Part 1

Understanding How LATEXWorks

LATEXtakes in a number of different input files and outputs anumber of different files.

The main input file is the .tex file.

Along with the .tex file, LATEXreads in .cls files and .sty files whichprovide all of the needed formatting information.LATEXoutputs a .dvi file and a .log file

Page 30: LaTeX Part 1

Compiling LATEX

In order to compile your LATEXdocument use the latex command onthe .tex file.

For example, if youare using a unix environment then the command would look like this:

latex name of file.tex

Page 31: LaTeX Part 1

Compiling LATEX

In order to compile your LATEXdocument use the latex command onthe .tex file.

For example, if youare using a unix environment then the command would look like this:

latex name of file.tex

Page 32: LaTeX Part 1

.cls files

.cls files specify the format of a specific type of documentdocument. LATEXcomes with four different document classes:

I book - This is good for writing longer books with manychapters

I report - This is good for longer works like dissertations,theses, short books

I article - This is good for conference presentations, shortreports, shorter documents

I letter - This is a simple way of writing a well-formatted letter.

These are mostly similar with some small differences. For instance,the book class allows for chapters and the article class allows forabstracts.There are also many .sty files that allow for more specificformatting control.

Page 33: LaTeX Part 1

.cls files

.cls files specify the format of a specific type of documentdocument. LATEXcomes with four different document classes:

I book - This is good for writing longer books with manychapters

I report - This is good for longer works like dissertations,theses, short books

I article - This is good for conference presentations, shortreports, shorter documents

I letter - This is a simple way of writing a well-formatted letter.

These are mostly similar with some small differences. For instance,the book class allows for chapters and the article class allows forabstracts.There are also many .sty files that allow for more specificformatting control.

Page 34: LaTeX Part 1

.cls files

.cls files specify the format of a specific type of documentdocument. LATEXcomes with four different document classes:

I book - This is good for writing longer books with manychapters

I report - This is good for longer works like dissertations,theses, short books

I article - This is good for conference presentations, shortreports, shorter documents

I letter - This is a simple way of writing a well-formatted letter.

These are mostly similar with some small differences. For instance,the book class allows for chapters and the article class allows forabstracts.There are also many .sty files that allow for more specificformatting control.

Page 35: LaTeX Part 1

.cls files

.cls files specify the format of a specific type of documentdocument. LATEXcomes with four different document classes:

I book - This is good for writing longer books with manychapters

I report - This is good for longer works like dissertations,theses, short books

I article - This is good for conference presentations, shortreports, shorter documents

I letter - This is a simple way of writing a well-formatted letter.

These are mostly similar with some small differences. For instance,the book class allows for chapters and the article class allows forabstracts.There are also many .sty files that allow for more specificformatting control.

Page 36: LaTeX Part 1

.cls files

.cls files specify the format of a specific type of documentdocument. LATEXcomes with four different document classes:

I book - This is good for writing longer books with manychapters

I report - This is good for longer works like dissertations,theses, short books

I article - This is good for conference presentations, shortreports, shorter documents

I letter - This is a simple way of writing a well-formatted letter.

These are mostly similar with some small differences. For instance,the book class allows for chapters and the article class allows forabstracts.There are also many .sty files that allow for more specificformatting control.

Page 37: LaTeX Part 1

.cls files

.cls files specify the format of a specific type of documentdocument. LATEXcomes with four different document classes:

I book - This is good for writing longer books with manychapters

I report - This is good for longer works like dissertations,theses, short books

I article - This is good for conference presentations, shortreports, shorter documents

I letter - This is a simple way of writing a well-formatted letter.

These are mostly similar with some small differences. For instance,the book class allows for chapters and the article class allows forabstracts.

There are also many .sty files that allow for more specificformatting control.

Page 38: LaTeX Part 1

.cls files

.cls files specify the format of a specific type of documentdocument. LATEXcomes with four different document classes:

I book - This is good for writing longer books with manychapters

I report - This is good for longer works like dissertations,theses, short books

I article - This is good for conference presentations, shortreports, shorter documents

I letter - This is a simple way of writing a well-formatted letter.

These are mostly similar with some small differences. For instance,the book class allows for chapters and the article class allows forabstracts.There are also many .sty files that allow for more specificformatting control.

Page 39: LaTeX Part 1

Output Files

DVIs (device independent) are files that contain a preview of yourdocument once it is compiled. It can be converted to a number ofdifferent formats, such as PDF for printing.

LOG files contain a transcript of the compilation process. Theymostly contain the same information that is printed to the screenduring the process.

Page 40: LaTeX Part 1

How to Generate a Table of Contents

Table of Contents in LATEXcan be generated automatically using the

\tableofcontents command.

Place the command wherever you want the table of contents toappear. This is usually right after the

\maketitle command.

The way

\tableofcontents

works is by taking entries from the sectioning commands. Youmust run the latex command twice to generate the ToC wheneveryou add new entries to it. The first time the entries are recordedon a .toc file. The second time they are actually typeset.

Page 41: LaTeX Part 1

How To Generate Indexes

LATEXcan automatically generate indexes

Include

\usepackage{makeidx}\makeindex

in the preamble.When you encounter a term in your document that you would liketo be indexed, use the

\index{term}term command

You will need to run LATEXtwice in order for the index to appear.Once for the entries to be recorded in a .idx file and twice for theentries to be typeset.

It is possible to create various levels of entries.

Page 42: LaTeX Part 1

Bib files

It is relatively simple to generate bibliographies in LATEXusingbibtex and many different bibliographic formats are available.

Bibliographic entries must be kept in a separate file, the .bib file

This is the basic format for bib file entries:

@BOOK{make up an abbreviation,AUTHOR = "author",TITLE = "book title",PUBLISHER = {who published it},ADDRESS = {where it was published},YEAR = year it was published}

Page 43: LaTeX Part 1

@BOOK{latex,AUTHOR = "Goossens, Michel",TITLE = "The \LaTeX Companion",PUBLISHER = {Addison Wesley Longman, Inc.},ADDRESS = {Reading, MA},YEAR = 1994}

Your document should reference the source as follows:

\cite[p. 24] {latex}

To make the bibliography appear in your document include thesecommands at the end where you want the bibliography to go:

\bibliography{filename}\bibliographystyle{plain}

Page 44: LaTeX Part 1

@BOOK{latex,AUTHOR = "Goossens, Michel",TITLE = "The \LaTeX Companion",PUBLISHER = {Addison Wesley Longman, Inc.},ADDRESS = {Reading, MA},YEAR = 1994}

Your document should reference the source as follows:

\cite[p. 24] {latex}

To make the bibliography appear in your document include thesecommands at the end where you want the bibliography to go:

\bibliography{filename}\bibliographystyle{plain}

Page 45: LaTeX Part 1

@BOOK{latex,AUTHOR = "Goossens, Michel",TITLE = "The \LaTeX Companion",PUBLISHER = {Addison Wesley Longman, Inc.},ADDRESS = {Reading, MA},YEAR = 1994}

Your document should reference the source as follows:

\cite[p. 24] {latex}

To make the bibliography appear in your document include thesecommands at the end where you want the bibliography to go:

\bibliography{filename}\bibliographystyle{plain}

Page 46: LaTeX Part 1

Bibliography styles

There are several different options for the bibliographystylecommand. It is also possible to define the style of the bibliographyusing external custom style files.

Go here for more info on bib styles:

http://amath.colorado.edu/documentation/LaTeX/reference/faq/bibstyles.html#styles

Page 47: LaTeX Part 1

Compiling the bibliography

Compiling a document with a bibliography is a little morecomplicated.

I run latex on the .tex file

I run bibtex on the .tex file

I run latex twice more

The first time you run latex, a .aux file is created which bibtex willsubsequently read. The subsequent latex runs allow latex toresolve all of the references between the document and the bib file.

Each time you add new references to your document you mustrepeat this process.

Page 48: LaTeX Part 1

Bibliography Assistance

You can use an external program to manage your bibliography.

A good program for this is Jabref

I Free

I Detailed editing of entries

I Compatibility with various formats

I Automatic key generation

You can get Jabref here: http://jabref.sourceforge.net/

Page 49: LaTeX Part 1

Where to get Help

There are several different resources for learning LATEXBooks:

I LATEXConcisely by Adrian Johnstone

I The LATEXCompanion by Michel Goossens

I A Guide to LATEXby Melmut Kopka

I LATEXFor Scientists and Engineers by David J. Buerger

I The LATEXGraphics Companion

I The LATEXWeb Companion

Page 50: LaTeX Part 1

Online: There are numerous online tutorials and user guides forLATEX, specific commands, packages, etc.

The Research Computing Lab: You can send questions to methrough our ticket systemhttp://www2.lib.virginia.edu/brown/rescomp/help/index.html

Page 51: LaTeX Part 1

What’s Coming Next?

Intro to LATEXPart 2 will cover:

I Including Notes

I Typesetting Mathematics

I Tables

I Graphics

I Figures

I Presentations