Upload
vanthuy
View
217
Download
1
Embed Size (px)
Citation preview
Introduction to LATEX
Henrik Thostrup Jensen
September 29th 2006
1
About
• What is LATEX
• How does it work
• Exercises
• Fetch slides and work from them• Not everyone works with same speed/focus• First a topic is explained, then an exercise is given
2
On learning
• ASK QUESTIONS DAMMIT!
• If something does not work• If you do not understand something• If you want to know something outside the
curriculum
• Not knowing is not failure• Not wanting to know is
• You are responsible for your learning• If you are not responsible today, you probably won’t
be tomorrow.
• Ask questions
3
What is LATEX
• Document preparation system
• A markup language - not WYSIWYG
• A front end to TEX(τεχ)
• Must be “compiled” to get a document
• The thing you should write your report in• Because it is better than the alternatives
4
A simple LATEXdocument
\documentclass{report}\begin{document}
some text\end{document}
5
Slightly more advanced LATEXdocument
% preamble\documentclass[10pt,twoside,a4paper]{report}
% content\begin{document}\chapter{Some chapter}\section{A section}some textual content\end{document}
6
Producing Output
• Compiling:latex file.tex• Will output file.dvi• Can be viewed with xdvi
• Postscript: dvips file.dvi -o file.ps
• PDF: dvipdf file.dvi -o file.pdf
• Alternative: pdflatex file.tex• Directly from LATEXto PDF
7
Document Structure 1/2
• First a preamble
• Font page, Title page, Preface
• Table of contents (auto generated)
• Contents
• Appendix
• Bibliography (auto generated using BibTEX)
8
Document Structure 2/2
• Split the document into several files
• Include other files using \input{file.tex}• One include/master file is usually the best
9
Preamble
• The cursing that goes before the document
• Not magical!
• Typical structure:
• Document class• Packages• Macros, environments, etc
10
Preamble Example
\documentclass[10pt,twoside,a4paper]{report}\usepackage[english]{babel}\usepackage{t1enc}\usepackage{graphicx}\usepackage{makeidx}\usepackage{xspace}\makeindex
\bibliographystyle{plain}
\newcommand{\word}[0]{My word\xspace}\renewcommand{\texttt}[1]{{\tt{\small{#1}}}}
11
About the Exercises
• First a concept is explained
• Then a small exercise is given
• Download the slides and follow them• Available on the course home page
• You can skip an exercise if you know the topic
12
Exercise 1
• Create a simple document using the previousexamples (or other sources)
• Compile it to a postscript or PDF file
13
Exercise 2
• Split the document into a master, a preamble, and acontent file, and recompile
14
Parts, Chapters, and Section
• \part• \chapter• \section• \subsection• \subsection• \subsubsection• \paragraph• Used to divide the report into logical chunks
• \part is usually not needed
• Note: These are specific to the report class
15
Exercise 3
• Create entries with everything from chapter toparagraph in your document, and recompile
16
Italic, Bold, Teletype, and Verbatim
• Sometimes you want text in italic or something else
• \textit{words in italic}• \textbf{words in bold}• \texttt{words in teletype}• Shorthand notation: {\it words in italic}• The verbatim environment create a teletype section
in which no escaping is necessary:\begin{verbatim}\ ∼{}\end{verbatim}
17
Exercise 4
• Insert italic, bold, and teletype text into yourdocument
• Insert a verbatim section in your document
18
Lists
• To create a numbered list:
\begin{enumerate}\item thing\item object
\end{enumerate}
• To create a bulleted list use itemize, instead ofenumerate.
• Also possible to create a description lists, see theLATEXcheat sheet for details.
19
Exercise 5
• Create a numbered list in your document
• Create a bulleted list in your document
20
Labels and References
• Used for referencing within the document• Example:
\section{Introduction}\label{sec:introduction}
\ref{sec:introduction}\pageref{sec:introduction}
• \ref refers to section or figure number• \pageref refers to page number• It is custom to use cha prefix for chapters, sec for
section, and fig for figures.• Note: You will often need to compile the document
two or three times to get page references right.
21
Exercise 6
• Create a label for a section and create a reference,and a page reference.
22
Figures 1/2
• The graphic and graphicx packages provides a simplemethod for including figures:
\includegraphics{myfigure.eps}
• Scaling:
\includegraphics[width=6cm]{myfigure.eps}
• Alternatively, it is possible to use:
\begin{figure}... \end{figure}
• Can do more (e.g., better placement control)• Usually \includegraphics is enough
23
Figures 2/2
• Bitmap files (bmp, gif, jpg, png, etc.) tend to lookbad when printed. Use vector graphics wheneverpossible.
• For postscript files eps is preferred, for pdf, includeother pdf documents.
• If you exclude the dot-suffix (e.g., .eps) in\includegraphics, LATEXwill look for eps forpostscript, and pdf for pdf documents.
24
Exercise 7
• Insert a figure into your document.
• Scale it
• Create a label for the figure, and refer to it
• Create an eps and pdf version of the figure and makesure the document can be compiled to bothpostscript and pdf
• Hint: Use epstopdf
25
Table of Contents
• LATEXcan generate this automatically• Insert the following in your master file:
\tableofcontents
• Usually followed by:
\cleardoublepage
• The level of section inclusion can be set. E.g.,:\setcounter{tocdepth}{1} includes parts,chapters, and sections.
• Note: As a table of contents is build using pagereferences, LATEXshould be run several times, usuallytwo, sometimes three.
26
Exercise 8
• Create a table of content for your document
• Remove subsection entries from the table of content
27
latexmk
• You can skip this part of you are afraid of Unix
• Or if you do not want to make your life easier
• latexmk is a Perl script which can run LATEXtheright amount of times to get pagerefs correct.
• Usage: latexmk file.tex (produces dvi output)
• Or: latexmk -pdf file.tex for pdf output
• If you use Unix you can copy the script to your PC
28
Exercise 9
• Use latexmk to compile your document to dvi andpdf
29
Math Mode
• LATEXrocks at math
• Math mode can be entered in two ways:• Easy: $ math mode $• Longer:
\begin{equation}math mode\end{equation}
• Example: $ dˆ2\sqrt{2\pi} $ produces d2√
2π
• The LATEXcheat sheet is handy when writing math
30
Exercise 10
• Create the following formula in your document:e iπ + 1 = 0d = b2 − 4ac , x1 = −b+
√d
2a
31
Page Styles
• Changing the layout style in LATEXis easy
• The page style is set like this: \pagestyle{plain}• Page style can be set anywhere in the document, and
will be style of the following pages, until redefined
• Build-in page styles are: plain, empty, headings,myheadings
• The package fancyheadings has some fancy styles,e.g., fancy, fancyplain
• \thispagestyle set the style for current page only
32
Exercise 11
• Set your page style to fancy• Be sure to include the fancyheadings package
• Now set it back, because fancy looks silly
33
Page Numbering
• Page numbering is usually done automatically
• But sometimes this does not fit
• Resetting the current page number to 1:\setcounter{page}{1}
• It is also possible to change the page number style:\pagenumbering{roman}.arabic is default numbering style.
34
Exercise 12
• Set your page numbering to start with one in theintroduction
• Use roman numerals to number the pages before theintroduction
35
BibTEX
• The way to do citations in LATEX
• Have one file with all books, articles, etc.• Can be shared across several documents
• Only includes the cited works in the report
• BibTEXautomatically sorts the entries by last name
• To use BibTEX:\bibliographystyle{plain} in the preamble\bibliography{bibliography} in the masterAnd have a file called bibliography.bib with yourbibliography.
• Then use \cite{cite entry} to cite.
36
Exercise 13
• Fetch the example bibliography.bib from thecourse web page.
• Cite the entry in your document, set it up for usingBibTEX, and compile
• Note: It is a good idea to use ∼, instead of a spacebefore \cite.This creates a space which cannot be line breaked.
37
Title Page
• The title page is the thing that goes between thefront page and the preface
• Has to look a certain way
• There is a LATEXversion of this available at the coursehomepage.
38
Exercise 14
• Download the example title page from the courseweb page
• You need title.tex and logo.eps
• Edit the file to reflect your project (or somethingelse) and insert it into your document
• You should have a file called synopsis.tex whichcontains your synopsis (or some garbage text).
39
Getting Further with LATEX
• Print out the LATEXcheat sheet:• http://www.stdout.org/~winston/latex/
• The “LaTeX Companion” is a good book
• But just use LATEXand you will get better
40
LATEXBeyond Reports
• Beamer• Can create very nice slides• http://latex-beamer.sourceforge.net/• This presentation was created with it• AAU theme: http://www.cs.aau.dk/~ltm/
• Short Documents• Will rid you of the feeling that LATEXis complicated• And documents just look way better in LATEX
41
Summary
• Hopefully you will know a bit more LATEXnow
• Ask questions if there is anything more you wouldlike to know
• Anything on these slides can be found in less thanfive minutes using google
• Now, go drink beer!
42