3- Start LaTeXing - Mobile Cloud Family

advertisement
Preparing scholarly text
using TexStudio
By
Saeid Abolfazli
Faculty of Computer Science and IT, University Malaya
Malaysia. Email: Abolfazli.s@gmail.com
Website: www.mobilecloudfamily.com
LaTeX Blog: http://www.mobilecloudfamily.com/blog
Outline
 Introduction to TexStudio
 Customizing TexStudio environment
 Structure of a tex file
 Compiling a tex file
 Title
 Authors name and affiliations
 Abstract
 Keywords
 Sections
 Table
 Figure
 References
2
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
1- Introduction to TexStudio
3
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Change Menu Language, Font
and Size
Options-> Configure TeXstudio -> “General"
4
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Change typing font and size
Options-> Configure TeXstudio -> "Editor"
5
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Change editors colors
Options-> Configure TeXstudio -> "Editor"
6
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
2- Structure of a tex file
\documentclass{document type/or class
name}
7
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
2- Structure of a tex file
\documentclass{document type/or class
name}
For instance
\documentclass{article} or
\documentclass{ieeetran}
8
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
2- Structure of a tex file
\documentclass{article}
\begin{document}
Hello world!
\section{Section 1}
Your text appears here
\subsection{Subsection 1}
Your text appears here
Figures
Tables
References
Bibliography and biography
\end{document}
9
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Can be anywhere in text
Structure of a tex file Con’t
Commonly used document types are:
-
Article
-
Book
-
Special class name like IEEEtran
Allowed hierarchies
•
Article: \part{}, \section{}, \subsection{}, \subsubsection{},
\paragraph{}, \subparagraph{}.
•
Book: \part{}, \chapter{}, \section{}, \subsection{},
\subsubsection{}, \paragraph{}, \subparagraph{}.
•
I will get back to this topic later in this workshop
10
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Make a New Tex file
You can make a new file from one of the
following options:
1- Wizard->quick start
2- Menu Bar File-> New from Template->
3-Scripting
Tips: 1- LaTeX is case sensitive
2- All tags in LaTeX are lower case
11
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Customize a tex document
[options] will be used to manipulate a
command.
\documentclass[options]{article}
\begin{document}
Hello world!
\end{document}
If you want to alter the document like paper
size, font size , etc you should customize the
\documentclass command
12
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
The most common options for the standard document
classes are listed in the following table:
Sets the size of the main font in the document.
If no option is specified, 10pt is assumed.
a4paper,
Defines the paper size.
letterpaper, The default size is letterpaper. A5paper, B5paper,
...
executivepaper, and legalpaper can be specified.
onecolumn, Instructs LaTeX to typeset the document in one column or
twocolumn two columns.
Specifies whether double or single sided output should be
generated. The classes article and report are single sided
twoside,
and the book class is double sided by default. Note that
oneside
this option concerns the style of the document only. The
option twoside does not tell the printer you use that it
should actually make a two-sided printout.
makes LaTeX indicate hyphenation and justification
problems with a small square in the right-hand margin of
draft
the problem line so they can be located quickly by a
human.
It also suppresses the inclusion of images and
13 Prepare Scholarly
Articles Using LATEX - By Saeid Abolfazli
shows only a frame where they would normally occur.
10pt,12pt
Hands-on Practice 1
 Create a simple tex file
 Make two sections:
1- Introduction
Write one paragraph text
2- Background
Write one paragraph text
Under background create another subsection called
Literature Review
Write one paragraph text
14
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Compiling the Tex file
1. Press F1 to build and View
2. F11 To run the BibTex command (if you have
references in your file)
3. F6 for Compile
>>>> Lets compile our file
Tip:
 If you just changed your database file,
it is recommended to remove the old .bib file of your
manuscript before you continue.
15
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
LATEX Common File Formats
.tex
.aux
.bbl
.bib
.dvi
.toc
.lof
.lot
.sty
.bst
.cls
LaTeX or TeX input file. It can be compiled with latex.
Usually stores information associated with crossreferences.
Bibliography file output by BiBTeX and used by LaTeX
Bibliography database file
Device Independent File. This is the main result of a
LaTeX compile run with latex.
Stores all your section headers. It gets read in for the
next compiler run and is used to produce the table of
contents.
This is like .toc but for the list of figures.
And again the same for the list of tables.
LaTeX Macro package. This is a file you can load into
your LaTeX document using the \usepackage
command.
Prepare Scholarly
Articles Using
LATEX - By Saeid Abolfazli
BiBTeX
style
file.
Class files define what your document looks like. 16
Latex Commands
\commandname[option1,option2,...]{argument}
Example:
\includegraphics[height=2in]{image1.eps}
17
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Document class Options
 Font size (10pt, 11pt, 12pt)
 Paper size and format (a4paper, letterpaper, etc.)
 Draft mode (draft)
 Multiple columns (onecolumn, twocolumn)
