Basic Tutorial To L TEX Programming
Basic Tutorial To L TEX Programming
https://www.latex-project.org/
Contents ii
1 LATEX ? 1
1.1 WYSIWYG vs. LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Installing LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.1 Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.2 Mac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.3 Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Before running LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3.1 WYSIWYG-like tools for LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3.2 LATEX editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3.3 How to install manually a package for LATEX . . . . . . . . . . . . . . . . . . . 4
3 LATEX essentials 15
3.1 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2 Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.3 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.4 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
i
4.2.6 Inserting an image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
4.2.7 Inserting a list / enumeration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.2.8 Inserting a reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.2.9 Inserting web links and emails . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.2.10 Inserting a bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5 Spell checking 39
5.1 Using the command line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
5.2 Using Texmaker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
7 Examples 47
7.1 Title and authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
7.1.1 RevTex 4.1 - "revtex4-1" . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
7.1.2 American Chemical Society "achemso" . . . . . . . . . . . . . . . . . . . . . . 48
7.1.3 Elsevier "elsarticle" . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
7.1.4 Institute Of Physics "iopart" . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
7.2 Tables and figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.3 Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
8 Partial glossary 55
8.1 Useful commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
8.1.1 In text mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
8.1.2 In math mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
8.2 Useful environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
9 Error messages 59
9.1 LATEX errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
9.2 TEX errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
ii
LATEX ?
LATEX, shortcut for ’Lamport TEX’, is a document markup language invented by Leslie Lamport
in 1983. The purpose of LATEX is to simplify the utilization of the word processor TEX devel-
oped by Donald Knuth since 1977.
With typical word processors such as Microsoft Word and LibreOffice Writer, called WYSI-
WYG editors "What You See Is What You Get", one can immediately visualize the formatted
text and the final shape of the document on the screen.
In LATEX the writer uses plain text (as opposed to formatted text), relying on markup tagging
conventions to:
• define the general structure of a document (such as article, book, and letter).
A TEX distribution such as TeX Live or MiKTeX is used to produce an output file (such as PS,
PDF or DVI) suitable for printing or digital distribution.
Many ideas in this HowTo where inspired by the very good book "LATEX par la pratique" (in
French) by Christian Rolland [1] ...
1
Chapter 1. LATEX ? 2
Using a WYSIWYG editor you can visualize the result of your work immediately. With LATEX
few steps are required to obtain the final manuscript using the source file(s) in TEX language.
The sequence of these steps is called compilation, and the compilation process can slightly
change from one case to another.
To install the minimal Tex Live distribution on RedHat based Linux use:
Afterwards the following commands ensure that you will install on your computer all the
packages required to produce the examples proposed in this HowTo, many of which might
already be installed by the previous command.
• Scientific editors:
2
3 1.3. Before running LATEX
• Bibliography:
• Others:
1.2.2 Mac
You need to install the MacTeX distribution:
1.2.3 Windows
The best choice is probably to install the MiKTeX distribution which is an up-to-date imple-
mentation of TEX, LATEX and related programs for Windows:
Using these softwares you can prepare your LATEX manuscript in a Microsoft Word or Libre-
Office Writer kind of way, however they are limited and the source file they produce, if you
generate some errors, and you will, is usually complicated to read.
3
Chapter 1. LATEX ? 4
– GNU Emacs
– gVim
Hereafter I will use few examples from Texmaker, an opensource multiplateform (Linux, Mac,
Windows) software that provides a user interface with spell-checking (see ??), help to many
LATEX commands and a PDF reader.
When you try to typeset a document which requires a package which is not installed on your
system, LATEX will warn you with an error message that it is missing [see 9]. Most LATEX
installations come with a large set of pre-installed style packages, so you can use the package
manager of the TEX distribution or the one on your system to manage them. But many more are
available on the net. The main place to look for style packages on the Internet is Comprehensive
TEX Archive Network, CTAN. Once you have identified a package you need that is not in your
distribution, use the search engines of any CTAN server to find it. Download and follow this
procedure to install it (after opening the archive):
4
5 1.3. Before running LATEX
1. Extract the files of the package: run LATEX on the *.ins file, ex:
• For Windows open the *.ins using Texmaker and run a "Quick Build" [see 2.2.2]
2. Create the documentation: run LATEX twice on the *.dtx file, ex:
• For Windows open the *.dtx using Texmaker and run a "Quick Build" [see 2.2.2]
5
Chapter 1. LATEX ? 6
The folder to look for should probably be called texmf/ or texmf-local/ and its loca-
tion depends on your operating system:
• Linux: $HOME/texmf/
• Mac (MacTeX): /Users/username/Library/texmf/
• Windows (MikTeX): any folder registered as a user-managed texmf directory
The "right place" sometimes causes confusion, the "right place" for a LATEX .sty file is a
suitably-named sub-directory of texmf/tex/latex/ "Suitably-named" means sensible,
meaningful and probably short.
Often there is just a .sty file to move, but for complex packages there may be more,
and they may belong in different locations. For example, new BibTeX packages or font
packages will typically have several files to install. This is why it is a good idea to create
a sub-directory for the package rather than dump the files into misc along with other
unrelated stuff. In any case read the documentation to find out if there is a special or
preferred location to move them to.
6
7 1.3. Before running LATEX
7
LATEX - the first step
The LATEX file is a simple text file with the *.tex extension.
9
Chapter 2. LATEX - the first step 10
On the document class declaration line you can also find additional options, or keywords,
separated by a coma:
\documentclass[a4paper,12pt]{article}
In this example the first keyword specify the paper layout, the second is used to change the
default font size in the entire document. 3 different font sizes are available in the book and
article classes: 10pt, 11pt or 12pt, other are available using packages [see 3.3].
For more details about the different keywords or options, please refer the documentation of the
corresponding document class.
Almost all scientific journals provide their own guidelines for LATEX publishing, including the
document class you need to use, the trick is only, when needed, to download the class from the
web site of the journal and to know how to install it [See 1.3.3]. For example the American
Phsyical Society, APS (Phys. Rev., Phys. Rev. Lett. ...) and the American Institute of Physics,
AIP (J. Chem. Phys., Appl. Phys. Lett. ...) use the revtex4.1 class:
\documentclass[prb,twocolumn,showkeys,showpacs,english]{revtex4-1}
IOP Publishing (J. Phys.: Cond. Mat., Rep. Prog. Phys. ...) uses the iopart class:
\documentclass[jpcm,twocolumn,english]{iopart}
The American Chemical Society, ACS (J. Am. Chem. Soc., Chem. Mater. ...) uses the
achemso class:
\documentclass[jacs,twocolumn,preprint,english]{achemso}
Elsevier journals (J. Non-Cryst. Solids., Comp. Mat. Sci. ...) use the elsarticle class:
\documentclass[jncs,twocolumn,preprint,english,12pt]{elsarticle}
You must have noticed in these examples that a keyword is used to specify the journal it-self in
the options of the document class. Using this keyword LATEX will reproduce the exact layout of
the scientific journal you are targeting, from the title page to the style of the bibliography.
10
11 2.1. Structure of the document
• Packages = TEX or LATEX extensions that you need to use - [see 3.3]
– you might need to use in the preamble, these likely depend on the document class.
– you might need to create and use in the preamble - [see 2.1.3]
– you might need to create to use later in the main body of the manuscript - [see 2.1.3]
• Files that can be read by LATEX before processing the rest of the document - [see 3.4]
• Basic text
11
Chapter 2. LATEX - the first step 12
You need to run the command latex twice, the second time is mandatory to cross-check
and update references [see 4.2.8] and citations [see 4.2.10]. The latex command will
produce at least 3 files:
• *.dvi device independent, your manuscript.
• *.log LATEX log journal with information about the last compilation.
• *.aux LATEX auxiliary file.
Afterwards if you want to produce a PostScript, *.ps, use:
manuscript is the name of your TEX file without extension, thus without the *.tex.
12
13 2.2. Running LATEX
(b) Browse the "Quick Build" ("Compilation Rapide" in French) tab, and select the
"LaTeX + dvips + ps2pdf + See PDF" option:
Figure 2.2 The "Quick Build" tab in the Texmaker options dialog box. At this point you
need to select the "LaTeX + dvips + ps2pdf + See PDF" option.
(c) Use "Quick Build" button to prepare the PDF of your manuscript.
13
Chapter 2. LATEX - the first step 14
The compilation is a crucial step in the production of scientific document with LATEX, [see 6,9]
for more details.
14
LATEX essentials
3.1 Commands
Since LATEX is a programming language it is fundamental to be able to recognize a command,
and you probably already noticed that without commands there is not much that you can do no
matter how powerful LATEX is and how great is the thesis that you want to write.
In LATEX a command looks like:
\dosomething
You can also add an option to the command, placed in-between brackets, { }, immediately
after the command:
\dosomething{option}
Many, many commands have already been written and can be used to do many, many things,
in the following parts of this HowTo I will shortly present some of the most basic, important,
fundamental commands that you want to know to be able to write you precious PhD thesis or
your next article using LATEX.
However before this, I think that it can be useful to know how to define your own command in
LATEX:
\newcommand{\MyCommand}{What-it-does}
Here \newcommand{} is the LATEX command to define a command, the name of this new
command will be \MyCommand, and it will perform the {What-it-does} operations, exam-
15
Chapter 3. LATEX essentials 16
ple:
\newcommand{\napo}{[(P$_2$O$_5$)$_{1-x}$ (B$_2$O$_3$)$_x$]$_{0.65}$}
As a result, each time that LATEX will find the newly defined \napo command in the document,
it will replace it by its content and print: [(P2 O5 )1−x (B2 O3 )x ]0.65 .
\newcommand{\MyCommand}[1]{What-it-does-#1}
The number in red represents the number of options for the command, when defining the
command the option is referred to using #1, example:
\newcommand{\green}[1]{\textcolor{green}{#1}}
The \textcolor{col}{} is the standard LATEX command to change the font color of the
text between brackets, {}, to the color col. The \green command is simply a shortcut to
change the text color to green, thus each time LATEX will find the \green{something is
written here} command in the document, it will colored the text between brackets, {}, in
green like this: something is written here.
Of course more than one option can be used when defining your command:
\newcommand{\MyCommand}[2]{It-does-that-#1-and-this-#2}
Finally you might need to redefine an existing command, you do this using the instruction
\renewcommand{}, example:
\renewcommand{\figurename}{Fig.}
\renewcommand{\tablename}{Tab.}
Theses commands are used to define how the captions of inserted figures and tables start, the de-
fault values being respectively "Figure" for \figurename and "Table" for \tablename.
3.2 Environments
You should now be more familiar with the idea of command in LATEX many many commands
exist, many of them being available without any particular requirement. However many others
can only be used inside what is called an environment, ie. a part of the document where the
standard behavior of LATEX is modified to do particular things. To do these things LATEX will
give you access to a different set of commands not accessible otherwise.
16
17 3.2. Environments
To use an environment you need to open it with the \begin command, and when done with it
close it using the \end command:
\begin{something}
I want do something special here !
\end{something}
Among the many environments some very very useful, if not essentials, can be used to insert
equations [see 4.2.4], tables [see 4.2.5], images [see 4.2.6], lists and enumerations [see 4.2.7],
a bibliography [see 4.2.10] ... and much more.
Always remember when you opened an environment, using the \begin command, to close it,
using the \end command.
Many environments are used to insert floating objects, that can be moved in the document
independently from the main text body, like equations, tables or images. LATEX will handle
floating objects to maintain the best possible presentation, however there may be, and will be
times when you disagree. In this case additional options, keyword letters and symbol, to the
\begin command can be used to specify the position:
\begin{something}[htbp!]
I want do something special here !
\end{something}
Table 3.1 Keyword letters and symbol to specify the position of floating objects.
For example:
\begin{table}[!h]
I want do something special here !
\end{table}
Will insert a table, the options [!h] will ensure that it is inserted at the exact position it
appears in the source text.
17
Chapter 3. LATEX essentials 18
Like it is possible to define your own command(s), it is possible to define your own environ-
ment(s), however it is slightly more complicated. This is done using the \newenvironment
command:
my_env is the name of the new environment, Arg. is the number of arguments that you want
to pass to the environment (similar to 3.1), Def.Opt. is an optional parameter that gives the
default value of the first argument, the two following parameters describe what to do when
opening the environment (\begin command) and when closing it (\end command).
An alternative method is to use a set of \def commands:
The first \def\my_env command defines what to do when my_env is opened, the second
using \def\endmy_env defines what to do when the my_env.
The following examples can be used to define an abstract environment:
\def\abstract{
\newcommand{abstract}
\begin{center}
[1][ ]
\begin{minipage}{8cm}
{ \begin{center}
\begin{center}
\begin{minipage}{8cm}
{\bf Abstract}
\begin{center}
\end{center}
{\bf Abstract}
\par\small}
\end{center}
\par\small }
\def\endabstract{
{\end{minipage}
\end{minipage}
\end{center} }
\end{center}}
The minipage environment allows to create a new text area. This area created using the
\begin{minipage} command can contain anything that a normal text page can contain (text,
images, tables ...).
18
19 3.3. Packages
3.3 Packages
As already mentioned packages are extensions that add functionalities to LATEX, and there are
many, many packages. If you want to use a package you need first to have this package installed
[see 1.3.3] and then to tell LATEX about it the preamble section using the \usepackage com-
mand:
\usepackage{mypackage}
With this command LATEX will load the package mypackage, before continuing to process the
rest of the .tex file.
Some packages do have options, that you can specify using keywords, separated by a coma, in
between [ ] before the package name:
\usepackage[option1,option2,option3]{mypackage}
An comprehensive package list is given afterwards [see 4.1], it includes most of the packages
you might need to prepare a scientific article or your thesis.
3.4 Files
When writing your significant contribution to science keep in mind that clarity is essential.
Thus it can be cleaver to divide your LATEX file in several pieces, for example information
regarding each of the different chapter of your thesis could be in different files.
Two different commands exist to insert a file in a LATEX document, the \input command and
the \include command:
19
Chapter 3. LATEX essentials 20
\documentclass{book}
% Preamble section
\includeonly{intro,chapter1}
\begin{document}
\end{document}
LATEX automatically adds the .tex extension to the file names given by the \input and
\include commands.
Therefor in this example LATEX will look for the file preamble.tex in the preamble section,
this file can contains \usepackage, commands and environments declaration(s).
Afterwards in the main body section, LATEX will read the files intro.tex, chapter1.tex,
chapter2.tex and conclu.tex containing different the parts of the manuscript.
Only the main .tex file contains the \documentclass, \begin{document}, and
\end{document} commands. The contents of the file which name is specified by the
\input or the \include commands is simply inserted at the location of the command
during the compilation process.
The \include command inserts the file in the document using a new page, while the \input
command inserts the file without condition.
Also the \include command can be activated or deactivated by the \includeonly com-
mand. Therefore in the previous example only the files into.tex and chapter1.tex will be
inserted in the main document during the compilation. The combination of \include the
\includeonly command can be very useful when preparing large documents with extended
chapters like your thesis.
20
My first LATEX document
\documentclass{article}
\input{preamble}
\begin{document}
Here the preamble section consists of a single command, that tells LATEX to read a file, this file
called preamble.tex contains all the information regarding the packages and commands. One
of the advantages of this method is to have a main file easier to read, since it now only contains
your precious manuscript. Also if you decide to keep working using LATEX you could recall the
same preamble.tex file.
A comprehensive example of the preamble section is given afterwards, and most of the
packages you might need to write your piece of science and print your mark in history are listed
hereafter, you just need to adapt it to your personal use:
21
Chapter 4. My first LATEX document 22
% Insert images
\usepackage{graphicx}
% Colors
\usepackage{xcolor}
% Enumerations
\usepackage{enumerate}
% Mathematics
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amscd}
\usepackage{theorem}
% Tables
\usepackage{hhline}
\usepackage{multirow}
\usepackage{tabls}
% To use landscape pages in a portrait document
\usepackage{lscape}
% Spaces between lines
\usepackage{setspace}
%\onehalfspacing
%\doublespacing
%\setstretch{3}
22
23 4.2. Writing the manuscript
\ # % ∼ { } $ _ ˆ
• % starts a comments, everything that follow on the same line is not interpreted, read or
compiled by LATEX
23
Chapter 4. My first LATEX document 24
24
25 4.2. Writing the manuscript
* the result depends on the font environment the command is used in:
col is a color name, accessible using the xcolor package, many standard color names are
available (red, green, blue ...) if the color you want is not available you can define it using:
\definecolor{my_green}{rgb}{0.0,0.6,0}
The last arguments of the \definecolor commands are 3 numbers between 0.0 and 1.0 that
represent the color RGB code, with the Red, Green and Blue values.
The color must be defined before using it, therefore the \definecolor command must be
used before the \textcolor. We suggest to define all the colors you need in the preamble
section.
25
Chapter 4. My first LATEX document 26
Detail examples for each editor related document classes are provided in [Chap. 7].
The first option of the command, the [ ], is not mandatory and can be used to modify the name
of the section that will appear in the Table Of Contents, TOC, if any. The default name of the
section in the TOC is given by the second option of the command, its real title in the document.
26
27 4.2. Writing the manuscript
\chapter book
27
Chapter 4. My first LATEX document 28
The numbering of the chapters, parts, sections, etc, will be done automatically by LATEX, thus
there is no need for the user to specify any number.
If you do not want the section to be numbered use a * symbol:
\chapter*{Conclusion} Conclusion
% The conclusion
\appendix
Appendix A
\chapter{Additional data}
Additional data
In some classes, like book, it is possible to create a TOC, a list of figures and a list of tables:
28
29 4.2. Writing the manuscript
• Text letters (a,A → z,Z) are written in italic (a, A → z, Z), however numbers, symbols and
punctuation signs are written in standard roman characters.
• Superscript writing using the ˆ character and subscript writing using the _ character:
Note that if no brackets, { }, are used, then only the first letter/symbol/number following
the ˆ and the _ characters will be affected and upper-lower-scripted.
• Many, many, many symbols are accessible using commands, such as:
α β γ Γ δ ∆
1 √ R
∑ ∏ x y
2
~v ȧ h̄ d
abc
~ ∞ × ÷ ±
29
Chapter 4. My first LATEX document 30
Using the first method, using $ $ symbols, also called ’in-line’ equation it is possible to insert
maths in the text, for example the instructions:
The other method using an equation environment adds a number to your equation, so
that you can refer to this equation somewhere else in the document [see 4.2.8]:
\begin{equation}
\sum_{i=1}^{N} \frac{x-1}{\sqrt{\delta}} = \infty
\end{equation}
It will also be rendered separately from the text:
N
x−1
∑ √ =∞ (4.1)
i=1 δ
\begin{table}
\begin{tabular}{l|cr||}
& $\alpha$ & $\beta$ \\
\hline α β
\hline
a 2.0 1 × 10√−4
a & 2.0 & $1\times10^{-4}$ \\
b & -3.0 & $\sqrt5$ \\ b −3.0 5
c & 1.0 & $1\times10^2$ \\ c 1.0 1 × 102
\hline
\end{tabular} Table 4.2 My interesting table
\caption{My interesting table}
\end{table}
30
31 4.2. Writing the manuscript
The options of the \begin{tabular} command define the shape of the table, in the previous
example: {l|cr||}. The number of column(s) in the table is given by the number of letters,
here 3 letters hence the table will have 3 columns. The letter itself defines how the text is
centered in the corresponding column: l=left, c=center or r=right. The pipe symbol, {|} is
used to draw separator(s) (by default straight lines) between columns.
In the table it-self, the \hline is used to draw separator(s) between rows. On the same row,
columns are separated using the & symbol, the line is terminated using the \\ symbol.
In a multicolumn document it is possible to use the \begin{table*} and \end{table*}
commands to produce a table that use the entire width of the page instead of the default width
of a single column.
\begin{figure}
\includegraphics{image.eps}
\caption{My interesting figure}
\end{figure}
31
Chapter 4. My first LATEX document 32
• keepaspectratio=true % or false
• scale=0.75
• width=5cm
• height=8cm
• angle=90
• draft=false, this is the default value, if you set this option on true the image is not
inserted, instead you will see a blank space of the same size, this could be very useful
when preparing a large manuscript with many images, like your thesis.
\includegraphics[width=10cm,keepaspectratio=true,draft=true]{image.eps}
32
33 4.2. Writing the manuscript
\begin{itemize}
\item Element 1
\item Element 2 • Element 1
\begin{itemize}
• Element 2
\item Element 3
\item Element 4 – Element 3
\begin{itemize} =⇒ – Element 4
\item Element 5
\item Element 6 ∗ Element 5
\end{itemize} ∗ Element 6
\end{itemize}
\item Element 7 • Element 7
\end{itemize}
For an enumeration use the enumerate environment and the \item command:
\begin{enumerate}
\item Element 1
\item Element 2 1. Element 1
\begin{enumerate}
\item Element 3 2. Element 2
\item Element 4 (a) Element 3
\begin{enumerate} =⇒
\item Element 5 (b) Element 4
\item Element 6 i. Element 5
\end{enumerate} ii. Element 6
\end{enumerate}
\item Element 7 3. Element 7
\end{enumerate}
33
Chapter 4. My first LATEX document 34
\begin{figure}
\includegraphics{image.eps}
\caption{\label{pinte}My interesting figure}
\end{figure}
There is no need to number anything, LATEX does it for you. You can add a label using the
\label command to pretty much any object in the document, including all the objects and
environments presented previously in this HowTo. There is only one simple rule to respect for
the floating objects, like the tables or the figures, and that is to put the \label command inside
the \caption command. Finally remember that each label, in other word each KEYWORD, used
in the \label{KEYWORD} command, must be unique.
34
35 4.2. Writing the manuscript
1. Use the thebibliography environment, and create an entry for the reference using the
\bibitem command:
\begin{thebibliography}
\bibitem{old_work_a}
D. umb and I. diot,
J. Non-Smart. Sci. \textbf{00}, 0000-0007 (2015).
\bibitem{old_work_b}
R. Car and M. Parrinello,
Phys. Rev. Lett. \textbf{55}, 2471-2474 (1985).
\end{thebibliography}
You need to create all the entries in the bibliography your-self, eventhough it is not
complicated it has to be done very carefully. You define the style of the citations yourself
using LATEX commands, ie. the author name format, the order the authors list, journal,
year, appear in ... Be careful to create the entries in the order you want them to appear in
the bibliography section. To have the citations in the order they appear in the article/thesis
can be tricky, in particular in you keep modifying the source file.
35
Chapter 4. My first LATEX document 36
2. Use BibTeX: then you let LATEX, BibTeX and the scientific editors do the job for you.
The only thing that you need then in your TEX file is to use the 2 following commands:
\bibliographystyle{unsrt}
\bibliography{biblio}
The first command \bibliographystyle set the style of the bibliography using a
keyword, in this example unsrt, among others like: abbrv, alpha, plain.
Table [Tab. 4.3] presents few differences between the default BibTeX styles. Many others
bibliography styles are available, in particular using the natbib package.
The \bibliography command tells LATEX to import the file biblio.bib (the .bib
extension being added automatically) using BibTeX to create the bibliography. This
so-called BibTeX file contains all the elements of the bibliography, in the BibTeX format
with entries that looks like:
@Article{old_work_b,
author = "Car, R. and Parrinello, M.",
journal = "Phys. Rev. Lett.",
volume = 55,
number = 22,
pages = "2471-2474",
numpages = 3,
year = 1985,
publisher = "American Physical Society"
}
The first line starting with an @ gives the document type, here an article (among others
like: book, phdthesis, proceedings, conference ...) and the associated keyword.
The next lines are the fields to describe the bibliographic reference.
The software Mendeley provides a very nice graphical interface to help you manage your
BibTeX file.
36
37 4.2. Writing the manuscript
• Most of the scientific editors provide the BibTeX entries for their publications,
which means that you only need to browse their web sites, find the page of the
appropriate article, and copy-paste the entry in your own BibTeX file, then simply
use the corresponding keyword in your manuscript.
• You can use the same BibTeX file for all your works with LATEX, this means that you
just need to do prepare an entry the first time you need the reference, then simply
recall the appropriate keyword.
• No matter the number of entries in the BibTeX file LATEX and BibTeX will only use
the ones cited in your article and ignore the others.
• No need to take care of the order of the entries in the BibTeX file, the citations in
your bibliography will be sorted automatically.
37
Chapter 4. My first LATEX document 38
To use BibTeX the compilation sequence changes, and you need to enter the following
sequence of commands:
In Texmaker you need to change the "Quick Build" options to "LaTeX + Bib(la)Tex +
LaTeX (x2) + dvips + ps2pdf + See PDF", see figure [Fig. 4.3].
Figure 4.3 The "Quick Build" tab in the Texmaker options dialog box for BibTeX. At this
point you need to select the "LaTeX + Bib(la)Tex + LaTeX (x2) + dvips + ps2pdf
+ See PDF" option.
38
Spell checking
#!/bin/bash
TFILE=$1
aspell -c -t --lang=en_EN $TFILE".tex"
You could spell check your LATEX document simply using:
39
Chapter 5. Spell checking 40
2. Browse the "Editor" ("Editeur" in French) tab, and check that the appropriate dictio-
nary is being used:
Figure 5.2 The "Editor" tab in the Texmaker options dialog box. At this point you need to
select the appropriate dictionary.
40
41 5.2. Using Texmaker
3. Use "Check Spelling" button in the file menu (or the Ctrl+Maj+F7 keyboard shortcut) to
check your manuscript:
For Windows dictionnaries are installed with Texmaker and can be found in:
41
LATEX advantages and drawbacks
Drawbacks
You will need to learn few things about programming
It is obvious that the first thing about LATEX is that you need to learn a bit, to say the least, about
programming. If your are not willing to spend some time learning how things are behind the
curtains, well forget about LATEX.
• Because you will waste time trying to find that f*****g command your are looking for.
That is the way it is, I wish I could tell you that you will be fluent in LATEX by the end of
the day, and the commands will come to you naturally. Nope. As everybody, and even
after years of experience, you will still waste time to look for a particular command to do
that particular thing you really need to do.
• Because when you will find that f*****g command it will not work.
And you will need to take time to install the package that contains this precious command
that you really really need.
43
Chapter 6. LATEX advantages and drawbacks 44
• To avoid to waste too much time debugging errors during the compilation process.
The compilation will fail, many times, because of silly mistakes like:
Trying to find where the error comes from, will be time consuming, and as much as
possible you want to avoid that.
• To keep your working directory clean enough to know what is going on.
Indeed after the compilation process of your main *.tex file the directory will be filled
with many files, created by LATEX and potentially BibTeX. It will also contains images,
probably a significant number for your thesis. Think about creating sub-directory(ies) to
sort and organize everything, it will be easier to find the information you might look for
afterwards.
Advantages
If you are not too scared already, then hope for you there is young Padawan.
Your ally is the force in LATEX and a powerful ally it is !
Now is the time to learn why the light side of the force is the way to go.
It looks great !
You will see by yourself soon enough that there is no way to match the quality of a document
produced using LATEX.
44
45
Hopefully by now you understand that with LATEX this can become almost automatic. Conse-
quently you can save a lot of time to do something else.
45
Examples
\documentclass[prb,twocolumn,superscriptaddress]{revtex4-1}
% Use the "superscriptaddress" in the documentclass options.
\begin{document}
\author{M. Me}
\affiliation{My great institution - France}
\author{Y. You}
\affiliation{My great institution - France}
\author{H. He}
\affiliation{The third author institution - USA}
\begin{abstract}
This great work is about to blow your mind !
\end{abstract}
\maketitle
\end{document}
47
Chapter 7. Examples 48
\documentclass[jacs,twocolumn]{achemso}
\author{M. Me}
\affiliation{My great institution - France}
\author{Y. You}
\affiliation{My great institution - France}
\author{H. He}
\affiliation{The third author institution - USA}
\begin{document}
\begin{abstract}
This great work is about to blow your mind !
\end{abstract}
\maketitle
\end{document}
48
49 7.1. Title and authors
\documentclass[jncs,twocolumn]{elsarticle}
\begin{document}
\author[1]{M. Me}
\author[1]{Y. You}
\author[2]{H. He}
\address[1]{My great institution - France}
\address[2]{The third author institution - USA}
\begin{abstract}
This great work is about to blow your mind !
\end{abstract}
\maketitle
\end{document}
49
Chapter 7. Examples 50
\documentclass[jpcm,twocolumn]{iopart}
\begin{document}
\author{M. Me$^1$}
\author{Y. You$^1$}
\author{H. He$^2$}
\address{(1) My great institution - France}
\address{(2) The third author institution - USA}
\begin{abstract}
This great work is about to blow your mind !
\end{abstract}
\maketitle
\end{document}
50
51 7.2. Tables and figures
\begin{table}[!h]
\caption{Label and description of the e- acceptor diimide cores studied.}
\vspace{0.3cm}
\begin{tabular}{rlcllc}
Id & Label & $N$ & Formula & \multicolumn{2}{c}{Diimide familly + 3D} \\
\hline
\\
& & & & & \multirow{4}{5cm}
{\includegraphics[width=0.9\linewidth,keepaspectratio=true,draft=false]
{img/NDI.eps}} \\
1 & NDI & 32 & C$_16$H$_10$O$_4$N$_2$ &
\multirow{2}{4cm}{\bigg}Naphthalene} \\
2 & NDI\_F4 & 38 & C$_{16}$H$_6$O$_4$N$_2$F$_4$ \\
\\
\\
3 & ADI & 38 & C$_20$H$_12$O$_4$N$_2$ &
\multirow{4}{4cm}{\Bigg}Anthracene} \\
\multirow{4}{5cm}
{\includegraphics[width=1.0\linewidth,keepaspectratio=true,draft=true]
{img/ADI.eps}} \\
4 & ADI\_F2 & 38 & C$_{20}$H$_{10}$O$_4$N$_2$F$_2$ \\
5 & ADI\_CN2 & 40 & C$_{22}$H$_{10}$O$_4$N$_4$ \\
6 & ADI\_Br2 & 38 & C$_{20}$H$_{10}$O$_4$N$_2$Br$_2$ \\
\end{tabular}
\end{table}
The table above provides and example of the usage for the following commands:
• \multicolumn
usage: \multicolumn{#NUM}{#LAYOUT}{Data to display}}
with: #NUM= number of column, #LAYOUT = l=left, c=center, r=right
51
Chapter 7. Examples 52
Table 7.1 Label and description of the e- acceptor diimide cores studied.
Id Label N Formula Diimide familly + 3D
1 NDI 32 C16 H10 O4 N2
Naphthalene
2 NDI_F4 38 C16 H6 O4 N2 F4
52
53 7.3. Equations
7.3 Equations
Example 1
\begin{equation}
S_{\textrm{T}}(k) - 1 \equiv
\sum_{\alpha = 1}^n \sum_{\beta = 1}^n
\frac{c_\alpha c_\beta b_\alpha b_\beta}{\left< b \right>^2}
\left[S_{\alpha\beta}^{\textrm{FZ}}(k) - 1\right]
\end{equation}
n n cα cβ bα bβ h FZ
i
ST (k) − 1 ≡ ∑∑ Sαβ (k) − 1 (7.1)
α=1 β=1 hbi2
Example 2
\begin{equation}
E_\textrm{tot} =
\underbrace{\sum_{i=1}^{occ} n_i \, \langle \psi_i |
- \frac{\nabla^2}{2} | \psi_i \rangle}
_T_\textrm{s}[\rho] \quad + \quad
\underbrace{
\frac{1}{2}
\int_\mathbb{R}^6
\frac{(\rho(\textbf{r}) + \rho^Z(\textbf{r}))
(\rho(\textbf{r}’)+ \rho^Z(\textbf{r}’))}
{|\textbf{r}-\textbf{r}’|}
\, d\textbf{r} \, d\textbf{r}’}
_E_\textrm{POT}[\rho] \atop \quad + \quad
\underbrace{
\int_\mathbb{R}^3 \rho(\textbf{r})
\epsilon_\textrm{XC}[\rho] \, d\textbf{r}}
_E_\textrm{XC}[\rho]
\end{equation}
Z
occ
∇2 1 (ρ(r) + ρZ (r))(ρ(r′ ) + ρZ (r′ ))
Etot = ∑ ni hψi | − |ψi i + dr dr′
i=1 2 2 R 6 ′
|r − r |
| {z } | {z }
Ts [ρ] EPOT [ρ] (7.2)
Z
+ ρ(r)εXC [ρ] dr
3
|R {z }
EXC [ρ]
53
Partial glossary
• \AA
- The Angström symbol: Å
• \footnote{Here is my footnote}
- To produce footnote(s):
I want to insert\footnote{a footnote here}.
I want to insert1 .
• \par
- To start a new paragraph.
• \caption
- To insert a caption: \caption[Small caption]{Full caption}
The first optional argument is the name of the object for the list of figures or the list of
tables, this is interesting if the caption of the figure or the table is long.
1a footnote here
55
Chapter 8. Partial glossary 56
• \rangle
- the symbol: i
• \langle
- the symbol: h
• \underbrace{Equation}_{Information}
To underbrace part(s) of an equation:
\underbrace{y = a×x + b}_\textrm{Too simple !} y = a×x+b
| {z }
Too simple !
• \lbrack
- the symbol: [
• \rbrack
- the symbol: ]
• \left + symbol in: {,(,[ .. and \right + symbol in: },),] ...
ensure that the symbols to be displayed immediately after the commands \left and
\right will be large enough compared to the expression between \left and \right,
see equation 7.1 for an example.
• \sum_{From}ˆ{To}
The sum symbol:
N
\sum_{i=0}ˆ{N} ∑
i=0
56
57 8.2. Useful environments
• \prod_{From}ˆ{To}
The product symbol, the usage is similar to the \sum command:
N
\prod_{i=0}ˆ{N} ∏
i=0
• \int_{From}ˆ{To}
The integral symbol, the usage is similar to the \sum and the \prod commands:
Z N
\int_{i=0}ˆ{N}
i=0
see equation 7.2 for more examples.
• flushright
- definition: To insert right centered text.
- usage: \begin{flushright} \end{flushright}
• flushleft
- definition: To insert left centered text.
- usage: \begin{flushleft} \end{flushleft}
• table
- definition: To insert a floating table.
- usage: \begin{table}[htbp!] \end{table}
• tabular
- definition: To use a column/row based layout.
- usage: \begin{tabular} \end{tabular}
57
Chapter 8. Partial glossary 58
• equation
- definition: To insert an equation.
- usage: \begin{equation}[htbp!] \end{equation}
It is not possible to use the equation environment inside the tabular environment, use
the $ $ or $\displaystyle $ commands instead.
• figure
- definition: To insert a floating figure.
- usage: \begin{figure}[htbp!] \end{figure}
• itemize
- definition: To insert a list
- usage: \begin{itemize} \end{itemize}
• enumerate
- definition: To insert a numbered list.
- usage: \begin{enumerate} \end{enumerate}
• minipage
- definition: To insert a new content area, it is not mandatory but you can specify between
[ ] how the text is centered in the minipage, c = centered, l = left, r = right, t = top, b =
bottom. Then define the size of the frame, between { }.
- usage: \begin{minipage}[clrtb]{?cm} \end{minipage}
• bibliography
- definition: To insert a bibliography.
- usage: \begin{bibliography} \end{bibliography}
• landscape
- definition: To insert a page in landscape view, even if the document is in portrait view.
- usage: \begin{landscape} \end{landscape}
• picture
- definition: To draw using LATEX commands ... no idea how it works !
- usage: \begin{picture} \end{picture}
58
Error messages
59
Chapter 9. Error messages 60
• ! Missing \begin{document}.
The command \begin{document} was not found in the source file, insert it at the
appropriate location.
60
61 9.2. TEX errors
• ! Extra } or forgotten $.
The command to enter and exit the math mode, $, do not match, there is an extra or a
missing $.
61
Chapter 9. Error messages 62
• ! Missing { inserted.
! Missing } inserted.
There is probably a { or a } missing, or a syntax error before the line of the error.
• ! Missing $ inserted.
A math command was used outside the math mode. Put the command between $.
62
Some useful links
• The TEX Users Group, TUG: https://www.tug.org/ The TUG was founded in 1980 to
provide an organization for people who are interested in typography and font design,
and/or are users of the TeX typesetting system invented by Donald Knuth.
• The Comprehensive TEX Archive Network, CTAN: http://ctan.org/ The CTAN is the pri-
mary repository for TEX-related software on the Internet. CTAN has many thousands of
items, to find any information regarding TEX or LATEX you can use:
– The CTAN search page: http://ctan.org/search.html
– The CTAN TEX catalogue: http://texcatalogue.ctan.org/
All existing LATEX packages are listed and can be downloaded from the CTAN website.
63
Bibliography
[1] Christian Rolland. LATEX par la pratique. O’Reilly, 1999. (On page 1.)
[2] S. Le Roux. Basic tutorial to BASH programming. 2016. (On pages 12 et 39.)
This document has been prepared using the Linux operating system and free softwares:
The text editor "gVim"
The GNU image manipulation program "GIMP"
And the document preparation system "LATEX 2ε ".