³ ³ ³ Q u v dx V M L ³ ³³ L dx M dy ¨¨ ¸¸ C D ¹ b a f x f ... · The Workflow Borrowed...
Transcript of ³ ³ ³ Q u v dx V M L ³ ³³ L dx M dy ¨¨ ¸¸ C D ¹ b a f x f ... · The Workflow Borrowed...
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Dipl.-Inform. Oliver PajonkInstitute of Scientific ComputingTechnical University Braunschweig
LATEX2ε
Introductory Short Course
9 October 2008 1
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Outline
I. Introduction and History– What is LaTeX and where does it come from?
II. The Basics of LaTeX– Workflow, short examples of LaTeX documents
with explanation, structure of a document
III. Advanced Topics– Table of contents, cross-references,
mathematics, floating objects, presentation slides, bibliography
IV. Further Information– Tips: editors, LaTeX distributions, links
9 October 2008 2
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Outline
I. Introduction and History– What is LaTeX and where does it come from?
II. The Basics of LaTeX– Workflow, short examples of LaTeX documents
with explanation, structure of a document
III. Advanced Topics– Table of contents, cross-references,
mathematics, floating objects, presentation slides, bibliography
IV. Further Information– Tips: editors, LaTeX distributions, links
9 October 2008 3
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
What is LaTeX?
• “LaTeX is a document markup language and document preparation system for the TeXtypesetting program.” - Wikipedia
• Typesetting vs. WYSIWYG
– You do not see the final document while writing
– In fact, you do not care at all for the layout of the final document (ideally)
– You do not mark parts of the text as “bold” or “italic”, you mark them as “emphasized” or “section heading”
– LaTeX takes care of what this actually looks like (and it does it’s job very well)
9 October 2008 4
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
History and Features of LaTeX
• Short History:– 1978: Donald Ervin Knuth develops the TeX (τεχ)
typesetting system– 1985: Leslie Lamport introduces LaTeX, a high level
language that uses TeX for typesetting– 1989: Microsoft Word for Windows 1.0 is released (just to
give you an idea)
• The central part, TeX, is feature frozen it will continue to work as it does currently– Trivia: the current version of TeX is 3.141592 (from 2002)– It approaches π with every increment to reflect the
stability of the system
• Additions come only via packages• TeX is almost 30 years old while LaTeX is more than 20
years it can be considered pretty stable
9 October 2008 5
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
The Workflow Borrowed from Bookmakers
• LaTeX uses the following workflow metaphor:1. The author writes a book (article, report, whatever)
using his typewriter
2. Then a layouter decides the layout based onexperience and writes annotations for the typesetter
3. The typesetter takes the text and the annotations of the layouter and creates the actual book from these
• You are the author
• LaTeX is the layouter – But you give it hints by using commands, since it is a
stupid one
• TeX is the typesetter
9 October 2008 6
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Outline
I. Introduction and History– What is LaTeX and where does it come from?
II. The Basics of LaTeX– Workflow, short examples of LaTeX documents
with explanation, structure of a document
III. Advanced Topics– Table of contents, cross-references,
mathematics, floating objects, presentation slides, bibliography
IV. Further Information– Tips: editors, LaTeX distributions, links
9 October 2008 7
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
When to Use LaTeX?
• For any long texts (reports, books etc.)• Mathematics
– This is in fact one of the strengths of LaTeX
• Not so good for very short texts (letters,…)– There is some overhead for short texts– Here a WYSIWYG word processor can be faster
• It is hard to create customized layouts– As LaTeX does the layouting you are not supposed to
influence it too much– You can influence layouting but this requires deep
knowledge of LaTeX itself– Remember: this is intended to be this way as it normally
saves you from tedious work, it is not a flaw!
9 October 2008 8
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Overview: The LaTeX Workflow
• Essentially: LaTeX is programming language• Interpreter translates source file to output• The basic workflow is:
9 October 2008 9
LaTeX Source Files LaTeX
Interpreter
OutputDocument
LaTeX / Text Editor
User
CreatesDocument Invokes
How does the output look like?
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Interlude: Output Formats in LaTeX
• Historical output formats– DVI (from device independent) is the default output
format of TeX– It can be conveniently converted to PostScript using dvips
– Not state of the art anymore, though still in use
• Today: Adobe PDF– Portable Document Format– Very portable indeed: Adobe Reader for all major OSes– Easier to handle, thus the preferred format– Can contain hyperlinks, internet links, JPEGs, PNGs
and even other PDFs (convenient for vector graphics)– Modern LaTeX distributions can create PDFs directly
using pdflatex
9 October 2008 10
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Example: Simple LaTeX Source File
• A simple LaTeX source file is:
9 October 2008 11
\documentclass{article}
\begin{document}
This is a small \LaTeX{} document.
\end{document}
• The output document looks approximately like this:
• Not very impressive?• But the strength of LaTeX does not lie in simple
documents
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
LaTeX Commands and Comments
• What we learn from this simple document:– We have seen that LaTeX commands normally start
with the letter “\”
– Parameters to commands are enclosed by “{“ and “}” (empty parameter lists are simply written as “{}”)
– The actual content is simply typed as normal text
• Other important points:– Comments (ignored parts of the text) start with the
letter “%”
– Options to commands are passed between “[“ and “]” between the command and its parameters
– Special characters can be escaped by writing a “\” in front of them. Examples: “\%”, “\{“, “\}”
9 October 2008 12
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Example: A More Complex LaTeX Source File (1/2)
9 October 2008 13
\documentclass[a4paper,11pt]{article}
% define the title
\author{O.~Pajonk}
\title{More Complex Example}
\begin{document}
% generate title
\maketitle
% print toc
\tableofcontents
\section{This is a Section Heading}
This is the content of this section
\section{Another Heading}
\ldots{} and some more content.
\end{document}
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Example: A More Complex LaTeX Source File (2/2)
9 October 2008 14
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
The Basic Structure of a Document
1. Preamble– The section between the beginning of the file and the start of
the document section is called preamble– The most important command: \documentclass– Then there may be some \usepackage commands and
others– It ends with the last line before \begin{document}
2. Top Matter– Information about the document itself, like author, title and
date
3. Main Matter– The main content sections of your document
4. Back Matter– Bibliography, Index, Appendices…– It ends with \end{document}
9 October 2008 15
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
The Standard Document Classes
Document Class Description
article A simple document class for articles, protocols and all short texts
report Longer documents can use this class – it has chapters and direct support for double sided printing
book This is for writing real books – it has parts and other “big show” features
letter For writing letters, obviously
beamer This is an extra package that allows the creation of extraordinary presentation slides using LaTeX (interesting if you have much mathematical formulas in your presentation)
9 October 2008 16
• Here we have a small list of important document classes that are available:
• There are many others, even very specialized ones, for example: Chess position layout classes Chemical formulae classes
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Some LaTeX Packages
Package Name Description
babel Multilanguage support
amsmath,
amssymb
New math environments and symbols
inputenc A very handy package if you are writing in a language different from english (e.g. allows you to enter umlauts like ü,ö,ä,ß directly)
a4wide Enables the efficient usage of the A4 page format
enumerate Extensions to the enumerate environment
varioref Very handy extension of the reference mechanisms of LaTeX
lscape Allows you to change the orientation of some pages
9 October 2008 17
• Remember: packages are loaded using the \usepackage command in the preamble
• There are many, many more packages for almost everything you can typeset
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Try it Yourself!
• Login to one of the student terminals• Create a text file containing the LaTeX source
from some slides ago– You can use any text editor or LaTeX editor for this– You can also use the example LaTeX document from
my homepage
• Save it and run two times:
9 October 2008 18
~$ pdflatex yourfilename.tex
• This should create a PDF file called yourfilename.pdf
• You can look at this file for example with the Adobe Viewer or KPDF
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Outline
I. Introduction and History– What is LaTeX and where does it come from?
II. The Basics of LaTeX– Workflow, short examples of LaTeX documents
with explanation, structure of a document
III. Advanced Topics– Table of contents, cross-references,
mathematics, floating objects, presentation slides, bibliography
IV. Further Information– Tips: editors, LaTeX distributions, links
9 October 2008 19
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Creating a Table of Contents
• To create a table of contents you type \tableofcontents{} where it should appear
• The rest is done by LaTeX automatically!
• This can be done also for– List of figures
– List of tables
– Even custom content lists can be created
• Important:– Use proper sections, subsections etc. in your
document as these will appear in the table of contents
– Run pdflatex at least twice to update changes
9 October 2008 20
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Cross-References
• You can use cross-references very conveniently in LaTeX
• The basic steps:1. Put \label{whatever} next to the thing that
you want to reference from elsewhere, for example straight after a \section or \subsectioncommand
2. Put \ref{whatever} and it will give you the number of the section (subsection, figure environment etc.)
3. Put \pageref{whatever} and it will give you the number of the page where the section (subsection, figure environment etc.) appears
• When using PDF output these numbers are translated into inter-document hyperlinks!
9 October 2008 21
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Mathematics in LaTeX
• One of the best features of LaTeX• You can quickly write any mathematical formula (even
very complicated ones)• Small Example:
9 October 2008 22
\documentclass{article}
\begin{document}
$$ \int_{-\infty}^{\infty} f(x) \, dx=0 $$
\end{document}
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Floating Objects in LaTeX
• Figures and tables are considered as floating objects in LaTeX– This means they can “float” on the pages, they have
no fixed position– You can tell LaTeX your preferences on positioning
(like “top of page”, “bottom of page” etc.), but this is only a suggestion
• Inserting floating objects in LaTeX can be a problem because of the automatic layouting– They tend to appear in the wrong place, especially if
you have not enough text to fill the pages around these objects!
• It requires some experience to achieve good results but it is absolutely possible
9 October 2008 23
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Example: Floating Object in LaTeX
9 October 2008 24
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=5cm]{fish}
\caption{This is a fish}
\end{figure}
\end{document}
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Creating Presentation Slides with LaTeX Beamer
• With the LaTeX Beamer document class it is very easy to create good-looking presentations using LaTeX– The Institute of Scientific Computing has a
presentation template for LaTeX that looks exactly like the PowerPoint one you are looking at
• This is especially nice if – you already have material written in LaTeX and you
want to make a presentation from it ( seminar work!)
– you have many mathematical formulas to present
• See the homepage of “latex beamer” for further information– The creators have written a very good manual
9 October 2008 25
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Maintaining a Bibliography with BibTeX
• Maintaining a bibliography with BibTeX is very convenient:– You create a BibTeX database file and enter all the
articles, reports, books, … you have read
– You can assign them a reference key (similar to normal reference labels) and then use the \cite{referencekey} command
– You can reuse this database for all your documents and add up all the things you read together with comments
• You can edit this file with any text editor, but
• There is a very nice (and free) BibTeX database management program called JabRef
9 October 2008 26
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Outline
I. Introduction and History– What is LaTeX and where does it come from?
II. The Basics of LaTeX– Workflow, short examples of LaTeX documents
with explanation, structure of a document
III. Advanced Topics– Table of contents, cross-references,
mathematics, floating objects, presentation slides, bibliography
IV. Further Information– Tips: editors, LaTeX distributions, links
9 October 2008 27
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Some LaTeX Distributions
• TeXLive – a multiplatform LaTeX distribution
• teTeX – a UNIX LaTeX distribution, usually already installed on Linux systems (no longer updated)
• MiKTeX – a Microsoft Windows distribution
• proTeXt – based on MiKTeX, adds some programs and tools
9 October 2008 28
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Specialized Editors for LaTeX
• Plain LaTeX/TeX Editors:
– Kile is a very good LaTeX editor for Linux/KDE
– LEd is a free Windows LaTeX Editor
– TeXnicCenter is a free Windows LaTeX Editor
– There are other free editors, Wikipedia has a nice list
• Other Editors:
– LyX is a WYSIWYM LaTeX Editor (some like it, some don’t)
– GNU TeXmacs is “a free WYSIWYG editor with special features for scientists” (converter to LaTeX exists)
– JabRef is a free BibTeX editor (written in Java)
9 October 2008 29
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
Pointers to Further Information
• A “must read”: Tobias Oetiker - Not So Short Introduction to LaTeX (free PDF available online; LaTeX source code too!)
• Book: Frank Mittelbach et al - The LaTeX Companion (2nd edition) [Amazon]
• Website of the Institute of Scientific Computing (there are some LaTeX templates)
• CTAN – comprehensive TeX archive network (you can get almost anything related to LaTeX/TeX there)
9 October 2008 30
dxvudvudxvu
b
a
b
a
b
a
dxxgxfxgxfdxxgxf )()(')()()(')(
dAy
L
x
MdyMdxL
DC
3
!3
)('''2
!2
)(''
!1
)(')()()()()( axaxaxafxf
afafaf
The End
• That’s all, folks!• These slides are available as PDF file at my homepage:
http://www.wire.tu-bs.de/mitarbeiter/opajonk
• I have created a small example document that you can play with to get a feeling for LaTeX
• The slides contain a lot of links that can be a starting point for your own investigations
• LaTeX is learning by doing and needs practice, but I promise that it will pay off in the end
Thank you for your attention! Any questions?
9 October 2008 31