LatexNotes

Lesson 1 of 12

Maths mode: your first formula

Where maths goes in a LaTeX document, which characters you type as they are, and the backslash that starts every command. About ten minutes.

LaTeX writes maths as plain text: you type a description of the formula, and LaTeX sets it like a printed textbook. In this course you type into boxes on the page and see the result at once, so there is nothing to install.

Two ways into maths mode

In a LaTeX document, maths lives in maths mode. There are two ways in:

  • $...$ for maths inside a sentence, such as y=mx+cy = mx + c.
  • \[...\] for a formula on a line of its own, centred.
LaTeX
The line $y = mx + c$ crosses the y-axis at $c$.
\[ y = mx + c \]

You may meet $$...$$ in older documents. It does the same job as \[...\], but \[...\] is the one to use.

In the boxes on this course you are always in maths mode already, so you type just the maths: y = mx + c, without the dollar signs. (Type them anyway and they are ignored.)

What you type as it is

Letters, digits and most of the symbols on your keyboard go in as they are:

  • Letters come out italic, because in maths a letter is a variable: xx, yy, aa.
  • Digits stay upright: 20242024.
  • + - = < > ( ) [ ] / ! ' , . : ; all work as they are. A typed - becomes a proper minus sign, longer than a hyphen.

Edit the formula below: change a number, add a term, and watch it update.

f(x)=3x−1f(x) = 3x - 1

Spaces do not count

In maths mode LaTeX ignores the spaces you type. 2x+3=7 and 2 x + 3 = 7 give exactly the same result, because LaTeX spaces a formula by itself, from what each symbol is: more room around == than around ++, and none between 22 and xx. Type spaces only to keep your LaTeX easy to read.

Try it: add or remove spaces in the box, and nothing moves.

2x+3=72x+3=7

The flip side: a word typed in maths mode turns into italic letters multiplied together. Here the word "area" reads as a×r×e×aa \times r \times e \times a:

area=3×4area = 3 \times 4

Words inside maths need \text{...}, which comes in lesson 11.

Commands start with a backslash

Anything that is not on your keyboard has a command: a backslash followed by a name. \pi gives π\pi, \times gives ×\times and \infty gives ∞\infty.

C=2πrC = 2\pi r

A command's name ends at the first character that is not a letter. So \pi r is π\pi times rr, but \pir is a command LaTeX does not know, and you get an error. Leave a space after a command when a letter follows it.

Two things catch everyone out:

  • * is not a times sign: it prints an asterisk. Use \times for ×\times, or \cdot for a centred dot, as in a⋅ba \cdot b.
  • % starts a comment, so LaTeX ignores everything after it on the line. Write \% for a percent sign.

Braces group, and are not printed

Curly braces { } group things for LaTeX and never appear in the output. From the next lesson on you will use them all the time, as in x10x^{10}. To print a brace, put a backslash before it: \{ and \} give {\{ and }\}.

A={1,2,3}A = \{1, 2, 3\}

Practise

Type each formula in the box under it. It is marked as you type, and Enter takes you to the next one.

  1. 2x+3=72x + 3 = 7

  2. y=mx+cy = mx + c

  3. f(x)=3x−1f(x) = 3x - 1

  4. C=2πrC = 2\pi r

  5. 6×7=426 \times 7 = 42

  6. a⋅b=b⋅aa \cdot b = b \cdot a

  7. A={1,2,3}A = \{1, 2, 3\}

  8. x=50%x = 50\%

In short

  • $...$ puts maths in a sentence, \[...\] on a line of its own.
  • Letters, digits and most keyboard symbols are typed as they are, and spaces are ignored.
  • Commands start with a backslash. * is not multiplication: use \times or \cdot.
  • Braces group without being printed. \{ and \} print them, and \% prints a percent sign.

Next, in lesson 2: powers and subscripts, with ^ and _.

Would you rather write it by hand?

LatexNotes turns a photo or PDF of your handwritten maths into LaTeX like this. Free to try, no sign-up.

Convert your handwriting to LaTeX →