Download as pdf or txt
Download as pdf or txt
You are on page 1of 67

LATEX: An Introduction to Malaysian Academicians

1 What is LaTeX
LaTeX, which is pronounced ’Lah-tech’ or ’Lay-tech’, is a document preparation
system for high-quality typesetting. It is most often used for medium-to-large
technical or scientific documents but it can be used for almost any form of pub-
lishing.

LaTeX is not a word processor! Instead, LaTeX encourages authors not to


worry too much about the appearance of their documents but to concentrate
on getting the right content. LaTeX is based on the idea that it is better to
leave document design to document designers, and to let authors get on with
writing documents. LaTeX is the de facto standard for the communication and
publication of scientific documents and is available as free software.

How we can benefit from LaTeX?


LaTeX is well-suited for scientific and technical documents. Its superior type-
setting of mathematical formulas is legendary. It produces very high quality
output, it is extremely stable, and handles complex documents easily no matter
how large they are.

Further remarkable strengths of LaTeX are its cross-referencing capabilities,


its automatic numbering and generation of list of contents, figures and tables,
indexes, glossaries and bibliographies.

Open source
The source of LaTeX is completely free and readable for everyone. This enables
to study and to change everything from the core of LaTeX to the latest extension
packages. There’s a huge LaTeX community with a lot of friendly, helpful
people. Even it cannot benefit from the open source code directly, they can
read the sources and assist.

Portability
LaTeX is available for nearly every operating system such as Windows, Linux,
Mac OS X and many more. Its format is plain text - readable and editable, on
all systems.

LaTeX itself doesn’t have a graphical user interface; that’s one of the reasons
why it’s so portable. Can choose any text editor. There are many editors even
specialized in LaTeX, for every operating system.

LaTeX generates PDF output - printable and readable, on most computers and
looks identical regardless of the operating system. Besides PDF, it supports

2017
c LPSK, INSPEM, UPM 1
LATEX: An Introduction to Malaysian Academicians

DVI, PostScript, and HTML output, preparing the ground for distribution both
in print and online, on screen, electronic book readers, or smart phones.

Protection for your work


LaTeX documents are stored in human readable text format, not in some obscure
word processing format, that may be altered in a different version of the same
format. Word processor document could be infected with viruses, malicious
macros could destroy the data. Did you ever hear of a virus ”hiding” in a text
file? LaTeX is not threatened by viruses.

What are the challenges?


Though writing LaTeX looks like programming, dont be afraid. Soon will know
the frequently used commands. Text editors with auto completion and keyword
highlighting will support. They might even provide menus and dialogs with
commands.

Why LaTeX is better choice than Microsoft Word?


Microsoft Word is for general purpose documentation. As against that LaTeX
is a strongly typed language engineered for technical documentation. In crude
sense some of the advantages of using LaTeX is the programming approach
to putting your stuff in place. Various packages help in creating a sharp and
nicely written articles, reports, etc. There are certain commands for many
mathematical building blocks. For graphics again we have packages and some
more commands. But once you get to know these commands, writing and
creating high quality documents is but a walk in a dream. Microsoft Word
does have many facilities, but the format and the way one uses it is very dis-
ordered and not so sturdy. Across different versions, many basic properties like
alignment, are found to be varying giving one a not so uniform rendering.

LaTeX is for science, Word for general use (and even for that...) LaTeX makes
it very simple to handle equations, figures, bibliographies, indexes, etc. With
LaTeX you focus on the content of the document and let the program handle
how the output is formatted. LaTeX is more stable, especially if writing thesis
or reports. You can get enough details on Latex from net. A lot of user friendly
and easy to use interfaces are available. If you want to write a paper with LaTeX
you can start from a template like this below.

\title{Title of the paper}


\author{Author}
\date{11 November 2013}

\begin{document}
\maketitle

2017
c LPSK, INSPEM, UPM 2
LATEX: An Introduction to Malaysian Academicians

\section{Introduction}
Write the introduction here...

\section{Title of first section}


Write the first section of the paper here...

\section{Title of second section}


Write the second section of the paper here...

\subsection{Title of the subsection}


This is a subsection of the second section

\subsection{Title of the subsection}


This is another subsection of the second section

\section{Conclusions}
The conclusions are here...

\end{document}

About the software


Although these pieces of software may be bundled together in a package, you
need three or four distinct programs to constitute a fully functional LaTeX
system.
1. A suitable editor for preparing and modifying your input files.
2. The TeX processor itself.
3. A program to display the compiled version of your file on screen.
4. A program to convert the compiled file into a form suitable for sending to
your printer.
The wonderful thing about all this software is that it is in the public domain.
You can download it for free from any one of many archive sites maintained at
both academic institutions and commercial Internet servers around the world.

2 Getting started
General parts
The latex code consists of two general parts:

1. The preamble consists of the parameters for the document, i.e. the mar-
gins, the font, the spacing, the document type, supplementary packages,

2017
c LPSK, INSPEM, UPM 3
LATEX: An Introduction to Malaysian Academicians

etc. Some Latex commands require the use of a package defined in the
preamble.
2. The body contains the text, figures, tables, etc.

Let’s start with the simplest working example:


\documentclass{article}

\begin{document}
First document. This is a simple example, with no
extra parameters or packages included.
\end{document}
The first line of code declares the type of document, in this case is a arti-
cle. Then enclosed in the \begin{document}...\end{document} tags you must
write the text of your document.

The preamble of a document


In the previous example the text was entered after the \begin{document} com-
mand. The part of your .tex file before this point is called the preamble. In the
preambleyou define the type of document you are writing, the language and
several other elements. For instance, a normal document preamble would look
like this:
\documentclass[12pt, letterpaper]{article}
\usepackage[utf8]{inputenc}

\title{First document}
\author{Hubert Farnsworth \thanks{funded by the ShareLaTeX team}}
\date{February 2014}
Below a detailed description of each line:

1. \documentclass[12pt, letterpaper] {article}


As said before, this defines the type of document. Some additional param-
eters inside brackets and comma-separated can be passed to the command.
In the example, the extra parameters set the font size (12pt) and the pa-
per size (letterpaper). Of course other font sizes (9pt, 11pt, 12pt) can be
used, the default size is 10pt. As for the paper size other possible values
are a4papper and legalpaper; see the article about Page size and margins
for more details about this.
2. \usepackage{}
This is the encoding for the document. Can be omitted or changed to
another encoding but utf-8 is recommended. Unless you specifically need
another encoding, or if you are unsure about it, add this line to the pream-
ble.

2017
c LPSK, INSPEM, UPM 4
LATEX: An Introduction to Malaysian Academicians

The next three lines are self-descriptive. Anyway, you can see a descrip-
tion about what they actually do in the next section. Another important
parameter that can be passed to the \documentclass command is twocol-
umn if you want your text in a two-column format and twoside for two-side
paper sheet printing.

Displaying the title of your document


To display the title of your document you have to declare its components in the
preamble and then use some additional code:

\documentclass[12pt, letterpaper, twoside]{article}


\usepackage[utf8]{inputenc}

\title{First document}
\author{Hubert Farnsworth \thanks{funded by the ShareLaTeX team}}
\date{February 2014}

\begin{document}

\begin{titlepage}
\maketitle
\end{titlepage}

In this document some extra packages and parameters


were added. There is a encoding package
an a pagesize and fontsize parameters.

\end{document}

2017
c LPSK, INSPEM, UPM 5
LATEX: An Introduction to Malaysian Academicians

Figure 1: There is a block with three lines in the preamble that define what
information is going to be included in the title page.

1. \title{First document}
This is the title.
2. \author{Hubert Farnsworth}
Here you put the name of the Author(s) and, as a optional parameter,
you can add the next command:
3. \thanks{funded by the ShareLaTeX team}
This can be added after the name of the author, inside the braces of the
title command. It will add a superscript and a footnote with the text inside
the braces. Useful if you need to thank an institution in your article.

4. \date{February 2014} You can enter the date manually or use the com-
mand October 30, 2017so the date will be updated automatically at the
time you compile your document. Once you have that in the preamble
now in the body of your document you can use the next commands for
the information to be printed.

2017
c LPSK, INSPEM, UPM 6
LATEX: An Introduction to Malaysian Academicians

5. \begin{titlepage} \end{titlepage}
This declares an environment, a block of code with a specific behaviour
depending on its type. In this case whatever you include in this titlepage
environment will appear in the first page of your document.
6. \maketitle
This command will print the title, the author and the date in the format
shown in the example. If it’s not enclosed in a titlepage environment, it
will be shown at the beginning of the document, above the first line.

Basic formatting: abstract, paragraphs and newlines


Everything included inside the \begin{document} \end{document} commands
will be rendered in the final document.

\begin{document}

\begin{abstract}
This is a simple paragraph at the beginning of the
document. A brief introduction about the main subject.
\end{abstract}

In this document some extra packages and parameters


were added. There is a encoding package
an a pagesize and fontsize parameters.

This line will start a second Paragraph. And I can


brake\\ the lines \\ and continue in a new line.

\end{document}

Abstract
This is a simple paragraph at the beginning of the document. A
brief introduction about the main subject.

In this document some extra packages and parameters were added. There
is a encoding package an a pagesize and fontsize parameters. This line will
start a second Paragraph. And I can brake
the lines
and continue in a new line.

In scientific documents it’s a common practice to include a brief overview of


the main subject of the paper. In LaTeX there’s the abstract environment for
this. The abstract environment will put the text in a special format at the top
of your document.

2017
c LPSK, INSPEM, UPM 7
LATEX: An Introduction to Malaysian Academicians

When writing the contents of your document, if you need to start a new
paragraph you must hit the ”Enter” key twice (to insert a double blank line).
Notice that paragraphs have a white space before the first line.
To start a new line without actually starting a new paragraph insert a break
line point, this can be done by \\ (a double backslash as in the example) or the
\newline command

Comments
Sometimes it’s necessary to add comments to your LaTeX code for readability.
This is straightforward, put a % before the comment and LaTeX will ignore that
text.

\documentclass{article}
\usepackage[utf8]{inputenc} %codification of the document
\usepackage{comment}
%Here begins the body of the document
\begin{document}
This documents contains a lot of comments, none of them
will appear here, only this text.

This documents contains a lot of comments, none of them


will appear here, only this text.

\begin{comment}
This text won’t show up in the compiled pdf
this is just a multi-line comment. Useful
to, for instance, comment out slow-rendering
while working on the draft.
\end{comment}

\end{document}

This documents contains a lot of comments, non of them will appear


here, only this text.
This documents contains a lot of comments, non of them will appear
here, only this text.

This helps in multi-line comments instead of putting a % at the beginning


of each line. For this to work you must add the next line to your preamble:
\usepackage{comment} The % symbols is a reserved character, if you actually
need this symbol to be printed in your document, use \%.

2017
c LPSK, INSPEM, UPM 8
LATEX: An Introduction to Malaysian Academicians

3 About MiKTeX
MiKTeX (pronounced mick-tech) is an up-to-date implementation of TeX/La-
TeX and related programs for Windows (all current variants). It is very easy to
install MiKTeX. The MiKTeX Setup Wizard guides you through the installation
process. You don’t have to be a computer expert. A complete set of additions
(programs, styles, fonts, . . . ) are available to help you typeset your documents.
MiKTeX’s integrated package manager installs missing components from the
Internet, if required. For example, the LaTeX directive \usepackage{memoir}
would trigger the installer, if the memoir package is not already installed. This
unique feature allows you to keep your computer clutter-free: only install pack-
ages you actually need. The MiKTeX Update Wizard helps you to keep your
MiKTeX system up-to-date by installing the latest package updates. The TeX
output viewer Yap allows for an optimized edit-compile-view cycle (if the TeX
authoring system in use supports source specials). The MiKTeX package repos-
itory is updated regularly. MiKTeX is open source. Users are welcome to re-
distribute MiKTeX under certain conditions. Further information on MiKTeX
can be obtained from https://miktex.org/.

