Skip to content

Notebooks and Files for LaTeX Workshop (LIDA - Data Scientist Internship Programme)

License

Notifications You must be signed in to change notification settings

patricia-ternes/LIDA-LaTeX-workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 

Repository files navigation


Logo

Intro to LaTeX Workshop

Leeds Institute for Data Analytics (LIDA)

Author

  • Dr Patricia Ternes
    • Research Fellow, School of Geography, University of Leeds, UK
    • More information

Additional Materials

The workshop has two additional materials:

Table of Contents

Introduction

What is LaTeX

LaTeX, which is pronounced «Lah-tech» or «Lay-tech» (to rhyme with «blech» or «Bertolt Brecht»), is a document preparation system for high-quality typesetting.

Definition from here

LaTeX features

  • Typesetting journal articles, technical reports, books, and slide presentations.
  • Control over large documents containing sectioning, cross-references, tables and figures.
  • Typesetting of complex mathematical formulas.
  • Advanced typesetting of mathematics with AMS-LaTeX.
  • Automatic generation of bibliographies and indexes.
  • Multi-lingual typesetting.
  • Inclusion of artwork, and process or spot colour.
  • Using PostScript or Metafont fonts.

Features from here

Learning curve

learning

What I can do with LaTeX?

Overleaf

Overleaf is a collaborative online LaTeX editor

overleaf overview

First project

After creating an account, a page with the option Create First Project will appear (see image bellow). To create your first Project just click on the button, chose one template (here, the Blank Project) and give a name for your project.

first project

The next screen is the Projec page, see bellow:

project screen

This screen is divided in three columns, from left to right:

  1. Files
  2. Text source
  3. Output

Note that you can resize, minimize and maximize columns.

Preamble

The Overleaf automatically adds some elements to your code, even if you start with a blank project. So let's understand these elements.

Everything from line 1 up to line 7 is part of the Preamble.

The preamble is the first section of an input file, before the text of the document itself, in which you tell LaTeX the type of document, and other information LaTeX will need to format the document correctly.

The general syntax of a LaTeX document is

\documentclass{class}
   … your preamble goes here …

\begin{document}
   … your text goes here …
\end{document}

Document classes

Line 1: \documentclass{article}

The documentclass is the first command of a LaTeX document, and identifies the type of document contained in the input file (from here). The general syntax is

\documentclass[options]{class}

Some standard classes are:

  • article: For articles in scientific journals, presentations, short reports, program documentation, invitations, ...
  • report: For longer reports containing several chapters, small books, thesis, ...
  • book: For books.
  • letter: For writing letters.
  • beamer: For writing presentations (see LaTeX/Presentations).

See more about document classes here

The most common options for the generic document classes are:

  • Main font size: 10pt, 11pt, 12pt (default: 10pt)
  • Paper size: a4paper, letterpaper, a5paper, b5paper, executivepaper, legalpaper (default: letterpaper*)
  • Number of columns: onecolumn, twocolumn (default: onecolumn)

See more about document classes options here

Packages

Line 2: \usepackage[utf8]{inputenc}

While writing your document, you will probably find that there are some areas where basic LaTeX cannot solve your problem. If you want to include graphics, colored text or source code from a file into your document, you need to enhance the capabilities of LaTeX. Such enhancements are called packages (from here). The usepackage command tells LaTeX to load packages of environments, commands, and symbols for specific purposes (from here). The general syntax is

\usepackage[options]{package}

The most common packages are:

  • inputenc: input encoding
  • amsmath, amsfonts: contains a comprehensive set of mathematical symbols; particularly handy for rendering matrices
  • graphicx: to include graphics (images)
  • xcolor: to use colours in a wide variety of ways, including rgb, cmyk, hsb
  • fancyhdr: useful for customizing the headers and footers in your document
  • hyperref: to automatically insert hyperlinks into the document

Standard titles

Line 4: \title{ }

Line 5: \author{ }

Line 6: \date{ }

The standard classes provide four storing commands that are used to automatically create the title. The storing commands are

  • \title
  • \author
  • \thanks: footnote
  • \date

Line 12: maketitle

The title is created inside the text area through the command maketitle

Text

\begin{document}
   … your text goes here …
\end{document}

Sectioning commands

