Professional Documents
Culture Documents
Krishna Kumar ∗1
1 github.com/kks32
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 1 / 47
Outline
2 Introduction to LATEX2e
What is LATEX
Getting started with LATEX
Example
3 How LATEXworks
4 Good practices
Equations
Figures
table
bibTEX
5 Version Control
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 2 / 47
Why you shouldn’t use Word to write your thesis
adline
th e d e
Likelihood of Word crashing
day of
on the
dline
dea
to
eek
> 1w
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 3 / 47
Can you see beyond the WYSIWYG bubble?
At first sight it must seem intolerably At f rst sight it must seem intolerably degrading
degrading for Zen — however the reader may for Zen — however the reader may understand this
understand this word — to be associated with word — to be associated with anything so mundane
anything so mundane as archery. Even if he were as archery. Even if he were willing to make the big
willing to make a big concession, and to find concession, and to f nd archery distinguished as an
archery distinguished as an “art,” he would scarcely
“art,” he would scarcely feel inclined to look behind
feel inclined to look behind this art for anything
this art for anything more than a decidedly sporting
more than a decidedly sporting form of prowess.
form of prowess. He therefore expects to be told
He therefore expects to be told something about the
amazing feats of Japanese trick-artists who have the something about the amazing feats of Japanese trick-
advantage of being able to rely on a time-honored artists who have the advantage of being able to rely
and unbroken tradition in the use of bow and arrow. on a time-honored and unbroken tradition in the use
For in the Far East it is only a few generations since of bow and arrow. For in the Far East it is only a
the old means of combat were replaced by modern few generations since the old means of combat were
weapons, and familiarity in the handling of them by replaced by modern methods, and familiarity in the
no means fell into disuse, but went on propagating handling of them by no means fell into disuse, but
itself, and has since been cultivated in ever went on propagating itself, and has since been culti-
widening circles. Might one not expect, therefore, a vated in ever widening circles. Might one not expect,
description of the special ways in which archery is therefore, a description of the special ways in which
pursued today as a national sport in Japan? archery is pursued today as a national sport in Japan?
Nothing could be more mistaken than this Nothing could be more mistaken than this expec-
expectation. By archery in the traditional sense, tation. By archery in the traditional sense, which
which he esteems as an art and honors as a national he esteems as an art and honors as a national her-
heritage, the Japanese does not understand a sport itage, the Japanese does not understand a sport but,
but, strange as this may sound at first, a religious strange as this may sound at f rst, a religious ritual.
ritual. And consequently, by the “art” of archery he And consequently, by the “art” of archery he does not
does not mean the ability of the sportsman, which mean the ability of the sportsman, which can be con-
can be controlled, more or less, by bodily exercises,
trolled, more or less, by bodily exercises, but an abil-
but an ability whose origin is to be sought in
ity whose origin is to be sought in spiritual exercises
spiritual exercises and whose aim consists in hitting
and whose aim consists in hitting a spiritual goal, so
a spiritual goal, so that fundamentally the marksman
aims at himself and may even succeed in hitting that fundamentally the marksman aims at himself and
himself. may even succeed in hitting himself.
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 5 / 47
Ligatures, smallcaps, kerning
Ligatures
Smallcaps
Kerning
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 6 / 47
Outline
2 Introduction to LATEX2e
What is LATEX
Getting started with LATEX
Example
3 How LATEXworks
4 Good practices
Equations
Figures
table
bibTEX
5 Version Control
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 7 / 47
What is LATEX?
E 2 = (pc)2 + (m0 c 2 )2
LATEXis WYSIWYM (What You See is What You Mean)
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 8 / 47
History
It all started with Donald Knuth and “The Art of Computer Programming”
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 9 / 47
LATEXPros and Cons
Pros
It’s free and works on Macs, Windows, Unix/Linux.
LaTeX files are ASCII and are portable.
The typesetting is better, especially the maths.
Style changes are neater in LaTeX.
Cons
Special/Modern Font selection is difficult, but one can use XeTeX.
LaTeX encourages (almost insists on) structured writing and the separation
of style from content. This is not the way that many people (especially
non-programmers) are used to working.
Without a WYSIWYG front end, it’s not always easy to find out how to do
things.
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 10 / 47
Getting started with LATEX
Typesetting
TEXLive - full version
MiKTEX- Windows (Basic installer)
Off-line editors
TEXStudio
TEXMakerX
Online editors & LATEXcompilers
Overleaf (formerly WriteLATEX)
ShareLATEX
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 11 / 47
How LATEXworks? - The Magic
You write your document in plain text with commands that describe its
structure and meaning.
The LATEXprogram processes your text and commands to produce a
beautifully formatted document.
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 12 / 47
More examples of commands and their output. . .
\begin{itemize}
\item Despicable Me Despicable Me
\item Wall-E Wall-E
\item Tangled Tangled
\end{itemize}
\begin{figure}
\includegraphics{figs/minion}
\end{figure}
\begin{equation}
\alpha = \beta + 1 α = β +1 (1)
\end{equation}
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 13 / 47
Getting Started
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 14 / 47
Declarations and Environments
Environments. . .
Have matching begin and end declarations
Must be constrained
Eg., \begin{document} . . . \end{document}
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 15 / 47
Arguments
Required arguments. . .
Are contained in curly braces
Must be provided
Eg., \documentclass{article}
Optional arguments. . .
Are contained in square bracket
Can be left out, in which case default value is assumed
Give you more control over the commands
Eg., \documentclass[12pt]{article}
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 16 / 47
Title and Author
\title{The Title}
The Title
\author{A. Author}
A. Author
\date{\today}
November 11, 2014
\begin{document}
\maketitle Abstract
Abstract goes here...
\begin{abstract}
Abstract goes here...
\end{abstract}
\end{document}
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 17 / 47
Sections
\documentclass{article}
\begin{document} 1 Introduction
\section{Introduction} The problem of . . .
\subsection{Data Collection}
3 Results
\section{Results} 4 Conclusion
\section{Conclusion}
\end{document}
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 18 / 47
Let’s try that . . .
If you would like to try out the exercise on your machine. Go to Exercise /
paper.tex
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 19 / 47
Outline
2 Introduction to LATEX2e
What is LATEX
Getting started with LATEX
Example
3 How LATEXworks
4 Good practices
Equations
Figures
table
bibTEX
5 Version Control
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 20 / 47
\documentclass{}
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 21 / 47
LaTeX Structure - The Magic
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 22 / 47
LaTeX - Tool chains
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 23 / 47
Packages
The command:
\usepackage{amsmath}
Common packages
Environment Packages
Maths amsmath, amsfonts, amssymb
Maths Times Font mathptx
Figures graphicx, epsfig
Table tabularx, booktabs
Pagelayout geometry
Hyperlinks hyperref
Algorithms and code algpseudocode, algorithm, listings
Color color, xcolor
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 24 / 47
Outline
2 Introduction to LATEX2e
What is LATEX
Getting started with LATEX
Example
3 How LATEXworks
4 Good practices
Equations
Figures
table
bibTEX
5 Version Control
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 25 / 47
Typesetting Caveats
Quotation marks are a bit tricky: use a backtick ` on the left and an apostrophe
´ on the right.
Single quotes: ‘text’. Single quotes: ‘text’.
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 26 / 47
Equations, equations everywhere
Detexify http://detexify.kirelabs.org/classify.html
$\Omega = \sum_{k=1}^{n} \omega_k \times \mu$ Ω = ∑nk=1 ωk × µ
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 27 / 47
Never use equation arrays
\begin{equation}
E = m_0 c^2 \,,
\end{equation} E = m0 c 2 , (4)
\begin{equation}
E^2 = (m_0 c^2)^2 + (pc)^2 \,.
E 2 = (m0 c 2 )2 + (pc)2 . (5)
\end{equation}
\begin{align}
E = m_0 c^2 \,,\\ E = m0 c 2 , (6)
E^2 = (m_0 c^2)^2 + (pc)^2 \,.
\end{align} E 2 = (m0 c 2 )2 + (pc)2 . (7)
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 28 / 47
Vector graphics vs. Raster images
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 29 / 47
Formatting figures in LATEX
Always use relative scaling to specify the width of the figure, i.e.,
[width = 0.75\textwidth]
I prefer to centre the figure. To do that use \centering, do NOT use
\begin{center} and \end{center}
Tweak the caption location, label, separator: [labelsep=space,
tableposition=top]{caption}
You can use ~\cref{fig:minion} to cross reference the figure. Requires
package cleveref
\begin{figure}
\centering
\includegraphics[width=0.65\textwidth]
{figs/minion}
\caption[Minion]{
Dave the Minion from Despicable Me!}
\label{fig:minion} % Unique identifier
% for cross-reference
Figure: Dave the Minion from
\end{figure} Despicable Me!
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 30 / 47
\begin[option]{figure}
Parameter Position
h Place the float here, i.e., approximately at the same point it occurs
in the source text (however, not exactly at the spot)
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.
H Places the float at precisely the location in the LaTeX code. Re-
quires the float package. This is somewhat equivalent to h!
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 31 / 47
Colour blindness
\begin{tabular}{|l|c|c|c|c|}
\hline
& \multicolumn{2}{c}{Species I} &
\multicolumn{2}{c|}{Species II} \\
\hline
DM & mean & SD & mean & SD \\
\hline Species I Species II
\hline DM mean SD mean SD
I1MD & 6.23 & 0.91 & 5.2 & 0.7 \\
I1MD 6.23 0.91 5.2 0.7
\hline
I1LL 7.48 0.56 8.7 0.71
I1LL & 7.48 & 0.56 & 8.7 & 0.71 \\
\hline I2MD 3.99 0.63 4.22 0.54
I2MD & 3.99 & 0.63 & 4.22 & 0.54 \\ I2LL 6.81 0.02 6.66 0.01
\hline CMD 13.47 0.09 10.55 0.05
I2LL & 6.81 & 0.02 & 6.66 & 0.01 \\ CBL 11.88 0.05 13.11 0.04
\hline
CMD & 13.47 & 0.09 & 10.55 & 0.05 \\
\hline
CBL & 11.88 & 0.05 & 13.11 & 0.04\\
\hline
\end{tabular}
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 33 / 47
A nice looking table
\begin{tabular}{l c c c c}
\hline
\multirow{2}{*}{DM}
& \multicolumn{2}{c}{Species I}
& \multicolumn{2}{c}{Species II} \\
\cline{2-5}
& mean & SD & mean & SD \\ Species I Species II
\hline DM
mean SD mean SD
I1MD & 6.23 & 0.91 & 5.2 & 0.7 \\
I1MD 6.23 0.91 5.2 0.7
I1LL 7.48 0.56 8.7 0.71
I1LL & 7.48 & 0.56 & 8.7 & 0.71 \\
I2MD 3.99 0.63 4.22 0.54
I2LL 6.81 0.02 6.66 0.01
I2MD & 3.99 & 0.63 & 4.22 & 0.54 \\
CMD 13.47 0.09 10.55 0.05
CBL 11.88 0.05 13.11 0.04
I2LL & 6.81 & 0.02 & 6.66 & 0.01 \\
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 34 / 47
An even nicer looking table
\begin{tabular}{l c c c c}
\toprule
\multirow{2}{*}{DM}
& \multicolumn{2}{c}{Species I}
& \multicolumn{2}{c}{Species II} \\
\cmidrule{2-5}
& mean & SD & mean & SD \\ Species I Species II
DM
\midrule
mean SD mean SD
I1MD & 6.23 & 0.91 & 5.2 & 0.7 \\
I1MD 6.23 0.91 5.2 0.7
I1LL & 7.48 & 0.56 & 8.7 & 0.71 \\ I1LL 7.48 0.56 8.7 0.71
I2MD 3.99 0.63 4.22 0.54
I2MD & 3.99 & 0.63 & 4.22 & 0.54 \\ I2LL 6.81 0.02 6.66 0.01
CMD 13.47 0.09 10.55 0.05
I2LL & 6.81 & 0.02 & 6.66 & 0.01 \\ CBL 11.88 0.05 13.11 0.04
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 35 / 47
Formatting tables
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 36 / 47
bibTEX 1
@InProceedings{Brooks1997Methodology,
author = {Fredrick P. Brooks and John Kubiatowicz and
Christos Papadimitriou},
title = {A Methodology for the Study of the
Location-Identity Split},
booktitle = {Proceedings of OOPSLA},
Month = jun,
Year = 1997}
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 37 / 47
bibTEX 2
Each entry in the .bib file has a key that you can use to reference it in the
document. For example, Jacobson1999Towards is the key for this article:
@Article{Jacobson1999Towards,
author = {Van Jacobson},
...
}
It’s a good idea to use a key based on the name, year and title.
LATEX can automatically format your in-text citations and generate a list of
references; it knows most standard styles, and you can design your own.
Mendeley auto-generates bibTEXkeys.
Alternatively, use Google Scholar to get the references.
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 38 / 47
bibTEX 3
Use the natbib package2 with \citetand \citep for textual and
parenthetical citations, respectively.
Reference \bibliography at the end, and specify a \bibliographystyle.
\documentclass{article}
\usepackage[authoryear]{natbib} Brooks et al. [1997] show that . . . . Clearly, all odd numbers are prime
\begin{document} [Jacobson, 1999].
References
\citet{Brooks1997Methodology} Fredrick P. Brooks, John Kubiatowicz, and Christos Papadimitriou. A method-
show that \ldots. Clearly, ology for the study of the location-identity split. In Proceedings of OOPSLA,
June 1997.
all odd numbers are prime Van Jacobson. Towards the analysis of massive multiplayer online role-playing
\citep{Jacobson1999Towards}. games. Journal of Ubiquitous Information, 6:75–83, June 1999.
\bibliography{bib-example}
% if ‘bib-example’ is the name of
% your bib file
\bibliographystyle{plainnat}
% try changing to abbrvnat
\end{document}
2 There is a new package with more features named biblatex but most of the articles
or use it off-line
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 40 / 47
Outline
2 Introduction to LATEX2e
What is LATEX
Getting started with LATEX
Example
3 How LATEXworks
4 Good practices
Equations
Figures
table
bibTEX
5 Version Control
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 41 / 47
Final.doc
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 42 / 47
Keeping track of your files - Version Control
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 43 / 47
What’s Git?
Git is a distributed version control system that keeps track of your changes.
Git only stores the ‘delta’, i.e., only the difference between the previous
version and the current version, so it doesn’t take up lots of valuable hard
disk space. Git also compresses your file.
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 44 / 47
Using Git with your thesis
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 45 / 47
Creativity and Thesis
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 46 / 47
Acknowlegements
Krishna Kumar ( University of Cambridge ) Writing your papers and thesis more effectively LaTeX Course 2015 47 / 47