<<

My first LATEX document

Timothy Gummer August 12, 2019

Contents

Unnumbered section 3

1 Basic document structure3 1.1 Spacing...... 3 1.2 Lists...... 3 1.3 Styling...... 4 1.4 Tabular environments...... 4

2 ‘Math’ Mode 5 2.1 Basic syntax...... 5 2.2 Common symbols...... 6 2.3 Brackets...... 6 2.4 Big operators...... 6 2.5 The American Mathematical Society Packages...... 7 2.5.1 Symbols from amssymb ...... 7 2.5.2 An example: linear systems of equations...... 7 2.5.3 The commath package...... 8 2.5.4 More on align environments...... 9 2.5.5 Another example: distributions...... 9 2.6 Theorems and proofs...... 9 2.7 Life-like ...... 10

3 User-defined commands/macros 11

4 Colours 11

5 Links and references 11

6 Graphics 11

7 Floats 12

8 Verb and Listings 14 8.1 Verbatim...... 14 8.2 Listings...... 14

9 Actuarial Notation 15

1 10 References 15

2 Unnumbered section

Sections that use the suffix variant (unnumbered) of the section command are not included in the table of contents by default.

1 Basic document structure

1.1 Spacing

This is my first LATEX document. In this document, I will be learning all the basics of LATEX. Leave a line of code empty for a new . Use double backslash for a line break.

A line break combined with a new paragraph makes a larger space between the .

This text appears 3 centimetres below the previous. Some text. This text appears 5 centimetres to the right of the previous. Spaces in the input file do not always correspond to spaces in the output file, they are sometimes used to end commands instead so be careful (e.g. with LATEX).

1.2 Lists The enumerate and itemize environments are for lists of things.

• Apple

– Pink lady – Fuji

• Orange

• Banana

1. First

(a) Next

2. Second

3. Third

3 1.3 Font Styling There are several ways in which one might emphasise particular groupings of text: bold font, italic font, underlined font, font, , tiny font, small font, large font, huge font.

The emph command will emphasise a word by toggling italics. i.e.: The sixth word of this sentence is emphasised. The final word of this sentence is emphasised.

There are a few semantics about quotation marks and inverted commas one ought to know. Incorrect: ”quote”, or ’quote’. Correct: “quote”, or ‘quote’ (need to use back ticks on the left)

Typewriter font is typically used by convention for the names of packages and functions (sometimes in languages other than LATEX). e.g. “magrittr is a useful R package which contains pipe operators”. It is also often used for URLs.