More information available at
http://texblog.org/2013/02/13/latex-documentclass-optionsillustrated/
18
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Example
\documentclass{article}
\documentclass{ieeetran}
\documentclass[onecolumn]{ieeetran}
\documentclass[draft]{ieeetran}
\documentclass[12pt,a4paper,oneside,draft]
{report}
19
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Hands-on Practice 2
 Make your article twocolumn
 Change the font to 12pt
 Change the paper to draft mode
20
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Define the Title
 \begin{document}
\title{Latex Tutorial}
By using this command, you will not be able
to see the title. You have to ask Latex to
build and show the title to you. But usually
title includes some data about authors,
name, affiliation, address, email and so on.
21
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Write the Authors Name
 \author{Saeid Abolfazli}
Authors with Affiliation and address?
 \author{Saeid
Abolfazli \\
University of Malaya}
 Run Latex
Still we cannot see the title. Right?
What is the next step?
22
Generating the title with all relevant
informations
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Making the Title
\maketitle
23
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Define Abstract
\begin{abstract}
This is the paper's abstract (If any)
\end{abstract}
24
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Italic and Bold Fonts
If you wanna change the text to italic and
bold, use
 \textit{Italic}
 \textbf{Bold}
25
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Defining Keywords
 There is No tag for keywords,
 we use Italic font
 \textit{Keywords:} Latex Tutorial,
Introduction to Latex, BibTex,
University of Malaya
26
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Hands-on Practice 3
27
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Sectioning of the tex file
Note: Latex is case Sensitive (meaning that do not use capslock)
 \part
 \chapter (report style only)
 \section
 \subsection
 \subsubsection
 \subsubparagraph (milstd and book-form styles only)
 \subsubsubparagraph (milstd and book-form styles only)
Tip: using * makes the title to appear without numbering
 \section{Section 1} 
1. Section 1
 \section*{Section 1}
Section 1
28 Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Example
 \section{Introduction}
 \subsection{Motivation}
 \subsubsection{Challenges in this
section}
 Help: If you forgot the sectioning
order, you can use the menu bar
 Latex-> …
29
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Hands-on Practice 3
30
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Feed back
Do you think Latex is difficult?
If you use to it, you will love it.
Do practice from now please….
31
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Bullet Lists in Latex
If you are interested to have bullet Items, you can use
itemize environment.
\begin{itemize}
\item First Item
\item Second Item
\end{itemize}
Note: \item creates a default amount of indent.
32
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Hands-on Practice 4
33
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Numbered Lists in Latex
If you are interested to have bullet Items, you can use
itemize environment.
\begin{enumerate}
\item First Item
\item Second Item
\end{enumerate}
Note: \item creates a default amount of indent.
34
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Hands-on Practice 5
35
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
REST
Take a deep
breath and rest
for 5 minutes
36
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Packages in LATEX
 While writing your document, you will probably find that
there are some areas where basic LaTeX cannot solve
your problem. E.g., if you want to include graphics,
colored text or source code from a file into your
document, you need to enhance the capabilities of
LaTeX. Such enhancements are called packages.
Packages are activated with the following command.
\usepackage[options]{package name}
 For instance, \usepackage{graphicx} help you add
images to your file. Without including this package, we
can not insert pictures.
37
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Including jpg, png, pdf Graphics
You should use pdflatex compiler to insert these files
.pdf
and include it in your text using graphicx package.
38
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Steps to include a graphic file
1- Copy your file in your working directory where you have .tex file.
If not, you should provide full address while inserting figure
2- Use \usepackage{graphicx} before \begin{document} command.
3- Create a graphical environment by
\begin{figures}
commands
\end{figures}
439
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Steps to include a graphic file
4-Use the following commands to insert your file
\includegraphics[options]{name}
40
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Caption for Figures
Use
\caption{This is an optional Text for Caption} for
optional caption
41
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Hands on Practice 6
Insert image 3 into your file
Put “My First Figure” as caption
42
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Options for including graphics
\includegraphics[options]{name}
Example:
\includegraphics{image1}
\includegraphics[width=4in,height=3in]{image1}
\includegraphics[scale=0.5, angle=90]{image1}
43
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Practice 7
 Change height and width of figure to
height=0.09in,
width=0.9in
 Change its scale to 0.7
44
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
A problem in Figures
Do you have this problem?
 Placing figures where we want to appear
