L TEX How to Make Academic Documents Look Pretty Hafida Benhidour

LATEX
How to Make Academic Documents Look Pretty
Hafida Benhidour
Department of Computer Science
College of Computer and Information Sciences
King Saud University
Basics of LATEX
LATEX( pronounced /"lA:tEx/, /"lA:tEk/, /"leItEx/, or /"leItEk/)
(Wikipedia) is a computer program for typesetting text and
mathematical formulas.
Uses commands to create mathematical symbols.
Not a WYSIWYG program. It is a WYWIWYG (what you want is
what you get) program!
The document is written as a source file using a markup language
(like HTML).
The final document is obtained by compiling the source file.
Hafida Benhidour (KSU)
LATEX
2 / 41
Advantages of Using LATEX
Professional typesetting: Best output.
It is the standard for scientific documents.
Processing mathematical (& other) symbols.
Meaning based structuring (rather than appearance).
Knowledgeable and helpful user group.
Its FREE!
Platform independent.
Hafida Benhidour (KSU)
LATEX
3 / 41
Installing LATEX
Linux:
1
2
Install TeXLive from your package manager.
Install a LATEXeditor of your choice: TeXstudio, TexMaker, etc.
Windows:
1
2
Install MikTeX from http://miktex.org (this is the LATEXcompiler).
Install a LATEXeditor of your choice: TeXstudio, TeXnicCenter, etc.
Mac OS:
1
2
Install MacTeX (this is the LATEXcompiler for Mac).
Install a LATEXeditor of your choice.
Hafida Benhidour (KSU)
LATEX
4 / 41
Structure of a LATEXDocument
All latex documents have the following structure:
\ documentclass [ . . .
\ usepackage { . . . }
\ b e g i n { document }
...
\ end { document }
Hafida Benhidour (KSU)
]{...}
LATEX
5 / 41
LATEXCommands
Always begin with a backslash \: \documentclass, \usepackage.
Case sensitive.
Consist of letters only.
Some have parameters.
Square brackets [ ] after the command name are for optional
parameters.
Curly braces { } after the command name are for required parameters
Hafida Benhidour (KSU)
LATEX
6 / 41
The Command: \documentclass
article
\ documentclass [ options ]{ report }
book
letter
...
First line of all LATEXdocuments.
Specifies the type of the document:
article: Research paper.
report: Multi-chapter document.
book: For books.
letter: For letters.
[options] can be used to set font size (10, 11, or 12 pt), set paper
size, use one or two columns, etc.
These are predefined classes. Most science publishers (Springer,
Elsevier, IEEE, ACM etc.) have their own document classes.
Hafida Benhidour (KSU)
LATEX
7 / 41
Packages
\ usepackage { package }
Packages add new features and commands to LaTeX.
Common packages:
amsmath, amssymb: for math symbols.
graphicx: for including graphics and images.
Can also define new commands in the preamble, specify page
numbering, etc.
Hafida Benhidour (KSU)
LATEX
8 / 41
Input the Text
The body of the text is written after the \begin{document} command:
\ b e g i n { document }
E n t e r t h e document c o n t e n t h e r e
\ end { document }
Remark
\begin{...} commands always need to be followed (eventually) by
\end{...} commands.
Hafida Benhidour (KSU)
LATEX
9 / 41
A Simple LATEXDocument
The following is a very basic
LATEXdocument:
\ documentclass { a r t i c l e }
\ usepackage { graphicx }
\ b e g i n { document }
T h i s i s some
sample t e x t .
\ end { document }
This is some sample text.
This gives the following
output:
1
Hafida Benhidour (KSU)
LATEX
10 / 41
Sections of a Paper
First thing: you have to indicate the title and the author(s) of the paper:
\title{title}
\ author { authors }
\ date { date }
\ maketitle
Remark
Without \maketitle, the title and authors do not appear in the output.
Example
\ t i t l e {The Theory o f R e l a t i v i t y }
\ author { Albert E i n s t e i n }
\ d a t e {01/01/1926}
\ maketitle
Hafida Benhidour (KSU)
LATEX
11 / 41
Sections of a Paper
\ thanks { . . . }
\ b e g i n { a b s t r a c t } . . . . \ end { a b s t r a c t }
\ b e g i n { k e y w o r d s } . . . \ end { k e y w o r d s }
\thanks creates a footnote with whatever is in the braces. Usually used
after authors’ names for academic information
Example
\ t h a n k s { I want t o t h a n k t h e U n i v e r s i t y o f P r i n c e t o n f o r
s u p p o r t i n g t h i s work . }
\ begin { abstract }
I n t h i s p a p e r , I i n t r o d u c e a new t h e o r y t o e x p l a i n how t i m e
and s p a c e a r e r e l a t e d .
\ end { a b s t r a c t }
\ b e g i n { k e y w o r d s } R e l a t i v i t y ; s p a c e ; t i m e \ end { k e y w o r d s }
Hafida Benhidour (KSU)
LATEX
12 / 41
Sections
The document should be divided into sections, subsections, etc. Important
commands:
\ section { T i t l e of f i r s t section }
...
\ subsection {...}
...
\ s e c t i o n { T i t l e of second s e c t i o n }
...
\ subsection {...}
...
\ subsubsection { . . . }
...
LAT
EXformates the section titles and numbers them according to the
document class being used.
Hafida Benhidour (KSU)
LATEX
13 / 41
A Simple LATEXDocument
The following is a sampleLATEXdocument:
\ documentclass { a r t i c l e }
\ u s e p a c k a g e { g r a p h i c s , amsmath , amssymb }
\ b e g i n { document }
\ t i t l e {The Theory o f R e l a t i v i t y }
\ author { Albert E i n s t i e n }
\ d a t e {01/01/1926}
\ maketitle
\ begin { abstract }
I n t h i s p a p e r , I i n t r o d u c e a new t h e o r y t o e x p l a i n how t i m e
and s p a c e a r e r e l a t e d .
\ end { a b s t r a c t }
\ section { Introduction }
What i s t i m e and s p a c e ? . . .
\ s e c t i o n {The Theory }
Time and s p a c e a r e l i n k e d . . .
\ su bse cti on { Proof }
T h i s t h e p r o o f t o my t h e o r y
\ end { document }
Hafida Benhidour (KSU)
LATEX
14 / 41
A Simple LATEXDocument
This gives the following output:
The Theory of Relativity
Albert Einstien
01/01/1926
Abstract
In this paper, I introduce a new theory to explain how time and space
are related.
1
Introduction
What is time and space?...
2
The Theory
Time and space are linked...
2.1
Proof
This the proof to my theory
1
Hafida Benhidour (KSU)
LATEX
15 / 41
Cross-referencing
Cross references can be made using the commands \label and \ref.
Example
\ section { Introduction }
\ l a b e l { sec : i n t r o }
This i s the i n t r o d u c t i o n . . .
\ section { Conclusion }
As m e n t i o n e d i n S e c t i o n \ r e f { s e c : i n t r o } , we h a v e . . .
LATEXupdates the references automatically.
It is possible to use any identifier as a label.
It is custom to use the prefixes: sec:xxx for section labels, fig:xxx for
figure labels, chap:xxx for chapter labels, tab:xxx for table labels,
eq:xxx for equation labels.
Hafida Benhidour (KSU)
LATEX
16 / 41
Inserting Tables
To include tables, you must use the following commands.
Example
Figure \ ref { table example
} shows a t a b l e .
\ begin { table }
\ c a p t i o n {An Example o f a
Table }
\ label { table example }
\ centering
\ begin { tabular }{| c | c |}
\hline
T a b l e Head &
Column Head \\
\ h l i n e Copy & More \\
\hline
\ end { t a b u l a r }
\ end { t a b l e }
Hafida Benhidour (KSU)
Table 1 shows a table.
Table 1 : An Example of a Table
Table Head
Copy
Column Head
More
LATEX
17 / 41
Inserting Images
To include images, you must use a graphics package. The most common is
graphicx.
Example
Figure 1 shows the painting.
Figure \ r e f { f i g : monalisa }
shows t h e p a i n t i n g .
\ begin { f i g u r e }
\ c e n t e r i n g % To c e n t e r
t h e image
\ i n c l u d e g r a p h i c s [ width
=2.5cm ] { m o n a l i s a . j p g }
% Path and f i l e name
\ c a p t i o n {The M o n a l i s a }
\ l a b e l { f i g : monalisa }
\ end { f i g u r e }
Hafida Benhidour (KSU)
LATEX
Figure 1 : The Monalisa
18 / 41
Inserting Images
In general, a figure is included using:
\ begin { f i g u r e }[ options ]
\ centering
\ i n c l u d e g r a p h i c s [ o p t i o n s ] { f i l e name}
\ caption { Figure t i t l e }
\label{label}
\ end { f i g u r e }
In \begin{figure}[options], you can specify the position option:
1
2
3
4
t: top of page.
h: here.
!: let the compiler decide.
Any combination can be used.
The compiler tries its best to fulfill your wish, but not necessarily.
In \includegraphics[options], you can specify the height, the width,
the angle of rotation of the image.
Hafida Benhidour (KSU)
LATEX
19 / 41
Inserting Images
Example
Figure 2 shows the painting
rotated.
Figure \ r e f { f i g : monalisa2
} shows t h e p a i n t i n g .
\ begin { f i g u r e }
\ c e n t e r i n g % To c e n t e r
t h e image
\ i n c l u d e g r a p h i c s [ width
=2.5cm , a n g l e= 4 5 ] {
m o n a l i s a . j p g } % Path
and f i l e name
\ c a p t i o n {The M o n a l i s a }
\ l a b e l { f i g : monalisa2 }
\ end { f i g u r e }
Hafida Benhidour (KSU)
LATEX
Figure 2 : The Monalisa rotated
20 / 41
Typesetting Mathematical Equations
Latex is extremely good at typesetting math equations.
Equations are written as text.
First you have to switch to math mode:
Inline equations (equations within the text) are written between $ and
$.
Example
Code:
Assume t h a t $ \ a l p h a x +
\ b e t a y =1$ , t h e n . . .
Output:
Assume that αx + βy = 1, then ...
Hafida Benhidour (KSU)
LATEX
21 / 41
Typesetting Mathematical Equations
Equations on a separate line are enclosed between \[ and \].
Example
Code:
Assume t h a t :
\[
\ a l p h a x + \ b e t a y =1,
\]
then . . .
Output:
Assume that:
αx + βy = 1,
then ...
Hafida Benhidour (KSU)
LATEX
22 / 41
Typesetting Mathematical Equations
Numbered equations are written within the equation environment.
Example
Code:
Assume t h a t :
\ begin { equation }
\ l a b e l { eq : my−e q u a t i o n } % <= The e q u a t i o n l a b e l
\ a l p h a x + \ b e t a y =1,
\ end { e q u a t i o n }
then . . .
Output:
Assume that:
αx + βy = 1,
(1)
then ...
Hafida Benhidour (KSU)
LATEX
23 / 41
Typesetting Mathematical Equations
To refer a numbered equation, use the command \eqref. The
equation numbers are updated automatically.
Example
Code:
By u s i n g E q u a t i o n \ e q r e f { eq : my−e q u a t i o n 2 } , we o b t a i n : . . .
\ begin { equation }
\ l a b e l { eq : my−e q u a t i o n 2 }
\ a l p h a x= 1− \ b e t a y .
\ end { e q u a t i o n }
Output:
By using Equation (2), we obtain:
αx = 1 − βy.
Hafida Benhidour (KSU)
LATEX
(2)
24 / 41
Typesetting Mathematical Equations
There are other equation environments:For example align.
Example
Code:
Here i s t h e d e r i v a t i o n o f a famous e q u a t i o n :
\ begin { a l i g n }
( x−y ) ( x+y ) &= x ( x+y ) − y ( x+y ) \\
&= xˆ2+x y − y x − y ˆ2\\
&= x ˆ2 − y ˆ 2 .
\ end { a l i g n }
Output:
Here is the derivation of a famous equation:
(x − y)(x + y) = x(x + y) − y(x + y)
2
= x + xy − yx − y
2
2
=x −y .
Hafida Benhidour (KSU)
LATEX
2
(3)
(4)
(5)
25 / 41
Typesetting Mathematical Equations
To remove the numbering use align* instead.
Example
Code:
Here i s t h e d e r i v a t i o n o f a famous e q u a t i o n :
\ b e g i n { a l i g n ∗}
( x−y ) ( x+y ) &= x ( x+y ) − y ( x+y ) \\
&= xˆ2+x y − y x − y ˆ2\\
&= x ˆ2 − y ˆ 2 .
\ end { a l i g n ∗}
Output:
Here is the derivation of a famous equation:
(x − y)(x + y) = x(x + y) − y(x + y)
= x2 + xy − yx − y 2
= x2 − y 2 .
Hafida Benhidour (KSU)
LATEX
26 / 41
Typesetting Mathematical Equations
For long equations use multline. You can also remove the numbering
by using multline*.
Example
Code:
This i s a very long equation :
\ begin { multline }
( x−y ) ( x+y ) = x
− y ˆ2 = x ˆ2 − y ˆ 2 .
\ end { m u l t l i n e }
( x+y ) − y ( x+y )= x ˆ2 \\ +x y − y x
Output:
This is a very long equation:
(x − y)(x + y) = x(x + y) − y(x + y) = x2
+ xy − yx − y 2 = x2 − y 2 . (6)
Hafida Benhidour (KSU)
LATEX
27 / 41
Typesetting Mathematical Equations
You can write fractions, integrals, sums, products etc.
Example
Code:
This a very complicated equation :
\[
\ l o g ( \ p r o d { i =1}ˆn u i )= \ sum { i =1}ˆ{n} \ l o g ( u i ) .
\]
Output:
This a very complicated equation:
n
n
Y
X
log( ui ) =
log(ui ).
i=1
Hafida Benhidour (KSU)
i=1
LATEX
28 / 41
Typesetting Mathematical Equations
You can write fractions, integrals, sums, products etc.
Example
Code:
This a very complicated equation :
\[
\ i n t {1}ˆ{ y } \ f r a c {1}{ x } dx= \ l o g ( y ) .
\]
Output:
This a very complicated equation:
Z y
1
dx = log(y).
1 x
Hafida Benhidour (KSU)
LATEX
29 / 41
Typesetting Mathematical Equations
You can write fractions, integrals, sums, products etc.
Example
Code:
This a very complicated equation :
\[
\ i n t {1}ˆ{ y } \ f r a c {1}{ x } dx= \ l o g ( y ) .
\]
Output:
This a very complicated equation:
Z y
1
dx = log(y).
1 x
Hafida Benhidour (KSU)
LATEX
30 / 41
Typesetting Mathematical Equations
There is a large number of predefined mathematical symbols.
Example
Code:
Some \LaTeX math s y m b o l s :
\[
\gamma + \Gamma + \ p i + \ h a t { x } − \ b a r { y } = 0 . \ ]
\[
(P \ l o r Q) \ i m p l i e s R \ L e f t r i g h t a r r o w
(P \ i m p l i e s R) \ l a n d (Q \ i m p l i e s R) \ ]
Output:
Some math symbols:
γ+Γ+π+x
ˆ − y¯ = 0.
[(P ∨ Q)=⇒R] ⇔ [(P =⇒R) ∧ (Q=⇒R)]
Hafida Benhidour (KSU)
LATEX
31 / 41
Typesetting Mathematical Equations
You can also write matrices.
Example
Code:
$A$ i s a m a t r i x and $b$ i s a v e c t o r d e f i n e d by :
\ [ A= \ b e g i n { b m a t r i x }
1 & 2\\
−1 & 0
\ end { b m a t r i x } ,
b= \ b e g i n { b m a t r i x } 2\\ 1 \ end { b m a t r i x }
\]
Output:
A is a matrix and b is a vector defined by:
1 2
2
A=
,b =
−1 0
1
Hafida Benhidour (KSU)
LATEX
32 / 41
Using Graphical Equation Editors
The best way to write an equation is to write it directly as text: it is
faster and you have more control.
You can, however, use some graphical editors to help you write the
equations until you master LATEX.
Some LATEX editors (like TexStudio) offer some tool-bars with buttons
that can help you write math symbols or even draw the math symbols
(like the Math wizard in TexStudio).
There are also online LATEX equation editors, for example:
http://www.codecogs.com/latex/eqneditor.php.
Hafida Benhidour (KSU)
LATEX
33 / 41
Bibliography
The bibliography is usually inserted at the end of the document, before
\end{document}:
\ bibliographystyle { bibliography style }
\ bibliography { bibliography f i l e ( . bib f i l e )}
The bibliography style indicates to LATEXhow to format your
references.
Usually the bibliography style is indicated by the publisher. Common
styles: plain, apalike, acm, ieeetr, siam, ...
The bibliography file is of type BibTeX (extension .bib) containing all
your references (not necessary only those used in your document).
Example
\ bibliographystyle { plain }
\ b i b l i o g r a p h y {my−b i b l i o g r a p h y }
Hafida Benhidour (KSU)
LATEX
34 / 41
Bibliography: the BibTeX file
The BibTeX format for an journal paper:
Example
@ a r t i c l e { kornack2001 ,
a u t h o r =”D . Kornack and P . R a k i c ” ,
t i t l e =” C e l l P r o l i f e r a t i o n w i t h o u t N e u r o g e n e s i s i n A d u l t
Primate Neocortex , ” ,
j o u r n a l =” S c i e n c e ” ,
volume =”294” ,
p a g e s =”2127 −2130” ,
month=”Dec ” ,
y e a r =”2001” ,
}
a r t i c l e : an a r t i c l e from a j o u r n a l o r m a g a z i n e .
R e q u i r e d f i e l d s : AUTHOR, TITLE , JOURNAL , YEAR
O p t i o n a l f i e l d s : VOLUME, NUMBER, PAGES , MONTH, NOTE, KEY
Hafida Benhidour (KSU)
LATEX
35 / 41
Bibliography: the BibTeX file
The BibTeX format for an conference paper:
Example
@ i n p r o c e e d i n g s { goto2007 ,
a u t h o r = ”H . Goto , Y . Hasegawa , and M. Tanaka ” ,
t i t l e = ” E f f i c i e n t S c h e d u l i n g F o c u s i n g on t h e D u a l i t y o f MPL
Representatives ” ,
b o o k t i t l e = ” IEEE Symp . C o m p u t a t i o n a l I n t e l l i g e n c e i n
S c h e d u l i n g ( SCIS 0 7 ) ” ,
p u b l i s h e r = ” IEEE P r e s s ” ,
p a g e s = ”57 −64” ,
y e a r = ”2007” ,
}
i n p r o c e e d i n g s : an a r t i c l e i n a c o n f e r e n c e p r o c e e d i n g s .
Required f i e l d s : author , t i t l e , b o o k t i t l e , year
O p t i o n a l f i e l d s : e d i t o r , volume / number , s e r i e s , pages ,
a d d r e s s , month , o r g a n i z a t i o n , p u b l i s h e r , note , k e y
Hafida Benhidour (KSU)
LATEX
36 / 41
Bibliography: the BibTeX file
Example
@book { thalmann2012crowd ,
t i t l e ={Crowd S i m u l a t i o n } ,
a u t h o r ={Thalmann , D a n i e l and Musse , S o r a i a Raupp } ,
y e a r ={2012} ,
p u b l i s h e r ={ S p r i n g e r }
}
@article { pelechano2008virtual ,
t i t l e ={ V i r t u a l c r o w d s : Methods , s i m u l a t i o n , and c o n t r o l } ,
a u t h o r ={P e l e c h a n o , N u r i a and A l l b e c k , Jan M and B a d l e r ,
Norman I } ,
j o u r n a l ={ S y n t h e s i s L e c t u r e s on Computer G r a p h i c s and
Animation } ,
volume ={3} ,
number ={1} ,
p a g e s ={1−−176},
y e a r ={2008} ,
p u b l i s h e r ={Morgan \& C l a y p o o l P u b l i s h e r s }
}
Hafida Benhidour (KSU)
LATEX
37 / 41
Bibliography: citations
Citations are made using the command \cite{Label of the reference}. In
the next example, the plain style is used.
Example
I n \ c i t e { thalmann2012crowd } , the a u t h o r s p r e s e n t . . . .
I n \ c i t e { thalmann2012crowd , p e l e c h a n o 2 0 0 8 v i r t u a l } , crowd . . .
\ bibliographystyle { plain }
\ bibliography { bibliography }
Output
In [1], the authors present ... .
In [1,2], crowd ...
Hafida Benhidour (KSU)
LATEX
38 / 41
List of references
Hafida Benhidour (KSU)
LATEX
39 / 41
How to Obtain BibTeX Entries
Most online databases (IEEE, Elsevier, ACM etc.) can export
citations to the BibTeX format.
You can also use websites such as: citeulike.org or Google Scholar.
Hafida Benhidour (KSU)
LATEX
40 / 41
Help
Forums.
en.wikibooks.org, search for the command that you do not know how
to use it, you will find a lot of examples.
Hafida Benhidour (KSU)
LATEX
41 / 41