The commands for inserting sections are fairly intuitive. Of course, certain commands are appropriate to different document classes. For example, a book has chapters but an article doesn't (from here). Some examples:

  • \chapter{chapter name}: only books and reports
  • \section{section name}: not in letters
  • \subsection{subsection name}: not in letters
  • \subsubsection{subsubsection name}: not in letters
  • \paragraph{paragraph content}: not in letters

The \appendix macro can be used to indicate that following sections or chapters are to be numbered as appendices. For example:

\section{first section}
    ... some text ...

\section{second section}
    ... some text ...

\appendix
\section{first appendix}
    ... some text ...

\section{second appendix}
    ... some text ...

Table of contents

All auto-numbered headings get entered in the Table of Contents (also for list and figures) automatically. If you want to display the tables of content, just add the command.

  • \listoffigures
  • \listoftables
  • \tableofcontents

Lists

Typesetting lists is a large topic because LaTeX lists are extremely configurable, enabling creation of an enormous variety of list types and structures (from here). Bellow some standards lists are presented. If you want configure and customize your lists see more here.

Unordered lists

\begin{itemize}
    \item ... some text ...
    \item ... some text ...
    \item ... some text ...
\end{itemize}

Description lists

\begin{description}
    \item [some description] ... some text ...
    \item [some description] ... some text ...
    \item ... some text ...
\end{description}

Note that the [description] is optional.

Ordered lists

\begin{enumerate}
    \item ... some text ...
    \item ... some text ...
    \item ... some text ...
\end{enumerate}

Figures

To include images in your text you need include a package in the preamble. I recommend using the package graphicx.

\usepackage{graphicx}

The image is inserted using the command \includegraphics. The ideal is to use the figure environment to to properly include the image in the text. The complete command is

\begin{figure}[position option]
    \centering
    \includegraphics[figure options]{file path}
    \caption{Caption.}
    \label{fig:my_label}
\end{figure}

Some figures options are (from here):

  • scale
  • width
  • height
  • angle

Some size units are (see all here):

  • pt
  • mm
  • cm
  • \linewidth
  • \textheight

Figures are floats (containers for things in a document that cannot be broken over a page) and the LaTeX will automatically define the best location for the image. However, if we don't give some "tips" on how to do this, the end result can be very different from what you expect. Fortunately, we can add some options to help LaTeX define the best position for the image.

Some position options are (from here):

  • h: Place the float here, i.e., approximately at the same point it occurs in the source text (however, notexactly 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. Requires the float package, though may cause problems occasionally. This is somewhat equivalent to h!.

Tables

The tabular environment is the default LaTeX method to create tables. As for including figures, the ideal is to use the table environment to to properly include the table in the text. The complete command is

\begin{table}[position option]
    \centering
    \begin{tabular}{c|c}
       line 1 column 1  &  text: line 1 column 2\\
       line 2 column 1  &  text: line 2 column 2
    \end{tabular}
    \caption{Caption}
    \label{tab:my_label}
\end{table}

The number of columns and the alignment is defined as a parameter just after the tabular, here was {c | c}, meaning two centralized columns with one vertical line (you can define more - or none - vertical lines). The number of columns is related with the number of letters, and The column alignment is defined by letters:

  • l: left
  • c: centre
  • r: right

To create a new line just add the \\ command to the end of the previous line and write a new line. To drawn a horizontal line, use the \hline command after the \\.

In addition, there are additional packages and advanced commands that allow greater control over the table layout. See here for more information on tables.

Mathematical environment

If your document requires only a few simple mathematical formulas, plain LaTeX has most of the tools that you will ever need. If you are writing a scientific document that contains numerous complex formulas some additional packages are required from here). Recommended packages are:

  • amsmath or mathtools
  • amsfonts

For a complete description about the mathematical environment you can find here. Bellow I will summarize some basic concepts.

Math modes

Inline math mode

To type some equation in inline mode, you can use the $ ... $ delimiters.

... some text ... $ some equation $ ... some text ...

Unordered math mode

To type some equation in the unordered math mode, you can use the \[ ... \] delimiters.

... some text ... 
\[
    some equation
\]
... some text ...

Ordered math mode

To type some equation in the ordered math mode, you can use the \begin{equation} ... \end{equation} delimiters.

... some text ... 
\begin{equation}
    some equation
\end{equation}
... some text ...

Array environment

To type some equation in the array math mode (like a matrix), you can use the \begin{array} ... \end{array} .delimiters.