45
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Placement Specifiers
We need to tell LaTex where to put our graphics. TO do so,
the specifiers are used
Top of the page
t
Button of the page
b
Here
h
approximately at the same point it occurs in
the source text , but not exactly at the point
Exactly here
H
Requires the float package,
\usepackage{float}.
Override default
parameters
!
Override internal parameters LaTeX uses for
determining "good" float positions
You can mix few of these specifiers to make a better one.
46
I will explain more on 3rd day
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Placement Specifiers
Where to put specifiers?
\begin{figure} [placement specifier]
47
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Hands-on Practice 8
Insert a file named image1.jpg into your latex file. Command LaTex to
keep your file in top section where there is space. Override internal
parameters.
\begin{figure}[!ht]
\caption{This is my first Image}
\includegraphics{image1}
\end{figure}
Rotate image 90 degree
Resize image to half
48
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Justifying a figure in the text
\centering
\begin{center} \end{center}
\begin{flushleft} \end{flushleft}
\begin{flushright} \end{flushright}
\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{image1}
\caption{A picture ….}
\end{figure}
49
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Hands-on Practice 9
Create a document with following detail:
1- two-coloumn article
2- title: Hands-on Practice 9
3- Author: Your Name, My Name
4- Address and Affiliation: Your address and affiliation in 2 lines.
5- Abstract: Write 2 lines text as you wish
6- Define 5 keywords: Latex, Tutorial, Latex Workshop, Mobile
Cloud Computing Research Group
7- Create the introduction section including 5 lines.
8- Define a figure environment
9- Extend the figure environment to two columns
10- Put your image on highest available space.
11- Define a caption: This is a good and complex practice
12- insert image1.eps into your tex file.
13- the files size should be 4*3 inches .
50
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Including an eps File
-
The best format of figures in LaTeX is eps which is a vector
format.
-
.eps (encapsulated post script) does not work with pdflatex
-
You should change your compiling method
For .eps files to be successfully built, you have many solutions,
A) should use Latex interpreter as following (it is a default
mode)
Go to Options Configure TexStudio Quick Build
Change the option to Latex+DviPS+Ps2PDF+pdf viewer
B)You can also use epstopdf package to use pdflatex
C) Use XeLaTex
51
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Useful Tips
1- If you want to extend the image to two columns, you should use
* while defining the figure environment.
\begin{figure*}
\caption{your diagram caption}
\end{figure*}
2- Use \listoffigures to add a list of the figures in the beginning of
the document.
52
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
REST and Practice for 15 minutes
 Please do revise some of
the topics we just learnt.
 You can make the
following practice
53
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
OpenOffice
 Drawing layered architectures, diagram, and flowcharts
are essential in majority of papers and thesis.
 Apache OpenOffice is essential tool for designing such
figures.
 See how can we draw a flowchart
54
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Draw This one using OpenOffice

55
This figure appeared in a paper accepted for publication in journal of IEEE Communication
surveys and tutorials and follows copyright laws.
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Draw This one using OpenOffice
 This figure appeared in a paper accepted for publication in journal of IEEE
Communication surveys and tutorials and follows copyright laws.
56
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Selection and Exporting
 Tips:
 Always try to draw the figure in big scale
 Shrinking the figure size does not reduce the quality, but
increasing the size does.
 When exporting the output, select the area you want to
export. Make sure to click the selection only checkbox at
the export window.
 If you do export the file is very very big, the laTeX will
be unable to resize it. If you saw such thing, just reduce
the size.
 Try to use true type font suggested by the publisher.
 IEEE suggest times roman.
57
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Practice OpenOffice 1

Draw the following figures in OpenOffice
These figure appeared in a published paper in IEEE Mobcc’12 and follows copyright
laws.
58
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Tables in Latex
1- Define a table Environment
\begin{tabular}[pos]{table spec}
\end{tabular}
POS argument specifies the vertical position of the
table
59
b
bottom
c
center (default)
t
top
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Example
\begin{tabular}[b]{c c c c l l l r}
Means the table should be at top of the
page, it has 8 columns with
4 centered, 3 left, and 1 right justified
content.
60
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Table Specifications
\begin{tabular}[pos]{table
spec}
\end{tabular}
table spec argument tells LaTeX the alignment to
be used in each column and the vertical lines to
insert.
l
left-justified column
c
centered column
r
right-justified column
p{width}
paragraph column with text vertically aligned at the top
m{width}
paragraph column with text vertically aligned in the middle (requires array
package)
b{width}
paragraph column with text vertically aligned at the bottom (requires array
package)
|
vertical line
||
double vertical line
61
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Example
\begin{tabular}{c l r c l l l r}
Body
\end{tabular}
 This example draws a table with 8 cols with
