Introduction to L A TEX Javier Larrosa UPC Barcelona Tech November 2, 2016 Observation: I have never studied L A TEX. I have learned just what I have needed and forgotten quickly Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 1 / 30
L A TEX L A TEX (currently L A TEX 2ε) is a document preparation system The writer uses plain text as opposed to formatted text The source file (.tex) is compiled into an output file (such as.ps,.pdf,...) Free software Standard for scientific documents Environments: Linux: tex live Windows: MikTex MacOs: MacTex Web service: Overleaf.com, writelatex.com Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 2 / 30
A first Example from the command line: $ pdflatex file.tex file.pdf Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 3 / 30
Hello World %A hello world article \documentclass{article} \title{my first document} \date{\today} \author{javier Larrosa} \begin{document} \maketitle Hello World! \end{document} \documentclass[options]{class} options: 12pt, twoside, a4paper, twocolumn, landscape,... class: article, book, letter, beamer... Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 4 / 30
Article \begin{document} \maketitle \begin{abstract} hello \end{abstract} \section{a} \subsection{b} bla, bla, bla, bla,bla, bla. \subsubsection{c} bla, bla, bla, bla, bla, bla... \end{document} Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 5 / 30
Paragraphs The end of a paragraph is indicated leaving a blank line (the next paragraph will be indented by default) Non indent: \nonindent Line breaking: \newline Additional separation: \vspace{} Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 6 / 30
Font modes You can write in plain text, \textbf{boldface}, \textit{italics}, \underline{underline}. There are many other options You can write in plain text, boldface, italics, underline. There are many other options Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 7 / 30
Font sizes This is the standard size with respect to your document, this is {\small small size}, {\scriptsize smaller}, {\large large size}, {\Huge larger}. There are many other options. This is the standard size with respect to your document, this is small size, smaller, large size, larger. There are many other options. Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 8 / 30
Commands Commands Instruction to do something special \name[optional options]{mandatory options} Some commands have a so-called *-form to modify their functionality Examples: \rule[lift]{width}{height} produces a black rectangle \section*{heading} omits numbering Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 9 / 30
Environments Environments Treats differently the text within \begin{name}... \end{name} or {\name... } Examples: quote center Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 10 / 30
Commands, Environments, Packages You can define your own commands and environments You can import them as packages \usepackage{hyperef} allows PDF metadata and to create links \usepackage[utf8]{inputenc} allows to encode special characters (non-english text) \usepackage[spanish]{babel} proper hyphenation, etc \usepackage{algorithm2e} allows to write pseudo-code \usepackage{beamerposter} allows to write posters... Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 11 / 30
itemize environment That s a list: \begin{itemize} \item Hello \item Bye \end{itemize} And that is another: \begin{enumerate} \item first item \item second item \end{enumerate} That s a list: Hello Bye And that is another: 1 first item 2 second item Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 12 / 30
Figures with Graphics Figures \begin{figure}[t] \includegraphics[height=3cm]{upc.png} \caption{upc logo.} \end{figure} Figure 1: UPC logo. Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 13 / 30
Figures with Tables \begin{figure}[t] \begin{center} \begin{tabular}{ l c r } \hline 1 & 2 & 3 \\ \hline 4 & 5 & 6 \\ \hline 7 & 8 & 9 \\ \hline \end{tabular} \end{center} \caption{a table.} \end{figure} 1 2 3 4 5 6 7 8 9 Figure 2: A table. Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 14 / 30
math environment (also $...$) Inline mathematics $p,q,r$ Greek letter $\alpha, \Alpha$ Op. $\cdot, \times, \bowtie$ Subscripts $x_i, x^i, X_{a_i}^{b_j}$ Quantifiers $\sum_{i=0}^n, \prod_i, \forall$ Inline mathematics p, q, r Greek letter α, β Ops.,, Subscripts x i, x i, X b j a i Quantifiers n i=0, i, Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 15 / 30
equation environment (also $$...$$) Equations are numbered and centered $$ \phi({\cal X})=\sum_{i=1}^n f_i(x_i)$$ produces and φ(x ) = n f i (x i ) i=1 $$ \frac{a+b}{(c+d) 2 }= F(X)$$ produces a + b (c + d) 2 = F (X ) Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 16 / 30
array environment The \emph{characteristic polynomial} $\chi(\lambda)$ of the $3 \times 3$~matrix \[ \left( \begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} \right)\] is given by the formula \[ \chi(\lambda) = \left \begin{array}{ccc} \lambda - a & -b & -c \\ -d & \lambda - e & -f \\ -g & -h & \lambda - i \end{array} \right.\] The characteristic polynomial χ(λ) of the 3 3 matrix a b c d e f g h i is given by the formula χ(λ) = λ a b c d λ e f g h λ i. Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 17 / 30
References L A TEXallows you to label many types of items (e.g. formulas, section, figures,...) for posterior reference in the item include \label{ident} in the text write \ref{ident} \begin{figure}[t] \includegraphics[height=1cm]{upc.png} \label{fig-upc} \caption{upc logo.} \end{figure}... in Figure \ref{fig-upc} we can see the UPC logo... Figure 3: UPC logo.... in Figure 18 we can see the UPC logo... Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 18 / 30
Bibliographic databases and bibtex bibtex is an auxiliary program that automatically constructs a bibliography by searching in a database Databases are named name.bib The latex document must contain \bibliography{name.bib} optional \bibliographystyle{} Within the document cite as \cite{ident} Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 19 / 30
Database Entries: article bibsource = {dblp computer science bibliography, http://dblp @article{dblp:journals/stp/dijkstraf89, author = {Edsger W. Dijkstra and W. H. J. Feijen}, title = {The Linear Search Revisited}, journal = {Structured Programming}, volume = {10}, number = {1}, pages = {5--9}, year = {1989}, timestamp = {Thu, 03 Jan 2002 12:26:55 +0100}, biburl = {http://dblp.uni-trier.de/rec/bib/journals/stp/d } Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 20 / 30
Database Entries: conference article @inproceedings{dblp:conf/acm/papadimitriouak12, author = {Christos H. Papadimitriou and Leonard M. Adleman and Richard M. Karp and Donald E. Knuth and Robert E. Tarjan and Leslie G. Valiant}, title = {An Algorithmic View of the Universe}, booktitle = {{ACM} Turing Centenary Celebration, {ACM-TURING California, USA, June 15-16, 2012}, pages = {13:1}, year = {2012}, crossref = {DBLP:conf/acm/2012t}, url = {http://doi.acm.org/10.1145/2322176.2322189} } Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 21 / 30
Bibtex usage from the command line $ pdflatex file.tex $ bibtex file $ pdflatex file.tex $ pdflatex file.tex Overleaf Overleaf takes care of the bibliography automatically. You only have to add the bibliography database to the overleaf project. Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 22 / 30
Some useful packages algorithm2e beamer beamerposter Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 23 / 30
algorithm2e \begin{algorithm}[h] \SetKwProg{Fn}{Function} {is}{end} \Fn{Search $(X,a)$}{ \KwData{$X$ is a vector, and $a$ is an element} \KwResult{$i$ s.t. $X[i]==a$, $-1$ if $a$ is not in $X$} \BlankLine \For{$i\leftarrow 0$ \KwTo $X.length()-1$}{ \lif{$x[i]==a$}{\return $i$} } \Return $-1$;} \end{algorithm} 1 Function Search (X, a) is Data: X is a vector, and a is an element Result: i such that X [i] == a, 1 if a is not in X 2 for i 0 to X.length() 1 do 3 if X [i] == a then return i; 4 end 5 return 1; 6 end Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 24 / 30
basic instruction blocks \If{}{} \Else{}{} \For{}{} \ForEach{}{} \While{}{} \Return{} You can define your own Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 25 / 30
algorithm2e: line-version instruction blocks \If{$A$}{$B$} \lif{$a$}{$b$} 1 if A then 2 B 3 end 4 if A then B; Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 26 / 30
algorithm2e You can easily change the aspect of your algorithms: C Python Pseudo-code Multiligual support lined/unlined numbered/unnumbered lines may be labeled and referenced in the text Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 27 / 30
algorithm2e There are several environments that produce different caption titles: algorithm function procedure *-version for double column Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 28 / 30
beamer documentclass beamer The beamer documentclass allows easy slides generation frames: \begin{frame}{title}... \end{ frame} Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 29 / 30
beamer \documentclass{beamer} \mode<presentation> { \usetheme{madrid} \usecolortheme{default} \usefonttheme{default} \setbeamertemplate{navigation symbols}{} \setbeamertemplate{caption}[numbered] } Javier Larrosa (UPC Barcelona Tech) Slides Template November 2, 2016 30 / 30