LaTeX Notes
LaTeX Notes
LaTeX Notes
1. The Not So Short Introduction to LATEX2e by Tobias Oetiker, Hubert Partl, Irene Hyna and Elisabeth
Schlegl, Version 5.06, June 20, 2016
2. https://www.sharelatex.com/learn/Main_Page
3. https://www.overleaf.com/learn/latex/Main_Page
4. The examdesign class by Jason Alexander
Soft Skill Course:
Scientific Document preparation using Latex
Syllabus
Subject Code : UOMS062
Unit 1
Overview of LaTeX - Document Classes – Formatting and Page Layout
Unit 2
Math Formulas – Math Symbols - Footnotes – Boxes
Unit 3
Environments – Sectioning – Cross references
Unit 4
Table of contents - Bibliography – Indexes – Letter Typing
Unit 5
Beamer Presentation – Poster Presentation.
References :
1. The Not So Short Introduction to LaTeX2e by Tobias Oetiker Hubert
Partl, Irene Hyna and Elisabeth Schlegl.
2. LaTex : Structured documents for TeX unofficial LaTeX references
manual July 2010.
3. https://www.sharelatex.com/ learn/Main_Page
Overview:
What is LaTeX?
Advantages of LaTeX
TeX Distributions
The set of programs that make possible to complile TeX and TaTeX documents is
called a TEX typesetting or a TEX distribution. There are many TEX distributions
available for different operating systems:
LaTeX Editors:
There are many advanced text editors specifically dedicated to LATEX for the
most popular operating systems, some of them can be downloaded for free
while others are proprietary software:
Open Source: AUCTEX, GNU TeXmacs, Gummi, Kile, LaTeXila, MeWa, TeXShop,
TeXnicCenter, Texmaker, TeXstudio, TeXworks
This specifies what sort of document you intend to write. After that, add
commands to influence the style of the whole document, or load packages that
add new features to the LATEX system. To load such a package you use the
command
\usepackage{...}
When all the setup work is done, you start the body of the text with the
command
\begin{document}
Now you enter the text mixed with some useful LATEX commands. At the end of
the document you add the
\end{document}
command, which tells LATEX to call it a day. Anything that follows this
command will be ignored by LATEX.
Document Classes :
The first information LATEX needs to know when processing an input file is the
type of document the author wants to create. This is specified with the
\documentclass command.
\documentclass[options]{class}
\begin{document}
Typing Place
\end{document}
Here class specifies the type of document to be created.
The options parameter customises the behaviour of the document class. The
options have to be separated by commas.
Example: \documentclass[11pt,twoside,a4paper]{article}
which instructs LATEX to typeset the document as an article with a base font
size of eleven points, and to produce a layout suitable for double sided printing on
A4 paper.
Document Classes
10pt, 11pt, 12pt Sets the size of the main font in the
document. 10pt is default.
a4paper, letterpaper a5paper, Defines the paper size. The default size is
b5paper, executivepaper, letterpaper.
legalpaper
While writing your document, you will probably find that there are some areas
where basic LATEX cannot solve your problem. If you want to include graphics,
coloured 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
\usepackage[options]{package}
command, where package is the name of the package and options is a list of
keywords that trigger special features in the package. The \usepackage
command goes into the preamble of the document. Modern TEX distributions
come with a large number of packages preinstalled. If you are working on a Unix
system, use the command texdoc for accessing package documentation.
The following files are may generated when you run LATEX on your input
file:
.dvi Device Independent File. This is the main result of a LATEX compile run.
Look at its content with a DVI previewer program or send it to a printer with
dvips or a similar application.
.log Gives a detailed account of what happened during the last compiler run.
.toc Stores all your section headers. It gets read in for the next compiler run and
is used to produce the table of contents.
.aux Another file that transports information from one compiler run to the next.
Among other things, the .aux file is used to store information associated with
cross-references.
.idx If your document contains an index. LATEX stores all the words that go into
the index in this file. Process this file with makeindex.
.ind The processed .idx file, ready for inclusion into your document on the next
compile cycle.
Font Size:
LATEX normally chooses the appropriate font and font size based on the logical
structure of the document (e.g. sections). In some cases, you may want to set
fonts and sizes by hand.
Font sizes are identified by special names, the actual size is not absolute but
relative to the font size declared in the \documentclass statement
Command Output
\small
\normalsize
\large
\Large
\LARGE
\huge
\Huge
Example:
Font families
By default, in standard LATEX classes the serif typeface (a.k.a. roman) font is
used. The other font typefaces (sans serif and typewriter, a.k.a. monospace) can
be used by entering some specific commands
Default font families
typeface switch
Command Output
family command
\textrm{Sample
serif (roman) \rmfamily
Text 0123}
\textsf{Sample
sans serif \sffamily
Text 0123}
typewriter \texttt{Sample
\ttfamily
(monospace) Text 0123}
Font styles
The most common font styles in LATEX are bold, italics and underlined, but
there are a few more.
switch
Style Command Output
command
\textmd{Sample
Medium \mdseries
Text 0123}
\textbf{Sample
Bold \bfseries
Text 0123}
\textup{Sample
Upright \upshape
Text 0123}
\textit{Sample
Italic \itshape
Text 0123}
\textsl{Sample
Slanted \slshape
Text 0123}
small \textsc{Sample
\scshape
caps Text 0123}
\mathbb{ } is standard command for typing set notations of set of real
numbers, complex numbers, natural numbers and integers
\mathbb{R,C,Z,N}
Spacing :
The Space Between Words :
A tilde ‘~’ character generates a space that cannot be enlarged and additionally
prohibits a line break.
Indent
If you want to indent a paragraph that is not indented, use
\indent
as the first command of the paragraph. This might come in handy when you start
a document with body text and not with a sectioning command.
Horizontal Space
LaTeX determines the spaces between words and sentences automatically. To
add horizontal space, use:
\hspace{length}
Example
Vertical Space
The following command is used for getting space between to lines.
\vspace{length}
Text Alignment
The environments flushleft and flushright generate paragraphs that are
either left- or right-aligned. The center environment generates centred text.
Emphasized Words
If a text is typed using a typewriter, important words are emphasized by
underlining them.
\underline{text}
to emphasize text. What the command actually does with its argument depends
on the context:
Paragraph formatting
The default LATEX formatting is fine and makes documents quite readable, but it
can be changed if you need a different looking document.
The size of the subsequent paragraph indents is determined by the command
\setlength{\parindent}{value}.
The length parameter that characterises the paragraph spacing is
\setlength{\parskip}{value},
There are three commands that control the line spacing:
1. \renewcommand{\baselinestretch}{value}
2. \setlength{\baselineskip}{value}
3. \linespread{value}
Example :
\documentclass{article}
\setlength{\parindent}{4em}
\setlength{\parskip}{1em}
\renewcommand{\baselinestretch}{2.0}
\begin{document}
This is the first paragraph, contains some text to test the
paragraph interlining, paragraph indentation and some other
features. Also, is easy to see how new paragraphs are
defined by simply entering a double blank space.
Hello, here is some text without a meaning. This
text should show what a printed text will look like at
this...
\end{document}
14
Paper size, orientation and margins
Paper size, orientation and margins are the most common page elements that must
be changed depending on the type of document. To do this we have use geometry
package
For example, let's create a document with legal paper size, landscape orientation
and a 2 in margin:
or
\usepackage{geometry}
\geometry{legalpaper, landscape, margin=2in}
\usepackage{geometry}
\geometry{
a4paper,
left=20mm,
top=20mm,
}
Multiple columns
To create a document with multiple columns, the package multicol provide a set of
commands for that.
\documentclass{article}
\usepackage{multicol}
\begin{document}
\bf{1 First Section}\\
All human things are subject to decay. And when fate
summons, Monarchs must obey.
\begin{multicols}{3}
Hello, here is some text without a meaning. This text
should show what a printed text will look like at this
place.If you read this text, you will get no information.
Really? Is there no information? Is there...
\end{multicols}
\end{document}
15
Page numbering
Page numbering in LATEX uses Arabic numbers by default, but this can be changed to
use Roman numerals and/or letters. You can also combine several numbering styles in a
single document. This can be done by using the command
\pagenumbering{your style}
In books, is customary to use Roman numerals for the pages before the first
chapter/section, and Arabic numbers for the rest of the document. There are two
commands available in the book document class that accomplish this:
16
\frontmatter
The pages after this command and before the command \mainmatter, will be
numbered with lowercase Roman numerals.
\mainmatter
This will restart the page counter and change the style to Arabic numbers.These two
are works for book document class only.
\documentclass{book}
\begin{document}
\frontmatter
text...
Some text...
\mainmatter
More text….
\end{document}
If your document class is not book or you need more control over the page counter
and the numbering style, see the next example:
\documentclass{article}
\pagenumbering{roman}
\begin{document}
Some text here...
Some more text here..
\pagenumbering{arabic}
More text here...
\end{document}
17
Unit 2
Math Formulas – Math Symbols - Footnotes – Boxes
Mathematical Mode:
LaTeX allows two writing modes for mathematical expressions: the inline mode
and the display mode. The first one is used to write formulas that are part of a text.
The second one is used to write expressions that are not part of a text or paragraph,
and are therefore put on separate lines.
18
Subscripts and superscripts:
The use of superscripts and subscripts is very common in mathematical expressions
involving exponents, indexes, and in some special operators. Superscripts and
Subscripts can be specified using the ^ and the _ characters. Most math mode
commands act only on the next character, so if you want a command to affect
several characters, you have to group them together using curly braces: {...}.
$ a_1^2 + a_2^2 = a_3^2 $\\
$ x^{2 \alpha} - 1 = y_{ij} + y_{ij} $\\
$ (a^n)^{r+s} = a^{nr+ns} $\\
Some mathematical operators may require subscripts and superscripts. The most
frequent cases are those of the integral \int and the summation (\sum) operators,
whose bounds are typeset precisely with subscripts and superscripts.
$\sum_{i=1}^{\infty}\frac{1}{n^s}=
\prod_p\frac{1}{1-p^{-s}} $
19
If you want equations with equation number then you should enclose them between
\begin{equation} and \end{equation}. You can then \label an equation
number and refer to it somewhere else in the text by using the \eqref command. If
you don’t want LATEX to number the equations, use the starred version of equation
using an asterisk, equation*.
20
Fractions and Binomials:
A built-up fraction is typeset with the \frac{...}{...} command. In in-line
equations, the fraction is shrunk to fit the line. This style is obtainable in display
style with \tfrac. The reverse, i.e. display style fraction in text, is made with
\dfrac. Often the slashed form 1/2 is preferable, because it looks better for small
amounts of ‘fraction material:’
Continued fractions:
The usage of fractions is quite flexible, they can be nested to obtain more complex
expressions.
The fractions can be nested
\[ \frac{1+\frac{a}{b}}{1+\frac{1}{1+\frac{1}{a}}} \]
Now a wild example
\[ a_0+\cfrac{1}{a_1+\cfrac{1}{a_2+\cfrac{1}{a_3+\cdots}}}
\]
21
Integrals, sums and limits:
Integrals:
The command \limits changes the way the limits are displayed in the integral, if not
present the limits would be next to the integral symbol instead of being on top and
bottom.
\[ \int\limits_0^1 x^2 + y^2 \ dx \]
Example
22
Multiple integrals:
To obtain double/triple/multiple integrals and cyclic integrals you must use
amsmath and esint packages.
$$\iiiint_V \mu(t,u,v,w)
\,dt\,du\,dv\,dw$$
$$\idotsint_V \mu(u_1,\dots,u_k)
\,du_1 \dots du_k$$
23
$$\sum_{n=1}^{\infty} 2^{-n} =
1$$
In similar way you can obtain expression with product of a sequence of factors
using the command.
\prod_{lower}^{upper}
$$\prod_{i=a}^{b} f(i)$$
Limits :
$$\lim_{x\to\infty} f(x)$$
24
Integral and sum limits improvement:
In inline math mode the integral/sum/product lower and upper limits are placed
right of integral symbol. Similar is for limit expressions. If you want the limits of an
integral/sum/product to be specified above and below the symbol in inline math
mode, use the \limits command before limits specification.
Improved integral
$\int\limits_{a}^{b} x^2 dx$
inside text
Improved sum
$\sum\limits_{n=1}^{\infty}
2^{-n} = 1$ inside text
Note the difference in typesetting style between text style and display style
equations:
25
In text style, enclose tall or deep math expressions or sub expressions in \smash.
This makes LATEX ignore the height of these expressions. This keeps the line
spacing even.
There are also differences between math mode and text mode. For example,
in math mode:
1. Most spaces and line breaks do not have any significance, as all spaces are
either derived logically from the mathematical expressions, or have to be
specified with special commands such as \,, \quad or \qquad
2. Empty lines are not allowed. Only one paragraph per formula.
3. Each letter is considered to be the name of a variable and will be typeset as
such. If you want to typeset normal text within a formula then you have to
enter the text using the \text{...} command.
26
entered as \alpha, \beta, \gamma, . . . , uppercase letters are entered as \Gamma,
\Delta, . . .
While the dot sign to indicate the multiplication operation is normally left out, it is
sometimes written to help the eye in grouping a formula. Use \cdot to typeset a
single centered dot. \cdots is three centered dots while \ldots sets the dots low (on
the baseline). Besides that, there are \vdots for vertical and \ddots for diagonal
dots.
The commands \overline and \underline create horizontal lines directly over or
under an expression:
The commands \overbrace and \underbrace create long horizontal braces over or
under an expression:
27
Widehats and tildes covering several characters are generated with \widetilde and
\widehat. Notice the difference between \hat and \widehat and the placement of
\bar for a variable with subscript. The apostrophe mark ’gives a prime:
Vectors are often specified by adding small arrow symbols on the tops of variables.
This is done with the \vec command. The two commands \overrightarrow and
\overleftarrow are useful to denote the vector from A to B:
Names of functions are often typeset in an upright font, and not in italics as
variables are, so LATEX supplies the following commands to typeset the most
common function names:
For functions missing from the list, use the \DeclareMathOperator command. There
is even a starred version for functions with limits. This command works only in the
preamble so the commented lines in the example below must be put into the
preamble.
28
For the modulo function, there are two commands: \bmod for the binary operator
“a mod b” and \pmod for expressions such as “x _ a (mod b):”
For binary relations it may be useful to stack symbols over each other.
\stackrel{#1}{#2} puts the symbol given in #1 in superscript-like size over #2
which is set in its usual position.
To get more control over the placement of indices in complex expressions, amsmath
provides the \substack command:
LATEX provides all sorts of symbols for bracketing and other delimiters. Round
and square brackets can be entered with the corresponding keys and curly braces
with \{, but all other delimiters are generated with special commands (e.g.
\updownarrow).
29
If you put \left in front of an opening delimiter and \right in front of a closing
delimiter, LATEX will automatically determine the correct size of the delimiter. Note
that you must close every \left with a corresponding \right. If you don’t want
anything on the right, use the invisible “\right.”:
30
List of Greek letters and math symbols
31
32
Footnotes
With the command
\footnote{footnote text}
a footnote is printed at the foot of the current page. Footnotes should always be put
after the word or sentence they refer to.
Example :
I'm writing something here to test \footnote{footnotes
working fine}
several features.
33
The command \footnote{footnotes working fine} adds a superscript to the
word right before the command and prints the corresponding footnote. You can
change the type of numbers printed by the footnote counter
The command
\renewcommand{\thefootnote}{\roman{footnote}}
sets the number styles to lowercase roman. Other possible styles are:
34
Boxes
parbox, minipage
A \parbox is a box of specific width formatted in paragraph mode.
\parbox[pos]{width}{text}
or
\begin{minipage}[pos]{width}
text....
\end{minipage}
width defines the width of the paragraph box. Text will be broken into lines so that
it fits within this width.
pos selects which baseline to join. It can be top, bottom, or center. This parameter is
often confusing to new users! See the special note below.
makebox and mbox
Makebox creates a single-line box, optionally of fixed width, but otherwise large
enough to hold its contents. mbox is the shorthand version of Makebox. You cannot
place line breaks (\\) within a Makebox.
\mbox{text}
\makebox[width][pos]{text}
The pos parameter takes a one letter value : c- center, l- flushleft, r-flushright, or s-
spread the text to fill the box.
framebox and fbox
The command \framebox behaves identically to \makebox except that it
additionally draws a box around its contents.
\fbox{text}
\framebox[width][pos]{text}
35
Unit 3
Environments – Sectioning – Cross references
Environments:
\begin{environment}
Text
\end{environment}
Environments can be nested within each other as long as the correct nesting order
is maintained.
\begin{aaa}...\begin{bbb}...\end{bbb}...\end{aaa}
The itemize environment is suitable for simple lists, the enumerate environment for
enumerated lists, and the description environment for descriptions.
\begin{itemize}
\item $A \subset B$ \verb+&+ $B\subset A \Rightarrow A = B$
\item $x\leq y$ and $y\leq x \Rightarrow x=y$
\item subset of a countable set is countable
\end{itemize}
36
\begin{itemize}
\item[$\maltese$] $A \subset B$ \verb+&+ $B\subset A
\Rightarrow A = B$
\item[$\maltese$] $x\leq y$ and $y\leq x \Rightarrow x=y$
\item[$\maltese$] subset of a countable set is countable
\end{itemize}
\begin{enumerate}
\item $A\subset B$\verb+&+ $B\subset A \Rightarrow A=B$
\item $x\leq y$ and $y\leq x \Rightarrow x=y$
\item subset of a countable set is countable
\end{enumerate}
\begin{enumerate}[(a)]
\item $A \subset B$ \verb+&+ $B\subset A \Rightarrow A = B$
\item $x\leq y$ and $y\leq x \Rightarrow x=y$
\item subset of a countable set is countable
\end{enumerate}
37
\begin{enumerate}
\setcounter{enumi}{5}
\item $A \subset B$ \verb+&+ $B\subset A \Rightarrow A = B$
\item $x\leq y$ and $y\leq x \Rightarrow x=y$
\item subset of a countable set is countable
\end{enumerate}
\includegraphics[key=value, . . . ]{file}
to include file into your document. The optional parameter accepts a comma
separated list of keys and associated values. The keys can be used to alter the width,
height and rotation of the included graphic.
38
The universe is immense and it seems to be homogeneous, in
a large scale, everywhere we look at.
\includegraphics{universe}
There's a picture of a galaxy above
The
command \graphicspath{ {images/} } tells LaTeX to look
inthe images folder. The path is relative to the current working directory - so, the
compiler will look for the file in the same folder as the code where the image is
included.
You can also set multiple paths if the images are saved in more than one folder. For
instance, if there are two folders named images1 and images2, use the command.
\graphicspath{ {./images1/}{./images2/} }
The path can also be absolute, if the exact location of the file on your system is
specified. For example:
Example
\documentclass{article}
\usepackage{graphicx}
\graphicspath{ {./images/} }
\begin{document}
The universe is immense and it seems to be homogeneous, in a large scale,
everywhere we look at.
39
\includegraphics{universe}
There's a picture of a galaxy above
\end{document}
Positioning
In the previous section was explained how to include images in your document, but
the combination of text and images may not look as we expected. To change this we
need to introduce a new environment.
\begin{figure}[h]
\includegraphics[width=8cm]{Plot}
\end{figure}
40
Parameter Position
Place the float here, i.e., approximately at the same point it occurs
H
in the source text (however, not exactly at the spot)
In the next example you can see a picture at the top of the document, despite being
declared below the text.
\begin{figure}[t]
\includegraphics[width=8cm]{Plot}
\centering
\end{figure}
41
The additional command \centering will centre the picture. The default alignment
is left.
Captioning:
Captioning images to add a brief description and labeling them for further reference
are two important tools when working on a lengthy text.
Example:
\begin{figure}[h]
\caption{Example of a parametric plot ($\sin (x), \cos(x), x$)}
\centering
\includegraphics[width=3cm]{spiral}
\end{figure}
Figures can be referenced within the text by adding a label to the figure
environment, then later use that label to refer the picture.
\begin{figure}[h]
\centering
\includegraphics[width=0.25\textwidth]{mesh}
\caption{a nice plot}
\label{fig:mesh1}
\end{figure}
As you can see in the figure \ref{fig:mesh1}, the function grows near 0. Also, in the
page \pageref{fig:mesh1} is the same example.
42
Tables :
Tables are common elements in most scientific documents, LATEX provides a large
set of tools to customize tables, change the size, combine cells, change the colour of
cells and so on. The tabular environment is the default LATEX method to create
tables.
\begin{tabular}{ c c c }
cell1 & cell2 & cell3 \\
cell4 & cell5 & cell6 \\
cell7 & cell8 & cell9
\end{tabular}
Here {c c c} tells LaTeX that there will be three columns and that the text inside each
one of them must be centred.
The tabular environment is more flexible, you can put separator lines in between
each column.
\begin{tabular}{ |c|c|c| }
\hline
cell1 & cell2 & cell3 \\
cell4 & cell5 & cell6 \\
cell7 & cell8 & cell9 \\
\hline \end{tabular}
43
{ |c|c|c| }- This declares that three columns, separated by a vertical line, are going to
be used in the table. Each c means that the contents of the column will be centred,
you can also use r to align the text to the right and l for left alignment.
\hline - This will insert a horizontal line on top of the table and at the bottom too.
There is no restriction on the number of times you can use \hline.
\begin{center}
\begin{tabular}{||c c c c||}
\hline
Col1 & Col2 & Col2 & Col3 \\ [0.5ex]
\hline\hline
1 & 6 & 87837 & 787 \\
\hline
2 & 7 & 78 & 5415 \\
\hline
3 & 545 & 778 & 7507 \\
\hline
4 & 545 & 18744 & 7560 \\
\hline
5 & 88 & 788 & 6344 \\ [1ex]
\hline
\end{tabular}
\end{center}
44
\begin{tabular}{|c|c|c|c|}
\hline
1 & 234 & 4 & 456 \\
\hline
1345 & 345 & 567 & 78 \\
\cline{2-4}
346 & 456 & 678 & 45 \\
\hline
\end{tabular}
\begin{tabular}{|c|c|c|c|}
\hline
1 & \multicolumn{3}{c|}{Value}\\
\hline
1345 & 345 & 567 & 78 \\
\hline
346 & 456 & 678 & 45 \\
\hline
\end{tabular}
Matrix
$\left(
\begin{array}{cccc}
* & * & * & * \\
* & * & * & * \\
* & * & * & * \\
\end{array}
\right)$
$\left(
\begin{array}{cccc}
1 & 2 & 4 & 5 \\
5 & 5 & 4 & 6 \\
6 & 7 & 8 & 5 \\
\end{array}
\right)$
45
$$\left[
\begin{array}{cccc}
1 & 2 & 4 & 5 \\
5 & 5 & 4 & 6 \\
6 & 7 & 8 & 5 \\
\end{array}
\right]$$
$$\left|
\begin{array}{cccc}
1 & 2 & 4 & 5 \\
5 & 5 & 4 & 6 \\
6 & 7 & 8 & 5 \\
\end{array}
\right|$$
$$\left\{
\begin{array}{cccc}
1 & 2 & 4 & 5 \\
5 & 5 & 4 & 6 \\
6 & 7 & 8 & 5 \\
\end{array}
\right\}$$
$\left(
\begin{array}{cccc}
1 & 2 & \cdots & n \\
3 & 6 & \cdots & 3n \\
\vdots & \vdots & \vdots & \vdots \\
2n+1 & 2n+2 & \cdots & m \\
\end{array}
\right)$
46
Cases
$$ d(x,y)=
\left\{
\begin{array}{ll}
0 & \hbox{ if } x = y \\
1 & \hbox{ if } x \neq y
\end{array}
\right. $$
Equation array
\begin{eqnarray}
x^2+y^2+z^2 & = & 1 \\
a x^2+b y^2+c z^2 &=& 2\\
f(x) &=& x^2+\frac{x}{2}\\
g(x,y) &=& xy^2+yx^2
\end{eqnarray}
\begin{eqnarray}
x^2+y^2+z^2 &=& 1 \\
a x^2+b y^2+c z^2 &=& 2 \\
\nonumber f(x) &=&
x^2+\frac{x}{2}\\
g(x,y) &=& xy^2+yx^2
\end{eqnarray}
\begin{eqnarray*}
x^2+y^2+z^2 &=& 1 \\
a x^2+b y^2+c z^2 &=& 2 \\
f(x) &=& x^2+\frac{x}{2} \\
g(x,y) &=& xy^2+yx^2
\end{eqnarray*}
\begin{eqnarray*}
f(x) & = & \dfrac{x^2-9}{x-3}\\
& = & \dfrac{x^2-3^2}{x-3}\\
& = & \dfrac{(x-3)(x+3)}{x-3}\\
& = & x+3.
\end{eqnarray*}
47
Quote, Quotation, and Verse
The quote environment is useful for quotes, important phrases and examples.
Printing Verbatim
The + is just an example of a delimiter character. Use any character except letters, *
or space.
48
Sections and chapters:
Documents usually have some levels of chapters and/or sections to keep its
contents organized. LATEX supports this type of organization and also
customization of the sectioning and numbering. The command
\section{your section name here}
marks the beginning of a new section, inside the braces is set the title. Section
numbering is automatic and can be disabled. LATEX can organize, number, and
index chapters and sections of document. There are up to 7 levels of depth for
defining sections depending on the document class:
-1 \part{part}
0 \chapter{chapter}
1 \section{section}
2 \subsection{subsection}
3 \subsubsection{subsubsection}
4 \paragraph{paragraph}
5 \subparagraph{subparagraph}
\part and \chapter are only available in report and book document classes.
The command \title{}, \author{} used for title and author name of the
book/article/report and the command \maketitle will print the title and author
name in your document. The \date{ } command is used for date.
\documentclass{article}
\title{Sections and Chapters}
\author{Gubert Farnsworth}
\date{\today}
\begin{document}
\maketitle
49
\section{Introduction}
This is the first section. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortisfacilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent
imperdietmi nec ante. Donec ullamcorper, felis non sodales...
\section{Second Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis
facilisissem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi
necante...
\end{document}
Unnumbered sections:
To get an unnumbered chapter, section, sub-section, etc. add an asterisk before the
opening curly brace. These will not go into the table of contents.
\documentclass{article}
\title{Sections and Chapters}
\author{Gubert Farnsworth}
\date{\today}
50
\begin{document}
\maketitle
\section*{Introduction}
This is the first section.
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Etiam lobortisfacilisis sem. Nullam nec mi et
neque pharetra sollicitudin. Praesent imperdietmi nec ante.
Donec ullamcorper, felis non sodales...
\section*{Second Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque pharetra
sollicitudin. Praesent imperdiet mi necante...
\end{document}
51
Numbered theorems, definitions, corollaries and lemmas:
\documentclass{article}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}
\begin{document}
\section{Introduction}
Theorems can easily be defined
\begin{theorem}
Let $f$ be a function whose derivative exists in every point, then $f$ is
a continuous function.
\end{theorem}
\begin{theorem}[Pythagorean theorem]
\label{pythagorean}
This is a theorema about right triangles and can be summarised in the next
equation
\[ x^2 + y^2 = z^2 \]
\end{theorem}
And a consequence of theorem \ref{pythagorean} is the statement in the next
corollary.
\begin{corollary}
There's no right rectangle whose sides measure 3cm, 4cm, and 6cm.
\end{corollary}
You can reference theorems such as \ref{pythagorean} when a label is assigned.
\begin{lemma}
Given two line segments whose lengths are $a$ and $b$ respectively there is a
real number $r$ such that $b=ra$.
\end{lemma}
52
There are three new environments defined in the preamble.
\newtheorem{theorem}{Theorem}[section]
This is the example presented in the introduction but it has the additional
parameter [section] that restarts the theorem counter at every new section.
\newtheorem{corollary}{Corollary}[theorem]
A environment called corollary is created, the counter of this new environment will
be reset every time a new theorem environment is used.
\newtheorem{lemma}[theorem]{Lemma}
In this case, the even though a new environment called lemma is created, it will use
the same counter as the theorem environment.
53
Similarly one can create the following environments
\newtheorem{example}[theorem]{Example}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{caution}[theorem]{Caution}
\newtheorem{axiom}[theorem]{Axiom}
\newtheorem{property}[theorem]{Property}
\newtheorem{remarks}[theorem]{Remark}
\newtheorem{note}[theorem]{Note}
\newtheorem{exercise}[theorem]{Exercise}
\newtheorem{notation}[theorem]{Notation}
\newtheorem{observation}[theorem]{Observation}
\documentclass{article}
\usepackage{amsthm}
\newtheorem*{remark}{Remark}
\begin{document}
Unnumbered theorem-like environments are also posible.
\begin{remark}
This statement is true, I guess.
\end{remark}
\end{document}
Proofs
Proofs are the core of mathematical papers and books and is customary to keep
them visually apart from the normal text in the document. The
package amsthm provides the environment proof for this.
\documentclass{article}
\usepackage{amsthm}
54
\begin{document}
\begin{lemma}
Given two line segments whose lengths are $a$ and $b$ respectively there
is a real number $r$ such that $b=ra$.
\end{lemma}
\begin{proof}
To prove it by contradiction try and assume that the statemenet is false,
proceed from there and at some point you will arrive to a contradiction.
\end{proof}
\end{document}
The word Proof is italicized and there is some extra spacing, also a special symbol is
used to mark the end of the proof.
\documentclass{article}
\usepackage{amsthm}
\renewcommand\qedsymbol{$\blacksquare$}
\begin{document}
\begin{lemma}
Given two line segments whose lengths are $a$ and $b$ respectively there
is a real number $r$ such that $b=ra$.
\end{lemma}
\begin{proof}
55
To prove it by contradiction try and assume that the statemenet is false,
proceed from there and at some point you will arrive to a contradiction.
\end{proof}
\end{document}
\renewcommand\qedsymbol{QED}
To print the traditional QED (quod erat demonstrandum) at the end of a proof.
Cross referencing
If you need to insert cross-references to numbered elements in the document (like
equations, sections and figures) there are commands to automate it in LATEX.
The command
\label{ }
is used to set an identifier that is later used in the command
\ref{ }
to set the reference. The \pageref{} is used for page references.
56
\newcommand{\bp}{\begin{proof}}
\newcommand{\ep}{\end{proof}}
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\N}{\mathbb{N}}
Article Preparation:
Article Format
57
Bibliography:
To create a bibliography we have use the following command:
\begin{thebibliography}
\bibitem{label} Your content….
\end{thebibliography}
\cite{label name}.
Examples
\documentclass[a4paper, 12pt]{article}
\title{Introduction to Latex}
\author{AAAAAAAAAA\footnote{First author, Email :
[email protected]} , BBBBBBBBBBB\footnote{Corresponding Author,
Email :[email protected]}\\Institute Name and Address}
\date{\today}
\begin{document}
\maketitle
\begin{abstract}
In this paper we will present introduction to Latex…
{\bf Keywords:} LaTex,TeX\\
{\bf MSI Code:}
\end{abstract}
\section{Introduction}
TeX is a typesetting markup language created by …
\section{Advantages}
Professionally crafted layouts are available, which make a document
really look as if “printed.”…
\section{LaTeX Editors}
There are many advanced text editors specifically dedicated to …
\subsection{Packages}
While writing your document, you …
\section{Conclusion}
TeX is a typesetting markup language created…
\section*{Acknowledgement}
I thank the funding agency....
\begin{thebibliography}{50}
58
\bibitem{ref1}{Author 1, Author 2 and Author 3, \emph{Book title
here}, Publisher Name, Year.}
\bibitem{ref2}{Author 1, \emph{Book Title here}, Publisher Name,
Place, Year.}
\bibitem{ref3}{Author 1 and Author 2, \emph{article title here},
Volume, Issue, Year, Page Numbers. }
\end{thebibliography}
\end{document}
\documentclass[a4paper, 12pt]{article}
\usepackage{authblk}
\title{Introduction to Latex}
\author[1]{AAAAAAAA\footnote{first author : [email protected]}}
\author[2]{BBBBBBBB\footnote{corresponding author: [email protected]}}
\affil[1]{Institute A}
\affil[2]{Institute B}
\date{\today}
\begin{document}
\maketitle
\begin{abstract}
In this paper we will present introduction to Latex…
{\bf Keywords:} LaTex,TeX\\
{\bf MSI Code:}
59
\end{abstract}
\section{Introduction}
TeX is a typesetting markup language created by …
\section{Advantages}
Professionally crafted layouts are available, which make a document
really look as if “printed.”…
\section{LaTeX Editors}
There are many advanced text editors specifically dedicated to …
\subsection{Packages}
While writing your document, you …
\section{Conclusion}
TeX is a typesetting markup language created…
\section*{Acknowledgement}
I thank the funding agency....
\begin{thebibliography}{50}
\bibitem{ref1}{Author 1, Author 2 and Author 3, \emph{Book title
here}, Publisher Name, Year.}
\bibitem{ref2}{Author 1, \emph{Book Title here}, Publisher Name,
Place, Year.}
\bibitem{ref3}{Author 1 and Author 2, \emph{article title here},
Volume, Issue, Year, Page Numbers. }
\end{thebibliography}
\end{document}
60
Unit 4
Title and Table of Contents
If you want to add an unnumbered section in table of contents, we have to use the
command
\addcontentsline.
\documentclass{article}
\title{Sections and Chapters}
\author{Gubert Farnsworth}
\begin{document}
\maketitle
\tableofcontents
\section{Introduction}
This is the first section. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Etiam lobortisfacilisis sem.
Nullam nec mi et neque pharetra sollicitudin.Praesent
imperdietmi nec ante. Donec ullamcorper, felis non
sodales...
\addcontentsline{toc}{section}{Unnumbered Section}
\section*{Unnumbered Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque
pharetra sollicitudin. Praesent imperdiet mi necante...
61
\section{Second Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque
pharetra sollicitudin. Praesent imperdiet mi necante...
\end{document}
The default title for the table of contents is "Contents", this can be changed into
whatever you need. For example the
line \renewcommand{\contentsname}{Summary} will write "Summary" instead of
the default value.
\documentclass{article}
\title{Sections and Chapters}
\author{Gubert Farnsworth}
\renewcommand{\contentsname}{Summary}
\begin{document}
\maketitle
62
\tableofcontents
\section{Introduction}
This is the first section. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Etiam lobortisfacilisis
sem. Nullam nec mi et neque pharetra sollicitudin.Praesent
imperdietmi nec ante. Donec ullamcorper, felis non
sodales...
\addcontentsline{toc}{section}{Unnumbered Section}
\section*{Unnumbered Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque
pharetra sollicitudin. Praesent imperdiet mi necante...
\section{Second Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque
pharetra sollicitudin. Praesent imperdiet mi necante...
\end{document}
63
Bibliography:
To create a bibliography we have use the following command:
\begin{thebibliography}
\bibitem{label} Your content….
\end{thebibliography}
\cite{label name}.
\renewcommand\bibname{Reference}
Example:
\begin{thebibliography}{9}
\bibitem{notes} John W. Dower {\em Readings compiled for
History 21.479.} 1991.
\bibitem{impj} The Japan Reader {\em Imperial Japan 1800-
1945} 1973: Random House, N.Y.
\bibitem{norman} E. H. Norman {\em Japan's emergence as a
modern state} 1940: International Secretariat, Institute
of Pacific Relations.
\bibitem{fo} Bob Tadashi Wakabayashi {\em Anti-Foreignism
and Western Learning in Early-Modern Japan} 1986: Harvard
University Press.
\end{thebibliography}
Indexes:
In some big documents, for example books, is customary to make an alphabetic list
containing the main terms. With LATEX and the package imakeidx, an index can
be generated quite easily.
\documentclass{article}
\usepackage{imakeidx}
64
\makeindex
\begin{document}
\section{Introduction}
In this example several keywords\index{keywords} will be used
which are important and deserve to appear in the Index\index{Index}.
Terms like generate\index{generate} and some\index{others} will
also show up.
\printindex
\end{document}
65
Output
The standard page styles are invoked in LATEX by means of the command:
\pagestyle{your style}
empty: Both the header and footer are cleared (blank) in this page style.
plain: This is the default style. The header is empty and the footer contains page
numbers in the centre.
myheadings: The footer is empty in this page style. The header contains the page
number on right side (on odd pages) or on left side (on even pages) along with
other user-supplied information; there is an exception for the first page of each
chapter, where the footer contains centred page number while the header is blank.
66
\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rhead{Share\LaTeX}
\lhead{Guides and tutorials}
\rfoot{Page \thepage}
\begin{document}
\section{First Section}
Hello, here is some text without a meaning. This text
should show what a printed text will look like at this
place. If you read this text, you will get no information.
Really? Is there no information? Is there a diffence
between this ...
\end{document}
The command \fancyhf{ } clears the header and footer, otherwise the elements
of the default "plain" page style will appear.
\rhead{ } prints the text included inside the braces on the right side of the
header.
67
\lhead{ } prints the text set inside the braces on the left side of the header.
\chead{ } is similar to the previous commands, in this case the text is centered
on the header.
\rfoot{Page \thepage} prints the word "Page" and next the page number
which is automatically set by \thepage on the right side of the footer.
\lfoot{ } prints the parameter passed inside the braces on the left -side of the
footer.
\cfoot{ } is similar to the previous two commands, prints its parameter on the
centre of the footer.
Book Preparation:
Example
\documentclass[a4paper,12pt]{book}
\usepackage{amsmath, amssymb, graphicx, enumerate, amsthm}
\usepackage{imakeidx}
\makeindex
\pagestyle{myheadings}
\pagenumbering{roman}
\title{Introduction to Latex}
\author{author name}
\begin{document}
\maketitle
\noindent
\textcopyright{} 2013, Publisher Name,\\
First Edition 2000\\
68
Second Edition 2005\\\\
\noindent
All rights reserved. This work may be distributed and or modified
under the conditions
of the License.\\\\
\noindent
ISBN No :\\
\chapter*{Preface}
Here is preface...
\tableofcontents
\chapter{Introduction}
\pagenumbering{arabic}
TeX \index{Tex} is a typesetting markup language created by Donald E.
Knuth (1977); it has extensive capabilities to typeset math. LaTeX
\index{LaTex} (pronounced lay-tekh) is an extension of TeX designed
by Leslie Lamport. Its major features include a strong focus on
document structure and the logical markup of text; automatic
numbering and cross-referencing. LaTeX enables authors to typeset and
print their work at the highest typographical quality, using a
predefined, professional layout.
\section{Advantages}
Professionally crafted layouts are available, which make a document
really look as if “printed.”The typesetting of mathematical formulae
is supported in a convenient way.
\section{LaTeX Editors}
There are many advanced text editors \index{Editors} specifically
dedicated to LATEX for the most popular operating systems, some of
them can be downloaded for free while others are proprietary
software: Open Source: AUCTEX, GNU TeXmacs, Gummi, Kile, LaTeXila,
MeWa, TeXShop, TeXnicCenter, Texmaker, TeXstudio, TeXworks
\chapter{Page Layouts}
In this chapter we will see…
\section{Formatting}
If you want to include graphics, coloured 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 command, where package is the name of the package
\index{package} and options is a list of keywords that trigger
special features in the package.
\section{Line Breaking and Page Breaking}
Books are often typeset with each line having the same length. LATEX
inserts the necessary line breaks and spaces between words by
optimizing the contents of a whole paragraph.
\section{Vertical Space}
The space between paragraphs, sections, subsections, is determined
automatically by LaTeX. If necessary, additional vertical space
between two paragraphs can be added with the command:
69
This command should normally be used between two empty lines. If the
space should be preserved at the top or at the bottom of a page, use
the starred version of the command.
\chapter{Conclusion}
TeX is a typesetting markup language created by Donald E. Knuth
(1977); it has extensive capabilities to typeset math. LaTeX
(pronounced lay-tekh) is an extension of TeX designed by Leslie
Lamport.
\begin{thebibliography}{50}
\bibitem{ref1}{Author 1, Author 2 and Author 3, \emph{Book title
here}, Publisher Name, Year.}
\bibitem{ref7}{Author 1, \emph{Book Title here}, Publisher Name,
Place, Year.}
\bibitem{ref6}{Author 1 and Author 2, \emph{article title here},
Volume, Issue, Year, Page Numbers. }
\end{thebibliography}
\printindex
\end{document}
\documentclass{letter}
\signature{Your name}
\address{Street \\ City \\ Country}
\begin{document}
\begin{letter}{Company name \\ Street\\ City\\ Country}
\opening{Dear Sir or Madam:}
\closing{Yours Faithfully,}
\ps{P.S. Here goes your ps.}
\encl{Enclosures.}
\end{letter}
\end{document}
70
The sample output is the following:
71
Exam design Class:
Exam design class is used for preparing question papers. It provides several
features useful for designing tests or question sets:
(1) Explicit markup of questions and answers;
(2) Automatically generate answer keys;
(3) Multiple versions of the same test can be generated automatically, with
the ordering of questions within each section randomly permuted so as to
minimize cheating;
\documentclass{examdesign}
To define title and information of the question paper on top we will use the
following command
\begin{examtop} . . . \end{examtop}
Fill-in-the-blank Environment:
\begin{shortanswer}
\begin{question}
Define countable set.
\begin{answer}
A set X is said to be countable if X is finite or there
exists a bijection from X to N.
\end{answer}
\end{question}
\begin{question}
What is uncountable set.
72
\begin{answer}
A set which is not countable is called uncountable
\end{answer}
\end{question}
\end{shortanswer}
\begin{truefalse}
\begin{question}
\answer{False} Every subset of a uncountable set is
countable.
\end{question}
\begin{question}
\answer{True} Every compact set is closed.
\end{question}
\end{truefalse}
\begin{multiplechoice}
\begin{question}
A matrix is singular if
\choice{determinant is non zero}
\choice{determinant is 1 }
\choice[!]{determinant is zero }
\choice{none of the above}
\end{question}
\begin{question}
A matrix is singular if
\choice{determinant is non zero}
\choice{determinant is 1 }
\choice[!]{determinant is zero }
\choice{none of the above}
\end{question}
\end{multiplechoice}
Matching Environment:
73
Example:
\documentclass{examdesign}
\usepackage{amssymb,amsmath}
\Fullpages
\NumberOfVersions{3}
\begin{document}
\begin{examtop}
\begin{center}
\textbf{University of Madras} \\
\textbf{Final Exam}\\
\textbf{Question Type \Alph{version}} \\
\textbf{November 5, 1997}
\end{center}
\noindent Name:\rule{3in}{.6pt}\\\\
\noindent Reg. No.: \rule{3in}{.6pt}
\end{examtop}
74
\answer{True} Every compact set is closed.
\end{question}
\end{truefalse}
\end{document}
75
Unit 5
Beamer Presentation :
Beamer is a LaTeX class to create powerful, flexible and nice-looking presentations
and slides. Let us start with an example.
\documentclass{beamer}
%Information to be included in the title page:
\title{Sample title}
\author{Anonymous}
\institute{ShareLaTeX}
\date{2014}
\begin{document}
\frame{\titlepage}
\begin{frame}
\frametitle{Sample frame title}
This is a text in first frame. This is a text in first frame. This is a text in first frame.
\end{frame}
\end{document}
76
The command \frame{\titlepage}, generates the title page. This page may contain
information about the author, institution, event, logo, and so on.
The frame environment creates the second slide, the self-descriptive
command \frametitle{Sample frame title} is optional.
Example for Title frame with two authors and logo on right corner.
\title[Wavelets]{Introduction to Wavelets}
\institute[RIASM]
{
\inst{1}
Ramanujan Institute for Advanced Study in Mathematics\\
University of Madras
\and
\inst{2}
Department of Statistics\\
University of Madras
}
\logo{\includegraphics[height=1.5cm]{lion-logo.png}}
77
\title[Wavelets]{Introduction to Wavelets}
The title of your presentation must be inside braces. You can set an optional shorter title in the
square brackets: in the example, this is Wavelets.
\subtitle
Subtitle for you presentation. This can be omitted if unnecessary
\institute[RIASM]{\inst{1}Ramanujan ...}
In the argument of this command, you can declare the institute each author belongs to. The
parameter inside brackets, the acronym of the institute/university, is optional. Then the name of
the institute is added inside braces; if there's more than one institute they must be separated with
an \and command. The \institute command is optional, but it is required for the superscripts
inserted by the \inst commands in the previous code.
\logo{\includegraphics...}
This adds a logo to be displayed. In this theme, the logo is set at the lower right corner. You can
use text, or include an image.
Usually when you have a long presentation, it's convenient to divide it into sections or even
subsections. In this case, you can add a table of contents at the beginning of the document. Here is
an example:
\begin{frame}
\frametitle{Table of Contents}
\tableofcontents
\end{frame}
78
Themes and colorthemes
It's really easy to use a different theme in your slideshow. For example,
the Madrid theme (most of the slideshows in this article use this theme) is set by
adding the following command to the preamble:
\usetheme{Madrid}
Below are two more examples:
Berkeley beamer
theme
79
Copenhagen
beamer theme
The themes can be combined with a colortheme. This changes the colour used for
different elements.
\documentclass{beamer}
\usetheme{Madrid}
\usecolortheme{beaver}
80
It's also possible to put the table of contents at the beginning of each section and
highlight the title of the current section
\AtBeginSection[]
{
\begin{frame}
\frametitle{Table of Contents}
\tableofcontents[currentsection]
\end{frame}
}
{
\begin{frame}
In this slide \pause
81
Highlighting important sentences/words
In a presentation is a good practice to highlight the important points to make it easier for your
audience to identify the main topic.
\begin{frame}
\frametitle{Sample frame title}
\begin{block}{Remark}
Sample text
\end{block}
\begin{alertblock}{Important theorem}
Sample text in red box
\end{alertblock}
\begin{examples}
Sample text in green box. The title of the block is ``Examples".
\end{examples}
\end{frame}
82
Fonts
You can change several parameters about the fonts. Here we will mention how to resize them and
change the type of font used.
The font size can be passed as a parameter to the beamer class at the beginning of the document
preamble. Below is an example of how a 17 font size looks like.
\documentclass[17pt]{beamer}
\usepackage[utf8]{inputenc}
\usetheme{Madrid}
\usecolortheme{beaver}
Available font sizes are 8pt, 9pt, 10pt, 11pt, 12pt, 14pt, 17pt, 20pt. Default font size is 11pt (which
corresponds to 22pt at the full screen mode).
83
To change the font types in your beamer presentation there are two ways, either you use a font
theme or import directly a font from your system. Let's begin with a font theme:
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usefonttheme{structuresmallcapsserif}
\usetheme{Madrid}
\usepackage{bookman}
\usetheme{Madrid}
84
The command \usepackage{bookman} imports the bookman family font to be used in the
presentation. The available fonts depend on your LATEX installation, the most common are: mathptmx,
helvet, avat, bookman, chancery, charter, culer, mathtime, mathptm, newcent, palatino, pifont and
utopia.
Columns
Sometimes the information in a presentation looks better in a two-column format. In such cases use
the columns environment:
\begin{frame}
\frametitle{Two-column slide}
\begin{columns}
\column{0.5\textwidth}
This is a text in first column.
$$E=mc^2$$
\begin{itemize}
\item First item
\item Second item
\end{itemize}
\column{0.5\textwidth}
This text will be in the second column
and on a second tought this is a nice looking
layout in some cases.
\end{columns}
\end{frame}
85
After the frame and frametitle declarations start a new columns environment delimited by
the \begin{columns} \end{columns}. You can declare each column's width with
the \column{0.5\textwidth} code, a lower number will shrink the width size.
86