4 Installation on Windows (MiKTeX and TeX-


works)
Copying conditions
The ”Basic MiKTeX Installer” is used to install a Basic MiKTeX system on
personal computer running Windows. Start it with a double-click on the down-
loaded file.

Figure 2: Read the text carefully and click ”I accept the MiKTeX copying
conditions”, click ”Next”, to go to the next page.

2017
c LPSK, INSPEM, UPM 9
LATEX: An Introduction to Malaysian Academicians

Figure 3: Click install MiKTeX and click ”Next”

Figure 4: Click Complete MiKTeX and click ”Next”

Shared installation
Create the option to shared MiKTeX installation. Use this Option, if you are
the Administrator (of your Computer) and if you want to install MiKTeX for all
users (this Option is not available, if you are logged into a limited user account).

Click ”Anyone who uses this Computer (all users), if you want to install MiK-
TeX for all users.

Click ”Only for ...”, if you want to install MiKTeX for yourself only.

2017
c LPSK, INSPEM, UPM 10
LATEX: An Introduction to Malaysian Academicians

Figure 5: Click ”Next” to go to the next page

Installation directory
Make the option to specify the MiKTeX installation directory:

Click ”Browse”, to specify another (than the default) directory location.

Figure 6: Click ”Next” to go to the next page

2017
c LPSK, INSPEM, UPM 11
LATEX: An Introduction to Malaysian Academicians

Figure 7: Click ”Next” to go to the next page

Settings
It also have the option to change the default behavior of the integrated package
manager for the case where a required package is missing. Select ”Ask me
first”, if the package manager shall ask for permission. Select ”Always”, if the
package manager is always allowed to install missing packages. Select ”Never”,
if disallow the installation of missing packages. All these preferences can be
changed later.

Figure 8: The installer allows to set the preferred paper size. Click ”Next” to
go to the next page

2017
c LPSK, INSPEM, UPM 12
LATEX: An Introduction to Malaysian Academicians

Review
Before the actual installation process begins, get a chance to review your deci-
sions.

Figure 9: If satisfied with the settings, then click ”Start” to start the actual
installation.

Installation Process
The installation will take a few minutes. The progress bar shows an approximate
percentage of completion.

Figure 10: When the installation has finished, click ”Next” to open the last
page.

2017
c LPSK, INSPEM, UPM 13
LATEX: An Introduction to Malaysian Academicians

Finish
MiKTeX is now installed. The installation also includes the TeXworks editor.

Figure 11: Click ”Close”, to close the installer..

After installed MiKTeX, it is recommended that you run the update wizard in
order to get the latest updates.

5 LaTeX distributions
The styles, contents and layout in a LaTeX document are defined by means
of tags or commands in a plain .tex file, this file can be used to generate the
”human-readable” version of the document to PDF output format.
The set of programs that make possible to compile TeX and LaTeX documents
is called a TeX typesetting or distribution. There are many TeX distributions
available for different operating systems:
• MiKTeX for Windows
• TeX Live for Linux and other UNIX-like systems
• MacTeX redistribution of TeX Live for Mac OS X
• teTeX for Linux and other UNIX-like systems, now is no longer actively
maintained
• proTeXt is based on MiKTeX

6 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

2017
c LPSK, INSPEM, UPM 14
LATEX: An Introduction to Malaysian Academicians

others are proprietary software.


Here are some examples of popular editors for LaTeX:

TeXworks (Recommended editor)

Figure 12: Texworks editor

TeXworks is another multi-platform, open-source LaTeX editor. TeXworks is


a LaTeX editing tool that is based off another open-source LaTeX editor –
TeXshop. It provides a GUI-based approach to LaTeX editing and features
many of the key advantages found in the previous mentioned tools. TeXworks
features a built-in PDF viewer just like in the above mentioned tools, but this
tool also possesses an auto-synchronisation feature to it.

TeXworks features many of the key capabilities of a LaTeX editor like auto-
completion, auto-correction, Unicode support and more. If only the basic bare
bones of a LaTeX editor is required, It ticks in all the boxes perfectly. This tool
although does not feature many of the key features, its minimalistic approach to
LaTeX editing gets the work done without fussing much about its functionali-
ties. Code folding, Insertion of graphics/tables, interaction with external editors
and its powerful built-in PDF viewer and exporter makes this tool one of the
best LaTeX editors that the academia often tend to consider.
• Key Features: Code folding, auto-completion, auto-correction, Unicode
support and built-in PDF viewer.
• Platforms Supported: Windows, Mac OS X and Linux.
• Official Website: https://www.tug.org/texworks/

2017
c LPSK, INSPEM, UPM 15
LATEX: An Introduction to Malaysian Academicians

TeXmaker

Figure 13: Texmaker editor

TeXmaker is one of the most popular open-source, multi-platform solution to


LaTeX editing. This tool is available for all major platforms and possesses fea-
tures that make a great case for any LaTeX text editor. To get started with
TeXmaker, its configuration window allows users to set-up all the basic settings
of their LaTeX document before starting work on it. TeXmaker also allows
users to set-up the spell-checking and other document layout settings through
the ‘Quick start’ window. The ‘Structure View‘ allows users to streamline their
documents into separate sections, labeling each one in the process. Inserting
Tables, Math formulae, cross-references, pictures, etc is pretty straightforward
with TeXmaker.

Once the groundwork of your document layout is set up using TeXmaker, the
document can now be compiled to get it extracted as a PDF, HTML or ODF
file format. Another key feature of TeXmaker is the way it allows users to track
errors during the compilation stage. All warnings and errors are displayed to let
the user take the needed action regarding the same. Parts/sections of your doc-
uments could be easily folded/unfolded using TeXmaker. This tool is also great
for creating a structured Bibliography section of your document. Keyboard
short-cuts are abundant for TeXmaker and it makes the overall experience with
this tool pretty worthwhile.
• Key Features: Unicode support, Code folding, Spell-checking, Built-in
PDF viewer, Auto-completion, 370 mathematical symbols and more.
• Platforms Supported: Windows, Mac OS X and Linux.

2017
c LPSK, INSPEM, UPM 16
LATEX: An Introduction to Malaysian Academicians

• Official Website: http://www.xm1math.net/texmaker/

ShareLaTeX

Figure 14: ShareLaTeX editor

If all of the above tools do not interest you in trying out LaTeX editors, here
is one that doesn’t need any kinds of installations on your local device. Share-
LaTeX takes all of your LaTeX document editing tasks online and now you can
edit your documents right from your web browser. One of its key features is the
400 templates that come built-in with it. Among these templates are Techni-
cal paper layouts, Scientific magazine articles, CV and more. You can simply
choose one such layout and get started on editing your content without worrying
much about the formatting associated with it.

Other key features of ShareLaTeX is the way it allows users to collaborate on a


document. You can now collabarate with other members on your document and
visualize changes in real-time. Dragging and dropping of images, external shar-
ing of the completed document, Document History and Chat feature are some
of the key advantages of using ShareLaTeX. The Document History allows users
to check the revision history of a document and undo changes that were made
to the document in the past. Trusted by over 400,000 academia, ShareLaTeX
is all in all, a powerful LaTeX editor, right from your web browser.
• Key Features: Collaboration supported, Document history, Dropbox
and GitHub syncing supported, Over 400 ready-to-use templates, no in-
stallations needed and more.
• Platforms Supported: Web-based, Supports all major web browsers.
• Pricing: Free (1 Collaborator), USD15/month (10 Collaborators), USD30/month
(Unlimited collaborators).

2017
c LPSK, INSPEM, UPM 17
LATEX: An Introduction to Malaysian Academicians

• Official Website: https://www.sharelatex.com/

Overleaf

Figure 15: Overleaf editor

Another great online LaTeX editing tool is Overleaf. Trusted by over 200,000
academia worldwide, Overleaf is a great LaTeX editing tool with all the fea-
tures that make your document creations easy. Overleaf comes with over 100’s
of templates ranging from Lab report and Thesis to Resume/CV and formal let-
ters. If starting over fresh isn’t something you’d consider, getting started with
one of their many templates is an easy way to develop professionally formatted
documents.

Among the key features of Overleaf are the ability to collaborate with your
team members on technical papers or academia documents. This real-time col-
laboration brings transparency to the editing work that is being put in by all the
authors involved in its development. Your final document could easily be shared
to different social networks and Git account using your custom generated link.
Make this link as ‘Read-only’ or ‘Read-and-Write’ depending on the person you
are sharing the document with. Mathematical formulae insertion is one of the
important aspects of LaTeX editors and Overleaf provides a real-time preview
of your text as it gets entered. Its Error control and Notation support makes
co-authors familiar with WYSIWIG editors easily take up to this tool.

• Key Features: Real-time collaborations, Effortless sharing, Real-time


previewing, Rich Text Editing, Easy error tracking, Document revision
history and more.
• Platforms Supported: Web-based, Supports all major web browsers.

2017
c LPSK, INSPEM, UPM 18
LATEX: An Introduction to Malaysian Academicians

• Pricing: Free (Unlimited Collaborates, No Dropbox support, 1 GB stor-


age), USD8/month (10 GB storage, 240 files per project, Dropbox sup-
port), USD12/month (20 GB Storage, 500 files per project).
• Official Website: https://www.overleaf.com/

7 LaTeX Output Format


The most commonly used output format is Portable Document Format (PDF).
PDF is a file format based on PostScript, used to represent documents in a
manner independent of application software, hardware, and operating systems.
It is now widely used as a file format for printing and for distribution on the
Web. The following are some advantages of having output in PDF format:
Document format is maintained Sharing documents in other formats across
computers can prove to be very different. This can cause confusion among
the end users. Using PDF format, the document will be presented exactly
how it was layed out.
PDF is ubiquitous PDF has been widely adopted globally as it is easy to
view and share.
Samller file size PDF has the big advantage of compressing high-quality files
to a relatively small file size. That is useful for saving hard drive space,
particularly with limited storage resources.
Paswword protection PDF files can be password-protected, giving the abil-
ity to secure sensitive information.
Cross platform PDF works on all the major operating systems currently in
use. Viewing The viewer can be on a PC or a Mac, or even on a smart
phone.
Easy integration of non-text elements PDF allows to maintain visually-
pleasing layouts for non-text elements such as images & hyperlinks, and
make use of links that will open up in the viewer’s web browser.

PDF is here to stay The likelihood of PDF to go away is small although


technology moves quickly. Due to it’s widespread applications, it is here
to stay for the long-haul.

8 LaTeX Environments
Environments are used to format blocks of text in a LaTeX document. A LaTeX
document of any style (article, letter or report) starts (right after the preamble)
with the tag \begin{document} and ends with \end{document} which serves
as the overall environment of the document.

2017
c LPSK, INSPEM, UPM 19
LATEX: An Introduction to Malaysian Academicians

Defining Environments
Environments are delimited by an opening tag \begin and a closing tag \end.
Everything inside those tags will be formatted in a special manner depending
on the type of the environment.

Example

\begin{tabular}{ c c c }
cell1 & cell2 & cell3 \\ cell1 cell2 cell3
cell4 & cell5 & cell6 \\ cell4 cell5 cell6
cell7 & cell8 & cell9 \\ cell7 cell8 cell9
\end{tabular}

