Math 390: LATEX Lecture Notes Sean Malory Fylde B41 s.malory@lancaster.ac.uk Contents 1 Introduction to the Course 1 1.1 Aims of the Course . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 The Structure of the Course and How It Will Be Assessed . . . . . . . . . . . . . . . . . . . . . . . . 1 1.3 How to Use These Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.4 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 Introduction to LATEX 2.1 2.2 2.3 2.4 What is 3 LAT EX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Learning LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Structure of a LATEX Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Commands, Environments, Special Characters and Quotation Marks . . . . . . . . . . . . . . . . . . 3 Writing Mathematics in LATEX 3.1 Math Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 4 4 6 8 8 3.2 Subscripts and Superscripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.4 Equation Referencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.5 Delimiters (Brackets) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.6 Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.7 A Note on Punctuation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 4 Producing Tables and Figures 9 18 4.1 Floating Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 4.2 Captions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 4.3 Table/Figure Referencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 4.4 Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 4.5 Including Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 4.6 Tikz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 i 5 Structure and Citations 24 5.1 Structuring a Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 5.2 Adjusting Page Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 5.3 Constructing Large Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 5.4 Typesetting Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 5.5 Bibliography and Citations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 6 Beamer Presentations 31 6.1 Frames and Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 6.2 Presentation Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 6.3 Dynamic Overlays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 ii 1 Introduction to the Course 1.1 Aims of the Course The primary aim of this course is to teach you how to use the typesetting package LATEX to produce professional looking documents and presentations that include mathematical content. In particular by the end of this course you should be able to • Write a basic LATEX document which compiles and produces a pdf. • Write Mathematics within LATEX. • Include a table in your LATEX document. • Include graphics from file into your LATEX document. • Create basic plots using the Tikz package. • Include citations using the Bibtex and Natbib packages. • Make a presentation with the Beamer package. 1.2 The Structure of the Course and How It Will Be Assessed The structure of the course is as follows: 1. Tuesday, 26th May: Introduction and basics. This is Section 2 of these notes. 2. Wednesday and Thursday, 27th and 28th May: How to typeset Mathematics. This is Section 3 of these notes. 3. Monday, 1st June: How to include tables and figures in LATEX. This is Section 4 of these notes. 4. Tuesday, 2nd June: How to structure your document and include citations. This is Section 5 of these notes. 5. Wednesday, 3rd June: How to create a presentation using Beamer. This is Section 6 of these notes. The LATEX part of Math390 is worth 15% of the entire module. Full details of this assessment for this module can be seen in Table 1. The deadlines for submission of assessments are as follows: 1. Four mathematical questions and answers: Sunday, 31st May at midnight. 2. Full latex document (including corrected maths questions and answers): Sunday, 7th June at midnight. 3. Presentation slides: Friday, 12th June at 10am. The first submission is intended to allow me to give you feedback before you finally submit the work on Thursday. For this submission marks will only be deducted for not submitting work or submitting incomplete work. Once you have had feedback, you will have an opportunity to correct mistakes before submitting the complete document. All work should have both the LATEX code and final PDF submitted under the relevant coursework title on Moodle. 1 Table 1: Table showing the breakdown of marks for this module. Assessment Available marks A Latex document containing: Four mathematical questions and answers One table 18 2 One figure included from outside of LAT EX Two figures created using the Tikz package 2 Two citations using Bibtex 4 A coherent final document with correct structure 4 A short set of presentation slides created using Beamer Total 4 6 40 Up to 4 bonus marks (with a maximum total of 40) for innovation. 1.3 How to Use These Notes On moodle there is a pdf titled Useful Symbols. This pdf is an adaptation of a document provided by David Carlise from the University of Manchester. It contains all the mathematical symbols you will need in this course and a whole lot more! Alongside each symbol is the corresponding LATEX command needed to produce that symbol. It will be very helpful to have. Surprisingly although this list contains the most commonly used symbols (and everything you will need) it is by no means comprehensive. For a full list of all the symbols available you can look at the aptly named Comprehensive LATEX Symbol List (http://www.tex.ac.uk/ctan/info/symbols/comprehensive/symbols-a4.pdf). Along with the Useful Symbols file these notes are self-contained. That is all the information you require to complete the course to the highest standard is contained within these notes and the Useful Symbols pdf. Nevertheless for extra reading I recommend the following references. • The Not So Short Introduction to LATEX 2ε - Tobias Oetiker - Version 5.04, 2014 [2]. • More Math into LATEX - George Grätzer - 4th Edition - 2007 [1]. • The LATEX wikibook (http://en.wikibooks.org/wiki/LaTeX). The first two references are available on moodle. The third reference is available online. Throughout these notes I will try to give useful examples of LATEX code along with the resulting output. Any LATEX code will be in typewriter font and will be enclosed in a box therefore distinguishing it from normal text. For example I will write $\lambda$ to signify LATEX code whose corresponding output is λ. Any code that is in triangular brackets, such as <this> will be optional code that the user has to specify. For example, \textbf{<text>} refers to the \textbf command which makes the font of any section of text, represented by <text>, boldface. 2 1.4 Installation Please familiarise yourself with the installation tutorial which is available on moodle. I have uploaded an installation guide for a Windows operating system only. Unfortunately I do not have access to a Mac operating system and therefore can not test, and hence give reliable instructions on, installing the necessary software on a Mac. If you do own a Mac then I suggest following these instructions: http://www.howtotex.com/howto/installing-latex-on-macos-x/. If you use a Linux operating system then I will presume you are tech savvy enough to install LATEX and all other necessary components yourself. You should be able to find instructions online for any Linux distribution you have. You can install LATEX and use it within various text editors in several ways. Since most of you will be new to LATEX here is what I recommend if you want to install a full LATEX system on your own laptops: • Windows Users: Download and install MiKTeX which comes with its own text editor called TeXworks. I recommend using this text editor (at least initially). By all means use a more sophisticated text editor if you wish. However you will have to set up any such editor by yourself. • Linux Users: Most Linux distributions come with a TeX system. Some (for example Ubuntu 12.04) come with an out-of-date TeX system. Once you have a TeX system then you can install a text editor. Most commonly used text editors in Linux have support for LATEX. This includes gedit, emacs, vim, sublime etc. For a LATEX specific text editor I recommend Kile. 2 2.1 Introduction to LATEX What is LATEX? LATEX is a word-processor which produces very high quality type-set printing. It is primarily used by anyone who intends to publish work that contains complicated mathematical formulas. It is designed to cope with the special problems of mathematics, such as its layout and its use of symbols. The large majority (if not all) publishers within a mathematical field will ensure that their authors write in LATEX. Moreover all your lecture notes from mathematics will have been typeset using LATEX. It is therefore an essential skill for anyone wishing to go into academia (or industry research) within the field. Furthermore it will be necessary for anyone undertaking a project in the upcoming year to write that project using LATEX. Compared to the more conventional word-processors (such as Microsoft Word), LATEX may seem quite difficult to use at first. This is natural. There is a learning curve to using any new software and LATEX is no different. Hopefully, however, by the end of this course you should be more comfortable with using LATEX and should be able to manage the basics. I will (almost certainly) use the term “LATEX” wrong throughout these notes. This is partly due to convenience. Essentially “LATEX” allows your computer to compile tex documents, in which you have typed “LATEX” commands. This is similar to programming languages like C and Fortran. 3 2.2 Learning LATEX Part of the problem with learning LATEX initially is that unlike conventional word-processors you can not just type and go. There is a bit of overhead in the beginning when first creating a LATEX document. Moreover most text editors for LATEX are not WYSIWYG (what you see is what you get). Typically you will write source code in a text editor and then you will compile the code which will produce an output of the document. This is in stark contrast to something like Microsoft Word and as such can be fairly daunting in the beginning. When you first use LATEX start by writing a basic document (see Section 2.3) and try to compile the document (this is to check everything is working correctly on your computer). Once you have a basic document up and running call this document template. This will be your template file. If you learn something new about LATEX then from now on you should add that bit of knowledge (i.e. the code) to the template file along with a brief description of what that new code does and check that the file compiles. This way you do not have to remember every bit of knowledge you have accumulated and instead can refer to your template file. You can type % to comment out text in your LATEX document that you do not want to compile. This is useful if you want to write notes explaining what a piece of code does. For example typing $\lambda$ % This command produces a greek lambda. will only produce λ (i.e. the section of text after the percentage sign is suppressed). Whenever you write a new block of mathematics (i.e. not normal text) within LATEX it is advisable to compile the document and check the output. The purpose of this is twofold. Firstly it enables you to check if your document (and the new block of mathematics) looks like what you had envisaged/tried to create. Secondly it alerts you to any errors and/or warnings. If you get a stream of errors start by correcting the error at the top of the list. It is typically the case that the errors lower down are more cryptic because they are caused by the error at the top of the list (which causes a knock on effect). Fix this error and then re-build and see if the other errors still appear. Warnings can often be ignored when writing a document. However once you have finished writing the document and you still get warnings then they usually should be addressed as they can mean that you have referenced something that does not exist or have an equation that goes off the page. If you are unsure about how to do something in LATEX then the references in Section 1.3 can be useful. If you are looking for a particular command for a symbol then you can consult the Useful Symbols document. Alternatively you can use detexify (http://detexify.kirelabs.org/classify.html) which is a LATEX handwritten symbol recognition (you simply draw the symbol you want on the screen and, hopefully, it will tell you the corresponding LATEX code needed to produce that symbol). If at all you can not find the command you are looking for or are struggling with doing something in particular then do not be afraid to search google for help. Any conceivable problem you have someone else has had before you and there is a good chance they sought help online. 2.3 Structure of a LATEX Document The basic structure of any LATEX document is as follows. 4 \documentclass{<class>} % Preamble. This is where all the information relating to the document goes. \begin{document} % Body. This is where all the text that you want to appear in your document goes. \end{document} The command \documentclass{<class>} is at the start of all LATEX documents and tells LATEX the type of document you are writing, such as a book, an article, a flyer etc. We will begin with the article class, which is a general purpose document. Later, in Section 6, we will introduce the beamer class which is used for creating presentation slides. These classes are primarily the ones you will need. The Preamble is where the overall construction of your document takes place. Anything related to the entire document goes in the preamble. The preamble can contain the following useful commands. • \usepackage{<package>} . This command includes the package with name <package>. A package is a set of commands and environments that extend the functionality of LATEX. The three packages that are extremely useful to have are amsmath, amssymb and hyperref. The amsmath package “provides various features to facilitate writing math formulas and to improve the typographical quality of their output” [3]. The amssymb package provides access to a wider range of mathematical symbols. The hyperref package automatically turns all of your references into hyperlinks, which is particularly useful in large documents. • \newcommand{<name>}{<function>} . This command allows you to define new commands with the name <name>. The command then does whatever is defined by <function>. • \newtheorem{<name>}{<output>}[<numberby>] . This command allows you to define a new “theorem”. This is not a theorem in the mathematical sense. Instead a theorem in the LATEX sense is any kind of labelled portion of text that we feel is important and that we want to look separated from the rest of the text. Typically such portions have sequential numbers attached to them. This includes mathematical theorems, lemmas, corollaries, examples etc. The theorem is referenced using <name>. That is once defined you can call it by typing \begin{<name>} % Important information here. \end{<name>} Whenever you use the theorem LATEX will print the text specified by <output> along with a number next to it. The number is typically defined in relation to the Section or Subsection the theorem is placed in (depending on whether <numberby> was section or subsection). That is if section is chosen and the theorem is the third theorem in Section 4 then the number will be 4.3. Often you will want common theorems to share a counter (a counter records the number of theorems currently in the section or subsection). To do this you can use the following command: \newtheorem{<name>}[<counter>]{<output>} where <counter> is the name of a previously defined theorem that you want this type of theorem to share a counter with. 5 • \input{<file>} . This command essentially copies all of the text from another tex file and places it where this command is placed. Hence you can write all of your preamble in a separate tex file and include this tex file in the current file with this one command. This is in order to avoid cluttering your text file. Typing \begin{document} tells LATEX that your document is starting now. Anything written after this command and before \end{document} will be included in your document (unless commented out using % of course) and will correspond to something you see in the compiled pdf. Here is an example of a LATEX document. Example 2.3.1 Type in this code and compile to see the resulting pdf. \documentclass{article} \usepackage{amsmath, hyperref, amssymb} \newtheorem{theorem}{Theorem}[section] \newcommand{\ZZ}{\mathbb{Z}} \begin{document} \section{Integer Theorem} \begin{theorem} The integers, denoted by $\ZZ$ form a countable set. \end{theorem} \end{document} Here we have done two things. Firstly we have defined a new theorem (in the LATEX sense) which is called using \begin{theorem} and corresponds to a Theorem in the mathematical sense. When called LATEX writes Theorem in the compiled document with a number next to it which corresponds to the Section. Secondly we have defined a new command, given by \ZZ, for the set of integers, which is normally written in LATEX using \mathbb{Z} . This is in order to save us from typing \mathbb{Z} each time we want to talk about the set of integers. Typically you will not create all of the preamble from scratch. Instead you will use a template and make the necessary adjustments. Often templates are obtained either online, from a supervisor or a mix of the two along with adjustments you have made in the past (personal preferences). As such I have uploaded to moodle a template file called header. This template includes the majority of the preamble you will need. Download this file to the folder where you will write your LATEX documents. Then you can include it in your preamble by typing the command \input{header.tex} . Look through it and make sure you understand how the commands \usepackage , \newcommand and \newtheorem work. 2.4 Commands, Environments, Special Characters and Quotation Marks Commands: In LATEX terminology, a command is a short piece of text beginning with a backslash \ and ending in either a space or a pair of braces {} depending on whether or not the command needs 6 an argument (if the command needs an arguement then that arguement will go inside the braces). Commands are used both in text and equations, to produce effects and special characters. For example, typing \textbf{bold face} produces bold face, whilst typing \tableofcontents tells LATEX to produce a table of contents with the necessary sections, subsections and headings. This is how the table of contents in these notes was produced. Environments: An environment is a section of the document to which different formatting rules are applied. These usually begin with \begin{<environment>} and end with \end{<environment>} where <environment> tells LATEX what type of environment you want. For example, a centred piece of text is obtained by wrapping the text in \begin{center}...\end{center} . Custom Commands and Environments: As we have seen previously you can define your own commands and environments using the commands \newcommand and \newenvironment in the preamble. Take a look at the header.tex file on moodle to see some of the commands and environments you can create. Special Characters: In addition to commands beginning with a backslash, there are a few special characters that serve special purposes, and so will not display as expected if required in text. For example a backslash, \ , and curly brackets, {}, cannot be used directly. Other characters that serve a special purpose within LATEX include &%~^_ and #. Most of these can be inputted by prefixing the symbol with backslash (e.g. \#). Unfortunately a double backslash also carries a special meaning in LATEX (see Alignment below) and therefore to get a backslash in normal text you need to type \textbackslash . Code Commenting: As mentioned previously the percent symbol % tells LATEX to ignore the rest of the line. The sole purpose of this is so that you can add comments to your LATEX code reminding you what that particular bit of code does. Most text editors have their own special commands that allow you to comment out many lines or sections in one go. Alignment: A double backslash \\ is used to start a new line. It is not normally needed in text mode where line-breaks are automatic. However it is useful when trying to produce tables, arrays, or equations across several lines. An ampersand & is used for alignment. Again it is very useful when trying to produce tables, arrays, or equations across several lines where it acts as a place mark telling LATEX where to align the columns. To start a new paragraph in LATEX simply type \par. Quotation Marks: Unfortunately, quotation marks in LATEX do not automatically adjust at either end of a word. At the beginning of a word you must use either one or two backticks `. At the end of a word you must use the apostrophe either once or twice ´. LATEX does not interpret the double quotation mark correctly and so do not use it. 7 3 Writing Mathematics in LATEX 3.1 Math Environments Math Environments are the sections of a document where you will write your mathematical expressions. These environments will produce text in a different format to that of the normal environment. The main purpose of this is to differentiate between a text “x” and a mathematical variable “x”. These environments will also be the place where you type in commands that will be interpreted and converted into mathematical expressions. This differentiates commands for an expression, e.g. \cap , and the actual expression; ∩. In LATEX, never write maths outside a math environment even though this is may be possible for simple expressions. If you are referring to a variable x then make sure that variable is inside a math environment. This ensures consistency and allows a reader to easily distinguish the “maths” from the normal text. There are many math environments, but the ones that are used most often are the following: • $...$ for inline equations (i.e. equations within normal text). • \[...\] for unnumbered display equations on a new line (short command). • \begin{equation}...\end{equation} • \begin{equation*}...\end{equation*} for numbered display equations on a new line. for unnumbered display equations on a new line (long com- mand). • \begin{align}...\end{align} • \begin{align*}...\end{align*} for numbered display equations aligned across several lines. the unnumbered version of align. Note: Most math environments have a starred equivalent which corresponds to the unnumbered version of that particular environment. Occasionally you will want to number some lines of a display environment but not all of them. For instance, if you derive an expression over several lines you will typically only want to label (and thus have a number associated with) the last line which is typically the most important. In such a scenario you can use the unstarred version of the environment and suppress the number on any line by typing \nonumber at the end of that line. Here are a few examples of using math environments. Example 3.1.1 I can type $\mathbb{N}$ to respresent the set of natural numbers, N, inline. I can also type $\mathcal{F}$ to represent some set, F, inline. “bb” denotes blackboard bold font (typically used for special sets of numbers such as R, Q, Z etc.) and “cal” denotes calligraphic font (typically used for special sets in general such as a σ-algebra, F, the power set of a set X, P(X), the class of all ordinals, O etc.). Example 3.1.2 If I type \[\sum_{i=1}^n w_i\] then this displays the summation n X i=1 8 wi on a new line. This is exactly the same as typing the following: \begin{equation*}\sum_{i=1}^n w_i\end{equation*} Example 3.1.3 If I type \begin{align*} x + 3y & = 12 \\ 2x + 3y & = 15 \end{align*} then this displays the following aligned equations x + 3y = 12 2x + 3y = 15 across several lines. Note that the ampersand is placed where I want the alignment to be and the double backslash indicates a new line. 3.2 Subscripts and Superscripts Producing subscripts and superscripts is very easy in LATEX. An underscore, _, indicates a subscript and a caret, ^ indicates a superscript. For example, $x_i$ produces xi whilst $\chi^2$ produces χ2 . These can be used together: \chi^2_1 produces χ21 . If your superscript or subscript is longer than one character in length then you have to enclose the superscript/subscript with curly brackets, {} so that LATEX knows where the beginning and end of your superscript/subscript is. For instance, notice how x^{20} gives x20 whereas x^20 gives the nonsensical x2 0. Superscripts and subscripts are commonly used in conjunction with mathematical operators over sets (often this type of notation is for convenience). In such a setting the superscript and subscript describe the set over which the operator is to be applied. The subscripts and superscripts are added in exactly the same way as above by immediately preceding the operator with an underscore or caret. The following examples illustrate this. Example 3.2.1 Typing \[\sum_{i=1}^n w_i\] displays n X wi i=1 which is shorthand for w1 + w2 + . . . + wn . Similarly we can type \[\prod_{i=1}^n w_i\] to display n Y wi i=1 which is shorthand for w1 × w2 × . . . × wn . The command for the multiplication sign is \times . Example 3.2.2 9 Typing \[\int_0^{\infty}e^{-x^2}\;\mathrm{d}x\] ∞ Z displays 2 e−x dx 0 The “rm” in \mathrm denotes Times New Roman. Note that this changes the font of the letter d to Times New Roman. This is to distinguish the letter d from a variable and therefore to distinguish the symbol dx (which has a particular meaning) from the multiplication d × x = dx. The \; command tells the interpreter to add a little space after the integrand (the thing we are integrating). This is for stylistic purposes only. Adding it in makes it easier for the eye to seperate the integrand from the variable of integration. You can read more on spacing in Section 3.6. Example 3.2.3 Typing \[\lim_{n\rightarrow\infty} a_n \quad , \quad \sup_{x\in A} |f(x)|\] displays lim an n→∞ , sup |f (x)| x∈A Note here how I have used \quad to add space. Again to see more ways of adding (and removing) space see Section 3.6. You should avoid using mathematical operators with subscripts and superscripts inline. This is because things n X Pn like i=1 wi or even wi look messy or out of place. If you have to talk about a simple summation inline (for i=1 example) then it is better to write w1 + w2 + . . . + wn . A limit on the other hand can be written colloquially. That is we can talk about the limit of an as n → ∞. 3.3 Arrays In LATEX an array is a table of information. An array is very flexible. It is the perfect choice whenever you have a collection of elements that you want aligned in a specific way over several lines. They are typically used to create matrices, and functions that are defined piecewise. However they can be used more generally to create tables and aligned equations. Arrays can be created by typing \begin{array}{}...\end{array} . When you create an array you need to specify the number of columns and how they are aligned in the curly brackets {} after \begin{array} . To do this you decide how to align each of the columns (from left to right). You can align columns to the left (with l), to the right (with r) and in the centre (with c). The number of letters within the bracket indicates how many columns the array has. For instance, \begin{array}{crl}...\end{array} creates an array with three columns. The first is centre aligned, the second is right aligned and the third is left aligned. On the other hand \begin{array}{ccccc}...\end{array} creates an array with five columns where every column is centre aligned. It can be cumbersome to type as many c’s as you want centre aligned columns and so you can specify the number by typing *{n}c where n is the number of columns you want to be centre aligned. Hence 10 \begin{array}{*{5}c}...\end{array} produces an array with the same structure as \begin{array}{ccccc}...\end{array} . Any information within an array is aligned column-wise using an ampersand. It is helpful to think of the ampersand as forming the line that would seperate your columns (if it were visible). That is, it helps to look at a & b a & b a & b a & b and see a b a b a b a b even though the line will not appear in the compiled document. To begin a new row (a new line) of an array you have to type a double backslash at the end of the row you want to end. This tells LATEX that anything after that double backslash is on a new row of the array. Sometimes you will want horizontal lines to separate rows of an array and vertical lines to separate the columns. This is common when writing matrices in block form (i.e. writing a matrix in terms of smaller submatrices). To draw a horizontal line which spans a whole row and above a particular row you can type \hline at the beginning of that row. To draw a horiztonal line which only spans some of the columns you can type \cline{<start-end>} where <start-end> defines which column you want the line to start at and which column you want the line to end at. For example \cline{<2-4>} draws a horizontal line that spans columns 2 to 4. To draw a vertical line to separate the columns you need to add a vertical line in those curly brackets where you defined the columns and their alignment. For instance \begin{array}{c|c|c}...\end{array} all of which are centre aligned and separated by vertical lines. Here are a few examples of using arrays in different contexts. Example 3.3.1 I can create the 3 × 3 identity matrix by typing \[ \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array} \right) \] 11 creates an array with three columns, which gives 1 0 0 0 0 1 0 1 0 Here I have used \left before the opening bracket and \right before the closing bracket. This forces the bracket to be of the correct height (i.e. high enough to encompass the formula within). You can read more about this in Section 3.5. Since matrices are so common there are pre-defined matrix environments such as \begin{matrix}...\end{matrix} . Such environments work in a similar way to the array environment and so will not be expanded upon here. You can see the mathematics section of the LATEX wikibook (http://en.wikibooks.org/wiki/LaTeX/Mathematics) for more information. Example 3.3.2 I can create a block diagonal matrix by typing \[\left( \begin{array}{c|c} A & 0 \\ \hline 0 & B \end{array} \right)\] which produces A 0 0 B Example 3.3.3 For any set, A, I can create the indicator function corresponding to that set by typing \[ 1_A(x) = \left\{ \begin{array}{rl} 1 & \text{if} x \in A \\ 0 & \text{if} x \nin A \end{array} \right. \] 12 which gives 1 1A (x) = 0 if x ∈ A if x ∈ /A You always have to have a closing \right accompanying an opening \left . Therefore if you do not want a closing bracket (as in this example) you can use a full stop to act as an invisible closing bracket. Example 3.3.4 If I want to have multiple alignments within one environment I can do this using the array environment as follows. \[ \begin{array}{rclcrcl} f(x) & = & \sqrt{x^2-9} & \text{for} & |x| & \geq & 3\\ g(x) & = & 1/(x-1) & \text{for} & x & \neq & 1 \end{array} \] which produces Instead you could use the f (x) = g(x) = √ x2 − 9 1/(x − 1) for |x| ≥ 3 for 6= x \begin{alignat}...\end{alignat} 1 environment. See the mathematics sec- tion of the LATEX wikibook (http://en.wikibooks.org/wiki/LaTeX/Mathematics) for more details. 3.4 Equation Referencing To make a document easier to follow we can reference equations that have a label attached to them. Any line of the numbered (those without a star) math environments discussed in Section 3.1 can have labels attached to them. To do this we simply add \label{<labelname>} to that line. By default numbered environments place a number on every line. This may not be what we want. As discussed in Section 3.1 we can supress the number on any given line by typing \nonumber at the end of that line. Lines without numbers cannot be referenced. To refer to an equation labelled <labelname> within the text we can type \eqref{<labelname>} . The “eq” tells LATEX that this reference is referencing an equation and thus LATEX places the reference number in a bracket. Note: You can reference more than just equations in LATEX. As such it is advised (particularly in long documents) to have label names that are unambiguous. For example the one in \label{one} is not a good label name. Not only do you not know what type of environment the label is referring to (an equation, a section, a table etc.) but you also do not know what the term one stands for. On the other hand \label{eq:CauchySchwartz} is a good label name. The “eq” notifies you that this is a label for an equation and the “CauchySchwartz” informs you that it corresponds to the Cauchy-Schwartz inequality. To automatically turn all your references into hyperlinks as in this document (so that you can click on them and be taken to the corresponding place in the document) you can add the package \usepackage{hyperref} to the preamble. 13 Here are a few examples demonstrating the use of labelling and referencing. Example 3.4.1 I can label two simultaneous equations by typing \begin{align} \label{eq:SimulOne} x + 3y & = 12 \\ \label{eq:SimulTwo} 2x + 3y & = 15 \end{align} which displays. x + 3y = 12 (1) 2x + 3y = 15 (2) Then I can reference the first by typing \eqref{eq:SimulOne} and the second by typing \eqref{eq:SimulTwo} . So I can write things like by subtracting (1) from (2) I get that x = 3. Example 3.4.2 Somtimes you will only want to reference one line (typically the last) of a math environment. For example \begin{align} x^2-2xy + y^2 & = (x-y)^2 \nonumber \\ \label{eq:Ineq} & \geq 0 \end{align} produces x2 − 2xy + y 2 = (x − y)2 ≥0 (3) from which I can refer to inequality (3). Recall that the \nonumber command tells LATEX to suppress the number on the first line. 3.5 Delimiters (Brackets) Delimiters in LATEX are essentially brackets. They come in various forms such as parentheses, square brackets, curly brackets and vertical lines. Most delimiters in math environments can be created by using the corresponding key on your keyboard. For example $()$ gives you round brackets, (), $[]$ gives you square brackets, [], $||$ gives you straight lined brackets, ||, and so on. Some delimiters do not have a corresponding key. A typical example are the brackets used for a norm. For such delimiters there will be a special command. For instance a bracket used for a norm can be gotten by typing $\|\|$ which results in kk. 14 Curly brackets, {} have a special meaning in LATEX (typically to encompass arguments you want to pass to a LATEX command). As such if you want to use them as brackets in a math environment (for instance if you want enclose the elements of a set) then you have to put a backslash in front of each curly bracket. For instance $\mathbb{N} = \{0, 1, 2, \ldots\}$ produces N = {0, 1, 2, . . .}. Often you will want Delimiters to be of a larger size than the default. Typing \left before the opening delimiter and \right before the closing delimiter tells LATEX to automatically resize the delimiters so that they are large enough to enclose the formula in between them. Although this is often sufficient sometimes you will want finer control over the size of delimiters (for asthetic purposes). You can manually control the size of a delimiter by typing (for increasing size) \big , \Big , \bigg , or \Bigg before the delimiter. Below are a couple of examples showing you how to use delimiters. Example 3.5.1 If I want to define the open ball (with respect to some set Ω and some norm) of radius r and centre a I can type \[B(a, r):= \{x\in\Omega:\|x-a\|<r\}\] which displays B(a, r) := {x ∈ Ω : kx − ak < r} Example 3.5.2 I can define the Lp norm of a function f : R → R as \[\|f\|_p := \left(\int_{\mathbb{R}} |f|^p\;\mathrm{d}x\right)^{1/p}\] which gives Z kf kp := p 1/p |f | dx R Example 3.5.3 Note how the delimiters look too big if I write \[\left(\sum\limits_{x\in S} f(x)^2\right)^{1/2}\] which produces !1/2 X f (x)2 x∈S Instead I can manually control the size of the delimiter by writing \[\bigg(\sum\limits_{x\in S} f(x)^2\bigg)^{1/2}\] which produces X x∈S 15 f (x) 2 1/2 3.6 Miscellaneous Inside math environments adding whitespace (with the spacebar or with tab) does nothing. This is because LATEX determines space automatically. If you want to add or remove white space you have to use special commands. To add space you can use \, \: \; \quad \qquad for increasingly large amounts of space. Alternatively you can use the more general \hspace{<length>} to add horizontal space equivalent to that specified by <length>. This command can also be used outside of a math environment and in normal text. For an explanation of the different units of length LATEX recognises see Section 5.2.1. To remove small amounts of space you can use \!. However if you want to remove large amounts of white space use \hspace{<length>} where <length> is a negative value. Here are a few examples showing how to add and remove white space. Example 3.6.1 If I want to seperate two formulas on a single line with a comma but have an extra space before and after the comma I can write \[a^2+b^2 = c^2\quad,\quad e^{i\pi} + 1 = 0\] which produces a2 + b2 = c2 , eiπ + 1 = 0 Example 3.6.2 Notice how there is too much whitespace after the summation sign if I type \[\sum_{x\in\{2, 3, 5, \ldots, 19\}} 1/x\] which produces X 1/x x∈{2,3,5,...,19} This can be remedied by removing the white space. I can type, for example, \[\sum_{x\in\{2, 3, 5, \ldots, 19\}}\hspace{-1.5em}1/x\] which produces X 1/x x∈{2,3,5,...,19} Recall that normal text is interpreted differently inside a math environment. Therefore if you want to put normal text inside such an environment you have to type \text{<text>} inside the environment. For example typing \[x/y < 1\quad\text{hence}\quad x < y\] results in x/y < 1 hence 16 x<y If you want to display a fraction you can type $\frac{}{}$ . The numerator goes inside the first set of braces and the denominator in the second. For example I can rewrite the last example by typing \[\frac{x}{y} < 1\quad\text{hence}\quad x < y\] which produces x <1 y 3.7 hence x < y A Note on Punctuation Standard punctuation rules apply to typed mathematics. To separate the “maths” from the punctuation I recommend adding extra space using \; before the punctuation. For example I can type \[ x^2 - 2xy + y^2 \geq 0\;,\] to produce the inequality x2 − 2xy + y 2 ≥ 0 , from which I can deduce that x2 + y 2 ≥ 2xy . 17 4 4.1 Producing Tables and Figures Floating Environments Tables and figures are usually included in documents inside floating environments. As their name suggests, these environments are allowed to “float” to optimise the layout of the document. This means that the exact placement of the table or figure is decided by LATEX when it builds the document, and cannot be fixed precisely by the user. However floating environments do allow you to input options that allow some control over where the float is placed. The two main floating environments are figure and table. They are called much the same way as other environments are, that is by typing \begin{figure}[<options>] or \begin{table}[<options>] . You place your options (in terms of characters) in the square brackets. The main options are here, at the top of the page, at the bottom of the page, or in a dedicated page of floats. For example typing \begin{table}[htbp] will place a table here, at the top of the page, at the bottom of the page, or in a dedicated page of floats depending on what LATEX decides is best. To override what LATEX thinks is the best position of the float you can use an exclamation mark. For example typing \begin{figure}[h!] will put a figure at the same point in the document as the code, if at all possible. As with all manual over-rides, it is best to leave this until the document is finished and you are at the “tweaking” stage. This is because your document will continue to change length as you make adjustments. 4.2 Captions Captions can be placed in both the figure and table environments. You should always add a caption to tables and figures, even if the depiction is clear. This is because a caption also doubles up as a label allowing you to refer to the table or figure in the main text. To add a caption, insert \caption{<caption_text>} inside the environment. It is convential that the caption appears above a table so insert the caption command before the tabular environment. On the other hand the caption usually appears below a figure, so insert the caption command after the \includegraphics{} command. Captions should include enough detail to allow a reader to understand what the table/figure is showing without referring to the main body of text. This is because the part of the main body of text referring to the table/figure may be quite a distance from the table/figure itself. 4.3 Table/Figure Referencing You can reference tables and figures in exactly the same way as you referenced equations in Section 3.4. The only difference is that you need a caption associated with the float to add a label to it. Provided this is the case then you can add a label in exactly the same way as before by typing \label{<name>} . Then you can refer to the table/figure in the main body of text by typing \ref{<name>} . Note that we do not need the “eq” unlike when we were referencing equations. This is because it is typical not to have brackets around the reference when the reference corresponds to anything other than an equation. 18 As before it is advised to have label names that are unambiguous. Examples of good label names are fig:CosPlot and tab:AlgorithmResults . 4.4 Tables Tables are produced in a similar way to arrays in math environments (see Section 3.3). The environment that produces tables is called tabular, and this environment is usually (although not always) enclosed in a table environment. The tabular environment produces the table itself, whilst the table environment handles placement on the page and contains captions and labels. This is similar to arrays where we place the array environment inside a math environment. Just like arrays we have to specify the number of columns and how each column is aligned. This is done in exactly the same way as for arrays (see Section 3.3) by including characters in curly brackets after typing \begin{tabular} . As a recap \begin{tabular}{crl}...\end{tabular} creates a table with three columns. The first is centre aligned, the second is right aligned and the third is left aligned. On the other hand \begin{tabular}{*{5}c}...\end{tabular} creates a table with five columns where every column is centre aligned. There is one extra type of column alignment and this is given by p{width} . The p stands for paragraph and the width tells LATEX how wide you want that column to be. Text is wrapped (carries over to the next line) to ensure that the column is no wider than the value given by width. Horizontal and vertical lines are added in exactly the same way as for arrays (see Section 3.3). To recap you can draw horizontal lines by typing \hline (which draws a horizontal line which spans all columns) or \cline{<start-end>} (which draws a horizontal line which spans columns start to end). You can draw vertical lines by typing | between the characters which define your columns and their alignment. You can create cells which span multiple columns by typing the following: \multicolumn{<number>}{<alignment>}{<contents>} . This is useful if you want to create subtitles in your table. <number> tells LATEX how many columns you want this cell to span. <alignment> tells LATEX how you want the cell to be aligned (i.e. c for centre). <contents> is where you put the content of that cell. It can be tedious to manually type all of your information into a table in LATEX, particularly if your table is large. In such a scenario I recommend using LaTable (https://www.ctan.org/pkg/latable?lang=en). This is free software which allows you to load in a csv file that contains your data (which you can create using Excel or R) and automatically creates the code to include that table in LATEX, thus avoiding the need to type in all the data yourself. Here is an example demonstrating some of the commands needed to create a simple table. Example 4.4.1 I can create a simple table of the extreme scores in a maths exam by typing 19 \begin{table}[h!] \centering \caption{This table contains the three highest and three lowest scorers in the 2014 end of year maths exam.} \label{tab:ExamRes} \vspace{1em} \begin{tabular}{llr} \hline \multicolumn{3}{c}{Exam Results} \\ Forename & Surname & Score \\ \hline Aloisio & Roope & 92 \\ Adilet & Modred & 90 \\ Ese & Jef & 87 \\ \vdots & \vdots & \vdots \\ Jaime & Gundhram & 12 \‘{E}lie & Chile Tino & 10 & Iarlaith & 9 \\ \\ \\ \hline \end{tabular} \end{table} which produces the following table. Table 2: This table contains the three highest and three lowest scorers in the 2014 end of year maths exam. Exam Results Forename Surname Score Aloisio Roope 92 Adilet Modred 90 Ese .. . Jef .. . 87 .. . Jaime Gundhram 12 Èlie Chile 10 Tino Iarlaith 9 I can then reference the table by typing \ref{tab:ExamRes} . For example, Table 2 shows the extreme results of the 2014 end of year maths exam. All names were generated using a random name generator. If, by chance, your name is listed please contact me and I’ll generate a new one! Note that I’ve had to add a little vertical space after the caption using \vspace{1em} . This is the vertical equivalent to the hspace command introduced in Section 3.6 and can take negative values (if you want to 20 remove excess white space). The different units of length that LATEX can understand are explained briefly in Section 5.2.1. 4.5 Including Figures You may want to include an external picture in your document. To do this you must first have \usepackage{graphicx} included in your preamble. Then you can type \includegraphics{<filepath>} in your figure floating environment. <filepath> tells LATEX where your file is and is relative to the folder that the tex file is in. That means if your picture is in the same folder as the tex file then you can just type the filename (i.e. you can type \includegraphics{mypicture.png} ). However to avoid clutter I recommend saving all your pictures in a folder called Pictures which is contained in the same folder as the tex file you are working on. Then you can type \includegraphics{Pictures/mypicture.png} (that is the png file called mypicture in the Pictures folder in the same folder that your tex file is in). Note how it was necessary to include the file extension (in this case png). The picture file must be of an acceptable format. If you are producing a pdf file (which is the case in this course) then the acceptable file formats are .png, .jpg, .pdf or .eps. You may wish to adjust the size of your picture. This is done by typing the following: \includegraphics[width=0.5\textwidth]{mypicture.png} . This tells LATEX to make the width of the picture half that of the text width (the maximum width of a line of text). You can include different size options in the square brackets, but this will not be necessary in this course. Check out the LATEX wikibook (http://en.wikibooks.org/wiki/LaTeX/Importing Graphics#Including graphics) to see the different sizing options. Here is an example of how to include a simple picture of the Mandelbrot set obtained from wikipedia: http://en.wikipedia.org/wiki/Mandelbrot set. Example 4.5.1 I can include a picture called mandelbrot.jpg by typing \begin{figure}[h!] \centering \includegraphics[width=0.5\textwidth]{Pictures/mandelbrot.jpg} \caption{This is a picture of the Mandelbrot set.} \label{fig:mandel} \end{figure} which produces Figure 1. 21 Figure 1: This is a picture of the Mandelbrot set. 4.6 Tikz The Tikz package provides a powerful set of commands and environments for producing high-quality diagrams, figures and plots in LATEX. The functionality of Tikz is too extensive to do the package justice. In this subsection we will give a brief overview of the Tikz package and its capabilities. We will concentrate on plotting curves, but Tikz can produce a variety of diagrams, including: Directed Acyclic Graphs (DAGs); Flowcharts; Hasse diagrams; and many others. For more details see here: http://www.texample.net/tikz/examples/. To include Tikz figures in your document you have to add \usepackage{tikz} to your preamble. Then, preferably inside a figure floating environment, you can initiate a Tikz picture by typing the following: \begin{tikzpicture}[xscale = a, yscale = b, domain = c:d] and you can end the tikz picture by typing \end{tikzpicture} . The xscale number (in this case a) tells LATEX how to scale the x-axis and similarly the yscale number (in this case b) tells LATEX how to scale the y-axis. domain (in this case from a to b) tells Tikz the range of the plotting variable \x. You can include plotting commands within the tikzpicture environment. All Tikz commands must end in a semi-colon. The main command we will be interested in is the \draw command. In particular typing \draw[<->] (a, b) -- (c, d) draws a line betwen the coordinates (a, b) and (c, d) with an arrow at both ends. This is useful, for example, to draw axes. To draw a smooth line (for example a function) we can type \draw[color = blue, smooth] which tells Tikz that you want to draw a smooth, blue line. Now to tell Tikz what you want to plot you can (after the \draw command but before the semi-colon) type \plot(\x, f(\x)) . This tells Tikz that you want to plot the function f(x) against the plotting variable \x over the domain you specified when initiating the tikzpicture environment. You might want to add a label to your graph (not a LATEX label referencing the figure but a Tikz label on the figure). You can do this by typing \node[<location>]{<label>} after the plotting command but before the semi-colon. The <location> argument tells Tikz where you want the label to go. The basic location arguments 22 are: above which places the label above the line that was plotted, below which places the label below the line that was plotted, right which places the label to the right of the line that was plotted and left which places the label to the left of the line that was plotted. <label> tells Tikz what you want to include within the label. Here is a basic example showing you how to use Tikz to produce a plot of the cosine function from −2π to 2π. Example 4.6.1 I can create a plot of the cosine function from −2π to 2π by typing \begin{figure}[h!] \centering \begin{tikzpicture}[xscale=0.5, yscale=1, domain=-2*pi:2*pi] \draw[<->] (-2*pi, 0) -- (2*pi, 0) node[above]{$x$}; \draw[<->] (0, -2) -- (0, 2) node[right]{$y$}; \draw[color=blue, smooth] plot(\x, {cos(\x r)}) node[above]{$f(x) = \cos(x)$}; \end{tikzpicture} \caption{This is a plot of the function $f(x) = \cos(x)$ between $-2\pi$ and $2\pi$.} \label{fig:CosPlot} \end{figure} which produces y f (x) = cos(x) x Figure 2: This is a plot of the function f (x) = cos(x) between −2π and 2π. Note: The r inside the function definition is needed to tell Tikz that the plotting variable is in radians and not degrees! 23 5 5.1 Structure and Citations Structuring a Document A typical LATEX document (like this one) is split up into partitions. The partitions available depend on the documentclass. Within the article documentclass there are sections, subsections and subsubsections. The report documentclass also offers chapters. Each one of these partitions starts with a heading and the size of the heading depends on the type of partition. You can add a new partition titled <partition_name> by typing \section{<partition_name>} , or \chapter{<partition_name>} \subsection{<partition_name>} , \subsubsection{<partition_name>} , depending on the type of partition you want. Any partition can be referenced. To do this you must add a label just like you did to reference math environments and floating environments by typing \label{<label_name>} . Then you can reference that label by typing \ref{<label_name>} as you have done before. Like previously it is advisable to make your label names unambiguous. The main title of your document is automatically formatted by LATEX. First you must define the elements of your title in the preamble. Then you can create the title by typing \maketitle in the body of the document in the place where you want the title to go. You define the content of the title (what the title says) by typing \title{<title_name>} in the preamble. You define the author of the document by typing \author{<author_name>} in the preamble. You define the date of the document by typing \date{<date>} in the preamble. If you do not want the date to be shown then you can leave <date> to be empty (that is \date{} ) whereas if you want the date to be today’s date (the date the document is compiled on) then you can use the command \today (that is \date{\today} ). The following example shows how I created the title for this document. Example 5.1.1 The title for this document was created by typing \title{Math 390: \LaTeX} \author{Sean Malory\\ Fylde B41\\ \href{mailto:s.malory@lancaster.ac.uk}{s.malory@lancaster.ac.uk} } \date{} \begin{document} \maketitle ... \end{document} LATEX also automatically formats the table of contents. To include a table of contents you only have to type \tableofcontents in the main body of the document where you want the table of contents to go. You can begin a new page by typing \newpage or \pagebreak . The newpage command finishes the page without 24 adjusting it and starts a new one. On the other hand the pagebreak command finishes the page, will spread out the paragraphs on that page so there is not a large white space at the bottom and then starts a new page. Typically, however, one starts a new page at the end of sections/chapters by typing \clearpage . This acts like the newpage command but also clears any floats. That is it places the floats before it starts a new page so that floats remain in the section they were created in. To include a footnote in your document you can type \footnote{<content>} in your document exactly where you want the marker for the footnote to be. The marker for the footnote is a number (depending on how many footnotes you have on that page) in a superscript format. <content> is what you want to include in the footnote. LATEX will then automatically create the footnote at the bottom of the page. Moreover if you have the hyperref package (which you should all have if you are using the header.tex file from moodle) then your footnote marker will also be a link to the footnote. For example if I type Euler\footnote{Leonhard Euler (1707-1783)} 1 then this produces the following: Euler along with the footnote at the bottom of the page. Adding an appendix to your document is simple. First you tell LATEX that you want to start your appendix by typing \appendix . Then, after this command, you can add sections as normal and LATEX will automatically interpret them as appendices and will change their numbering to capital letters. Adding bullet points to your document is achieved by using a list environment. The two main types of list environment are itemize and enumerate and are created by typing \begin{itemize} and \begin{enumerate} respectively. The former is for dotted bullet points while the latter is for numbered bullet points. Inside your list environment you add bullet points by typing \item followed by what you want to go next to the bullet point. You can get nested bullet points just by nesting list environments. This is useful, for example, if you have a question which has smaller questions within it. The following example shows how to create numbered bullet points. Example 5.1.2 I can create a simple list of questions by typing \begin{enumerate} \item Let $f(x) = x$. Show the following: \begin{enumerate} \item $f(x)$ is continuous on $\mathbb{R}$. \item $f(x)$ is differentiable on $\mathbb{R}$. \end{enumerate} \item Is the same true for $g(x) = \sqrt{x^2}$? \end{enumerate} which produces 1. Let f (x) = x. Show the following: (a) f (x) is continuous on R. (b) f (x) is differentiable on R. √ 2. Is the same true for g(x) = x2 ? 1 Leonhard Euler (1707-1783) 25 5.2 Adjusting Page Layout To adjust the margins of the document as a whole you can use the geometry package by typing the following: \usepackage[top=2in, bottom=1.5in, left=1in, right=1in]{geometry} which defines the size of the margins, in inches, at the top, bottom, left and right of the doument. There are many parameters you can change that affect the document layout. You can change these parameters by typing \setlength{<parameter>}{<length>} where <parameter> tells LATEX the parameter you want to set and <length> tells LATEX how big you want that parameter to be. This setlength command can be placed in a variety of places depending on what parts of the document you want to be changed. You can place it in the preamble (so as to affect the whole document), in the main body of the document (so as to affect the document from where the command is placed) and in an individual environment (so as to affect only that environment). The most useful parameters that you can change are as follows. • \textwidth : This refers to the width of a line of text. • \textheight : This refers to the height of the body of text. • \parindent : This refers to the size of the indent on the first line of a paragraph. • \parskip : This refers to the height of space between paragraphs. Some parameters affect list environments only. These are as follows. • \topsep : This refers to the amount of extra vertical space at the top of a list. • \itemsep : This refers to the amount of extra vertical space between the list items. • \leftmargin : This refers to the distance between the left margin and the list items. • \rightmargin : This refers to the distance between the right margins and the list items. You can also alter these parameters by typing which tells LATEX to add <length> (which can be negative) to <parameter>. This is useful when changing parameters for particular \addtolength{<parameter>}{<length>} sections of the document since you can simply adjust the parameter lengths you set in the preamble. 5.2.1 A Note on Units In LATEX commands various units can be used, including the standard mm, cm, in and pt which correspond to millimeters, centimeters, inches and points (like the pt in Microsoft Word). LATEX also includes two other types of units which are 1ex and 1em. The former is the height of an “x” in the current font (useful for defining heights) while the latter is the width of an “M” in the current font (useful for defining widths). 5.3 Constructing Large Documents Large documents can be constructed from multiple .tex files. This can be useful when writing a document such as a dissertation or thesis as it avoids clutter and allows you to work on separate sections of your document at a 26 time. Typing \input{<filename>} simply copies all of the code from the file <filename> and pastes it in the document where the input command is placed. It can be used in the body of the document or in the preamble (like we did with the header.tex file). The command \include{<filename>} is a little more sophisticated. It inserts a clearpage command before and after the contents of the file, and writes section information to the .aux file of the parent file. This is useful for adding sections and chapters to you document. For instance, a typical main tex file with three sections looks like this \begin{document} \maketitle \tableofcontents \include{Section1} \include{Section2} \include{Section3} \end{document} where the text for each of the sections are included in the files Section1.tex, Section2.tex and Section3.tex. These files should be placed in the same folder as the main tex file. 5.4 Typesetting Code For some of you it will be important to include code in your LATEX document. You may have written some R code that you want to include in your dissertation, for instance. To do this you can use the listings package by typing \usepackage{listings} in the preamble. Then you can choose what programming language you want to include by typing \lstset{language=<language>} where <language> is the language you want. To see the choice of programming languages you can look at the LATEX wikibook: http://en.wikibooks.org/wiki/LaTeX/Source Code Listings#Supported languages). Now to add code you can type \begin{lstlisting}[frame=single]<code>\end{lstlisting} fines a code environment where <code> is the code you want to include in your document. Here is an example of including code into a LATEX document. Example 5.4.1 If I want to include some R code which produces a cosine plot I can type \begin{lstlisting} x <- seq(-2*pi, 2*pi, 0.01) y <- cos(x) plot(x, y, type = "l") \end{lstlisting} which produces x <− seq(−2∗ pi , 2∗ pi , 0 . 0 1 ) 27 which de- y <− cos ( x ) plot ( x , y , type = ” l ” ) 5.5 Bibliography and Citations A citation is a reference to material from another source that you have included in your document. This source will typically be a book, or an article from a journal. There are several conventions for adding citations to your work however the most common convention in mathematics is the Harvard system. Generally speaking this is where you include acknowledgement of the author by including their name followed by the year of the publication you are referencing. If, however, you are quoting the author then the citation should also include the page of the publication that the quote comes from. To include a citation in LATEX you can type \citet{<bib_ref>} or \citep{<bib_ref>} where <bib_ref> is a reference to a publication included in your BibTeX file which we will explain how to create in Subsection 5.5.1. The citet command (with the t) produces a reference consisting of the authors name along with a number corresponding to the reference in the bibliography, whereas the citep command (with the p) just produces the number. To include a page number (say p32) you can, for example, type \citep[p32]{<bib_ref>} . LATEX will include a maximum of two authors in the reference. If there are more than two authors then LATEX will use “et al.”. Here are a few examples of citing other work. Example 5.5.1 Typing \citet{oet:2014} provides a great resource for learning \LaTeX produces “Oetiker [2] provides a great resource for learning LATEX”. Example 5.5.2 Typing Some authors offer an approach to learning \LaTeX\ that is geared towards mathematicians, for example \citep{grat:2007} produces “Some authors offer an approach to learning LATEX that is geared towards mathematicians, for example [1]”. 5.5.1 The List of References: BibTeX and Natbib The list of references (bibliography) is typically placed at the end of your document. There are several ways to include a bibliography. Here we shall use BibTeX and a package called Natbib. A BibTeX file is simply a separate file that contains all the information about the references we wish to include in our document. The package Natbib then helps LATEX read that file and format the references to form a bibliography. 28 To use the Natbib package we include the command \usepackage[<label_type>]{natbib} in our preamble. The <label_type> option tells Natbib what format we want our labels to be. In this document the labels are numbers and this is achieved by having <label_type> as numbers. Then we can choose a format for our bibliography by typing where <style> tells LATEX what style we want our bibliography to formatted in. This document uses the plainnat style (the nat at the end is necessary for natbib to format things \bibliographystyle{<style>} properly). To create a BibTeX file (which stores all the information about the references) we can simply open a new file in whichever text editor we are using and then save that file with a .bib extension. Such a file simply contains the list of references we wish to be added to our document in a particular form. The most common references are to books and articles from journals. In the example below we give a simple BibTeX file showing how to add a reference for a book and a reference for an article. Both these examples have been obtained from the LATEX wikibook (http://en.wikibooks.org/wiki/LaTeX/Bibliography Management#BibTeX). There you can see examples for a variety of different types of references. The lines that are commented out (start with a percent sign, %) correspond to optional fields. @article{<article_label>, author = "", title = "", journal = "", %volume = "", %number = "", %pages = "", year = "XXXX", %month = "", %note = "", } @book{<book_label>, author = "", title = "", publisher = "", %volume = "", %number = "", %series = "", %address = "", %edition = "", year = "XXXX", %month = "", %note = "", } 29 The <article_label> and <book_label> are what you will use to reference these references in the text. You can add your bibliography to your document by typing \bibliography{<filename>} where you want the bibliography to go, which will typically be at the end. When you compile a LATEX document that contains a bibliography the following order of compiliation should be used: LATEX =⇒ BibTeX =⇒ LATEX =⇒ LATEX. In most text editors, however, you can just build the pdf twice. For articles in academic journals, you can usually find and download the BibTeX entry from the journal website. Try searching through Onesearch which will take you to the article’s page on the journal website. There is usually an “export citation” option. This is useful for making sure that your references are correct and up to date. 30 6 Beamer Presentations A Beamer presentation is a sequence of slides written within LATEX. This allows easy integration of mathematics in talks such as lectures, seminars and conferences. The only thing that is different in the Beamer documentclass is the structure of your document. In particular the use of frames (slides) and dynamic overlays (text popping up when the user clicks the mouse). To tell LATEX that you want to create a Beamer presentation your preamble needs to look like the following. \documentclass{beamer} \usetheme{<theme_name>} \usecolortheme{<colour_name>} \title[<short>]{<long>} \subtitle{<name>} \author[<short>]{<long>} \institute{<name>} \date{\today} The \usetheme and \usecolortheme commands tell LATEX what theme and what colour theme you want your slides to be. A full list of themes and the corresponding colour themes can be seen here: http://www.hartwork.org/beamertheme-matrix/. The title command tells LATEX the title of your presentation (both in long and short versions). The short version is used in the headers and footers of your chosen theme (if the theme has headers and footers) whereas the long version is the version used on the title page (if you choose to include this). Similarly the subtitle command tells LATEX what the subtitle of your presentation is and is included in the title page (if you have one). The author command tells LATEX the authors of the work you are presenting (not just the author of the presentation) with long and short versions that work exactly the same as the title command. The institute command tells LATEX which institute you are associated with and is included in the title page if you choose to have one. The date command tells LATEX the date you want on your title page. 6.1 Frames and Sections The main parts of a Beamer presentation are frames. Roughy speaking these are slides of the presentation. However each frame can be split into a sequence of slides which corresponds to overlays. Each frame begins with \begin{frame} and ends with a corresponding \end{frame} and can contain a title by including \frametitle{<name>} where <name> is the title for that particular frame. Beamer presentations are also structured into sections, in the same way as other LATEX documents. Unlike frames this section structure is not immediately visible, but is used to build the table of contents (if you choose to have one) and for navigation purposes in some of the Beamer themes. There can be several frames in each section. Two common frames (normally the first two) to include in a presentation are the title frame and the table of contents frame. These are easily added using the \titlepage and the \tableofcontents commands. For example the following typically corresponds to the first two frames of a Beamer presentation: 31 \begin{frame} \titlepage \end{frame} \begin{frame} \frametitle{Summary} \tableofcontents \end{frame} 6.2 Presentation Content The content within a Beamer presentation is normally written in note-form. This is because the slides of a presentation are there to support what the presenter is saying and is not there to be read in detail. This is what printed notes are for. As such Beamer presentations often at their core contain bullet points, figures, simple tables and highlighted text. Bullet points are included in Beamer in exactly the same way as described in Section 5.1 using the itemize and enumerate environments. Figures and tables are included in exactly the same way as desribed in Section 4.1 using the \includegraphics and \begin{tabular} commands. However, for both tables and figures you do not usually enclose them in a floating environment as you would within a normal document. Instead you can centre tables and figures by enclosing the relevant commands in \begin{center} and \end{center} . Highlighting Important Information There are two main ways of highlighting important information in your presentation. The first encompasses that information in a highlighted block. There are several environments built into beamer that create highlighted, bordered blocks for text, figures etc. They are all very similar, with slightly different formatting that depends on the theme used. We will concentrate on the block environement. To include a portion of your document in a block environment simply wrap that portion in \begin{block}{<block_name>} and \end{block} . <block_name> tells LATEX what you want the title of the block to be. You can also highlight certain pieces of information in your presentation more subtly just by changing the colour of the text. This can be done by using the command \alert{<text>} where <text> is the text you want to be highlighted. The following code provides an example of the two kinds of highlighting. You can \alert{highlight} certain words you feel hold greater importance. \begin{block}{Remark} Using too many highlighted blocks can make your presentation look cluttered. \end{block} Columns It is also easy to divide a slide into two or more columns. The following is an example: 32 \begin{columns}[T] \begin{column}{0.5\linewidth} ... \end{column} \begin{column}{0.5\linewidth} ... \end{column} \end{columns} The [T] aligns the columns at the top. The 0.5\linewidth tells LATEX to make the columns as wide as half of the length of a line. 6.3 Dynamic Overlays Unlike PowerPoint, Beamer does not animate slides as such. Instead, there are commands that create duplicates of slides in the PDF document, with different content displayed, so that when the presenter clicks through it appears to animate the slide. The most useful of these are: (a) \pause . (b) \onslide<<number>>{<text>} . (c) \alert<<number>>{<text>} . (d) Any formatting command such as \textbf<<number>>{<text>} . The \pause command tells LATEX that the portion of text before the \pause command is included on the first slide of that frame. The next portion (between this pause command and the next) is shown on the second slide of that frame (along with what was on the first slide). The other commands take an argument which is a number or range of numbers. For example \onslide<1,3> shows the text on the first and third slide of a frame, whereas \textbf<2> makes the text bold on the second slide only. The command \alert<<number>> makes the contents a different colour from the normal text on the slides specified by <number>. What the colour is depends on the colour theme of your presentation. The following examples demonstrate these commands. Example 6.3.1 You can use the pause command as follows. \begin{frame} \frametitle{Pause Example Slide} This text is the text you first see when the slide is loaded onto the screen.\\ \pause When you click next you see this text. \end{frame} Example 6.3.2 You can use the onslide and alert commands as follows. 33 \begin{frame} \frametitle{Onslide & Alert Example Slide} \alert<1>{This text is shown on all slides but is higlighted only on the first.}\\ \onslide<2, 3>This text is shown only on slides 2 and 3.\\ \onslide<3>This text is shown on slide 3. \end{frame} One of the best features of using Tikz with Beamer is that all these overlay commands can be used within the Tikz environment. This means that a diagram can be built up incrementally using overlay commands such as \pause . Overlay effects default to invisible if not specified. That is, for example, the command \onslide<3>{<text>} causes the text <text> to be invisible when not on the third slide of that frame. You can specify the elements that are to be “hidden” to be either invisible, or faint but transparent. To set this, use the command \setbeamercovered{} with either “invisible” or “transparent” as the argument. This command can appear in the preamble which applies to all frames, or within a specific frame to apply to that frame only. Handouts The disadvantage of using these effects is that it increases the number of slides in your PDF document. You may wish to print out copies without the overlay effects, with only one slide per frame. To do this, simply alter the \documentclass command to \documentclass[handout]{beamer} . 34 References [1] G. Grätzer. Math into latex, 2007. [2] T. Oetiker. The not so short introduction to latex 2ε, 2014. Version: 5.04. [3] American Mathematical Society. Ams-latex. http://www.ams.org/publications/authors/tex/amslatex. 35