Beruflich Dokumente
Kultur Dokumente
∗
Huan Ha
Abstract
I think most of us, researchers and students use LATEX for the needs of typing
mathematics in our document. While Word processors such as Microsoft Word,
Libre Office and Page gives a nice What-You-See-Is-What-You-Get editor, their
functions to typeset and export mathematic formulas are very limited, partic-
ularly for not-at-ease-using-mouse people like myself. I always feel that typing
mathematics in Word is a pain, it makes too long time and I have to move
the mouse too much to find the correct button. In LATEX, you can “code” the
formulas and export it in high quality that you can use for presentations or
∗ hathuchuan@gmail.com
1
printable articles. It takes time to learn it, certainly, but one you know it, you
can do it a lot faster than moving the mouse around the screen.
LATEX also has the advantage of predefined layouts that are really useful for
publishing your article. By producing your text in LATEX, you can then use
any template from any publisher to change it style in seconds. Saving time on
defining “Heading1”, “Heading 2” . . . , you focus more on the writing task.
LATEX can also be used to produce presentations, not as fancy as Power
Point, Preview or Prezi, but with its predefined layouts, you can make it fast.
Another reason to use LATEX is the network effect. If you are in graduate and
post-graduate at university, in disciplines related to mathematics, almost every-
body is using LATEX to write. It is required if you want your article published
anyway.
2 Installing LATEX
2
A cross-platform distribution exists for Windows, Unix and MacOs is TeX Live.
I’ve never used it myself.
There are many LATEX editors on all platforms. I personally prefers TeXmaker
and its “children” TeXstudio. These two can be used on Windows, Mac and
Unix/Linux equally well.
If you are not happy with these two, check out the 8 best LATEXeditors of
the year 2017 or the big list of LATEX editors. TeXnicCenter and WinEdt are
specific for Windows while TeXShop is for MacOs. BaKoMa is a nice live-view1
editor but it is not free. The debate on which one is the best editor has been
for years and probably will never end. Use what you find suitable.
3 Fundamentals
The input for LATEXis a plain text file. Just open your editor and create a new
file, then you can start. This file need to be saved (as a .tex) file before you can
compile it.
Open your editor, create the new file and type
\documentclass[12pt]{article}
\usepackage{amsmath}
\linespread{1.6}
\begin{document}
This is the input file.
\end{document}
Then save it and press the COMPILE button. It is normally a right triangle on
the toolbar of the editor.
1 You will see how you miss a visual WYSIWYG (What you see is what you get) editor
when you look at the forest of codes in a standard LATEX editor
3
3.1 Preamble
This is where the “predefined layout” part of LATEX gets in. To make LATEX
understand what type of document you want to create and the layout of it, you
declare everything before to start writing the text. An example of an input file
is as follow:
Every command before \begin{document} in the input above is the pream-
ble.
You start by declaring the class of document by \documentclass[options]{class}.
The classes are
• minimal for minimal needs. It only set a page size and a base font.
• slides for slides with big sans serif letters. you’d better use the beamer
class instead
There are many options, for a full description, look at this document. For basic
usage, you don’t need to use much of them. The default font size is 10pt, so I
normally put 12pt in to have large font size.
\usepackage{...} is to load package that add new features to the LATEXsystem.
I will mention some usual packages in the following sections, whenever you see
a package (amsmath for mathematics typeset for example), you know that you
have to load that package (\usepackage{amsmath}) in the preamble to use it.
2 this document that you are reading uses this class
4
In the preamble, you also add commands to influence the style of the whole
documents, the command \linespread{1.6} tell LATEXabout the interline spac-
ing in the output document, here 1.6 means you want an equivalent of double
space in Microsoft Word.
When all the setup work is done, you start the body of the text with the
command \begin{document} At the end of the document, you add the com-
mand \end{document} to tells LATEX to finish. Anything after this command
will be ignore.
Remark: this is what makes LATEXis useful in publication. You can go to
the publisher, download their template, put in your preamble and everything
will be set in the required style. If I want to submit my paper to Elsevier Ltd.,
I type \documentclass{elsarticle}. No more job!
3.2 Commands
3.3 Comments
5
printed version.
\end{comment}
is an economic concept
3.4 Spaces
All types of spaces (blank space or tab) are treated uniformly as “space” in
LATEX. Several consecutive whitespace are treated as one “space”. Whitespace
at the start of a line is ignored, a single line break is treated as “whitespace”.
One thing to pay attention here, to start a new paragraph, make an empty
line. Most people completely underestimate the importance of well-placed para-
graph breaks. If you continue the same idea, you must be on the same paragraph.
When you start a new idea, a new paragraph must start. This is particularly
important when you have mathematics equation in the paragraph. Look at the
following input and the output in blue.
6
\begin{equation}
\max_{q_1, q_2} \pi^E = q_1 \Big(1 - q_1\Big)
+ q_2 \Big( 1 - q_2 - \sum_{1}^{m} r_k \Big)
\end{equation}
with $r_k$ the quantity of recycled material
produced by the recycler $k$ in the second period.
When a paragraph start (”In the second period”), the first line is indented,
this is the signal to the reader that you start a new idea. But at “with rk ”,
7
even though the equation breaks the line, the sentence is not indented, this tells
reader to keep going with the same idea as above.
If you want to break the line without starting a new paragraph, you have to
type \\ or \newline. The command \\* additionally prohibits a page break
after the forced line break.
If you want to have a page break, use the command \newpage.
# $ % ^ &_ { } ~ \
So when you type these characters, they will not appear in your output and
may cause errors that can stops LATEXto work unexpectedly. To typeset these
characters, use
The quotation mark in LATEXis not ideal, you have to use the “grave accent”
(`) for opening quotes and vertical quote (´) for closing. use two ` and two ´
for double quotes(the latter is the normal quotation marks on your keyboard).
‘‘ Please press the ‘x’ key." “ Please press the ‘x’ key.”
3.7 Ellipsis (. . . )
The command for ellipsis is \ldots (low dots), the ... makes the dots and
spaces smaller.
8
Not like this ... but like this:\\ Not like this ... but like this:
3.9 Environments
\begin{environment}
...
\end{environment}
These are the environments for listing, itemize is suitable for simple lists,
enumerate for enumerated lists and description for descriptions. Try the
following example:
9
\begin{enumerate}
\item You can use itemize for
simple list
1. You can use itemize for simple
\begin{itemize}
\item with black dots list
\item[-] or a dash.
• with black dots
\end{itemize}
- or a dash.
\item You can use description with
imagination 2. You can use description with
\begin{description}
imagination
\item[Stupid] when you hate it
\item[Smart] when you like it Stupid when you hate it
\item[$\infty$] if you want this ∞ if you want this list never end
list never end
\end{description}
\end{enumerate}
Listing in LATEX is leveled automatically when you nest many level of the
same listing environment.
10
\begin{itemize}
\item I know
\begin{itemize}
\item I’m stupid
\begin{itemize}
\item most of the time
\end{itemize} • I know
\end{itemize}
– I’m stupid
\end{itemize}
∗ most of the time
\begin{enumerate}
1. But I don’t know
\item But I don’t know
\begin{enumerate} (a) sometimes
\item sometimes
i. I’m too smart
\begin{enumerate}
A. particularly when
\item I’m too smart
it is unnecessary
\begin{enumerate}
\item particularly when it is
unnecessary
\end{enumerate}
\end{enumerate}
\end{enumerate}
\end{enumerate}
3.9.2 Tabular
The command tabular can be used to create beautiful tables in LATEX. The
code to type is
\begin{tabular}[pos]{cols}
...
\end{tabular}
11
cols is where you define the table’s column, if you want a vertical frame, use
|, the choices for alignment are l, r, c respectively for left, right and center
alignment.
\begin{tabular}{|l|l|}
\hline
Mai& Huynh \\
Mai Huynh
\hline
Huan An
Huan & An \\
\hline
\end{tabular}
\begin{tabular}{|p{5 cm}|}
\hline
Welcome to Box paragraph. Welcome to Box paragraph. We
We sincerely hope you will sincerely hope you will all enjoy
all enjoy the show.\\ the show.
\hline
\end{tabular}
4 Math typeset
\begin{equation}
<math>
12
\end{equation}
or
\begin{equation*}
<math>
\end{equation*}
The first one automatically put a number after your mathematics, the second
omits it.
\end{equation*}
4.2 Matrices
13
\begin{equation*}
\begin{matrix}
1 & 2 \\
3&4 \end{matrix} \qquad \begin{
bmatrix}
p_{11} & p_{12} & \ldots
& \vdots \\
p_{m1} & p_{m2} & \ldots
& p_{mn}
\end{bmatrix}
\end{equation*}
Because math mode doesn’t treat spaces when you type as spaces in the output.
You can insert special spacing commands: \, for 3/18 quad, \: for 4/18 quad,
\; for 5/18 quad, \ and \> for a medium size space, \quad and \qquad for
wider spaces. If you find that the space is to wide, you can also reduce it by
typing \! to reduce the space by -3/18 quad.
When you type multiple integrals as in $\int \int f(x,y) \di x \di y$ ,
RR
you will find the spacing between the integrals is too wide: f (x, y) dx dy.
Correct it by using \! - $\int \!\!\!\int f(x,y) \di x \di y$ or us-
ing amsmath with these command \iint, \iiint, \iiiint and idotsint like
RR
$\iint f(x,y) \di x \di y$ to get f (x, y) dx dy. The latter solution is
not only more efficient but also shorter to type.
14
4.4 Differential
Rb
a
x dx gives the conventional differential symbol a bit lean, to correct it, we
Rb
use \mathrm{d} as a x dx. If you have to write a lot of this, define the new
command by typing \newcommand{\ud}{\,\mathrm{d}} in the preamble, then
Rb
you can write \int_{a}^{b} x \di x to get the same thing a x dx.
Sometimes in math mode you need to write letters in different fonts like the
set of real numbers R or the Lagrangian expression L , then you have different
math fonts to choose. I simply stick to the one I like the most. Below are the
fonts to choose. As usual, if you use the specific letter a lot, it’s easier to set
new command \newcommand{\la}{\mathscr{L}} in the preamble so that you
can shorten your typeset \la for L
Example Command Required package
ABCDEabcde1234 \mathrm{ABCDE abcde 1234}
ABCDEabcde1234 \mathit{ABCDE abcde 1234}
ABCDEabcde \mathnormal{ABCDE abcde 1234}
ABCDEabcde∞∈34 \mathcal{ABCDE abcde 1234}
A BC DE \mathscr{ABCDE abcde 1234} mathrsfs
ABCDEabcde1234 \mathfrak{ABCDE abcde 1234} amsfonts or amssymb
ABCDEa1234 \mathbb{ABCDE abcde 1234} amsfonts or amssymb
Sometimes you need to tell LATEX the correct font size. In math mode, this
is set with the following commands: \displaystyle (123), \textstyle(123),
\scriptstyle (123) and \scriptscriptstyle (123)
Changing styles generally affects the way big operators and limits are dis-
P
played. If is placed in a fraction, it’ll be set in text style unless you tell
LATEXotherwise:
\begin{equation*}
15
P = \frac{\sum_{i=1}^n (x_i- x) (y_i- y)}
{\displaystyle{\left[ \sum_{i=1}^n(x_i-x)^2
\sum_{i=1}^n(y_i- y)^2 \right]^{1/2}}}
\end{equation*}
gives Pn
i=1 (xi − x)(yi − y)
P =" #1/2
n
X n
X
2 2
(xi − x) (yi − y)
i=1 i=1
In math mode you can use \mathbf to get bold symbols but it doesn’t work
on lower case Greek letters. There is a \boldmath command that works for
symbols too, but this can only be used outside math mode:
gives µ, M µ, M µ, M
\newtheorem{name}[counter]{text}[section]|
16
\begin{proof}
Proof. Trivial, use
Trivial, use
\begin{equation*}
E = mc2 .
E=mc^2.
\end{equation*}
\end{proof}
With the command \qedhere you can move the ‘end of proof’ symbol around
for situations where it would end up alone on a line.
\begin{proof}
Trivial, use
Proof. Trivial, use
\begin{equation*}
E=mc^2. \qedhere E = mc2 .
\end{equation*}
\end{proof}
\begin{proof}
This is a proof that ends
Proof. This is a proof that ends with
with an equation array:
an equation array:
\begin{IEEEeqnarray*}{rCl}
a & = & b + c \\ a=b+c
& = & d + e. \qedhere
= d + e.
\end{IEEEeqnarray*}
\end{proof}
17
\begin{proof}
This is a proof that ends
Proof. This is a proof that ends with
with an equation array:
an equation array:
\begin{IEEEeqnarray*}{+rCl+x*}
a & = & b + c \\ a=b+c
& = & d + e. & \qedhere
= d + e.
\end{IEEEeqnarray*}
\end{proof}
Here the + in {+rCl+x*} denotes the stretchable spaces, one on the left and
one on the right of the equations. But now on the right, after the stretching
column, we add an empty column x. This column is to put the \qedhere in.
Finally, we specify a *. This is a null-space to prevent IEEEeqnarray from
adding another unwanted space.
In the case of equation numbering, without declaring \qedhere, we’ve got
the same problem
\begin{proof}
Proof. This is a proof that ends with
This is a proof that ends
with a numbered equation:
a numbered equation:
\begin{equation}
a = b + c. (4)
a = b + c.
\end{equation}
\end{proof}
we have to correct it by
18
\begin{proof}
This is a proof that ends Proof. This is a proof that ends with
with a numbered equation: a numbered equation:
\begin{equation}
a = b + c. (5)
a = b + c. \qedhere
\end{equation}
\end{proof}
Another example is
\begin{proof}
Proof. This is a proof that ends with
This is a proof that ends
an equation array:
with an equation array:
\begin{IEEEeqnarray}{rCl}
a=b+c (6)
a & = & b + c \\
= d + e. (7)
& = & d + e.
\end{IEEEeqnarray}
\end{proof}
contrasting with
\begin{proof}
This is a proof that ends Proof. This is a proof that ends with
with an equation array:
an equation array:
\begin{IEEEeqnarray}{+rCl+x*}
a & = & b + c \\ a=b+c (8)
& = & d + e. \\ = d + e. (9)
&&& \qedhere\nonumber
\end{IEEEeqnarray}
\end{proof}
5 Graphics
19
\includegraphics[key=value, . . . ]{file}
to include file into your documents. The keys can be used to alter the width,
height and rotation of the included graphic.
\width scale graphic to the specified width
\height scale graphic to the specified height
Example:
\angle rotate graphic counterclockwise
\scale scale graphic size
\begin{figure}
\centering
\includegraphics[angle=90, width=0.5\textwidth]{test}
\caption{This is a test.}
\end{figure}
includes the graphic stored in the file test. The graphic is rotated by an angle of
90 degree and scaled to the final width of 0.5 the width of a standard paragraph.
6 Bibliography
This part is really important if you are writing academic documents. Check out
the BibTex program.
For short bibliography, you can include it in the input file as follow
20
7 Creating mathematical graphics
Sometime you will want to draw graphs directly in the input file because you
want a high-quality graph or you want to use the graph in slides with different
animations. Then LATEXprovides a package Tikz (\usepackage{tikz}) to help
you. The creation phase is tiring but you will enjoy the result when it is done.
8 Customizing LATEX
\newcommand{\di}{\,\mathrm{d}}
\newcommand{\la}{\mathscr{L}}
\newcommand{\tvsil}{The very short intro to \LaTeX}
and write This is $\di$, $\la$ and \tvsil, you will get
This is d, L and The very short intro to LATEX
Just as with \newcommand, you can also create your own environments with the
syntax
\newenvironment{name}[num]{before}{after}
21
8.3 Fonts and Sizes
8.4 Spacing
If you want the use large inter-line spacing (single, 1.5, double spacing in
Word), put \linespread{factor } in the preamble of your document. Use
\linespread{1.3} for 1.5 line spacing, and \linespread{1.6} for double line
spacing. Without declaring, the default line spread factor is 1.
9.1 Macros
22
Figure 1: Edit macros in TexStudio
Figure 9.1, you can find an illustration of editing macros in TexStudio. In this
example, I define the macro \serv to auto-complete for the world “servitiza-
tion”. As I am lazy and the word is rather weird, this macro helps me in writing
fast and correctly the word. In the other macro, \equa is to be replaced by the
environment
\begin{equation}
\end{equation}
the symbol %| or %<%> indicates the placeholders where located the cursor where
you start to write when the environment pops out. Here in the
23