Some symbols will not display automatically as they should as they have other uses and need to be ‘backslashed’. e.g. { & $ %

Indeed, backslash itself is displayed using the command textbackslash, \.

1.4 Tabular environments left centre right Text with automatic line break- ing text text text text

4 2 ‘Math’ Mode

2.1 Basic syntax Wrap an expression in $ symbols to enter math mode. Use two $ symbols (i.e. $$) to indicate display math mode. One can alternatively use \(\) for normal maths mode and \[\] for display maths mode (clearer start and end). y = mx +

5 ∗ 2 = 70/7 = 10 Use the caret symbol (ˆ) for right supercripts: a2 + b2 = c2.

Use the symbol for right subscripts: x1.

You need to use curly brackets to include more than on symbol in a subscript or supercript (par- ticularly double super- and subscripts as they provide enough ambiguity to cause an error): e2x, e2x, e−x2

46 Left subscripts and superscripts require a few empty curly brackets: x 10A. Greek letters: α, β, γ, θ, δ Some Greek letters have a variant:

φ, ϕ Some Greek letters are rather difficult to write by hand:

ξ, ζ

For Greek capital letters just capitalise the commands:

Γ, Λ, ∆

Fractions: 1 2 1 Appear smaller in normal maths mode: 3 1 Man make bigger with the displaystyle command 2 Mathematical operators should be distinguished from variables by unitalicising them: max f(x), exp x and log x. Use the mathrm or operatorname commands to do this on operators that don’t have predefined commands for their names.

To display text inside math mode use the text command. e.g. eiθ = cos θ + i sin θ . . . (known as Euler’s formula)

5 2.2 Common symbols Inequality symbols: >, <, ≥, ≤ √ √ Radicals: 2, 3 2 Y Integration and summation operators: R , RR , and P, (these get bigger when you make them into display maths mode)

Arrows: → (also use to), ←, ↔, ⇒, ⇐, ⇔, also long arrows: ←−, ⇐⇒

Set theory and logic: ∀, ∃, ∪, ∩, ∨, ∧, ∅ := {} also S etc.

Equivalence relations: ≡, ≈, ∼, 6= . . Dots: ·, ··· , ... , .,. ..

Maths bold (e.g. for vectors): x, X, b

Accented symbols: θˆ, X¯, X,a ¨

Others: ∞, ∂, ±, `, > (i.e. for transpose), | (i.e. “given” in for condition probability etc.)

2.3 Brackets (, [ and | are all available in maths mode as is.

To produce {, h, i k, you need to use commands.

[0, ∞) Use left and right to make brackets match the height of their contents.

1 1 ( ), 2 2 If you only need brackets on one side, use a fullstop symbol with the left or right command (“.”).

1 3

1

2

2.4 Big operators To make things appear above or below defined operators use the limits command. e.g.:

 1 n lim 1 + = e n→∞ n

6 ∞ X 1 rn = 1 − r n=0 This works for R , S etc. as well Use the stackrel command if you just want to stack two symbols. e.g.:

=?

2.5 The American Mathematical Society Packages We will learn some of the features of the American Mathematical Society Packages (AMS) packages by virtue of an example. of linear equations.

2.5.1 Symbols from amssymb

Q.E.D./ proof conclusion: , .

Set theory: ∅ = {} (a better-looking empty set)

Mathematical shorthand: ∴, ∵

Blackboard bold letters (mathbb): R, , C

Calligraphic letter (mathcal): L, A, B

2.5.2 An example: linear systems of equations Align:

x1 + x2 + x3 = 6 (1)

5x1 + 2x2 − 4x3 = −3 (2)

3x1 − x2 + 5x3 = 16 (3) a repeat of this to show some other features

x1 + x2 + x3 = 6 (4)

5x1 + 2x2 − 4x3 = −3 (a)

3x1 − x2 + 5x3 = 16

x1+ x2+ x3 = 6

5x1+2x2−4x3 = −3

3x1− x2+5x3 = 16 Cases: We might also like to present these equations as  x + x + x = 6  1 2 3 5x1 + 2x2 − 4x3 = −3  3x1 − x2 + 5x3 = 16

7 Some might also choose to use matrices instead,   x1 + x2 + x3 = 6 5x1 + 2x2 − 4x3 = −3  3x1 − x2 + 5x3 = 16 however the alignment here is not quite right. Matrices We can rewrite this in the form Ax = b       1 1 1 x1 6 5 2 −4 x  −3    2 =   3 −1 5 x3 16 We can then write it as an augmented matrix for Gaussian elimination:  

1 1 1 6   5 2 −4 −3   3 −1 5 16 This will yield the solution:   x1 x  x =  2 x3   1 2 =   3

 x = 1  1 i.e. x2 = 2 or in another way x1 = 1, x2 = 2, x3 = 3  x3 = 3

2.5.3 The commath package This package has a of predefined commands that make certain commonly use mathematical things much easier and more consistent. For example: • The norm command: kxk Z 1 • The dif command: ex dx (unitalicises the d and places a small amount of space between the 0 integrand and the differential).

dy • The od command: dx

∂y • The pd command: ∂x All of these are rather cumbersome to produce otherwise.

8 2.5.4 More on align environments ‘align’ environments can be uses to create alignments between particular elements of an array of math- ematical expressions. They are commonly used to align equals signs.

" #1 Z 1 x3 x2 dx = 0 3 0 1 = − 0 3 1 = 3 You need some extra & symbols to have multiple vertical alignments at once. (Put extra &’s between each object).

x1 = 1 x2 = 2 x3 = 3

x4 = 4 x5 = 5 x6 = 6

Environments related to the align environment: eqnarray and equation are redundant environments because everything they do, can be done (bet- ter) by the align environment. Although, equation does have some use if used in combination with the aligned environment discussed below.

There are also the aligned environment which allow for an align-like environment within regular maths mode and alignat environment which allows for more control when you wish to have multiple vertical alignments (using multiple & symbols when the above doesn’t work).

2.5.5 Another example: probability distributions We missed an important use of the cases environment above. Let X ∼ exp(λ), then it’s probability density function is: ( λe−λx, if x ≥ 0 fX (x) = 0, otherwise

2.6 Theorems and proofs Theorem 2.1 (theorem name). Statement of the theorem A ⇒ B.

Proof. Proof goes here.

Theorem 2.2 (another theorem). Statement of the theorem C ⇐⇒ D.

Proof. Use the qedhere command to make the Q.E.D. symbol appear in next to the last line correctly if the last line is an equation. D =⇒ C

9 2.7 Life-like mathematics The the package cancel is useful for “cancelling out” fractions etc..

One might combine this with the ams commands for under and over braces to make LATEX expression appear closer to being handwritten.

For example:

6 z2 }| { 60 4¡¡ × 5¡ × 3 6 = = 70 1 7 2¡¡ × 5¡ × 7 | {z } 7

10 3 User-defined commands/macros

Commands are defined in the preamble and can then be used anywhere in the document. 1 One might wish to make it easier to produce 2 . Or even shorten the names of commands such as 1 \displaystyle, . 2 One could also make a command for some text that is frequently used, then if you want to change something slightly, you can change it in one place and it will be reflected everywhere in the document. For example you could create a command for the title of your document. It is common to add a command to make the blackboard bold command shorter. R

4 Colours

Basic colours: red

dvipsnames colors: Apricot

HTML colors: dark olive green.

5 Links and references

This is section5 (use the ref command) on 11 (use the pageref command).

Links and references (name of this section). One can also do the same thing with equations for example:

y = mx + c (5)

Here we have equation (5).

The equation of a line above. You can also link to webpages using the url and href commands. e.g. https://www.google.com.au and google.

6 Graphics

A random scribble .png file.

11 A .pdf file we created in RMarkdown.

Histogram of z 20 15 Frequency 10 5 0

−3 −2 −1 0 1 2 3

z

7 Floats

Floats are numbered environments for things like figures and tables. They also “float” in a position.

12 Histogram of z 20 15 Frequency 10 5 0

−3 −2 −1 0 1 2 3

z

Figure 1: Histogram of simulated 100 standard normal random variates.

x 1 2 3 f(x) 1 4 9

Table 1: Tabulated values for the function f(x) = x2.

13 8 Verb and Listings

8.1 Verbatim It can write anything I want here as I like

nd @$#%^&*() \ ew

I can use verb in the middle of a line \LaTeX. How cool

8.2 Listings Lets display the R code we used to produce the pdf above. pdf(”graphic.pdf”) z <− rnorm (100) h i s t ( z ) dev . o f f ( )

pdf(”graphic.pdf”) z <− rnorm(100) hist ( z ) dev . off ()

1 pdf ("graphic.pdf") 2 z <- rnorm(100) 3 hist(z) 4 dev.off() Listing 1: R code for producing figure1.

Listing 2: The listing style for R code. 1 \ lstdefinestyle {R code }{ 2 language=R,% the language of the code 3 basicstyle=\scriptsize \ttfamily ,% the size of the that are used f o r the code 4 =left ,% where to put the line −numbers 5 numberstyle=\scriptsize \ c o l o r {Blue } ,% the style that is used for the l i n e −numbers 6 stepnumber=1,% the step between two line −numbers. If i t is 1, each line 7% will be numbered 8 numbersep=5pt,% how far the line −numbers are from the code 9 backgroundcolor=\c o l o r { white } ,% choose the background color. You must add \ usepackage { c o l o r } 10 showspaces=f a l s e ,% show spaces adding particular 11 showstringspaces=false ,% underline spaces within strings

14 12 showtabs=f a l s e ,% show tabs within strings adding p a r t i c u l a r underscores 13 frame=s i n g l e ,% addsa frame around the code 14 r u l e c o l o r =\c o l o r { black } ,% if not set, the frame −c o l o r may be changed on line −breaks within not−black text(e.g. commens(green here )) 15 t a b s i z e =2,% sets default tabsize to2 spaces 16 captionpos=b ,% sets the caption −p o s i t i o n to bottom 17 b r e a k l i n e s=true ,% sets automatic line breaking 18 breakatwhitespace=false ,% sets if automatic breaks should only happen at whitespace 19 keywordstyle=\c o l o r {RoyalBlue } ,% keyword style 20 commentstyle=\c o l o r {YellowGreen } ,% comment style 21 s t r i n g s t y l e =\c o l o r { ForestGreen } % string literal style 22 }

Listing2 is the code used to create the style for listing1.

9 Actuarial Notation

(p) a¨n , tpx

10 References

In the preamble:

\usepackage[round]{natbib} \bibliographystyle{unsrtnat}

At the end of the document:

\clearpage

\addcontentsline{toc}{section}{References} \bibliography{bib}

Run citation() and citation("magrittr") in R and put them in a file called “bib.bib”.

15