LATEX An introduction C.D. Emmery & M.M. van Zaanen Tilburg University October 22, 2013
What is L A TEX? System used to typeset documents. Typesetting: arranging all content in a document in order to achieve the best possible results in terms of stylistics, clarity and readability. Documents: journal articles, reports, books, slides, letters,... Broadly used in academic communities for writing journal articles and theses. 2 of 49
Why L A TEX rather than Word? Focus on content rather than layout. Dynamic elements. Automatically generated table of contents, figure numbers, reference numbers,... Flexibility. Runs on every OS. Good looking documents. Tables, figures, pictures, equations, special symbols, music,... Free! 3 of 49
However... Learning curve. Not interactive. Output? Complex data (tables). 4 of 49
How does L A TEX work? Similar to HTML Works with blocks, tags, or macros that serve a specific role. For example: \section{title of the section goes here} Here we type some text, \textbf{this part is bold}. \begin{itemize} <-- this begins a list \item this will be one item \item this will be the second item \end{itemize} <-- here we end the list 5 of 49
Phyisical and Logical tags Physical textbf: bold textit: italics Huge: big text Logical chapter: chapter number and title emph: emphasized text paragraph: paragraph title and text Physical tags concern layout Logical tags concern meaning Layout and content are seperated L A TEX handles the layout, not you 6 of 49
How does L A TEX work? Text and macro blocks. Reference list. Compiler. Result. 7 of 49
How does L A TEX work? 8 of 49
How to start? main.tex file document class packages title begin document content lists inputs reference list end document input.tex files.bib file 9 of 49
Document Class %% this is the beginning of our.tex file, from here we will start typing %% \documentclass{report} <-- report can be changed: %...% 10 of 49
Packages \documentclass{report} %% this is the LaTeX header %% %% here we can import additional packages %% \usepackage{lipsum} \usepackage{graphicx} \usepackage{} 11 of 49
Title %... % \usepackage{graphicx} \title{title of our Document} \author{your Name} \date{\today} 12 of 49
Beginning our Document Everything that is not a package call, import or title goes here. Start document environment. Add dynamic content lists. %... % \date{\today} %% here ends the header %% \begin{document} \maketitle \newpage \tableofcontents \listoffigures \listoftables 13 of 49
Table of Contents 14 of 49
Inputs & End Document Useful to shorten your main.tex file. %... % \listoftables \input{filename1.tex} \input{filename2.tex} \bibliographystyle{apalike} \bibliography{bibliography.bib} \end{document} %% end of document %% Note: comments and escapes (\% for %, % for comment). 15 of 49
What now? main.tex file input.tex files.bib file 16 of 49
Actual Content: Document Structure \chapter{chapter Name} \section{section name} \subsection{subsection Name} \subsubsection{subsubsection Name} \paragraph{paragraph Name} \subparagraph{subparagraph Title} Note that these do not have \begin tags 17 of 49
Actual Content: Document Structure %% new file chapter1.tex %% \chapter{some Chapter} Here we can place some introduction text that will head the actual section that will follow. \section{our Section} From here, we can start typing in our section, we probably want to also structure this in subsections. \subsection{one goes here} First subsection. \subsection{other goes here} This is our second subsection. 18 of 49
Chapter & Section 19 of 49
Actual Content: Document Structure Note that L A TEX automatically structures text in paragraphs: \subsection{other goes here}. This is our second subsection. This is another paragraph in our subsection, which will be formatted by LaTeX. 20 of 49
Actual Content: Mathematics $ math $ Math in text. \begin{equation} math \end{equation} Math separated from text, centered, and labeled. This example defines $a_1$ as the ratio $\frac{2 \cdot b}{c}$ minus $\beta$: \begin{equation} a.1 = \frac{2 \cdot b}{c} - \beta \end{equation} This example defines a 1 as the ratio 2 b c minus β: 21 of 49 a 1 = 2 b c β (1)
More Content: Tables \begin{table} \begin{tabular}{lc} % 2 columns, Left & Center Product & Cost \\ % & seprates cell \hline % horizontal line Eggs & 2 eur \\ % row ends with \\ Bacon & 3 eur \\ \hline \end{tabular} \caption{this is our caption.} \end{table} 22 of 49
More Content: Tables Result: Product Cost Eggs 2 eur Bacon 3 eur Table: This is our caption. 23 of 49
More Content: Tables \begin{tabular}{ l c r } \hline 1 & 2 & 3 \\ \hline 4 & 5 & 6 \\ \hline 7 & 8 & 9 \\ \hline \end{tabular} 1 2 3 4 5 6 7 8 9 24 of 49
More Content: Figures \begin{figure} \center \includegraphics{filename} \caption{sample picture} \label{samplepicture} \end{figure} 25 of 49
More Content: Figures Figure: Sample picture 26 of 49
More Content: Footnotes Here is some text\footnote{and here is our footnote.} Here is some text 1. 1 And here is our footnote. 27 of 49
And then? main.tex file input.tex files.bib file 28 of 49
BibTeX Storage of all references in an external file/database (.bib) Refer from several.tex-files Citation style flexible Reference management software as helpful tools EndNote, JabRef, Mendeley,... @article{lamport1986, title = {LaTeX: User s Guide \& Reference Manual}, author = {Lamport, Leslie}, year = {1986}, publisher = {Addison-Wesley} } 29 of 49
Citations \cite{tagname}... @article{lamport1986, <---... \cite{lamport1986} 30 of 49
Citations %... % \printbibliography Will look something like: 31 of 49
All done! main.tex file input.tex files.bib file Now it s your turn https: //www.dropbox.com/s/5cxn5v9d7zeb3rj/beamer_uvt.pdf 32 of 49
All done! Start with creating a new directory. Open TeXstudio. Options configure TeXstudio commands LaTeX, PdfLaTeX, BibTeX, Biber, Makeindex First icon right, point to: Computer D: texlive bin win32...exe Save your file in the new directory. Start working. To compile, click the green arrow. 33 of 49
Additional Material Wikibook: http://en.wikibooks.org/wiki/latex IMF: http://www.imf.au.dk/system/latex/ L A TEX-bog, Lars Madsen: http://www.imf.au.dk/system/latex/bog/ Official page: http://www.latex-project.org/ L A TEX Cheat Sheet: http://www.stdout.org/~winston/latex/ L A TEX and strict APA style: http: //dw.tug.org/pracjourn/2012-1/beitzel/beitzel.pdf 34 of 49
Additional Material: Headers \usepackage{fancyhdr} \pagestyle{fancy} \fancyhf{} \renewcommand{\headrulewidth}{0pt} \fancyhead[l]{\nouppercase{\leftmark}} \fancyhead[r]{\thepage} \setlength\fboxsep{0pt} \setlength\fboxrule{1pt} https://en.wikibooks.org/wiki/latex/page_layout# Customizing_with_fancyhdr 35 of 49
Additional Material: Page Numbering \pagenumbering{roman} % arabic, etc. 36 of 49
Additional Material: Renew & Avoid Titles Renew: \renewcommand{\abstractname}{acknowledgements} Avoid Indexing and Numbering: \section*{introduction} 37 of 49
Additional Material: Abstract & Appendix % beginning of document % \begin{abstract} Some text. \end{abstract} %very end of the document% \appendix \chapter{pseudo-code} Yadayada. 38 of 49
Additional Material: References as Links \usepackage[hidelinks=true]{hyperref} This will link all your cites to the entry in the Reference list. 39 of 49
Additional Material: Control References \usepackage[style=apa,sortcites=true,sorting=nyt, minnames=1,maxnames=3,natbib=true, hyperref=true,block=space]{biblatex} Sorting Replacing max names to et al. Allowing for handy cite options such as citep which will automatically do parantheses. 40 of 49
Additional Material: Referencing to Tables and Figures \begin{figure}... \caption{...} \label{ourlabel} \end{figure} In this sentence we will look at our example (Figure \ref{ourlabel}) This will dynamically adjust its assigned number 41 of 49
Additional Material: Quote Tip When typing in L A TEX, quotes such as: Will format like and, so quote and quote, therefore, we want to use: as opening quote. Which will format like this and this. 42 of 49
Additional Material: Figures side-by-side Simple way: \begin{figure} \begin{center}$ \begin{array}{cc} \includegraphics[width=50mm]{image1}& \includegraphics[width=85mm]{image2} \end{array}$ \end{center} \caption{2 images} \label{2images} \end{figure} Better alternative: en.wikibooks.org/wiki/latex/floats, _Figures_and_Captions#Subfloats 43 of 49
Additional Material: Booktabs Table Name First name Last Name Grade John Doe 7.5 Richard Miles 2 http://www.howtotex.com/packages/ improve-your-tables-with-booktabs/ 44 of 49
Additional Material: Two-sides printing \documentclass[twoside]{article} \usepackage[hmarginratio=1:1]{geometry} This will marge odd pages to the right so they will look good when double printed 45 of 49
Additional Material: Tikz Parse Trees \usepackage{tikz} \usepackage{tikz-qtree} \begin{tikzpicture} \tikzset{frontier/.style={distance from root=150pt}} \Tree [.S [.NP [.Det the ] [.N cat ] ] [.VP [.V sat ] [.PP [.P on ] [.NP [.Det the ] [.N mat ] ] ] ] ] \end{tikzpicture} 46 of 49
Additional Material: Tikz Parse Trees S NP VP Det N V PP P NP Det N the cat sat on the mat http://www.isi.edu/~chiang/software/texmf/ tikz-qtree-manual.pdf 47 of 49
Additional Material: Algorithms \begin{algorithm}[h] \SetAlgoLined \KwData{Set (S) of numbers (22, 4, 78, 23, 42, 13, 1337, 23)} \KwResult{Largest number (max) in our set (S)} max = 0\; \For{number in S}{ \eif{number $>$ max}{ max = number \; } { continue\; } } return max\; \caption{very simple algorithm to find the largest number in a set.} \label{algo1} \end{algorithm} 48 of 49
Additional Material: Algorithms Data: Set (S) of numbers (22, 4, 78, 23, 42, 13, 1337, 23) Result: Largest number (max) in our set (S) max = 0; for number in S do if number > max then max = number ; else continue; end end return max; Algorithm 1: Very simple algorithm to find the largest number in a set. 49 of 49