Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists...

Preview:

Citation preview

Introduction to LATEX for Computer Scientists

Simon Funke, Jonathan Feinberg

September 29, 2015

Overview

LATEX � A document markup language

Write what you mean (WYSIWYM), not what you see(WYSIWYG).

Easy consistency throughout large/many documents

Professional typesetting

Highly customizable and extendable

Compile to multiple formats

Superb math-typing

Presentations/Slides

Bibliography

etc.

Resources

�The Not So Short introduction to LATEX�

http://tobi.oetiker.ch/lshort/lshort.pdf

LATEX Wikibook

http://en.wikibooks.org/wiki/LaTeX

Draw and identify symbols

http://detexify.kirelabs.org

Beamer userguide (for presentations)

http://texdoc.net/texmf-dist/doc/latex/beamer/doc/

beameruserguide.pdf

Editing Latex

Overleaf (Web)

Kile (Linux)

Texshop (Mac)

Texniccenter (Windows)

Emacs + AUCTeX (advanced users)

Vim + Latex-suite (advanced users)

Writing LATEX code

�Hello World!� example

\documentclass{article}

\begin{document}

Hello World!

\end{document}

Hello World!

The bare necessities

\documentclass{article}

\begin{document}

\section{Numbered section}

\subsection*{Unnumbered subsection}

This is paragraph number one.

It is not indented.

This is paragraph number two.

It is indented.

\begin{verbatim}

This is verbatim text.

Monowidth and code friendly.

\ end{verbatim}

% This is a comment

\end{document}

1. Numbered section

Unnumbered subsection

This is paragraph number one. It is notindented.

This is paragraph number two. It isindented.

This is verbatim text.

Monowidth and code friendly.

The bare necessities

\documentclass{article}

\begin{document}

\section{Numbered section}

\subsection*{Unnumbered subsection}

This is paragraph number one.

It is not indented.

This is paragraph number two.

It is indented.

\begin{verbatim}

This is verbatim text.

Monowidth and code friendly.

\ end{verbatim}

% This is a comment

\end{document}

1. Numbered section

Unnumbered subsection

This is paragraph number one. It is notindented.

This is paragraph number two. It isindented.

This is verbatim text.

Monowidth and code friendly.

Making a title

\documentclass{article}

\title{Document title}

\author{Jonathan Feinberg}

\begin{document}

\maketitle

Lorem ipsum dolor sit amet, consectetur

adipiscing elit. Maecenas pellentesque

ut mauris non consectetur. Praesent ut

dolor a turpis malesuada pulvinar.

\end{document}

Document title

Jonathan Feinberg

September 29, 2015

Lorem ipsum dolor sit amet, consecteturadipiscing elit. Maecenas pellentesque utmauris non consectetur. Praesent ut dolora turpis malesuada pulvinar.

Making a title

\documentclass{article}

\title{Document title}

\author{Jonathan Feinberg}

\begin{document}

\maketitle

Lorem ipsum dolor sit amet, consectetur

adipiscing elit. Maecenas pellentesque

ut mauris non consectetur. Praesent ut

dolor a turpis malesuada pulvinar.

\end{document}

Document title

Jonathan Feinberg

September 29, 2015

Lorem ipsum dolor sit amet, consecteturadipiscing elit. Maecenas pellentesque utmauris non consectetur. Praesent ut dolora turpis malesuada pulvinar.

The Preamble

Document language

\documentclass{article}

\title{Norsk dokument}

\author{Jørgen}

\begin{document}

\maketitle

\end{document}

Norsk dokument

Jrgen

September 29, 2015

Document language

\documentclass[norsk]{article}

\usepackage[norsk]{babel}

\usepackage[utf8]{inputenc}

\title{Norsk dokument}

\author{Jørgen}

\begin{document}

\maketitle

\end{document}

Norsk dokument

Jørgen

7. oktober 2014

Mathematical typing

\documentclass{article}

\usepackage{amsmath, amssymb, bm}

\begin{document}

\begin{align*}

\bm{\alpha}^2 =

\left(

\alpha_0^2, \dots, \alpha_n^2

\right)

\end{align*}

\end{document}

α2 =(α20, . . . , α

2n

)

Einstein formulae: $e=mc^2$.

Einstein formulae: e = mc2.

Mathematical typing

\documentclass{article}

\usepackage{amsmath, amssymb, bm}

\begin{document}

\begin{align*}

\bm{\alpha}^2 =

\left(

\alpha_0^2, \dots, \alpha_n^2

\right)

\end{align*}

\end{document}

α2 =(α20, . . . , α

2n

)