This environment tabular takes an additional parameter { c c c } to deter-


mine the alignment of the cells. Environments may accept optional parameters
that usually are passed inside brackets [ ].

Examples of Some Common Environments


Some basic environments usually used for formatting text can be invoked just
by wrapping the command and the parameter within the { }.

{\it these will be italic}


but not these. these will be italic but not
these.
{\bf these will be bold} these will be bold but not
but not these. these.
these will be tiny but not these.

{\tiny these will be tiny}


but not these.

2017
c LPSK, INSPEM, UPM 20
LATEX: An Introduction to Malaysian Academicians

The center environment is commonly used for typesetting content to be


aligned in the centre.

\begin{center}
This text will be centred
since it’s inside a special This text will be centred since it
environment. is inside a special environment.
Environments provide a Environments provide a efficient
efficient way of modifying way of modifying blocks of text
blocks of text within your within your document.
document.
\end{center}

The centering environment is also used for the same purpose. centering
is commonly used to centre align something that is already vertically positioned
such as a figure. Whereas, center is used to implement a displayed construct
that happens to need centred content. The use of centering will be illustrated
in a figure environment example in this section.
The figure environment using the includegraphics utility from graphicx
package is used to insert figures in a document.

\begin{figure}
\centering
\includegraphics[scale=0.05]
{google}
\caption{Google} Figure 16: Google
\label{fig:google}

Note the use of centering to centre align the figure.


Use the quote and quotation environments for typesetting quoted material
or any other text that should be slightly indented and set off from the normal
text.

\begin{quotation}
The quote and quotation
environments are similar, but The quote and quo-
use different settings for tation environments
paragraph indentation and are similar, but use
spacing. different settings for
paragraph indentation
\em When in doubt, consult and spacing.
the manual. When in doubt,
\end{quotation} consult the manual.

2017
c LPSK, INSPEM, UPM 21
LATEX: An Introduction to Malaysian Academicians

The itemize environment sets off list items with ”bullets” like this:

\begin{itemize}
\item Javascript
\item HTML • Javascript
\end{itemize} • HTML

The enumerate environment numbers the list elements, like this:

\begin{enumerate}
\item Javascript
\item HTML 1. Javascript
\end{enumerate} 2. HTML

The tabular environment is used to display tables and the center environment
is used to display the table properly in the center such as:

\begin{center}
Numbers of Programmers:
\begin{tabular}{lr} Numbers of Programmers:
C++&175\\ C++ 175
Python&60\\ Python 60
Java&110\\ Java 110
\end{tabular}
\end{center}

In a description environment, we specify the item labels inside square


brackets after the \item command. For example:

Unique Features:
\begin{description} Unique Features:
\item[C++] Speed
C++ Speed
\item[Python] Flexsible
\end{description} Python Flexible

2017
c LPSK, INSPEM, UPM 22
LATEX: An Introduction to Malaysian Academicians

To display source codes or LaTeX commands, we can make use of verbatim


environment. The following examples illustrates the use of verbatim:

