Advanced Technology M 3 L T EX workshop A Write like a programmer! Martin Klein Schaarsberg University of T wente September 11 and 12, 2014
Write like a programmer? Why? Consistency and clarity by separation of content and style Flexibility and shareability from paper to book, poster and slides Scalability and stability from a 4 page paper to a 400 page book
Write like a programmer? How? Conceptualization define purpose, suitable medium and structure Implementation choose the right tool for the job Programming usually in plain text using language specific syntax Compilation translate code to result (pdf, web page or figure) (Publishing) to the web, print, e-mail, presentation
Write like a programmer? Example 1: Matlab Conceptualization show what sin ( x ) with x from 0 to 2 π looks like Implementation Matlab code Programming x = linspace(0,2*pi,100); plot(x,sin(x)) Compilation running the code with Matlab creates a figure (Publishing) to the web, print, e-mail, presentation
Write like a programmer? Example 2: HTML Conceptualization create a website with one heading Implementation HTML code Programming <html> <h1>Hello world!</h1> </html> Compilation open the code with a web browser (Publishing) to the web
Write like a programmer? Example 2: Latex Conceptualization create a PDF document that says ‘Hello world’ Implementation Latex Programming \documentclass{article} \begin{document} Hello world! \end{document} Compilation use pdflatex to create a pdf document from the code (Publishing) do whatever you want with the PDF
How does it work? ◮ You write your document in plain text with commands that describe its structure and meaning ◮ The latex program processes your text and commands to produce a beautifully formatted pdf document. De \emph{hoogste} vereniging van de UT! ↓ latex De hoogste vereniging van de UT!
Workflow Text editor Graphics Reference LaTeX program manager distribution TeXworks TeXnicCenter Gimp JabRef MiKTeX Texmaker Illustrator or text editor MacTeX Output Notepad Paint TeX Live document Source Included Citation LaTeX .pdf .dvi document graphics database packages .pdf .sty .eps .bib .tex .cls .png .dtx Processing .jpg files .aux .bbl LaTeX programs .log pdflatex .toc bibtex latex makeindex .out
An example L A T EX document Sample document \documentclass[10pt]{article} \title{Sample document} My name \author{My name} \date{\today} November 12, 2012 \begin{document} \maketitle \end{document}
An example L A T EX document Sample document \documentclass[10pt]{article} \title{Sample document} My name \author{My name} \date{\today} November 12, 2012 \begin{document} \maketitle 1 Introduction \section{Introduction} 1.1 Food \subsection{Food} \end{document}
An example L A T EX document Sample document \documentclass[10pt]{article} \title{Sample document} My name \author{My name} \date{\today} November 12, 2012 \begin{document} \maketitle 1 Introduction \section{Introduction} This is my \emph{first} This is my first document, cre- document, created on \today. ated on November 12, 2012. \subsection{Food} I like cookies, Pizza, and 1.1 Food chocolate. \end{document} I like cookies, Pizza, and chocolate.
An example L A T EX document Sample document \documentclass[10pt]{article} \title{Sample document} My name \author{My name} \date{\today} November 12, 2012 \begin{document} \maketitle 1 Introduction \section{Introduction} This is my \emph{first} This is my first document, cre- document, created on \today. ated on November 12, 2012. \subsection{Food} I like cookies, Pizza, and 1.1 Food chocolate. \end{document} I like cookies, Pizza, and chocolate.
Commands and environments ◮ Commands add extra functions to your text ◮ Format: \command[optional_args]{required_args} Example \today September 10, 2014 Use \emph{emphasis} Use emphasis Make it \textit{italic} Make it italic Make it \textbf{bold} Make it bold I love my \texttt{typewriter} I love my typewriter \textit{Emphasis is Emphasis is smart \emph{smart}}
Commands and environments ◮ Environments are used to treat sections specially ◮ Format: \begin{environment}[optional_args] ... \end{environment} Example \begin{enumerate} 1. First \item First 2. Second \item Second \item Third 3. Third \end{enumerate}
Document outline ◮ \title{} ◮ \author{} ◮ \date{} ◮ \maketitle{} ◮ \begin{abstract} ... \end{abstract} ◮ \part{} ◮ \chapter{} ◮ \section{} ◮ \subsection{} ◮ \subsubsection{} ◮ \paragraph{} ◮ \footnote{} ◮ \bibliography{}
Simple lists \begin{itemize} ◮ First item \item First item ◮ Second item \item Second item \end{itemize} \begin{enumerate} 1. First item \item First item \item Second item 2. Second item \end{enumerate} the ITco does not fix \begin{description} \item[the ITco] does not fix your your computer computer \item[the board] the board Best\'u\'u\'u\'u\'u\'ur! Bestúúúúúúr! \end{description}
Simple lists Lists can also be nested Example My favourite committee is My favourite committee is \begin{enumerate} \item ITco 1. ITco \item BOSS \item Other 2. BOSS \begin{itemize} 3. Other \item NICAT ◮ NICAT \item INCA ◮ INCA \item \dots ◮ . . . \end{itemize} \end{enumerate}
Paragraphs and whitespace One, two, three spaces One, two, three spaces or or even a linebreak make even a linebreak make no no difference for \LaTeX. difference for L A T EX. You can create a new You can create a new paragraph with a white- line, as you can see. paragraph with a If necessary, you can whiteline, as you can see. break . . . a . . . If necessary, you can line! break \dots \\ a \dots \\ line!
Special characters Some characters have special meaning in L A T EX, if you need them they have to be entered as L A T EX-commands: \ \textbackslash note: \\ = newline $ \$ & \& % \% # \# ~ \textasciitilde \_ _ ˜ \~{} { } \{ \} <> \textless \textgreater (not in math)
Breaks and spaces hard space ~ normal space \ line break \\ continue on new page \clearpage continue on new odd numbered page \cleardoublepage horizontal space \quad , \hspace{2cm} vertical space \medskip , \bigskip , \vspace{2cm}
Dashes, quotation marks and dots Hyphens socio-economic - En-dash 2011–2012 -- Em-dash Make no mistake—dashes --- are important Quotation marks ‘Awesome’! ` and ' “Awesome”! `` and '' Dots “In the beginning . . . ” ~\dots
Gotcha’s ◮ Most errors come from not matching { with a }, a \begin{} with an \end{} or $ with $ or using a symbol that has a special meaning to L A T EX. ◮ Undefined control sequence means you misspelled a command or you did not load the package necessary for that command. ◮ Putting parts of equations on separate lines in the code will make reading the code easier. Avoid blank lines, they will give errors .
Exercise 1 ◮ Exercise 1: see handout ◮ Practice with the following concepts: ◮ Creating PDFs ◮ Document structure ◮ White space, paragraphs and special characters ◮ Lists ◮ Presentation slides are available on http://martinkleinschaarsberg.nl/latex
Document class \documentclass[options]{class} ◮ Document classes: article journal papers, short reports report longer text with several chapters, e.g. thesis book books letter letters beamer slide presentations beamerposter conference posters ◮ Style packages such as Koma-Script and memoir provide alternative classes. Also several publishers have their own classes. Example \documentclass[10pt,a4paper,twoside]{article}
Document class \documentclass[options]{class} ◮ Options: Font size 10pt | 11pt | 12pt... Paper size a4paper | legalpaper... equations fleqn, leqno title titlepage | notitlepage columns onecolumn | twocolumn printing oneside | twoside Example \documentclass[10pt,a4paper,twoside]{article}
Packages ◮ Packages add functions to L A T EX ◮ In the preamble, before \begin{document} ◮ Format: \usepackage[options]{package} Example mathpazo loads the font Palatino amsmath provides useful math environments and characters xcolor colored text graphicx include pictures and diagrams hyperref cross-referencing in pdf
International support ◮ Use the babel package ◮ (e.g. \usepackage[dutch]{babel} ) ◮ Use \texteuro 30 to get €30 (requires the textcomp package) ◮ Use the icomma package if you want to use a comma as decimal separator ◮ Create accents like \'e , \`e , \^e (é, è, ê) ◮ Or directly input accented characters: 1. Set the input encoding, e.g. \usepackage[utf8]{inputenc} 2. Set the font encoding, e.g. \usepackage[T1]{fontenc} (with \usepackage{lmodern} or an other suitable font)
Inline and display equations ◮ Use $...$ for inline mathematics ◮ Use \begin{equation}...\end{equation} for displayed mathematics with numbering ◮ Use \begin{equation*} ... \begin{equation*} for displayed mathematics without numbering ◮ Use the amsmath package for more symbols and environments ◮ A good reference guide: AMS Short Math Guide
Recommend
More recommend