Einstein formulae: $e=mc^2$.

Einstein formulae: e = mc2.

Mathematical typing

\documentclass{article}

\usepackage{amsmath, amssymb, bm}

\begin{document}

\begin{align*}

\bm{\alpha}^2 =

\left(

\alpha_0^2, \dots, \alpha_n^2

\right)

\end{align*}

\end{document}

α2 =(α20, . . . , α

2n

)

Einstein formulae: $e=mc^2$.

Einstein formulae: e = mc2.

Aligning multiple expressions

\begin{align*}

a &= 1, 2, 3 & b, c, d &= 4 \\

\pi &\approx \frac{22}{7} & 1\cdot 2\cdots n &\equiv n!

\end{align*}

a = 1, 2, 3 b, c , d = 4

π ≈ 22

71 · 2 · · · n ≡ n!

Aligning multiple expressions

\begin{align*}

a &= 1, 2, 3 & b, c, d &= 4 \\

\pi &\approx \frac{22}{7} & 1\cdot 2\cdots n &\equiv n!

\end{align*}

a = 1, 2, 3 b, c , d = 4

π ≈ 22

71 · 2 · · · n ≡ n!

Cross-referencing

\section{First section}

\label{sec:first}

\section{Section section}

\label{sec:second}

\begin{align}

\label{eq:facorial}

n! \equiv 1\cdot 2\cdots n

\end{align}

Reference to sections \ref{sec:first}

and \ref{sec:second}.

Reference to equation

\eqref{eq:factorial}.

1. First section

2. Second section

n! ≡ 1 · 2 · · · n (1)

Reference to sections 1 and 2.Reference to equation (1).

Cross-referencing

\section{First section}

\label{sec:first}

\section{Section section}

\label{sec:second}

\begin{align}

\label{eq:facorial}

n! \equiv 1\cdot 2\cdots n

\end{align}

Reference to sections \ref{sec:first}

and \ref{sec:second}.

Reference to equation

\eqref{eq:factorial}.

1. First section

2. Second section

n! ≡ 1 · 2 · · · n (1)

Reference to sections 1 and 2.Reference to equation (1).

Tables

\begin{table}[htb!]

\begin{tabular}{|r|l|}

\hline

first & second \\

\hline

third & fourth \\

\hline

\end{tabular}

\caption{Table caption.}

\label{tab:table_label}

\end{table}

�rst second

third fourth

Table 1: Table caption.

Tables

\begin{table}[htb!]

\begin{tabular}{|r|l|}

\hline

first & second \\

\hline

third & fourth \\

\hline

\end{tabular}

\caption{Table caption.}

\label{tab:table_label}

\end{table}

�rst second

third fourth

Table 1: Table caption.

Figures

\begin{figure}[htb!]

\begin{center}

\includegraphics

[width=.9\textwidth]

{badass.jpg}

\end{center}

\caption{A true badass.}

\label{fig:figure_label}

\end{figure}

Figure 1: A true badass.

Figures

\begin{figure}[htb!]

\begin{center}

\includegraphics

[width=.9\textwidth]

{badass.jpg}

\end{center}

\caption{A true badass.}

\label{fig:figure_label}

\end{figure}

Figure 1: A true badass.

Bullet points

\begin{itemize}

\item first

\item second

\item last

\end{itemize}

\begin{enumerate}

\item first

\item second

\item last

\end{enumerate}

�rst

second

last

1 �rst

2 second

3 last

Bullet points

\begin{itemize}

\item first

\item second

\item last

\end{itemize}

\begin{enumerate}

\item first

\item second

\item last

\end{enumerate}

�rst

second

last

1 �rst

2 second

3 last

Code

The package minted allows to add Python/C(++)/Java withsyntax highlighting

minted requires Pygments, a Python package for codehighlighting. Pygments supports over 300 supported languagesand text formats

Alternative: listings package.

Python code with minted

...

\usepackage{minted}

\begin{document}

\begin{minted}{python}

import sys

def func():

print "Hello world"

\end{minted}

import sys

def func():

print "Hello world"

Python code with minted

...

\usepackage{minted}

\begin{document}

\begin{minted}{python}

import sys

def func():

print "Hello world"

\end{minted}

import sys

def func():

print "Hello world"

Customize minted

\begin{minted}

[frame=lines,

framesep=2mm,

linenos]{python}

import sys

def func():

print "Hello world"

\end{minted}

1 import sys

2 def func():

3 print "Hello world"

Customize minted

\begin{minted}

[frame=lines,

framesep=2mm,

linenos]{python}

import sys

def func():

print "Hello world"