\begin{verbatim}
/*The Parallel Hello World
Program*/ /*The Parallel Hello
#include <stdio.h> World Program*/
#include <mpi.h> #include <stdio.h>
main(int argc, char **argv) #include <mpi.h>
{ main(int argc, char **argv)
int node; {
MPI_Init(&argc,&argv); int node;
MPI_Comm_rank(MPI_COMM_WORLD, MPI_Init(&argc,&argv);
&node); MPI_Comm_rank(MPI_COMM_WORLD,
printf("Hello World from Node &node);
%d\n",node); printf("Hello World from Node
MPI_Finalize(); %d\n",node);
} MPI_Finalize();
\end{verbatim} }

Using table and tabular environments, we can create tables and position
it.

\begin{table}[H] Col1 Col2 Col3


\centering 1 6 87837
\begin{tabular}{|c c c|} 2 7 78
\hline 3 88 788
Col1 & Col2 & Col3 \\ [0.5ex]
\hline\hline
1 & 6 & 87837 \\
2 & 7 & 78 \\
3 & 88 & 788 \\ [1ex]
\hline
\end{tabular}
\end{table}

Note the use of float [H] for table to fix the position of the table.

Environments for Mathematical Equations



Simple equations, like xy or xn = a + b can be typeset right in the text line
by enclosing them in a pair of single or double dollar sign symbols. Examples
of using the mathematical mode utility are as below:

2017
c LPSK, INSPEM, UPM 23
LATEX: An Introduction to Malaysian Academicians

Solve the following equation:


$x_n = \sqrt{a + b}$ Solve
√ the following equation:
xn = a + b

Solve the following equation:


$$x_n = \sqrt{a + b}$$ Solve the following equation:

xn = a + b

A more complicated equation should be typeset in displayed math mode, like


this:
\[
z \left( 1 \ +\ \sqrt{\omega_{i+1} + \zeta -\frac{x+1}{\Theta +1}
y + 1}
\ \right)
\ \ \ =\ \ \ 1
\]

r !
x+1
z 1 + ωi+1 + ζ − y+1 = 1
Θ+1

The equation environment displays your equations, and automatically num-


bers them consecutively within your document, like this:
\begin{equation}\label{eq:1}
\left[
{\bf X} + {\rm a} \ \geq\
\underline{\hat a}
\sum_i^N \lim_{x \rightarrow k} \delta C
\right]
\end{equation}

" N
#
X
X + a ≥ â lim δC (1)
x→k
i

2017
c LPSK, INSPEM, UPM 24
LATEX: An Introduction to Malaysian Academicians

To typeset several equations together and have them properly aligned, use
the align environment:

Some important equations:


\begin{align} Some important equations:
E & = mc^2 \\
F & = ma \\ E = mc2 (2)
e^{i \pi} & = -1 F = ma (3)
\end{align} e iπ
= −1 (4)

The equations are aligned along the & and each line is terminated by \\. To
suppress the equation numbering (i.e. if the equations won’t be referred to) use
align* instead of align.
Piecewise functions may be defined using the cases environment from the
amsmath package:
\[ f(x) = \begin{cases}
0 & x\leq 0 \\
\frac{100-x}{100} & 0\leq x\leq 100 \\
0 & 100\leq x
\end{cases}
\]


0
 x≤0
100−x
f (x) = 0 ≤ x ≤ 100
 100
0 100 ≤ x

9 LaTeX Commands
LaTeX typesetting is made by using special tags or commands that provide a
handful of ways to format your document. Sometimes standard commands are
not enough to fulfill some specific needs, in such cases new commands can be
defined. Most of the LaTeX commands are simple English words preceded by a
special character.
A word of caution, LaTeX typesetting uses the American English spelling,
thus please be sure to use the correct spelling. Commands written using British
English spelling will not be run as LaTeX is spelling sensitive and this would
result in error. For instance, to centre align a content, we would use center
and not centre.

2017
c LPSK, INSPEM, UPM 25
LATEX: An Introduction to Malaysian Academicians

In a document there are


different types of In a document there are differ-
\textbf{commands} ent types of commands that de-
that define the way fine the way the elements are dis-
the elements are displayed. played. This commands may in-
This commands may insert sert special elements: αβΓ
special elements:
$\alpha \beta \Gamma$

In the above example there are different types of commands. For instance,
\textbf will make boldface the text passed as parameter to the command.
In mathematical mode ($...$) there are special commands to display Greek
characters such alpha, beta and gamma.
We may insert cross-references to numbered elements such as equations,
sections and figures in our document with ref and label commands in LaTeX.
The command label{ } is used to set an identifier that is later used in the
command ref{ } to set the reference. Additionally, we can insert the page
where these labels to be referenced appear using pageref command. For an
example, we have labelled this section (LaTeX Commands) as commands; the
Google figure as fig:google and the first mathematical equation on page 24 as
eq:1.

LaTeX commands are explained


in section \ref{commands}. LaTeX commands are ex-
plained in section 9.
Figure \ref{fig:google} on page Figure 16 on page 21 depicts
\pageref{fig:google} depicts the latest logo design of Google
the latest logo design of Inc.
Google Inc. Typical equations like equation
1 at the page 24 can be directly
Typical equations like solved.
\ref{eq:1} at the page
\pageref{eq:1} can be directly
solved.

Examples Of Some Basic Commands


Commonly used commands and their usage:
• %: comment
• \\: newline
• \usepackage{packagename}: load a package
• \title: title of document
• \begin: begin an environment

2017
c LPSK, INSPEM, UPM 26
LATEX: An Introduction to Malaysian Academicians

• \end: end an environment


• \textbf: text in bold
• \textit: text in italics
• \item: insert item in a list

• \large: text in large font


• \small: text in small font
• \underline: underline text

• \section: section heading


• \subsection: subsection heading
• \hline: horizontal line
• \centering: center text

• \label: label anything that is numbered for reference


• \ref: refer a labelled object
• \eqref: refer a labelled equation with parenthesis

Special Characters in LaTeX


The following symbols are reserved characters which have a special meaning in
LaTeX:

# $ % ^ & _ { } ~ \
All of these apart from the backslash \ can be inserted as characters in your
document by adding a prefix backslash:
\# \$ \% \^{} \& \_ \{ \} \~{}

Note that you need to type a pair of curly brackets {} after the hat ˆ and
tilde ˜, otherwise these will appear as accents over the following character. For
example, \^e will produce ê.
The backslash character \ can not be entered by adding a prefix of another
backslash \\, as this is used for line breaking. Use the \backslash command
instead.

2017
c LPSK, INSPEM, UPM 27
LATEX: An Introduction to Malaysian Academicians

10 Typesetting Text in LaTeX


Symbols
There are several things that you will need to know in order to type your doc-
ument LaTeX. The following keys are used to type text in a LaTeX source file :

a-z A-Z 0-9


+=*/()[]
You may also use the following punctuation marks:

,;. ? ! : ’ ’ -
and the spacebar, and Return (or Enter) key.There are thirteen special keys
that are mostly used in LaTeX instructions are reserved character which have
a special meaning. These symbols are:

\#”$%&@|ˆ {}˜
If you need to use them in your document, you will need to precede them
with a \. The only time this will not work is in the case of the backslash itself
since \\ is the command to create a new line. For examples, to put a \ in your
document you must type $\backslash$ , $ is typed as \$, the underscore ( ) is
typed as \ and % is typed as \%, whereas ä is typed as \”{a} and @ is simply
typed @.

In a LaTeX source file, each comment line begins with %. LaTeX willl ignore
everything on the line after the % character.

Line and Page Break


There are several commands you will need to know when it comes to line and
page breaking. Table 1 below lists these commands.

Table 1: Line and Page Breaking in LaTeX

\\ or \newline Starts a new line without starting a new paragraph


\\* Prohibits a page break after a line break
\newpage Starts a new page
\pagebreak[n] Enters a page break
\nolinebreak[n] Does not allow LaTeX to enter a line break
\nopagebreak[n] Does not allow LaTeX to enter a page break
Note: The optional ”[n]” argument, which can be set to a number between 1
and 4, is used to set the priority of the line or page break. If this value is set to
1, LaTeX will only perform the function if it thinks it will look good. Setting
the value at 4 forces LaTeX to perform the function.

2017
c LPSK, INSPEM, UPM 28
LATEX: An Introduction to Malaysian Academicians

Vertical and Horizontal Line Spacing


The command \hspace and \vspace leave horizontal and vertical space in your
text. Both commands take a mandatory parameter— the amount of blank space
you want to leave. The vertical space between lines can be changed by using a
few simple commands. Here are the commands used to do this:
\begin{center}
Your lines can have
\smallskip

small spaces between them, or


\bigskip

large ones.
\end{center}

Your lines can have small spaces between them, or large ones.

In addition you can use the \vspace {enter space here} command to set the
space lines to whatever you like. For example, \vspace{.75in} will leave .75
inches of blank space in your text. If vertical space is requested in the middle of
a paragraph, the space will appear after the current line has ended like below:

\begin{center}
These lines have a\\
\vspace{.75in} \$.75\$ inch space between them.
\end{center}

These lines have a

$.75$ inch space between them.

Space requested by the \hspace and \vspace commands disappears if it falls at


the beginning or end of a line or page. To create space that remains no matter
where it falls, use variations \hspace* and \vspace*. For example, the following
lines:

2017
c LPSK, INSPEM, UPM 29
LATEX: An Introduction to Malaysian Academicians

This text starts at the left margin\\


\hspace*{1in}This text starts a new line after a one-inch space

This text starts at the left margin


This text starts a new line after a one-inch space

Font Types and Styles


There are four characteristics that can describe any font: shape, series, family
and sizes. LaTeX allows you to individually change each of these characteristics
for any textual item within a document. The type styles (shapes, series and
family) can also be invoked in either a ”closed form” ad a command \cmd{the}
or in an ”open form” as a declaration {\decl the}. The ”closed form” is useful
for changing a word or two of text while the ”open form” when used without
a brace is useful for changing large sections of text.Table 2 lists several text
related commands you may find usefu in the ”closed form”.

Table 2: Text Fonts and Sizes

Command Declaration
\textbf \bfseries Boldface text
\textit \itshape Italic text
\textsl \slshape Slanted text
\underline \uline Underlined text
\textsc \scshape SMALL CAPS
\textup \upshape Upright text
\emph \em Emphasized text
\textrm \rmfamily Times New Roman
\texttt \ttfamily Typewriter
\textsf \sffamily Sans Serif
\tiny Tiny font size

\scriptsize Very small font


\footnotesize Footnote font size
\normalsize Normal font size
\large Large font size
\Large Larger font size
\LARGE Very large font
\huge huge
\Huge Largest font size
Note: Remember that the text you want to modified must go within {}. For
example, \textbf{enter text here}.

2017
c LPSK, INSPEM, UPM 30
LATEX: An Introduction to Malaysian Academicians

By default, in standard LaTeX classes the serif typeface (a.k.a. roman) font is
used. You can set up the use of sans font as a default in LaTeX document by
using the command:
\renewcommand{\familydefault}{\sfdefault}

Similarly, for using roman font as a default:


\renewcommand{\familydefault}{\rmdefault}

Note that the font size definitions are set by the document class. Depending
on the document style the actual font size may differ from that listed below.
And not every document class has unique sizes for all 10 size commands. Table
3 below lists the absolute point sizes in the article, proc, report, book, and letter.

Table 3: Absolute Point Sizes in Standard Classes

Size 10pt(default) 11pt option 12pt option


\tiny 5pt 6pt 6pt
\scriptsize 7pt 8pt 8pt
\footnotesize 8pt 9pt 10 pt
\small 9pt 10pt 11pt
\lnormalsize 10pt 11pt 12pt
\large 12pt 12pt 14pt
\Large 14pt 14pt 17pt
\LARGE 17pt 17pt 20pt
\huge 20pt 20pt 25pt
\HUGE 25pt 25pt 25pt

Please note that the absolute point sizes in LaTeX and Ms Word may not be
the same. For example, 12pt in LaTeX is not equivalence to 12pt in Ms Word.
MS Word uses a slightly different version of the unit ”point” (pt) than LaTeX
does. The 12 point of Ms Word will be PostScript point, which in LaTeX would
be called 12bp. A LaTeX pt is slightly smaller: it’s 1/72.27 inch, while a bp
\PostScript point is 1/72 inch. The difference in width is around 0.04pt and
0.03pt in height, which translates to about 0.01mm - a roughly 0.3% increase.
This is virtually negligible to the naked eye at regular font sizes. In order to get
the output looks like what we get in the MS Word documents with Times New
Roman 12pt, the commands are stated below:

\documentclass[12pt]{article}
\usepackage{tgtermes} %times font
\begin{document}

\end{document}

2017
c LPSK, INSPEM, UPM 31
LATEX: An Introduction to Malaysian Academicians

Environments
Itemize, Enumerate and Desription
The itemize environments is suitable for simple lists, the enumerate environ-
ment for enumerated lists, and the descriptions environment for descriptions.

\flushleft
\begin{enumerate}
\item You can nest the 1. You can nest the list
list environment to your taste: environment to your taste:
\begin{itemize} • But it might start to
\item But it might start to look look silly.
silly.
\item[-] With a dash. - With a dash.
\end{itemize} 2. Therefore remember:
\item Therefore remember:
\begin{description} Stupid things will not
\item[Stupid] things will not become smart because
become smart because they are in they are in a list.
a list. Smart things, though, can
\item[Smart] things, though, can be be presented beautifully
presented beautifully in a list in a list
\end{description}
\end{enumerate}

Flushleft, Flushright and Center


The environment flushleft and flushright generate paragraphs that are ei-
ther left- or right-aligned. The center environment generates centred text. If
you do not issue \\ to specify line breaks, LaTeX will automatically etermine
line breaks.The commands for doing this:

You can also justify your text


\begin{flushright}
to the right,
\end{flushright}
\begin{flushleft}
to the left,
\end{flushleft}
\begin{center}
or put it in the center of the page.
\end{center}.

2017
c LPSK, INSPEM, UPM 32
LATEX: An Introduction to Malaysian Academicians

You can also justify your text

to the right,

to the left,

or put it in the center of the page.

Quote, Quotation and Verse


The quote environment is useful for quotes, important phrases and examples.

A typographical rule of thumb for


the line length is: A typographical rule of thumb for
\begin{quote} the line length is:
On average, no line should be On average, no line
longer than 66 characters should be longer than 66
\end{quote} characters
This is why LaTeX pages have such
large borders by default and also This is why LaTeX pages have such
why multicolumn print is used in large borders by default and also why
newspapers. multicolumn print is used in newspa-
pers.

There are two similar environments: the quotation and the verse envi-
ronments. The quotation environment is useful for longer quotes going over
several paragraphs, because it indents the first line of each paragraph. The
verse environment is useful for poems where the line breaks are important.
The lines are seperated by issuing a \\ at the end of a line and an empty line
after each verse.

I know only one English poem by


heart. It is about Humpty Dumpty I know only one English poem by
\begin{flushleft} heart. It is about Humpty Dumpty
\begin{verse}
Humpty Dumpty sat on a wall:\\ Humpty Dumpty sat on
Humpty Dumpty had a great fall.\\ a wall:
All the King’s horses and all the Humpty Dumpty had a
King’s men\\ great fall.
Couldn’t put Humpty together again. All the King’s horses
\end{verse} and all the King’s
\end{flushleft}. men
Couldn’t put Humpty
together again.

2017
c LPSK, INSPEM, UPM 33
LATEX: An Introduction to Malaysian Academicians

11 Tables
The Tabular Environment
Used to typeset beautiful tables with optional horizontal and vertical lines. La-
TeX determines the width of the columns automatically. To construct a table,
start with :

\begin{tabular}[pos]{table spec}

• ”table spec” tells LaTeX the alignment to be used in a column and the
vertical lines to insert.
• ”pos” is used to specify the vertical position of the table relative to the
baseline of the surrounding text, e.g.
– h insert the table where the code is
– b insert the table at the bottom of the page (if space is available)
– t insert the table at the top of the page (if space is available), and
– p insert the table at the end of the document on a separate page

Table 4 listed the symbols to describe the table column:

Table 4: Description of symbol for tabular environment

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

The width necessary for each column is determined automatically from the
widest entry. Inside the tabular environment, use the tab character (&) to
move to the next column, && to end each line (except the last one) and \hline
to insert the horizontal line.

Standard Table
You can insert very nice looking tables into your document using LaTeX. To
insert a table into a LaTeX document, you must enter the table environment,
then define your table as required, using tabular environment. Table 5 is a

2017
c LPSK, INSPEM, UPM 34
LATEX: An Introduction to Malaysian Academicians

sample of a basic table which can be created in LaTeX using few commands
below:

\begin{table}[H] Table 5: Basic Table


\begin{center}
\caption{Basic Table}\label{Table} Variable Coef. S.E.
\begin{tabular}{l c r} % 3 columss
Party ID .356 .113
(left, center, right)
Age .465 .065
\hline \hline %draw double
horizontal line Income .234 .112
\textbf{Variable} & \textbf{Coef.}
& \textbf{S.E.}\\
\hline \hline
Party ID & .356 & .113\\
Age & .465 & .065\\
Income & .234 & .112\\
\hline
\end{tabular}
\end{center}
\end{table}

The tabular environment acts much like the array math environment, and
the | character instructs LaTeX to draw a vertical line between columns. You
can use the \hline command to draw horizontal lines. Here are the commands
used to create the table below:

\begin{table}
\begin{center}
\begin{tabular}{|l|c|r|} %3 columns (left, center, right);
vertical lines
\hline % draw horizontal line
Name & Oblateness & Diameter \\ \hline
Mercury & 0 & 3,100 \\
Venus & 0 & 7,700 \\
Earth & 1/297 & 7,927 \\
Mars & 1/192 & 4,200 \\
Jupiter & 1/15 & 88,700 \\
Saturn & 1/9.5 & 75,100 \\
Uranus & 1/14 & 32,100 \\
Neptune & 1/40 & 27,700 \\
Pluto & 0 & 3,600\\ \hline
\end{tabular}
\end{center}
\end{table}

2017
c LPSK, INSPEM, UPM 35
LATEX: An Introduction to Malaysian Academicians

Name Oblateness Diameter


Mercury 0 3,100
Venus 0 7,700
Earth 1/297 7,927
Mars 1/192 4,200
Jupiter 1/15 88,700
Saturn 1/9.5 75,100
Uranus 1/14 32,100
Neptune 1/40 27,700
Pluto 0 3,600

Using Paragraph Column and Spanning Column


The following example illustrates making paragraphs within a table and placing
text across multiple columns using the \multicolumn command. This command
has the form:

\multicolumn{n}{pos}{item}

where n is the number of columns to be spanned, pos specifies the alignment


of the item, and item is the text. This example is inside the table environment,
which ensures that the table will be ”floated” rather than broken across a page
and also provides the opportunity to supply a caption. Below are some examples
for multicolumn.

\begin{table}[hb] % place table ‘‘here’’ or at bottom of page


\centering
\caption{More Things You can Do With Tabular}
\bigskip
\begin{tabular}{|l|l|p{2.5in}|}
\hline
\multicolumn{2}{|c|}{Text in columns 1 and 2}
& A paragraph 2.5 inches wide \\
\hline
Column 1 & Column 2 & This text is a paragraph. It will wrap
around to the next line if necessary. \\
Column 1 & Column 2 & The paragraph column \\
\hline
\end{tabular}
\end{table}

2017
c LPSK, INSPEM, UPM 36
LATEX: An Introduction to Malaysian Academicians

Table: More Things You can Do With Tabular

Text in columns 1 and 2 A paragraph 2.5 inches wide


Column 1 Column 2 This text is a paragraph. It will wrap
around to the next line if necessary.
Column 1 Column 2 The paragraph column

It is sometime nice to have a column heading with a different alignment to


its column. The standard multicolumn command can be used to do this:

\begin{table}[h]
\caption{Sample Table Using Column Headings} \label{Table}
\begin{center}
\begin{tabular}{l c c c| c c c} &
\multicolumn{3}{c}{\textbf{Strong Actor}} & \multicolumn{3}{c}
{\textbf{Weak Actor}} \\
\cline{2-7}
\textbf{} & Inter & Intra & Extra & Inter & Intra & Extra \\
\hline
\textbf{Total} & 23 (55\%) & 7 (64\%) & 77 (76\%) & 19 (45\%) &
4 (36\%) & 24 (4\%)\\
\textbf{Pre-1950} & 15 (55\%) & 3 (100\%) & 74 (81\%) & 12 (45\%)
& 0 (0\%) & 18 (19\%)\\
\textbf{Post-1950} & 8 (53\%) & 4 (50\%) & 3 (33\%) & 7 (47\%)
& 4 (50\%) & 6 (67\%)\\
\hline
\end{tabular}
\end{center}
\end{table}

Table: Sample Table Using Column Headings

Strong Actor Weak Actor


Inter Intra Extra Inter Intra Extra
Total 23 (55%) 7 (64%) 77 (76%) 19 (45%) 4 (36%) 24 (4%)
Pre-1950 15 (55%) 3 (100%) 74 (81%) 12 (45%) 0 (0%) 18 (19%)
Post-1950 8 (53%) 4 (50%) 3 (33%) 7 (47%) 4 (50%) 6 (67%)

Horizontal space can be saved by printing long column headings sideways.


The rotating package can be used to achieve this with its sideways environ-
ment.

2017
c LPSK, INSPEM, UPM 37
LATEX: An Introduction to Malaysian Academicians

\usepackage{rotating}

Column 333
Column 22
Column 1
...
\begin{tabular}{|l|l|l|}
\hline
\multicolumn{1}{|c|}{
\begin{sideways} aa bbbb cccc
Column 1 \, aaa bbbb cccc
\end{sideways}}& aaaa bbbb cccc
\multicolumn{1}{c|}{ aaaaa bbbb cccc
\begin{sideways} aaaaaa bbbb cccc
Column 22 \,
\end{sideways}}&
\multicolumn{1}{c|}{
\begin{sideways}
Column 333 \,
\end{sideways}} \\\hline
aa & bbbb & cccc \\\hline
aaa & bbbb & cccc \\\hline
aaaa & bbbb & cccc \\\hline
aaaaa & bbbb & cccc \\\hline
aaaaaa & bbbb & cccc \\\hline
\end{tabular}

Sideways
The most versatile way to turn a table sideways is to use the sideways envi-
ronment from the rotate package.

\usepackage{rotating}
1,2
2,2
3,2
4,2
5,2
6,2
7,2
8,2
9,2

...
\begin{sideways}
1,1
2,1
3,1
4,1
5,1
6,1
7,1
8,1
9,1

\begin{tabular}{|l|l|}
\hline
1,1 & 1,2\\ \hline
2,1 & 2,2\\ \hline
3,1 & 3,2\\ \hline
4,1 & 4,2\\ \hline
4,1 & 4,2\\ \hline
5,1 & 5,2\\ \hline
6,1 & 6,2\\ \hline
7,1 & 7,2\\ \hline
8,1 & 8,2\\ \hline
9,1 & 9,2\\ \hline
\end{tabular}
\end{sideways}

2017
c LPSK, INSPEM, UPM 38
LATEX: An Introduction to Malaysian Academicians

Footnotes in Tables
A footnote is a non-floating longtable or tabulary table is put with any normal
page footnotes at the end of the page containing the table.
Footnotes can be kept next to their table by using a minipage to hold the
table. Each minipage has its own disjoint footnote counter, and uses alphabetic
lower case footnote marks. This method does not work for tabulary, but it can
be used with floating tables. The following is a tabular example:

\begin{minipage}{6cm} 1,2 1,2a


\begin{tabular}{|l|l|} 2,1 2,2
\hline 3,1 3,2
1,2 & 1,2\footnote{This is a 4,1 4,2
footnote.} 5,1 5,2
\\\hline 6,1 6,2
2,1 & 2,2 \\\hline
a This is a footnote.
3,1 & 3,2 \\\hline
4,1 & 4,2\\ \hline
5,1 & 5,2\\ \hline
6,1 & 6,2\\ \hline
\end{tabular}
\end{minipage}

12 Dealing with Graphics


Images are very important elements in many of the scientific documents. LaTeX
gives several options to handle images and make them look exactly what you
need. In this manual is explained how to inserting images in the most common
formats, how to shrink, enlarge and rotate them, and how to reference them
within your document.
Latex can not manage images by itself, so we need to use the graphicx pack-
age. To use it, we include the following line in the preamble: \usepackage{graphicx}
The command \graphicspath{ {images/} } tells LaTeX that the images
are kept in a folder named images under the current directory.
The \includegraphics{universe} command is the one that actually in-
cluded the image in the document. Here universe is the name of the file con-
taining the image without the extension, then universe.PNG becomes universe.
The file name of the image should not contain white spaces nor multiple dots.
Changing the image size and rotating the picture If we want to further specify
how LaTeX should include our image in the document (length, height, etc),
we can pass those settings in the following format:
Note: The file extension is allowed to be included, but it’s a good idea to
omit it. If the file extension is omitted it will prompt LaTeX to search for all
the supported formats.

2017
c LPSK, INSPEM, UPM 39
LATEX: An Introduction to Malaysian Academicians

The folder path to images


When working on a document which includes several images it’s possible to keep
those images in one or more separated folders so that your project is more organ-
ised. In the example at the introduction the command \graphicspath{ {images/} } tells
LaTeX to look in the images folder. The path is relative to the current working
directory. The path to the folder can be relative (recommended) if it is in the
same location as the main .tex file or in one of the sub-folders, or absolute if
you have to specify the exact path. For example:
Path in Windows format:
\graphicspath{ {c:/user/images/} }
Path in Unix-like (Linux, OsX) format
\graphicspath{ {/home/user/images/} }
Notice that this command requires a trailing slash / and that the path is in
between double braces. 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/} }
If no path is set LaTeX will look for pictures in the folder where the .tex file is
saved.

