48

Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

Introduction to LATEX for Computer Scientists

Simon Funke, Jonathan Feinberg

September 29, 2015

Page 2: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

Overview

Page 3: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 4: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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

Page 5: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

Editing Latex

Overleaf (Web)

Kile (Linux)

Texshop (Mac)

Texniccenter (Windows)

Emacs + AUCTeX (advanced users)

Vim + Latex-suite (advanced users)

Page 6: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

Writing LATEX code

Page 7: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

�Hello World!� example

\documentclass{article}

\begin{document}

Hello World!

\end{document}

Hello World!

Page 8: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 9: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 10: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 11: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 12: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

The Preamble

Page 13: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

Document language

\documentclass{article}

\title{Norsk dokument}

\author{Jørgen}

\begin{document}

\maketitle

\end{document}

Norsk dokument

Jrgen

September 29, 2015

Page 14: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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

Page 15: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 16: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 17: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 18: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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!

Page 19: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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!

Page 20: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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).

Page 21: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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).

Page 22: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 23: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 24: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 25: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 26: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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

Page 27: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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

Page 28: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 29: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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"

Page 30: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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"

Page 31: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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"

Page 32: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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"

Page 33: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

Presentations through Beamer

Page 34: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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}

...

Page 35: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

Frame title

This frame is written as follows:

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

This frame is written as follows:

\ end{frame}

Page 36: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

Frame title

This frame is written as follows:

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

This frame is written as follows:

\ end{frame}

Page 37: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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}

Page 38: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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}

Page 39: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

Splitting the frame vertically

\begin{columns}

\column{.33\textwidth}

Three

\column{.33\textwidth}

Unique

\column{.33\textwidth}

Subframes

\end{columns}

Three Unique Subframes

Page 40: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

Splitting the frame vertically

\begin{columns}

\column{.33\textwidth}

Three

\column{.33\textwidth}

Unique

\column{.33\textwidth}

Subframes

\end{columns}

Three Unique Subframes

Page 41: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.)

Page 42: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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/

Page 43: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 44: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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.

Page 45: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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

Page 46: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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

Page 47: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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

Page 48: Introduction to LaTeX for Computer Scientists · Introduction to L A T E X for Computer Scientists Simon Funke, Jonathan Feinberg September 29, 2015. Overview. ... minted requires

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