Cours L
ATEX EDITE de Paris
First steps with LATEX
Outline
LATEX: a typesetting system General Description LATEX Compilation Resources LATEX Documents Writing Text with LATEX Application
Outline
LATEX: a typesetting system General Description LATEX Compilation Resources
LATEX Documents Writing Text with LATEX Application
General principles
Pronounce “latek”: the last letter is a chi (𝜒) Typesetting system
Not WYSIWYG(what you see is what you get) like classical word processing software (Microsoft Word, OpenOffice Writer, etc.) A LATEX document: a text file (or several), usually with the.tex extension, structured withtags(sometimes calledmacrosor commands) with arguments (e.g., \section{Section title}) Special case: environments
\begin{center}
This text is centered
\end{center}
Advantages / a WYSIWYG system
(More or less)semanticstructuring of a document into chapters, sections, theorems, etc.
Possible to describe (relatively) easily complex mathematical equations
Better algorithms forjustification,hyphenation, etc., since they do not need to run in real time
Better typographic quality (e.g.,kerning,ligatures) cf.http://nitens.org/taraborelli/latex
Advantage of dealing withtext files: arbitrary text editor, version control, regular expressions, production from scripts, etc.
De factostandardin academia in mathematics, computer science, theoretical physics, etc.
History
End of the 1970s Donald E. Knuth creates the typesetting systemTEX to write his book The Art of Computer Programming Beginning of the 1980s Leslie Lamport writes the macro systemLATEX
on top of TEX
1985 Release ofLATEX 2.09
1994 Release of the current version of LATEX,LATEX 2𝜀 In progress Development of version3ofLATEX
First L
ATEX document
\documentclass{minimal}
\usepackage{cmap}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[francais]{babel}
\begin{document}
Bonjour à \emph{tous}!
% Et une équation
\[
\sum_{n=1}^{+\infty}
\frac 1{n^2}=\frac{\pi^2}{6}
\]
\end{document}
Bonjour àtous!
+∞X
n=1
1 n2 = π2
6
Equivalent in Plain TEX
\documentclass{minimal}
\usepackage{cmap}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[francais]{babel}
\begin{document}
Bonjour à \emph{tous}!
% Et une équation
\[
\sum_{n=1}^{+\infty}
\frac 1{n^2}=\frac{\pi^2}{6}
\]
\end{document}
Bonjour \‘a {\it tous\/}~!
% Et une équation
$$
\sum_{n=1}^{+\infty}
{1\over n^2}={\pi^2\over 6}
$$
\end
Outline
LATEX: a typesetting system General Description LATEX Compilation Resources
LATEX Documents Writing Text with LATEX Application
Output formats
DVI (device-independent file format) historical output format of TEX. Readable with YAP (Windows), Evince (Gnome), Okular (KDE), Skim (Mac OS X), etc.
PS (PostScript) page description language, understood by many printers. Readable with GhostView (Windows), Evince (Gnome), Okular (KDE), Skim (Max OS X), etc.
PDF (Portable Document Format) page description language.
Numerous readers, in particular Adobe Reader. The most convenient to distribute documents.
HTML A LATEX document can also be turned into a Web page or Web site, but the process is imperfect.
ODT It is possible to obtain an OpenDocument output, readable with Openoffice (e.g., to convert then into a Word document), but this does not work very well.
Compilation of a L
ATEX document
LATEX
DVI PostScript
HTML ODT pdflatex
latex dvips
dvipdfm
hevea, latex2html, tth, mk4ht htlatex mk4ht oolatex
ps2pdf
Recommended compilation methods
pdflatex to prefer; simple, fast, produces an output format directly readable by all.
latex + dvips + ps2pdf if used packages require a PostScript output (e.g., pstricks)
hevea or latex2html or tth or mk4ht htlatex for an HTML output. None of them is ideal. Sometimes produce formulas as images, sometimes as MathML, sometimes as enriched text.
mk4ht oolatex for an ODT output, convertible then in Word format with OpenOffice. Manual corrections to plan.
Outline
LATEX: a typesetting system General Description LATEX Compilation Resources LATEX Documents Writing Text with LATEX Application
L
ATEX Distributions
A LATEX distribution is a bundle of programs (pdflatex, dvips, etc.), fonts, LATEX packages, etc., with everything required to compile. Depending on the distributions, some slight differences of behavior are to be expected.
Most often used distributions:
TeX Live under Unix/Linux
MikTeX under Windows; see also proTeXt, that adds some supplementary tools (TeXnicCenter, GhostView) MacTeX under Mac OS X
How to edit a L
ATEX document?
Withanytext editor
With a text editor that hassyntax highlighting: emacs, vim, gedit, kate, etc.
With anintegrated environmentfor editing, compilation,
complementary tasks: TeXnicCenter, TeXworks, AucTeX (emacs), etc.
With agraphical interfacethat “hides” LATEX commands: LyX, Scientific Word (commercial)
Common issues
Overfull hboxes TEX does not manage to find a decomposition of the text into lines that fits in the margins. Identify on a case by case basis if the problem is really apparent, and if so solve it by hand.
Underfull vboxes TEX does not manage to put enough content on a page, which may look underfull. Identify on a case by case basis if the problem is really apparent, and if so solve it by hand.
Not understandable error message Error messages are (sometimes) not really understandable. No other solutions than to look attentively at the code in question, to try and reproduce the problem on a minimal example, etc. Deleting generated files (e.g.,.aux) sometimes helps.
When there is a compilation error
TEX display the error message:
! Undefined control sequence.
l.5 the \foo is
The problem is (often) at the end of the first highlighted line;
sometimes the problem is a consequence of another problem, difficult to identify.
Press <Enter> to resume, ignoring the incriminated portion, (seldom useful) or x<Enter> to stop the compilation.
TEX sometimes simply displays “*” and waits for an input. Most of the time, it means that an environment has not been closed. Press CTRL+C, then x<Enter>, to stop the compilation.
Where to find help?
In the documentation of each package, accessible with
“texdoc nom_du_package” if the package is properly installed, can be found on the CTAN package archive otherwise:
http://www.ctan.org/
In theTeX FAQ UK, very comprehensive:
http://www.tex.ac.uk/cgi-bin/texfaq2html
On thenewsgroupscomp.text.texorfr.comp.text.tex The Comprehensive LATEX Symbol List, accessible with “texdoc symbols-a4”
Find a LATEX symbol by drawing it:
http://detexify.kirelabs.org/classify.html
Books to go further
LATEX par la pratique, Ch. Rolland, O’Reilly France (in French, sold out, very good introduction)
The LATEX Companion, F. Mittelbach et al., Addison-Wesley (reference book listing a large number of LATEX packages and describing their use)
The TEXbook, D. E. Knuth, Addison-Wesley (very technical on the functioning of the TEX engine, but very interesting)
Outline
LATEX: a typesetting system LATEX Documents
Structure
Classes and Packages LATEX commands Writing Text with LATEX Application
Outline
LATEX: a typesetting system LATEX Documents
Structure
Classes and Packages LATEX commands Writing Text with LATEX Application
General structure: 1/2
A class declaration
\documentclass{minimal}
Reference to packages, possibly with other declarations
\usepackage{cmap}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[francais]{babel}
The beginning of the document
\begin{document}
General structure: 2/2
The body of the document Bonjour à \emph{tous}!
% Et une équation
\[
\sum_{n=1}^{+\infty}
\frac 1{n^2}=\frac{\pi^2}{6}
\]
The end of the document
\end{document}
Everything after a%is acommentand is ignored.
One document, several files
For a large document, useful to split it into several files (e.g., one per chapter, or even one per section)
The file content is included with \input{file_name}
No need to specify the.texextension
\begin{document}
\input{abstract}
\input{introduction}
\input{algorithm}
\input{experiments}
\input{conclusion}
\end{document}
Outline
LATEX: a typesetting system LATEX Documents
Structure
Classes and Packages LATEX commands Writing Text with LATEX Application
Common classes
Standard LATEX classes:
article, report, book articles, reports with several chapters, books minimal few features, only useful for very short documents And others:
scrartcl, scrreprt, scrbook (KOMA-Script) a configurable and modern alternative to standard classes
memoir an all-in-one alternative to standard classes, regrouping the features of many packages
beamer, prosper, foiltex classes for making presentation slides scrlttr2 (KOMA-Script) a class for letters
Other classes
But also:
Several classes to make posters
Classes provided by the organizers of a conference or the publisher of a scientific journal
Custom classes, adapted to your needs, built from the other classes
Classes specific to Télécom ParisTech (developed by C. Ware):
TheLibres Savoirsclasses to write up course notes, slides for courses or for scientific talks:http://perso.
telecom-paristech.fr/~ware/soft/tptlibressavoirs/
A class (being developed, but usable right now)for your dissertation:
http://perso.telecom-paristech.fr/~ware/soft/tpthese/
Character sets
Unicode: character repertoire, mapping each character, from whatever written language, to a given integer.
A → 65 𝜀 → 949
é → 233 ℵ → 1488
Character encoding: way to concretely represent, with a sequence of 0’s and 1’s, a Unicode character.
For instance, for the character “é”:
latin1 11101001(only for some characters) utf8 11000011 10101001
utf16 11101001 00000000
utf-8has the advantage of representing all Unicode characters, in a manner compatible with the legacy encodingASCII.
(Practically) essential packages (1/2)
\usepackage{cmap}
annotates PDF files with information allowing better search and copy of text. Imperative to load in first position.
\usepackage[encoding]{inputenc}
so that LATEX understands the character encoding of the file (commonly, encodingis utf8, latin1, cp1252, or applemac)
\usepackage[T1]{fontenc}
so that LATEX uses the 8 bit internal encoding of fonts, instead of the old OT1 7 bit font encoding, and properly realizes thehyphenation of accented words(sometimes useless if non-standard fonts are used)
(Practically) essential packages (2/2)
\usepackage{lmodern}
so that LATEX uses theLatin Moderntypefaces instead of Computer Modern, whose accents are less nicely drawn. Compare:
à à
.\usepackage[francais]{babel}
so that LATEX properly typesets theFrenchlanguage (many other languages are available); not needed for English, which is the default.
It is possible to specify several languages for a multilingual document.
Do not use \usepackage[french]{babel}, not maintained anymore.
Very useful packages (1/2)
amsmath (American Mathematical Society) numerous features to facilitate the production of mathematical texts (equations broken up on several lines, matrices, etc.)
amsthm definition of environments for theorems, definitions, proofs, etc.
geometry specify the margins and size of a page paralist improved list environments
Very useful packages (2/2)
array, multirow, booktabs complex tables
microtype activates microtypographic extensions that help improving text justification
url command \url{http://www.google.com/}
hyperref makes links (\url) and references (\ref) clickable in PDF. To put last in the list of loaded packages.
Outline
LATEX: a typesetting system LATEX Documents
Structure
Classes and Packages LATEX commands Writing Text with LATEX Application
Commands
A LATEX command may have zero, one, or several arguments and is generally used in the following manner (but there are exceptions!):
\command[optional argument]{argument 1}{argument 2}
A command without argument is written \command{}; the {} can be omitted if what follows is not a letter, e.g., \LaTeX! Some commands have a local effect, others affect the following of the document until the end of a scope(end of an environment, or } character).
An environment can be used as follows:
\begin{environment}[optional argument]{argument 1}{argument 2}
Content.
\end{environment}
Title, author, etc.
Most document classes (article, scrartcl, memoir, beamer, etc.) allow definingmeta-informationson the document, with the following commands put in the header of the document:
\title{Title of the document}
\author{Jean Dupont\and Jacques Durand}
\date{\today}
These commands do not produce any output, but one can ask LATEX to create a title for the document with \maketitle.
Example of title
\documentclass{scrartcl}
\usepackage{cmap}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[francais]{babel}
\title{Titre du document}
\author{Jean Dupont\and Jacques Durand}
\date{\today}
\begin{document}
\maketitle
\end{document}
Titre du document
Jean Dupont Jacques Durand
14 février 2010
Outline
LATEX: a typesetting system LATEX Documents
Writing Text with LATEX Raw text
Styling
Text Structuring Application
Outline
LATEX: a typesetting system LATEX Documents
Writing Text with LATEX Raw text
Styling
Text Structuring Application
Normal text
Text written normally, accented characters included
Spaces delimiting words, two space characters are equivalent to one, a newline character is equivalent to a space
Paragraphs are separated with \par or, more simply, by two successive newline characters
This is ordinary text, including accents:
éàôïçœ, it is typeset as proper by \LaTeX.
This text has two paragraphs!
This is ordinary text, including accents: éàôïçœ, it is typeset as proper by LATEX.
This text has two paragraphs!
Punctuation
Punctuation characters must by typed normally in LATEX, preferably without a space before and with a space after. LATEX (with the help of babel for other languages than English) takes care oftypography rules.
\usepackage[american,ngerman, francais]{babel}
...
Bonjour! Ça va?\par
\selectlanguage{american}
Hi! What’s up?\par
\selectlanguage{ngerman}
Hallo! Wie geht’s?
Bonjour ! Ça va ? Hi! What’s up?
Hallo! Wie geht’s?
Microtype and babel
Microtype can take care of adding spaces following typography rules, instead of what babel traditionally does. Useful if you have problems with “active characters” (e.g., colons causing a bug in a TikZ code).
Activated with:
\usepackage[babel=true,kerning=true]{microtype}
Typographic reminders
French English
. followed by a space followed by a double space (sometimes)
, followed by a space followed by a space
; followed by a space and preceded
with a thin unbreakable space followed by a space : followed by a space and preceded
with a thin unbreakable space followed by a space
? followed by a space and preceded
with a thin unbreakable space followed by a space
! followed by a space and preceded
with a thin unbreakable space followed by a space
Dashes and quotation marks
LATEX French American English
- - petite-fille, 1979 -1981 grand-daughter – -- Je l’ai cru – car il était
convaincant – et je l’ai suivi. Perron–Frobenius
Perron–Frobenius 1979–1981
— --- — Bonjour
— Ça va ?
I believed him—since he was convincing—and I fol- lowed him.
“ ” ‘‘ ’’ He said, “Hi”, I reckon.
‘ ’ ‘ ’ l’apostrophe “He said, ‘Hi’, didn’t he?”
« » \og \fg Il a dit : « Bonjour ».
In British typography, usage of ‘ ’ and “ ” is reversed.
Special characters
Some characters have aspecial meaningin LATEX and must be input differently:
_ \_
{ \{
} \}
$ \$
& \&
# \#
% \%
\ \textbackslash
C \texteuro (textcomppackage)
~ (unbreakable space) . . . \ldots (ellipsis)
Outline
LATEX: a typesetting system LATEX Documents
Writing Text with LATEX Raw text
Styling
Text Structuring Application
Font family (typeface)
The choice of a typeface impacts mathematical equations, it is therefore more complicated than in a traditional word processor.
Packages allows using another typeface than the default (Computer Modern or Latin Modern with \usepackage{lmodern}). cf.
http://ctan.tug.org/tex-archive/info/Free_Math_Font_Survey/
survey.html
With XeLATEX, a new engine, it is possible to use arbitrary typefaces if they are installed on the computer, but the rendering of mathematics is not homogeneous any more.
Font size
The following command impacteverything that follows:
\tiny example
\scriptsize example
\footnotesize example
\small example
\normalsize example
\large example
\Large
example
\LARGE
example
\huge
example
\Huge
example
Also note : 1st.
Font style (1/2)
The first command impacts the text that follows, the second one the text in argument.
\normalfont \textnormal Default style
\rmfamily \textrm Serif
\sffamily \textsf Sans serif
\ttfamily \texttt Typewriter
\mdseries \textmd Non bold
\bfseries \textbf Bold
\upshape \textup Normal variant
\itshape \textit Italic
\slshape \textsl Slanted
\scshape \textsc SMALL CAPS
Example: \rmfamily\textit{Hi, \bfseries Ho} Ha: Hi,HoHa
Font style (2/2)
Do not use \it, \bf, etc.: these commands do not al- low text both in italic and in bold, for instance.
\em et \emph have an effect similar to \itshape and \textit but:
\textit{An
\emph{emphasized}
portion can be found inside an italic text.}
An emphasized portion can be found inside an italic text.
When using \em or \itshape, it is required to end with an italic correction \/: {\em V}V VV {\em V\/}V VV.
Not needed with \emph or \textit.
Alignment
Environment Command Example
flushleft \raggedright This text is left-aligned, it is not justified.
flushright \raggedleft This text is right-aligned, not left-aligned.
center \centering This text is centered.
justify \justifying This text is justified, it is not left-aligned.
justify and \justifying require the package ragged2e. The same package provides FlushLeft, \RaggedRight, Center, etc., giving better results than standard LATEX commands.
\indent and \noindent specify if the following paragraph is indented.
Spacing
Horizontal spacing: \hspace{5cm} ou \hspace*{5cm} (the former is ignored at the beginning of a paragraph).
Vertical spacing: \vspace{5cm} ou \vspace*{5cm} (the former is ignored at the beginning of a page). There is also \smallskip,
\medskip, \bigskip.
Springs:
a\hfill b\par
a\hfill b\hfill\hfill c
a b
a b c
Same with \vfill!
Common length units
pt point
in inch 1 in = 72,27 pt cm centimeter 2,54 cm = 1 in mm millimeter 10 mm = 1 cm em em natural font height ex ex height of thexletter
Other useful commands
So says Smith:
\begin{quote}
\LaTeX, it’s great!
\end{quote}
Some code:
\begin{verbatim}
if (i%3==0) then { ++x; }
\end{verbatim}
Or inline: \verb+i%3+.
So says Smith:
LATEX, it’s great!
Some code:
if (i%3==0) then { ++x; } Or inline: i%3.
The character delimiting \verb can be chosen more or less arbitrarily.
\newpage for a page break, \\ or \newline for a line break (without changing paragraphs).
Outline
LATEX: a typesetting system LATEX Documents
Writing Text with LATEX Raw text
Styling
Text Structuring Application
Sections
Sections allow structuring a document and giving titles to parts of a document. Existing kinds of sections depend of the document class:
\part
\chapter
\section
\subsection
\paragraph
\subparagraph
\section{Introduction} is thus put at the beginning of an introduction. In standard classes, if one writes
\section*{Introduction}, an unnumbered section is added.
Table of contents
The \tableofcontents command builds a table of contents.
\tableofcontents
LATEX: a typesetting system General Description LATEX Compilation Resources LATEX Documents
Structure
Classes and Packages LATEX commands Writing Text with LATEX
Raw text Styling
Text Structuring Application
References
After defining a chapter, section, etc., the following command creates a labelreferring to this part of the document:
\label{arbitrary_label}
This label can then be used toreferto this part by its number or page number:
This notion was defined in Chapter~\ref{arbitrary_label}, starting page~\pageref{arbitrary_label}.
LATEX needs two runs over a document to retrieve these references, it should thus be run twice consecutively!
Lists, numbered and unnumbered
My favorite cities are:
\begin{enumerate}
\item Paris;
\item Rome;
\item Hong Kong.
\end{enumerate}
\bigskip I need to buy:
\begin{itemize}
\item milk;
\item carrots;
\item meat.
\end{itemize}
My favorite cities are:
1. Paris;
2. Rome;
3. Hong Kong.
I need to buy:
milk;
carrots;
meat.
See also the environments compactenum, inparaenum, etc., of the paralist package.
Description lists
\begin{description}
\item[HTML] HyperText Markup Language
\item[SVG] Scalable Vector Graphics
\item[XML] eXtensible Markup Language
\end{description}
HTML HyperText Markup Language
SVG Scalable Vector Graphics XML eXtensible Markup
Language
Footnotes
I know\footnote{Well, I think I do.}.
I knowa.
aWell, I think I do.
Outline
LATEX: a typesetting system LATEX Documents
Writing Text with LATEX Application
Application
Reproduce the example available on the course Web page (with the document class scrartcl).
Licence de droits d’usage
Contexte public} avec modifications
Par le téléchargement ou la consultation de ce document, l’utilisateur accepte la licence d’utilisation qui y est attachée, telle que détaillée dans les dispositions suivantes, et s’engage à la respecter intégralement.
La licence confère à l’utilisateur un droit d’usage sur le document consulté ou téléchargé, totalement ou en partie, dans les conditions définies ci-après et à l’exclusion expresse de toute utilisation commerciale.
Le droit d’usage défini par la licence autorise un usage à destination de tout public qui comprend : – le droit de reproduire tout ou partie du document sur support informatique ou papier,
– le droit de diffuser tout ou partie du document au public sur support papier ou informatique, y compris par la mise à la disposition du public sur un réseau numérique,
– le droit de modifier la forme ou la présentation du document,
– le droit d’intégrer tout ou partie du document dans un document composite et de le diffuser dans ce nouveau document, à condition que : – L’auteur soit informé.
Les mentions relatives à la source du document et/ou à son auteur doivent être conservées dans leur intégralité.
Le droit d’usage défini par la licence est personnel et non exclusif.
Tout autre usage que ceux prévus par la licence est soumis à autorisation préalable et expresse de l’auteur :[email protected]