Changing the image size and rotating the picture


If we want to further specify how LaTeX should include our image in the doc-
ument (length, height, etc), we can pass those settings in the following format:
The command \includegraphics[scale=1.5]{figure.here} will include
the image figure.here in the document, the extra parameter scale=1.5 will do
exactly that, scale the image 1.5 of its real size. You can also scale the image
to a some specific width and height. For example
\includegraphics[width=3cm, height=4cm]{figure.here}
As you probably have guessed, the parameters inside the brackets [width=3cm, height=4cm]
define the width and the height of the picture. You can use different units for
these parameters. If only the width parameter is passed, the height will be
scaled to keep the aspect ratio. The length units can also be relative to some
elements in document. If you want, for instance, make a picture the same width
as the text: For example
\includegraphics[width=\textwidth]{figure.here}.
Instead of \textwidth you can use any other default of length: \columnsep,
\linewidht, \textheight, \paperheight, etc. See the reference guide for a
further description of these units. There is another common option when includ-
ing a picture within your document, to rotate it. This can easily accomplished
in LaTeX: For example

2017
c LPSK, INSPEM, UPM 40
LATEX: An Introduction to Malaysian Academicians

\includegraphics[scale=1.2, angle=45]{figure.here}.
The parameter angle=45 rotates the picture 45 degrees counter-clockwise. To
rotate the picture clockwise use a negative number.

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. The figure environment is used
to display pictures as floating elements within the document. This means you
include the picture inside the figure environment and you don’t have to worry
about it’s placement, LaTeX will position it in a such way that it fits the flow
of the document.
Anyway, sometimes we need to have more control on the way the figures
are displayed. An additional parameter can be passed to determine the fig-
ure positioning. In the example, begin{figure}[h], the parameter inside the
brackets set the position of the figure to here. Below a table to list the possible
positioning values.

Parameter Position
h Place the float here, i.e., approximately at the same point it occurs in the source text
t Position at the top of the page.
b Position at the bottom of the page.
p Put on a special page for floats only.
! Override internal parameters LaTeX uses for determining ”good” float positions.
In the next example you can see a picture at the top of the document, despite
being declared below the text.
The additional command \centering will centre the picture. The default
alignment is left. It’s also possible to wrap the text around a figure. When the
document contains small pictures this makes it look better. For the commands
in the example to work, you have to import the package wrapfig. Add to the
preamble the line \usepackage{wrapfig}.
Now you can define the wrapfigure environment by means of the commands
\begin{wrapfigure}{l}{0.25\textwidth}\end{wrapfigure}.
Notice that the environment has two additional parameters enclosed in braces.
Below the code is explained with more detail:
{l}
This defines the alignment of the figure. Set l for left and r for right. Fur-
thermore, if you are using a book or any similar format, use instead o for the
outer edge and i for the inner edge of the page.
{0.25\textwidth}
This is the width of figure box. It’s not the width of the image itself, that
must be set in the includegraphics command. Notice that the length is relative
to the text width, but normal units can also be used (cm, in, mm, etc).

2017
c LPSK, INSPEM, UPM 41
LATEX: An Introduction to Malaysian Academicians

Captioning, labelling and referencing


Captioning images to add a brief description and labelling them for further
reference are two important tools when working on a lengthy text.

Captions
It’s really easy, just add the\caption{Some caption} and inside the braces
write the text to be shown. The placement of the caption depends on where
you place the command; if it’a above the includegraphics then the caption will
be on top of it, if it’s below then the caption will also be set below the figure.
Captions can also be placed right after the figures. The sidecap package
uses similar code to the one in the previous example to accomplish this. There
are two new commands
\usepackage[rightcaption]{sidecap}
As you may expect this line will import a package named sidecap, but there
is an additional parameter: rightcaption. This parameter establishes the place-
ment of the caption at the right of the picture, you can also use leftcaption.
In book-like documents outercaption and innercaption are also available. The
names of these are self-descriptive.
\begin{SCfigure}[0.5][h] \end{SCfigure}
Defines an environment similar to figure. The first parameter is the width of
the caption relative to the size of the image, as declared in includegraphics. The
second parameter h works exactly as in the figure environment. See the place-
ment section for more information. You can do a more advanced management
of the caption formatting. Check the further reading section for references.

Labels and cross-references


Figures, just as many other elements in a LaTeX document (equations, tables,
plots, etc) can be referenced within the text. This is very easy, just add a label
to the figure or SCfigure environment, then later use that label to refer the
picture.
There are three commands that generate cross-references in this example.

\label{fig:mesh1}

This will set a label for this figure. Since labels can be used in several types of
elements within the document, it’s a good practice to use a prefix, such as fig:
in the example.
\ref{fig:mesh1}
This command will insert the number assigned to the figure. It’s automatically
generated and will be updated if insert some other figure before the referenced
one.

2017
c LPSK, INSPEM, UPM 42
LATEX: An Introduction to Malaysian Academicians

\pageref{fig:mesh1}
This prints out the page number where the referenced image appears. The
\caption is mandatory to reference a figure.
Another great characteristic in a LaTeX document is the ability to auto-
matically generate a list of figures. This is straightforward.
\listoffigures
This command only works on captioned figures, since it uses the caption in the
table. The example above lists the images in this article. Important Note: When
using cross-references your LaTeX project must be compiled twice, otherwise
the references, the page references and the table of figures won’t work.

13 Colours in LaTeX
When writing any things, colour is one important method to highlights some
important messages from the writer to the reader. Colour in computer in the
term of RGB (Red, Green and Blue). LaTeX is same like other word processing
software, its also got method how to do regarding colour. Colouring the text
may involve colour box such as INSPEM .