\end{minted}

1 import sys

2 def func():

3 print "Hello world"

Presentations through Beamer

The code for this presentation

\documentclass[english]{beamer}

\usetheme[ifi]{UiO}

\usepackage[english]{babel}

\usepackage[utf8]{inputenc}

\usepackage{amsmath, amssymb, bm}

\title{Introduction to \LaTeX\ for Computer Scientists}

\author{Simon Funke, Jonathan Feinberg}

\date{\today}

\begin{document}

\begin{frame}

\titlepage

\ end{frame}

...

Frame title

This frame is written as follows:

\begin{frame}[fragile]{Frame title}

This frame is written as follows:

\ end{frame}

Frame title

This frame is written as follows:

\begin{frame}[fragile]{Frame title}

This frame is written as follows:

\ end{frame}

Frame title

This frame is written as follows:

\begin{frame}[fragile]{Frame title}

This frame is written as follows:

\begin{verbatim}

\ end{verbatim}

\ end{frame}

Frame title

This frame is written as follows:

\begin{frame}[fragile]{Frame title}

This frame is written as follows:

\begin{verbatim}

\begin{frame}[fragile]{Frame title}

This frame is written as follows:

...

\ end{frame}

\ end{verbatim}

\ end{verbatim}

\ end{frame}

Splitting the frame vertically

\begin{columns}

\column{.33\textwidth}

Three

\column{.33\textwidth}

Unique

\column{.33\textwidth}

Subframes

\end{columns}

Three Unique Subframes

Splitting the frame vertically

\begin{columns}

\column{.33\textwidth}

Three

\column{.33\textwidth}

Unique

\column{.33\textwidth}

Subframes

\end{columns}

Three Unique Subframes

UiO (and other) custom themes

University machines support the UiO theme

All UiO styles and templates can be downloaded from

http://www.mn.uio.no/ifi/tjenester/it/hjelp/latex/

Move (unpacked) material to texmf (linux, optional)

$ mv file_or_folder /usr/share/texmf/tex/latex/

Add folders to latex path

$ mktexlsr path/to/files_and_folders

(Neglect arg if loading texmf folder.)

Bibliography

A thesis must have a bibliography!

LATEX support bibliography through bibtex.

Bibliographies are stored in a separate .bib �le

Manage the bibliographies through reference managementssoftwares like Zotero:

https://www.zotero.org/

Bibtex in practice

% example.tex

\documentclass{article}

\begin{document}

Citing \cite{xkcd}.

\bibliographystyle{plain}

\bibliography{ref_file}

\end{document}

% ref_file.bib

@book{xkcd,

title = {What If},

author = {Monroe, R.},

year = {2014},

isbn = {9780544272996},

publisher = {Houghton Mifflin Harcourt}

}

Citing [1].

References

[1] R. Monroe. What If. Houghton Mi�in Harcourt, 2014.

Bibtex in practice

% example.tex

\documentclass{article}

\begin{document}

Citing \cite{xkcd}.

\bibliographystyle{plain}

\bibliography{ref_file}

\end{document}

% ref_file.bib

@book{xkcd,

title = {What If},

author = {Monroe, R.},

year = {2014},

isbn = {9780544272996},

publisher = {Houghton Mifflin Harcourt}

}

Citing [1].

References

[1] R. Monroe. What If. Houghton Mi�in Harcourt, 2014.

Compiling with pdflatex

Compile once to generate supplimentary �les

$ pdflatex -shell-escape example.tex

Create bibliography elements

$ bibtex example.aux

Compile to �ll references into document

$ pdflatex -shell-escape example.tex

Compile again for cross-references

$ pdflatex -shell-escape example.tex

Compiling with pdflatex

Compile once to generate supplimentary �les

$ pdflatex -shell-escape example.tex

Create bibliography elements

$ bibtex example.aux

Compile to �ll references into document

$ pdflatex -shell-escape example.tex

Compile again for cross-references

$ pdflatex -shell-escape example.tex

Compiling with pdflatex

Compile once to generate supplimentary �les

$ pdflatex -shell-escape example.tex

Create bibliography elements

$ bibtex example.aux

Compile to �ll references into document

$ pdflatex -shell-escape example.tex

Compile again for cross-references

$ pdflatex -shell-escape example.tex

Compiling with pdflatex

Compile once to generate supplimentary �les

$ pdflatex -shell-escape example.tex

Create bibliography elements

$ bibtex example.aux

Compile to �ll references into document

$ pdflatex -shell-escape example.tex

Compile again for cross-references

$ pdflatex -shell-escape example.tex

Recommended