different justifying.
62
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Introducing the table content
 Separating Cells, inserting new line.
&
column separator
\\
start new row (additional space may be specified
after \\ using square brackets, such as \\[6pt])
\hline
horizontal line
\newline
start a new line within a cell (in a paragraph column)
\cline{i-j}
partial horizontal line beginning in column i and ending in
column j
63
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Hands-on Practice 9
Define a table as following:

Has 5 cells,

All are left justified,

The table is located on buttom of the page,

The table should be expanded to the width of two columns,
\begin{tabular}[b]{c c c}
No & Description & Buy & Sell & Profit \\ \hline
1 & Laptop & 1000 & 1500 & 500 \\ \hline\begin{table}[b]
\caption{caption 1}
\begin{tabular}[c]{|l | l | l | l |l |}\hline
No & Description & Buy & Sell & Profit \\ \hline
1 & Laptop & 1000 & 1500 & 500 \\ \hline
\end{tabular}
\end{table}
64
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Hands-on Practice 10
 Draw the following table
65
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
\begin{tabular}[t]{c |c |c| c| c}
No & Description & Buy & Sell & Profit \\ \hline
1 & Laptop & 1000 & 1500 & 500 \\ \hline
2 & USB DISK & 100 & 150 & 50 \\ \hline
3 & Laptop & 1000 & 1500 & 500 \\ \hline
4 & USB DISK & 100 & 150 & 50 \\
\end{tabular}
66
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
5 Min Break
Mathematical
Equations in Latex
67
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Simple math in LaTex
Use $ Formula $ to define short math block
Example:
X+Y$X+Y$
X2  X_{2}
X4  X^2
(X2 + Y3)3  (X_{2} + Y_{3})^3
a
b  \frac{a}{b}
a’ {a}’
68
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
a’’ {a}’’
\therefore
\sin \cos \tan \cot
Greek
Letters: \alpha, \Alpha, \beta, \Beta, \gam
ma, \Gamma,
\pi, \Pi, \phi, \varphi, \Phi
69
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Hands-on Practice 11
Generate a code for following formula
$\alpha ^{3} + \Theta ^{5} = \gamma $
$ \sum_{x=0}^{10} X^2 + Y2 $
70
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
$\int_{a}^{b} Z^ \frac{x+y}{z+t} +
\int_{c}^{d} \sqrt{\frac{x+y}{z+t}}$
71
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Mathematical Equations in Latex
1. Include amsmath package. No need to
use $
2. Create a math environment as following:
\begin{math}
Math codes here
\end{math}
3. Generate the math code and paste in
math block.
\sum (X ^2 + Y^ 5)
72
Tip: Do not put any space between lines
in code
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
It is very tedious to write the equations
manually.
How easily generate complex math code?
73
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Easy equation generation
 It is boring and complicated to
program for mathematic equations.
 The best way is to use the following
portal where you can easily type your
formula and copy the code to the
latex file.
 http://www.codecogs.com/latex/eqn
editor.php
74
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Cross Referencing in LaTex
Once you created your sections, Tables, Figures, and
Equations, you should be able to refer to them
automatically. In order to do so, we use cross
referencing.
1- Labeling entities (\label{name})
2- Referring to labeled entities (\ref{name})
\section{Introduction} \label{intro}
The remainder of this article is as follows: Section
\ref{intro} describe….
75
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Labeling Equations
 If you need to number each formula and refer to
them in tex you can use the following method.
\begin{eqation} \label{1}
C_{DA}=\sum_{i=1}^{n} C_{i}
\end{equation}
From (\ref{1}) we conclude that….
76
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Some Handy Tips
77
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Relating authors and their affiliations
using * or other symbols
\documentclass{article}
\begin{document}
\title{Latex Tutorial}
\author{Saeid \thanks{This paper is submitted }
\maketitle
\end{document}
78
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Numbers instead of symbols?
 Put this commands before \maketitle
\makeatletter
\let\@fnsymbol\@arabic
\makeatother
79
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Troubleshooting Strange Errors in
Latex.
 Strange Errors: There are some cases that your
commands are not executing and some strange error
messages appear while you are sure that everything is
fine. In this case, close the file, quit the application,
remove all generated file except .bib and .tex files.
 Open the .tex file and compile from the beginning. If
not, try other error tracing approaches.
80
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
If you have any question visit
www.mobilecloudfamily/latex
81
Prepare Scholarly Articles Using LATEX - By Saeid Abolfazli
Download