The Color Package


Colour need packages to be load first in LaTeX before can be use according to
the writer. The two common packages used by the writer for writing their work
as

\documentclass[]{article}
\usepackage{graphicx}
\usepackage{color}
\usepackage{xcolor}
...
...
...

This package provides both foreground and background for colour manage-
ments and use device driver for configuration mechanism of the graphics package
to determine how to control the output. Here is the web site link regarding the
Color package, https://ctan.org/pkg/color?lang=en
This is Blue

This is \textcolor{blue}{Blue}

This example shows different examples on how to use the color package to
change the colour of elements in LaTeX.

2017
c LPSK, INSPEM, UPM 43
LATEX: An Introduction to Malaysian Academicians

• First item
• Second item

In the LaTeX command:

This example shows different examples on how to use the \texttt{color} package
to change the colour of elements in LaTeX.

\begin{itemize}
\color{blue}
\item First item
\item Second item
\end{itemize}

\noindent
{\color{red} \rule{\linewidth}{0.5mm} }

This example shows different examples on how to use the color package to
change the colour of elements in LaTeX.

• First item

• Second item

The background colour of some text can also be easily set. For instance, you
can change to orange the background of this text and then continue typing.

14 Mathematical Equations
There are many ways how to write equations in LaTeX. In this section we wil
show you the commands but at the end we will recommend the user using only
one command to present other commands available for LaTeX. A few rules about
writing equations are

1. The equation should be located at the centered of the text.


2. Its should be italiced.
3. Any referred equation should be numbered.
4. Any numbered equation should be referred in the texts.

5. All notations should be well defined.

2017
c LPSK, INSPEM, UPM 44
LATEX: An Introduction to Malaysian Academicians

Equation between the texts


The equation between the texts, we use \$ formula \$ i.e. the two symbols of
dollar signs. While we are using \[ . . . \] for any single equation in one
line without number of referencing. For more complex equations we suggest to
use \begin{align}...\end{align} with amsmath and amssymb packages.

The equation in the text. This


is the famous Pythagoras The equation in the text. This
theorem, written using is the famous Pythagoras theorem,
$ a^2 + x^2 = c^2$. written using a2 + x2 = c2 . The
The size of the equation size of the equation is automati-
is automatically being try to cally being try to adjusted within
adjusted within the text lines the text lines without number of
without number of referencing. referencing. At the same time the
At the same time the equation equation is being slanted.
is being slanted.

15 Delimiters
See how the delimiters are of reasonable size in these examples:

\[ \left(a+b\right)
\left[1-\frac{b}{a+b}\right]=  
a\] b
(a + b) 1 − = a,
\[\sqrt{|xy|}\leq\left| a+b
\frac{x+y}{2}\right| \]
p x + y
|xy| ≤ ,
2

Even when there is no matching delimiter:

\[ \int_a^bu\frac{d^2v}{dx^2}\,
dx=\left.u\frac{dv}{dx}\right| b Z b
b
d2 v
Z
_a^b-\int_a^b\frac{du}{dx} dv du dv
\frac{dv}{dx}\,dx.\] u dx = u − dx.
a dx2 dx a a dx dx

16 Spacing
Differentials often need a bit of help with their spacing as in:

2017
c LPSK, INSPEM, UPM 45
LATEX: An Introduction to Malaysian Academicians

\[\iint xy^2\,dx\,dy =
\frac{1}{6}x^2y^3,\] ZZ
1 2 3
xy 2 dx dy = x y ,
6

Whereas vector problems often lead to statements such as:

\[
u=\frac{-y}{x^2+y^2}\,,\quad
v=\frac{x}{x^2+y^2}\,, −y x
u= , v= , w = 0.
\quad w=0\,. x2
+ y2 x2 + y2
\]

Occasionally one gets horrible line breaks when using a list in mathematics
such as listing the first twelve primes 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 . In
such cases, perhaps include \mathcode‘\,="213B inside the inline maths envi-
ronment so that the list breaks: 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 . Be
discerning about when to do this as the spacing is different.

17 Arrays
Arrays of mathematics are typeset using one of the matrix environments as in:

\[
\begin{bmatrix}  
1 & x & 0 \\   1  
1 x 0   1 + xy
0 & 1 & -1 y = .
0 1 −1 y−1
\end{bmatrix} 1
\begin{bmatrix}
1 \\ y \\ 1
\end{bmatrix}
=\begin{bmatrix}
1+xy \\ y-1
\end{bmatrix}.
\]

Case statements use cases:

\[ \]
|x|=\begin{cases}
x, & \text{if }x\geq 0\,,
\\ -x, & \text{if }x< 0\,.
\end{cases}

2017
c LPSK, INSPEM, UPM 46
LATEX: An Introduction to Malaysian Academicians