\begin{equation}
    \begin{array}{cols} 
        row1 \\ 
        row2 \\ 
        . . .\\
        rowm 
    \end{array}
\end{equation}

Note that the array should be used inside a math mode!

Some functions

  • \frac{numerator}{denominator}: fraction
  • \sqrt{\frac{a}{b}}: square roots
  • \sqrt[n]{\frac{a}{b}}: roots of magnitude n
  • ^{n}: powers
  • _{n}: indices

LaTeX mathematical symbols

Mathematics has a huge variety of symbols, and they are all available in LaTeX. Bellow some ideas about what is available:

  • Greek and Hebrew letters
  • math constructs
  • Delimiters
  • Variable-sized symbols
  • Standard Function Names
  • Binary Operation and Relation Symbols
  • Arrow symbols
  • Math mode accents

You can see this file to find the commands for each symbol.

Bibliography with BibTeX

To including bibliography using a bibtex file is necessary:

  1. Create a bibtex file (extension .bib) with the citations.
  2. Include \bibliographystyle{unsrt} on preamble to define the numbered style.
  3. Use the \cite{bib_key} command to cite the reference.
  4. Insert the \bibliography{bib_file} command to print the bibliography.

The syntax is:

%in the preamble
%--------------------------------
    \bibliographystyle{unsrt}
%--------------------------------

% in the text
    ... some text \cite{bib_key} some text ...

%Where the bibliography will be printed
    \bibliography{bib_file}

The standard LaTeX bibliography supports numerical citation. If you need different styles, you can use a different bibliography package that includes different styles. A good example is the natbib package, with a syntax like:

%in the preamble
%--------------------------------
   \usepackage{natbib}
   \bibliographystyle{stylename}
%--------------------------------

% in the text
    ... some text \cite{bib_key} some text ...

%Where the bibliography will be printed
    \bibliography{bib_file}

and some styles options:

  • dinat
  • plainnat
  • abbrvnat
  • ksfh_nat

See here for more about the natbib package, and here for a complete explanation about the LaTeX bibliography.

The BibTeX file

Some standard templates for organize the references are:

@article{bib_key1,
    author    = " author 1 and author 2 and author 3",
    title     = "",
    journal   = "",
    volume    = "",  % Optional
    number    = "",  % Optional
    pages     = "",  % Optional
    year      = "XXXX",
    month     = "",  % Optional
    note      = "",  % Optional
}

Note that the authors' name are separated by and. Furthermore, each BibTeX entry has a unique bib_key. The bib_key is used as reference to link the citation in the main file with the BibTeX file.

@book{bib_key2,
    author    = "",
    title     = "",
    publisher = "",
    volume    = "",   % Optional
    number    = "",   % Optional
    series    = "",   % Optional
    address   = "",   % Optional
    edition   = "",   % Optional
    year      = "XXXX",
    month     = "",   % Optional
    note      = "",   % Optional
}

You can see more templates here.

Final Tips:

Special Characters!

As you may already notice, some characters are not interpreted as a text entrance, they are interpreted as commands. Some common special characters are:

LaTeX command Description Text-mode equivalence
$ Delimiter for math mode \$
% To comment some text \%
^ Superscript (math) \^
_ Subscript (math) \_
& Table column divisor \&
{ and } Used with several commands \{ and \}
~ Single space \~
\ Used with commands \textbackslash

See here to know more about special characters.

Spaces

The LaTeX have a huge control about the spaces in the output, but some information can be helpfull.

New Paragraph

The easeast way to create a new paragraph is by leaving an empty line in the code (see here). The syntax is

First paragraph ...

Second paragraph ...
this line is part of the second paragraph.

Line break

There are three commands to force a new line:

  • \\
  • \newline
  • \hfill \break

Page break

  • \clearpage
  • \newpage

The difference between them is the way that they handle with floats (like images and tables).

Horizontal blank spaces

  • ~: single space
  • \quad and \qquad: spaces in math mode (\qquad = 2*\quad)
  • \hspace{1cm}: add a horizontal space of the desired size.
  • \hfill: add the maximum possible horizontal space.

Vertical blank spaces

  • \vspace{1cm}: add a vertical space of the desired size.
  • \vfill: add the maximum possible vertical space.

About

Notebooks and Files for LaTeX Workshop (LIDA - Data Scientist Internship Programme)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages