Apr 1, 2017 - To include images, you must use graphicx package. Figure \ ref { fig : monalisa } shows the painting . \ begin { figure }. \ centering % To center.
Writing scientific papers using LATEX. Introduction to Latex and Beamer Hafida Benhidour Department of computer science King Saud University
04/01/2017
1 / 78
Contents
1
Introduction to LATEX
2
Introduction to Beamer
2 / 78
Introduction to LATEX
LATEX 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. The final document is obtained by converting the source file (.tex file) into a pdf file.
3 / 78
Advantages of Using LATEX
Professional typesetting: best output. It is the standard for scientific documents. Processing mathematical (& other) symbols. Knowledgeable and helpful user group. Its FREE! Platform independent.
4 / 78
Installing LATEX
Linux: 1 2
Install TeXLive from your package manager. Install a LATEX editor of your choice: TeXstudio, TexMaker, etc.
Windows: 1 2
Install MikTeX from http://miktex.org (this is the LATEX compiler). Install a LATEXeditor of your choice: TeXstudio, TeXnicCenter, etc.
Mac OS: 1 2
Install MacTeX (this is the LATEX compiler for Mac). Install a LATEX editor of your choice.
5 / 78
TeXstudio
6 / 78
Structure of a LATEX Document All latex documents have the following structure: \ documentclass [ . . . \ usepackage { . . . }
]{...}
\ b e g i n { document } ... \ end { document }
Commands always begin with a backslash \: \documentclass, \usepackage. Commands are case sensitive and consist of letters only. Some commands have parameters. Square brackets [ ] after the command name are for optional parameters. Curly braces { } after the command name are for required parameters 7 / 78
The command: \documentclass article report \ d o c u m e n t c l a s s [ o p t i o n s ] { beamer } book letter
First line of all LATEX documents. Specifies the type of the document: article (research paper), report (multi-chapter document), book (for books), beamer (for presentations).
[options] can be used to set font size (10, 11, or 12 pt), set paper size, use one or two columns, etc. \ d o c u m e n t c l a s s [ 1 2 pt , a 4 p a p e r , twocolumn ] { a r t i c l e }
Most publishers (Springer, Elsevier, IEEE, ACM etc.) have their own document classes. These are predefined classes. 8 / 78
Packages \ usepackage { package }
Packages add new features and commands to LaTeX. Common packages: amsmath, amssymb: for math symbols. graphicx: for including graphics and images. \ documentclass { report } \ usepackage { c o l o r } \ usepackage { graphicx } \ b e g i n { document } ... \ end { document }
9 / 78
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.
10 / 78
A Simple LATEX Document
The following is a very basic LATEX document:
This is some sample text.
\ 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 gives the following output: 1
11 / 78
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
12 / 78
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. \beginkeywords can be used with the classdocument IEEEtran.
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 }
13 / 78
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 } ... \ s u b s e c t i o n { T i t l e o f t h e sub−s e c t i o n } ... \ s e c t i o n { T i t l e of second s e c t i o n } ... \ subsection {...} ... \ subsubsection { . . . } ...
LATEXformates the section titles and numbers them according to the document class being used.
14 / 78
A Simple LATEX Document The following is a sample of a LATEX document (.tex file): \ 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 \ 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 }
...
15 / 78
A Simple LATEX Document Converting the (.tex) file to obtain the pdf file:
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
16 / 78
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 . . .
LATEX updates 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. 17 / 78
Spaces and line breaks Example Tex document: Skip a l i n e to t o r e t u r n t o a new l i n e . Here i s a new p a r a g r a p h .
Pdf document: Skip a line to to return to a new line. Here is a new paragraph.
Note: Use \\ to return to the line. Use \newpage to insert an empty page in your document. 18 / 78
Font styles Example Input: \textit{ italic } \ t e x t b f { bold } \ t e x t s c { small caps } \ texttt { typewriter } \emph{ e m p h a s i s } \ underline { underline }
Output: italic bold small caps typewriter emphasis underline 19 / 78
Special characters Use the percentage to write a comment. Input: The n e x t s e n t e n c e i s a comment . %The comment w i l l n o t be displayed .
Output: The next sentence is a comment. Use \ before most special characters to write them. Input: \{ \}
\$ \& \
\# \%
Output: {}$& #%
20 / 78
Inserting Tables To include tables, you must use the following commands. \ begin { table } \ c a p t i o n {An Example o f a Table } \ l a b e l { t a b l e example } \ centering \ begin { tabular }{| c | c |} \hline S t u d e n t & Grade \\ \ h l i n e 12 & 13 \\ \hline \ end { t a b u l a r } \ end { t a b l e } Table \ r e f { t a b l e example } shows a t a b l e .
Table : An Example of a Table
Student 12
Grade 13
The results of the experiments are shown in Table 1.
21 / 78
Inserting Tables You can use Quick Tabular of TexStudio (go to Menu Wizards) to create a table and insert it in your document. You can also use the following website to create tables: http://www.tablesgenerator.com/ to create a table and insert it in your document. You may need to add the package \usepackage{multirow} before \begin{document}
Table : Table created using Tablegenerator
a
b
c d
22 / 78
Inserting Images To include images, you must use graphicx package. Figure 1 shows the Figure \ r e f { f i g : monalisa } painting. 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 ] { . / F i g u r e s / 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 }
Figure : The Monalisa
23 / 78
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. 24 / 78
Inserting Images Figure 2 shows the painting rotated. 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 , a n g l e= 4 5 ] { . / Figures / monalisa . jpg } % 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 }
Figure : The Monalisa rotated
25 / 78
Typesetting Mathematical Equations
Latex is extremely good at typesetting math equations. Equations are written as text. Inline equations (equations within the text) are written between $ and $.
Example Tex document: Assume t h a t $ \ a l p h a x +
\ b e t a y =1$ , t h e n
Pdf document: Assume that αx + βy = 1, then
26 / 78
Typesetting Mathematical Equations Equations on a separate line are enclosed between \[ and \].
Example Tex document: Assume t h a t : \[ \ a l p h a x + \ b e t a y =1, \] then . . .
Pdf document: Assume that: αx + βy = 1, then ...
27 / 78
Typesetting Mathematical Equations Numbered equations are written within the equation environment.
Example Tex document: Assume t h a t : \ begin { equation } \ l a b e l { eq : my−e q u a t i o n } %