DAT5 presentation 11/10 2000

Download Report

Transcript DAT5 presentation 11/10 2000

Introduktion til LaTeX
Bent Thomsen
[email protected]
Institut for Datalogi
Introduktion
• TeX
– opfundet af Donald Knuth i 70’erne
– Revolutionerede bogtrykning
• LaTeX er en overbygning til TeX
– Oprindeligt udviklet af Lesley Lamport
– LaTeX en macro package som gør det
nemmere at bruge TeX
• Tex og LaTeX er Markup Sprog
– i stil med HTML, XML og RTF
2
LaTeX sales pitch
•
•
•
•
•
•
Høj typografi kvalitet – bogtryk kvalitet
Nemt at inkludere matematiske formler
Nemt at lave krydsreferencer
Nemt at lave litteratur liste
Source filer er plain text og derfor OS uafhængigt
Der findes LaTeX implementationer til all
operativ systemer (Unix, Linux, Dos, Windows,
MacOS, …)
• LaTeX er gratis
3
Word vs. Latex
Word
Små dokumenter
Latex
Store dokumenter
Flere personer …
Flere personer 
WYSIWYG
Compile
Knapper/menuer
Kommandoer
Svært at skifte udseende Nemt at skifte udseende
Editors til entiteter
In-text entiteter
Ingen/dårlige auto. ref.
Automatiske referencer
4
5
Kompilering
• Latex er ikke WYSIWYG
– Dokumenter skal kompileres
xdvi
gostview
.dvi
latex
.tex
dvips

lp
.ps

Mit
dokument
.log
smtp
Internet
6
LaTeX
• Al tekst er ren ASCII tekst
– Kan skrives i Edit, notepad, WinEdt, emacs, vi
....
– Men IKKE direkte i Word
• Brug ”save as” – ”plain text”
7
LaTeX og pdf-filer
• ps2pdf
.dvi
latex
.tex

dvips