(
x, if x ≥ 0 ,
|x| =
−x, if x < 0 .

2017
c LPSK, INSPEM, UPM 47
LATEX: An Introduction to Malaysian Academicians

2017
c LPSK, INSPEM, UPM 48
LATEX: An Introduction to Malaysian Academicians

Many arrays have lots of dots all over the place as in

\[
\begin{matrix}
-2 & 1 & 0 & 0 & \cdots & 0 −2 1 0 0 ··· 0
\\ 1 −2 1 0 ··· 0
1 & -2 & 1 & 0 & \cdots & 0 0 1 −2 1 ··· 0
\\ .. ..
0 0 1 −2 . .
0 & 1 & -2 & 1 & \cdots & 0 .. .. .. .. ..
\\ . . . . . 1
0 & 0 & 1 & -2 & \ddots & 0 0 0 ··· 1 −2
\vdots \\
\vdots & \vdots & \vdots &
\ddots & \ddots & 1 \\
0 & 0 & 0 & \cdots & 1 & -2
\end{matrix}
\]

18 Equation arrays
In the flow of a fluid film we may report:

\begin{eqnarray}
u_\alpha & = & \epsilon^2  
\kappa_{xxx} 2 1 2
uα =  κxxx y − y ,(5)
\left( y-\frac{1}{2}y^2 \right) 2
, v = 3 κxxx y , (6)
\label{equ} \\
p = κxx . (7)
v & = & \epsilon^3 \kappa_{xxx}
y\,,
\label{eqv} \\
p & = & \epsilon \kappa_{xx}\,.
\label{eqp}
\end{eqnarray}

Alternatively, the curl of a vector field (u, v, w) may be written with only
one equation number:

\begin{eqnarray} \frac{\partial u}{\partial z}


\omega_1 & = & -\frac{\partial w}{\partial x
\frac{\partial w}{\partial y} }\,,
-\frac{\partial v}{\partial z \label{eqcurl} \\
}\,, \omega_3 & = &
\nonumber \\ \frac{\partial v}{\partial x}
\omega_2 & = & -\frac{\partial u}{\partial y

2017
c LPSK, INSPEM, UPM 49
LATEX: An Introduction to Malaysian Academicians

}\,.
\nonumber
\end{eqnarray} ∂w ∂v
ω1 = − ,
∂y ∂z
∂u ∂w
ω2 = − , (8)
∂z ∂x
∂v ∂u
ω3 = − .
∂x ∂y

Whereas a derivation may look like


\begin{eqnarray*}
(p\wedge q)\vee(p\wedge\neg q) \quad
& = & p\wedge(q\vee\neg q) \\
& = & p\wedge T \\
& = & p
\end{eqnarray*}

(p ∧ q) ∨ (p ∧ ¬q) = p ∧ (q ∨ ¬q) by distributive law


= p ∧ T by multiple identity
= p by identity

19 Functions
Observe that trigonometric and other elementary functions are typeset prop-
erly, even to the extent of providing a thin space if followed by a single letter
argument:
\[
\exp(i\theta)=\cos\theta +i\sin\theta\,,\quad
\sinh(\log x)=\frac{1}{2} \left(x-\frac{1}{x} \right).
\]

 
1 1
exp(iθ) = cos θ + i sin θ , sinh(log x) = x− .
2 x

With sub- and super-scripts placed properly on more complicated functions,

2017
c LPSK, INSPEM, UPM 50
LATEX: An Introduction to Malaysian Academicians

\[
\lim_{q\to\infty}\|f(x)\|_q
=\max_{x}|f(x)|, lim kf (x)kq = max |f (x)|,
q→∞ x
\]

and large operators, such as integrals and


\begin{eqnarray*}
e^x & = & \sum_{n=0}^\infty \frac{x^n}{n!}
\quad\text{where }n!=\prod_{i=1}^n i\,, \\
\overline{U_\alpha} & = & \bigcap_\alpha U_\alpha\,.
\end{eqnarray*}

∞ n
X xn Y
ex = where n! = i,
n=0
n! i=1
\
Uα = Uα .
α

In inline mathematics the scripts are correctly placed to the side in order to
conserve vertical space, as in:

\( P∞
1/(1-x)=\sum_{n=0}^\infty x^n 1/(1 − x) = n=0 xn .
.
\)

20 Accents
Mathematical accents are performed by a short command with one argument,
such as:

\[
\tilde f(\omega)=\frac{1}{2\ Z ∞
pi} 1
f˜(ω) = f (x)e−iωx dx ,
\int_{-\infty}^\infty 2π −∞
f(x)e^{-i\omega x}\,dx\,,
\]

or

2017
c LPSK, INSPEM, UPM 51
LATEX: An Introduction to Malaysian Academicians

\[
\dot{\vec \omega}= ~˙ = ~r × I~ .
ω
\vec r\times\vec I\,.
\]

21 Command definition
The Airy function, Ai(x), may be incorrectly defined as this integral:

\[
\Ai(x)=\int\exp(s^3+isx)\,ds Z
\,. Ai(x) = exp(s3 + isx) ds .
\]

\newcommand{\D}[2]{\frac{\partial #2}{\partial #1}}


\newcommand{\DD}[2]{\frac{\partial^2 #2}{\partial #1^2}}
\renewcommand{\vec}[1]{\text{\boldmath$#1$}}

This vector identity serves nicely to illustrate two of the new commands:
\[
\vec\nabla\times\vec q
=\vec i\left(\D yw-\D zv\right)
+\vec j\left(\D zu-\D xw\right)
+\vec k\left(\D xv-\D yu\right).
\]

     
∂w ∂v ∂u ∂w ∂v ∂u
∇×q =i − +j − +k − .
∂y ∂z ∂z ∂x ∂x ∂y

22 Theorems et al.
Define new theorem as below:
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{definition}[theorem]{Definition}

2017
c LPSK, INSPEM, UPM 52
LATEX: An Introduction to Malaysian Academicians

\begin{definition}
[right-angled triangles] Definition 1 (right-angled trian-
\label{def:tri} gles). A right-angled triangle is a
A \emph{right-angled triangle} triangle whose sides of length a, b
is a and c, in some permutation of or-
triangle whose sides of length der, satisfies a2 + b2 = c2 .
~\(a\), \(b\) and~\(c\), in
some
permutation of order, satisfies
\(a^2+b^2=c^2\).
\end{definition}

\begin{lemma} \end{lemma}
The triangle with sides of
length
~\(3\), \(4\) and~\(5\) is Lemma 2. The triangle with sides
right- of length 3, 4 and 5 is right-angled.
angled.

This lemma follows from the Definition 1 as 32 + 42 = 9 + 16 = 25 = 52 .

\begin{theorem}[Pythagorean
triplets] \label{thm:py} Theorem 3 (Pythagorean triplets).
Triangles with sides of length Triangles with sides of length a =
\(a=p^2-q^2\), \(b=2pq\) and p2 − q 2 , b = 2pq and c = p2 + q 2
\(c=p^2+q^2\) are right-angled are right-angled triangles.
triangles.
\end{theorem}

Prove this Theorem~\ref{thm:py}


by Prove this Theorem 3 by the
the algebra \(a^2+b^2 algebra a2 + b2 = (p2 − q 2 )2 +
=(p^2-q^2)^2+(2pq)^2 (2pq)2 = p4 − 2p2 q 2 + q 4 + 4p2 q 2 =
=p^4-2p^2q^2+q^4+4p^2q^2 p4 + 2p2 q 2 + q 4 = (p2 + q 2 )2 = c2 .
=p^4+2p^2q^2+q^4
=(p^2+q^2)^2 =c^2\).

The real power of LaTeX (for us) is in the math environment. You push
and pop out of the math environment by typing $. For example, 2x3 − 1 = 5
is typed between dollar
PN signs as $2x^3 - 1 = 5$. Perhaps a more interesting
example is limN →∞ k=1 f (tk )∆t.
You can get a fancier, display-style math environment by enclosing your
equation with double dollar signs. This will center your equation, and display
sub- and super-scripts in a more readable fashion:

2017
c LPSK, INSPEM, UPM 53
LATEX: An Introduction to Malaysian Academicians

$$\lim_{N \to \infty}


\sum_{k=1}^N f(t_k) \Delta t.$$ N
X
lim f (tk )∆t.
N →∞
k=1

If you don’t want your equation line


to spacing a little bit.
be centered, but you want the
nice
indicies and all that, you can
If you don’t want your equa-
use
tion to be centered, but you want
\verb|\displaystyle| and get
the nice indicies and all that, you
your
can use \displaystyle and get
formula ‘‘in-line’’; using our
your formula “in-line”; using our
example: N
X
$\displaystyle \lim_{N \to \ example this is lim f (tk )∆t.
infty} N →∞
k=1
\sum_{k=1}^N f(t_k) \Delta t.$ Of course this can screw up your
Of line spacing a little bit.
course this can screw up your

There are many more things to know about LaTeX and we can’t possibly talk
about them all here. You can use LaTeX to get tables, commutative diagrams,
figures, aligned equations, cross-references, labels, matrices, and all manner of
strange things into your documents. You can control margins, spacing, align-
ment, et cetera to higher degrees of accuracy than the human eye can percieve.
You can waste entire days typesetting documents to be “just so”. In short,
LaTeX rules.
The best way to learn LaTeX is by example. Get yourself a bunch of .tex files,
see what kind of output they produce, and figure out how to modify them to do
what you want. There are many template and sample files on the department
LaTeX page and in real life in the big binder that should be in the computer
lab somewhere. Good luck!

23 Others
Notation. For p, q ∈ P and n ∈ ω we write (q, n) ≤ (p, n) if q ≤ p and Aq,n =
Ap,n .
\begin{notation} For $p,q\in P$ and $n\in\omega$
...
\end{notation}

2017
c LPSK, INSPEM, UPM 54
LATEX: An Introduction to Malaysian Academicians

24 Various font features of the amsmath package


Bold versions of special symbols
In the amsmath package \boldsymbol is used for getting individual bold math
symbols and bold Greek letters—everything inmath except for letters of the
Latin alphabet, where you’d use \mathbf. For example,

$$A_\infty + \pi A_0 \sim


\mathbf{A}_{\boldsymbol{\infty
}} A∞ + πA0 ∼ A∞ + πA0
\boldsymbol{+} \boldsymbol{\pi}
\mathbf{A}_{\boldsymbol{0}}$$

“Poor man’s bold”


If a bold version of a particular symbol doesn’t exist in the available fonts, then
\boldsymbol can’t be used to make that symbol bold. At the present time, this
means that \boldsymbol can’t be used with symbols from the msam and msbm
fonts, among others. In some cases, poor man’s bold (\pmb) can be used instead
of \boldsymbol:

$$\frac{\partial x}{\partial y}
\pmb{\bigg\vert} ∂x ∂y
\frac{\partial y}{\partial z}$$ ∂y ∂z

P Q
So-called “large operator” symbols such as and require an additional
command, \mathop, to produce proper spacing and limits when \pmb is used.
For further details see The TEXbook.

$$\sum_{\substack{i<B\\\text{ \kappa(r_i)$$
$i$
odd}}}
\prod_\kappa \kappa F(r_i)\
qquad XY XY
\mathop{\pmb{\sum}}_{\substack{ κF (ri ) κ(ri )
i<B i<B κ i<B κ
i odd i odd
\\\text{$i$ odd}}}
\mathop{\pmb{\prod}}_\kappa

Compound symbols and other features


Multiple integral signs
\iint, \iiint, and \iiiint give multiple integral signs with the spacing be-

2017
c LPSK, INSPEM, UPM 55
LATEX: An Introduction to Malaysian Academicians

tween them nicely adjusted, in both text and display style. \idotsint gives
two integral signs with dots between them.
\begin{gather}
\iint\limits_A f(x,y)\,dx\,
dy\qquad\iiint\limits_A f(x,y,z)\,dx\,dy\,dz\\
\iiiint\limits_A f(w,x,y,z)\,dw\,dx\,dy\,dz\\
\idotsint\limits_A f(x_1,\dots,x_k)
\end{gather}

ZZ ZZZ
f (x, y) dx dy f (x, y, z) dx dy dz (9)
A A
ZZZZ
f (w, x, y, z) dw dx dy dz (10)
A
Z Z
··· f (x1 , . . . , xk ) (11)
A

24.1 Over and under arrows


Some extra over and under arrow operations are provided inthe amsmath pack-
age. (Basic LaTeX provides \overrightarrow and \overleftarrow).

\begin{align*}
\overrightarrow{\psi_\delta(t)
−−−−−−→
E_t h}& ψδ (t)Et h = ψδ (t)Et h
=\underrightarrow{\psi_\delta(t −−−−−−→
←−−−−−−
) ψδ (t)Et h = ψδ (t)Et h
E_t h}\\ ←−−−−−−
←−−−−→
\overleftarrow{\psi_\delta(t) ψδ (t)Et h = ψδ (t)Et h
←−−−−→
E_t h}&
=\underleftarrow{\psi_\delta(t)
E_t h}\\
\overleftrightarrow{\psi_\delta
(t)
E_t h}&
=\underleftrightarrow{\psi_\
delta
(t) E_t h}
\end{align*}

2017
c LPSK, INSPEM, UPM 56
LATEX: An Introduction to Malaysian Academicians

These all scale properly in subscript sizes:

\[\int_{\overrightarrow{AB}} Z
ax\,dx\]

−→
ax dx
AB

Dots
Normally you need only type \dots for ellipsis dots in a math formula. The
main exception is when the dots fall at the end of the formula; then you need
to specify one of \dotsc (series dots, after a comma), \dotsb (binary dots, for
binary relations or operators), \dotsm (multiplication dots), or \dotsi (dots
after an integral). For example, the input:

Then we have the series $A_1,


A_2, Then we have the series
\dotsc$, A1 , A2 , . . . , the regional sum
the regional sum $A_1+A_2+\ A1 + A2 + · · · , the orthogonal
dotsb$, product A1 A2 · · · , and the infinite
the orthogonal product $A_1A_2 integral
\dotsm$, Z Z
and the infinite integral ···
\[\int_{A_1}\int_{A_2}\dotsi\]. A1 A2
.

Accents in math
Double accents:

\[\Hat{\Hat{H}}\quad\Check
{\Check{C}}\quad
ˆ ´ ` ˘
\Tilde{\Tilde{T}}\quad\Acute Ĥ ȡ T̃˜ Á G̀ Ḋ˙ ¨
D̈ B̆ ¯
B̄ V
{\Acute{A}}\quad
\Grave{\Grave{G}}\quad\Dot
{\Dot{D}}\quad
\Ddot{\Ddot{D}}\quad\Breve
{\Breve{B}}\quad
\Bar{\Bar{B}}\quad\Vec{\Vec{V
}}\]

This double accent operation is complicated and tends to slow down the
processing of a LaTeX file.

2017
c LPSK, INSPEM, UPM 57
LATEX: An Introduction to Malaysian Academicians

Dot accents
\dddot and \ddddot are available to produce triple and quadruple dot accents
in addition to the \dot and \ddot accents already available in LaTeX:

\[\dddot{Q}\qquad\ddddot{R}\]
... ....
Q R

Roots
In the amsmath package \leftroot and \uproot allow you to adjust the position
of the root index of a radical:
\sqrt[\leftroot{-2}\uproot{2}\beta]{k}

gives good positioning of the β: √


β
k

Boxed formulas
The command \boxed puts a box around its argument, like \fbox except that
the contents are in math mode:
\boxed{W_t-F\subseteq V(P_i)\subseteq W_t}

Wt − F ⊆ V (Pi ) ⊆ Wt .

Extensible arrows
\xleftarrow and \xrightarrow produce arrows that extend automatically to
accommodate unusually wide subscripts or superscripts. The text of the sub-
script or superscript are given as an optional resp. mandatory argument: Ex-
ample:

\[0 \xleftarrow[\zeta]{\alpha}
F\times\triangle[n-1]
\xrightarrow{\partial_0\alpha(b α ∂0 α(b)
− F × 4[n − 1] −−−−→ E ∂0 b
0←
)} ζ

E^{\partial_0b}\]

\overset, \underset, and \sideset


Examples:

2017
c LPSK, INSPEM, UPM 58
LATEX: An Introduction to Malaysian Academicians

\[\overset{*}{X}\qquad
\underset{*}{X}\qquad ∗ a
X X X
\overset{a}{\underset{b}{X}}\] ∗ b

The command \sideset is for a rather special purpose: putting symbols P at


the
Q subscript and superscript corners of a large operator symbol such as or
, without affecting the placement of limits. Examples:

\[\sideset{_*^*}{_*^*}\prod_k\
qquad
∗ Y∗ X0
\sideset{}{’}\sum_{0\le i\le m} Ei βx
∗ ∗
E_i\beta x k 0≤i≤m
\]

The \text command


The main use of the command \text is for words or phrases in a display:

\[\mathbf{y}=\mathbf{y}’
\quad\text{if and only if}\quad
y’_k=\delta_k y_{\tau(k)}\] y = y0 if and only if yk0 = δk yτ (k)

Operator names
The more common math functions such as log, sin, and lim have predefined con-
trol sequences: \log, \sin, \lim. The amsmath package provides \DeclareMathOperator
and \DeclareMathOperator*for producing new function names that will have
the same typographical treatment. Examples:

\[\norm{f}_\infty=
\esssup_{x\in R^n}\abs{f(x)}\]
kf k∞ = ess supx∈Rn |f (x)|

$$\meas_1\{u\in R_+^1\colon
f^*(u)>\alpha\}
=$$ 1
meas1 {u ∈ R+ : f ∗ (u) > α} =
$$\meas_n\{x\in R^n\colon
\abs{f(x)}\geq\alpha\} measn {x ∈ Rn : |f (x)| ≥ α} ∀α > 0.
\quad \forall\alpha>0.$$

2017
c LPSK, INSPEM, UPM 59
LATEX: An Introduction to Malaysian Academicians

\esssup and \meas would be defined in the document preamble as:


\DeclareMathOperator*{\esssup}{ess\,sup}
\DeclareMathOperator{\meas}{meas}
The following special operator names are predefined in the amsmath package:
\varlimsup, \varliminf, \varinjlim, and \varprojlim. Here’s what they
look like in use:

\begin{align}
&\varlimsup_{n\rightarrow\infty
} lim Q(un , un − u# ) ≤ 0 (12)
n→∞
\mathcal{Q}(u_n,u_n-u^{\#})\le0
\\ lim |an+1 | / |an | = 0 (13)
n→∞
&\varliminf_{n\rightarrow\infty
lim(mλi ·)∗ ≤ 0 (14)
} −→
\left\lvert a_{n+1}\right\rvert lim Ap ≤ 0 (15)
←−
/\left\lvert a_n\right\rvert p∈S(A)
=0\\
&\varinjlim (m_i^\lambda\cdot)
^*
\le0\\
&\varprojlim_{p\in S(A)}A_p\le0
\end{align}

\begin{align} &\varprojlim_{p\in S(A)}A_p\le0


&\varlimsup_{n\rightarrow\infty \end{align}
}
\mathcal{Q}(u_n,u_n-u^{\#})\le0
\\
&\varliminf_{n\rightarrow\infty lim Q(un , un − u# ) ≤ 0 (16)
} n→∞

\left\lvert a_{n+1}\right\rvert lim |an+1 | / |an | = 0 (17)


n→∞
/\left\lvert a_n\right\rvert
=0\\ lim(mλi ·)∗ ≤ 0 (18)
−→
&\varinjlim (m_i^\lambda\cdot) lim Ap ≤ 0 (19)
←−
^* p∈S(A)
\le0\\

\mod and its relatives


The commands \mod and \pod are variants of \pmod preferred by some authors;
\mod omits the parentheses, whereas \pod omits the ‘mod’ and retains the
parentheses. Examples:

2017
c LPSK, INSPEM, UPM 60
LATEX: An Introduction to Malaysian Academicians

\begin{align}
x&\equiv y+1\pmod{m^2}\\
x&\equiv y+1\mod{m^2}\\ x≡y+1 (mod m2 ) (20)
x&\equiv y+1\pod{m^2} 2
x≡y+1 mod m (21)
\end{align}
2
x≡y+1 (m ) (22)

Fractions and related constructions


The usual notation for binomials is similar to the fraction concept, so it has a
similar command \binom with two arguments. Example:
\begin{equation}
\begin{split}
\sum_{\gamma\in\Gamma_C} I_\gamma&=2^k-\binom{k}{1}2^{k-1}
+\binom{k}{2}2^{k-2}\\
&\quad+\dots+(-1)^l\binom{k}{l}2^{k-l}+\dots+(-1)^k\\
&=(2-1)^k=1
\end{split}
\end{equation}

   
X k k−1 k k−2
Iγ = 2k − 2 + 2
1 2
γ∈ΓC
(23)
 
k k−l
+ · · · + (−1)l 2 + · · · + (−1)k
l
= (2 − 1)k = 1

There are also abbreviations


\dfrac \dbinom
\tfrac \tbinom
for the commonly needed constructions
{\displaystyle\frac ... } {\displaystyle\binom ... }
{\textstyle\frac ... } {\textstyle\binom ... }
The generalized fraction command \genfrac provides full access to the six
TEX fraction primitives:
\begin{align}
\text{\cn{over}: }&\genfrac{}{}{}{}{n+1}{2}&

2017
c LPSK, INSPEM, UPM 61
LATEX: An Introduction to Malaysian Academicians

\text{\cn{overwithdelims}: }&
\genfrac{\langle}{\rangle}{}{}{n+1}{2}\\
\text{\cn{atop}: }&\genfrac{}{}{0pt}{}{n+1}{2}&
\text{\cn{atopwithdelims}: }&
\genfrac{(}{)}{0pt}{}{n+1}{2}\\
\text{\cn{above}: }&\genfrac{}{}{1pt}{}{n+1}{2}&
\text{\cn{abovewithdelims}: }&
\genfrac{[}{]}{1pt}{}{n+1}{2}
\end{align}

 
n+1 n+1
\over: \overwithdelims: (24)
2 2
 
n+1 n+1
\atop: \atopwithdelims: (25)
2 2
 
n+1 n+1
\above: \abovewithdelims: (26)
2 2

Continued fractions
The continued fraction

\begin{equation}
\cfrac{1}{\sqrt{2}+
\cfrac{1}{\sqrt{2}+ 1
\cfrac{1}{\sqrt{2}+ √ 1
\cfrac{1}{\sqrt{2}+ 2+
√ 1
\cfrac{1}{\sqrt{2}+\dotsb 2+
√ 1
}}}}} 2+
\end{equation} √ 1
2+ √
2 + ···
(27)

Left or right placement of any of the numerators is accomplished by using


\cfrac[l] or \cfrac[r] instead of \cfrac.

Smash
In amsmath there are optional arguments t and b for the plain TEX command
\smash, because sometimes it is advantageous to be able to ‘smash’ only the top
or only the bottom of something while retaining the natural depth or height. In

2017
c LPSK, INSPEM, UPM 62
LATEX: An Introduction to Malaysian Academicians


the formula Xj = (1/ λj )Xj0 \smash[b] has been used to limit the size of the
radical symbol.
$X_j=(1/\sqrt{\smash[b]{\lambda_j}})X_j’$
Without the use of \smash[b] the formula would have appeared thus: Xj =
(1/ λj )Xj0 , with the radical extending to encompass the depth of the subscript
p

j.

The ‘cases’ environment


‘Cases’ constructions like the following can be produced using the cases envi-
ronment.
\begin{equation}
P_{r-j}=
\begin{cases}
0& \text{if $r-j$ is odd},\\
r!\,(-1)^{(r-j)/2}& \text{if $r-j$ is even}.
\end{cases}
\end{equation}

(
0 if r − j is odd,
Pr−j = (28)
r! (−1)(r−j)/2 if r − j is even.

Notice the use of \text and the embedded math.

Matrix
Here are samples of the matrix environments,\matrix, \pmatrix, \bmatrix,
\Bmatrix, \vmatrix and \Vmatrix:

\begin{equation} \end{bmatrix}
\begin{matrix} \end{equation}
\vartheta& \varrho\\\varphi& \
varpi
\end{matrix}\quad
\begin{pmatrix}
\vartheta& \varrho\\\varphi& \
varpi
\end{pmatrix}\quad
\begin{bmatrix}
\vartheta& \varrho\\\varphi& \
varpi

2017
c LPSK, INSPEM, UPM 63
LATEX: An Introduction to Malaysian Academicians

   
ϑ % ϑ % ϑ %
ϕ $ ϕ $ ϕ $
(29)

\begin{equation}
\begin{Bmatrix}  
\vartheta& \varrho\\\varphi& \ ϑ % ϑ
% ϑ
%
varpi ϕ $ ϕ $ ϕ $
\end{Bmatrix}\quad (30)
\begin{vmatrix}
\vartheta& \varrho\\\varphi& \
varpi
\end{vmatrix}\quad
\begin{Vmatrix}
\vartheta& \varrho\\\varphi& \
varpi
\end{Vmatrix}
\end{equation}

To produce a small matrix suitable for use in text, use the smallmatrix
environment.
\begin{math}
\bigl( \begin{smallmatrix}
a&b\\ c&d
\end{smallmatrix} \bigr)
\end{math}
To show the effect of the matrix on the surrounding lines of a paragraph, we
put it here: ac db and follow it with enough text to ensure that there will be at
least one full line below the matrix.
\hdotsfor{number } produces a row of dots in a matrix spanning the given
number of columns:
ϕ
0 ... 0
(ϕ1 , ε1 )


ϕkn2 ϕ
(ϕ , ε ) (ϕ , ε ) . . . 0

W (Φ) = 2 1

2 2
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ϕkn1 ϕkn2 ϕkn n−1 ϕ
(ϕ , ε ) (ϕ , ε ) . . . (ϕ , ε

n 1 n 2 n n−1 ) (ϕn , εn )
\[W(\Phi)= \begin{Vmatrix}
\dfrac\varphi{(\varphi_1,\varepsilon_1)}&0&\dots&0\\
\dfrac{\varphi k_{n2}}{(\varphi_2,\varepsilon_1)}&

2017
c LPSK, INSPEM, UPM 64
LATEX: An Introduction to Malaysian Academicians

\dfrac\varphi{(\varphi_2,\varepsilon_2)}&\dots&0\\
\hdotsfor{5}\\
\dfrac{\varphi k_{n1}}{(\varphi_n,\varepsilon_1)}&
\dfrac{\varphi k_{n2}}{(\varphi_n,\varepsilon_2)}&\dots&
\dfrac{\varphi k_{n\,n-1}}{(\varphi_n,\varepsilon_{n-1})}&
\dfrac{\varphi}{(\varphi_n,\varepsilon_n)}
\end{Vmatrix}\]
The spacing of the dots can be varied through use of a square-bracket option,
for example, \hdotsfor[1.5]{3}. The number in square brackets will be used
as a multiplier; the normal value is 1.

The \substack command


The \substack command can be used to produce a multiline subscript or su-
perscript: for example
\sum_{\substack{0\le i\le m\\ 0<j<n}} P(i,j)
produces a two-line subscript underneath the sum:
X
P (i, j) (31)
0≤i≤m
0<j<n

A slightly more generalized form is the subarray environment which allows you
to specify that each line should be left-aligned instead of centered, as here:
X
P (i, j) (32)
0≤i≤m
0<j<n

\sum_{\begin{subarray}{l}
0\le i\le m\\ 0<j<n
\end{subarray}}
P(i,j)

Big-g-g delimiters
Here are some big delimiters, first in \normalsize:

\[\biggl(\mathbf{E}_{y}
\int_0^{t_\varepsilon}L_{x,y^x(  Z tε 
s)}
Ey Lx,yx (s) ϕ(x) ds
\varphi(x)\,ds \biggr) 0
\]

and now in \Large size:

2017
c LPSK, INSPEM, UPM 65
LATEX: An Introduction to Malaysian Academicians

{\Large
\[\biggl(\mathbf{E}_{y}
\int_0^{t_\varepsilon}L_{x,y^x(
 Z tε 
s)} Ey Lx,yx (s) ϕ(x) ds
\varphi(x)\,ds \biggr) 0
\]}

25 References and Bibliography


There are two methods for creating a bibliography. The first can be used
for short documents with only a few sources, and is fairly simple. The sec-
ond method is used for large documents and theses, and involves using a pro-
gram called ”bibtex”. In this notes we only focus on simple method using
\begin{thebibliography} ... \end{thebibliography}. If all of this seems
complicated, there is a simpler way to produce a quick bibliography for your
document. This can be used for smaller papers, ones that don’t need a very
extensive bibliography. Something like this will work fine:

\begin{thebibliography}{1}

\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}

You can put this at the end of your LaTeX file. If you want to refer to
something from your bibliography you can put something like this in your file:

This is obvious \cite{norman}.


This is obvious [3].

The only awkward using \begin{thebibliography} ... \end{thebibliography}


is that all the references listed as \bibitem will be appeared in the References
Section.

2017
c LPSK, INSPEM, UPM 66
LATEX: An Introduction to Malaysian Academicians

References
[1] John W. Dower Readings compiled for History 21.479. 1991.
[2] The Japan Reader Imperial Japan 1800-1945 1973: Random House, N.Y.
[3] E. H. Norman Japan’s emergence as a modern state 1940: International
Secretariat, Institute of Pacific Relations.

[4] Bob Tadashi Wakabayashi Anti-Foreignism and Western Learning in Early-


Modern Japan 1986: Harvard University Press.

2017
c LPSK, INSPEM, UPM 67

You might also like