ps2pdf
.log
.ps
.pdf
8
Latex-dokument
• Dokument opbygges med kommandoer
• Kommandoer
– Starter med \
•
•
•
•
Efterfulgt af bogstaver, f.eks \bf og \section
Termineret med mellemrum
Tager sommetider parametre i { … }
Speciel-karakter er også kommandoer
– f.eks. æ som skrives \ae eller {\ae}
• Du kan definere dine egne kommandoer
– Nye kommandoer skal overholde de regler
9
10
LaTeX dokumentets struktur
• Preamble
– Document Class
• Predefined formats: article, letter, report, book, …
– Packages used
• Added Functionality
• Main Body
– Text
– Bibliography references
11
Preamble – et must
• Primær funktionalitet
– Layout: dokumenttype, punktstørrelse, ...
• Fordele:
– Nemt at skifte layout
• Styres fra eet sted
– Nemmere at være flere personer
• Selvdefinerede kommandoer
• Preamble scope
\documentclass ... \begin{document}
12
Body of Text
• Start with \begin{document}
• End with \end{document}
• Typesetting Text
–
–
–
–
–
\\ or \newline and \newpage
Quotations
Bold \textbf{……………} or \bf
Italics \emph{…………} or \textit{………} or \it
Underline \underline{…………} or \ul
13
Format
• Sections
–
–
–
–
–
\section{…}
= 1. Latex is Great
\subsection{…} = 1.1 Why Latex is Great
\subsubsection{…} = 1.1.1 Reason One
\appendix - changes numbering scheme
\chapter{…} - To be used with book and report
document classes
• Titles, Authors and others
– \title{…}
– \footnote{…}
\author{…}
14
Format Contd.
•
•
•
•
•
\maketitle - Display Title and Author
\tableofcontents - generates TOC
\listoftables - generates LOT
\listoffigures - generates LOF
Labels
– \label{marker} - Marker in document.
– \pageref{marker} - Displays page no. of marker.
– \ref{marker} - Displays section location of marker.
• Itemize
– Use either enumerate, itemize or description.
– see handout for example.
15
Lists
• Source
– \begin{itemize}
– \item Apple
– \item Orange
– \end{itemize}
• Result
– Apple
– Orange
16
Lists
• Enumerate instead of itemize gives a
numbered list
• Lists can be nested
17
Environment
• Something between
– \begin{name}
– \end{name}
• Many command, for example \bf affect
the text until the end of environment
• Environments can be nested
• Examples:
– itemize, center, abstract
18
Group
• Group is some text between { and }
• Many commands work until the end of the
group
• Code
– put {one word \bf in bold} here
• Result
– put one word in bold here
19
Alignment
• Environments center, flushleft,
flushright
• Example
– \begin{flushright}
– Right aligned
– \end{flushright}
• Result
Right aligned
20
Font size
\tiny \scriptsize
\footnotesize
\small \normalsize
\large \Large
\LARGE \huge
\Huge
21
• Columns
Tabular
Two Columns
– \begin{tabular}{|…|…|}
– \end{tabular}
• Rows
–
–
–
–
& - Split text into columns
\\ - End a row
\hline - Draw line under row
e.g. 123123 & 34.00\\ \hline
l = automatically adjust
size, left justify
r = automatically adjust
size, right justify
p = set size
e.g p{4.7cm}
c = centre text
22
Example of table
\begin{tabular}{|l|r|c|} \hline
Date & Price & Size \\ \hline
Yesterday & 5 & big \\ \hline
Today & 3 & small \\ \hline
\end{tabular}
Date
Price
Size
Yesterday
5
Big
Today
3
Small
23
Floating Objects
• Floating objects can stop splitting of tables and
images over pages.
\begin{figure}[options]
\end{figure}
\begin{table}[options]
\end{table}
• They will now appear in the
– List of Figures (LOF) and
– List of Tables (LOT).
Options (recommendations)
h = place table here
t = place at top of page
b = place at bottom of page
24
Example of floating figure
•
•
•
•
•
\begin{figure}[ht]
\centering\epsfig{file=uni.ps, width=5cm}
\caption{Aalborg University}
\label{uni}
\end{figure}
Figure~\ref{uni}
shows...
25
Cross-references
(internal references)
• \label{key-string}
– assigns the key key-string to the current
element of the document
• \ref{key-string}
– inserts a string identifying that the element keystring refers to
• \pageref{key-string}
– inserts the number of the page that key-string is
on.
26
Cross-reference Example
Figure \ref{f:figexample} in Section \ref{s:IntroSection}
is on page \pageref{f:figexample}.
Results in:
Figure 1 in Section 1 is on page 1.
27
Images
• Use epsfig package
• \usepackage{epsfig}
• Including images in main body
• \epsfig{file=filename.eps, width=10cm,
height=9cm, angle=90}
• Creating EPS - Use xv and/or xfig.
• MS Power Point, save as GIF and convert to
EPS.
28
Matematik & LaTeX
• Math-mode inde i teksten med $
...om variablen $a$ gælder at $a \in
[0,\infty[$ og $a \geq b$....
• Eksplicit math-mode med $$
... om $a$ gælder følgende: $$a \mid a \in
[0,\infty[ \;\wedge\; a \geq b$$ Derfor ....
• I environments som equation
\begin{equation}
\label{eq:a}
a \mid a \in [0,\infty[ \;\wedge\; a
\geq b
\end{equation}
29
Variance Equation Example
\documentclass{article}
\begin{document}
\begin{equation} \label{E:variance}
\sigma^{2} =
\frac{\sum\limits_{i=1}^{n}
\left(x_{i} - \bar{x}\right)^{2}}
{n-1}
\end{equation}
\end{document}
30
31
Egne kommandoer
• Ny kommando uden parametre
\newcommand{\ny}{ .... }
\ny
• Ny kommando med parametre
\newcommand{\ny}[2]{ ..#1 ... #2.. }
\ny{par1}{par2}
• Nyt environment
\newtheorem{proof}{\sc Bevis}
\def\theproof{}
32
Store Latex-dokumenter
• Inkludering af filer i en fil: \input
• Et dokument (master.tex) består af:
\input{preamble.tex}
\begin{document}
\input{interessant-tekst.tex}
\end{document}
• Al tekst er ren ASCII tekst
– Kan skrives i notepad, WinEdt, emacs, vi ....
– Men IKKE direkte i Word
• Brug ”save as” – ”plain text”
33
Store Latex-dokumenter
• Et dokument i Latex kan bestå af flere filer
preamble
master
fil 1
Samler dokumentet
fil n-2
…
34
Håndkodet litteraturliste
project.tex
...tekst \cite{Hansen:2002}.
\begin{bibliography}{1}
\bibitem{Hansen:2002}
Peter Hansen.
\newblock {\em Hansens Bog}.
\newblock Gyldendal, 2002.
\bibitem{ ... }
...
\end{bibliography}
35
Litteraturdatabase vha. BiBTeX
project.bib
@book{Hansen:2002,
author
= {Peter Hansen},
title
= {Hansens Bog},
publisher = {Gyldendal},
year
= 2002
}
project.tex
...tekst \cite{Hansen:2002}.
\bibliographystyle{plain}
\bibliography{project, P0}
36
Creating a Bibliography with BibTeX
• Must create a bibliography database
– References.bib file
– read by BibTeX
• Bibliographies can have different formats
– e.g., Alphabetical, Numbered, etc.
• BibTeX formats entries based on the
bibliography style chosen
– e.g., Plain, Alpha, IEEE, ACM, etc.
37
BibTeX Entry
• Entry Type: book, article, in proceeding, etc.
• Keyword identifying publication
• Series of Fields
– Author
– Journal
– Title, etc.
• Example:
@book{pressman97,
title = {Software Engg, A practitioner’s Approach},
author = {Roger S.Pressman},
publisher = {McGraw-Hill},
year = {1997}
}
38
Referencing a .bib Entry
• References.bib file must be included in LateX by
using
\bibliography{References}
• Cite the reference by using:
\cite{cite-key}
• Example:
– In \cite{pressman97}, the characteristics of software
are discussed.
– Result: In [1], the characteristics of software are
discussed.
39
Kompilering med BiBTeX
.tex
LaTeX
LaTeX
.aux
.bib
.aux
LaTeX
.dvi
.bbl
BiBTeX
.blg
I terminalvindue:
Eller i emacs:
latex project
bibtex project
C-c L
C-c C-c
40
”Putting it all together”
• Et komplet projekt...
–
–
–
–
–
–
Punktopstilling
Selvdefineret kommando
Tabel
Figur
Matematik
Litteraturliste
41
Kompilering
• Latex er ikke WYSIWYG
– Dokumenter skal kompileres
xdvi
gostview
.dvi
latex
.tex
dvips

lp
.ps

Mit
dokument
.log
smtp
Internet
42
LaTeX
• Al tekst er ren ASCII tekst
– Kan skrives i Edit, notepad, WinEdt, emacs, vi
....
– Men IKKE direkte i Word
• Brug ”save as” – ”plain text”
43
LaTeX og pdf-filer
• ps2pdf
.dvi
latex
.tex

dvips

ps2pdf
.log
.ps
.pdf
44
Conclusions
• Latex is optimal for master and phd thesis
• Latex has a steep learning curve
– So start practicing now!
•
•
•
•
Mathematical formulae are easy.
Cross references are easy
Litterature lists are very easy
You may use bibtex search engines
– http://liinwww.ira.uka.de/bibliography/index.html
• Consider converting Postscript files to PDF
(more widespread in Windows world) and to
conserve space.
45