Skip to main content

Math LaTeX Crash Course

LaTeX for Math Crash Course

(It’s easy, don’t worry)

CodeCogs

CodeCogs is a website that’ll allow you to test your LaTeX math code in real time. A stable internet connection is required for the ‘real time’ part.

I highly recommend following along with this tutorial.

Note that LaTeX is not only for math, so if you google “how to… latex,” you might see results for non-math related stuff.

What is LaTeX for Math?

It’s a way to let you type math as code, and make it look pretty.

Typing operators

++, - and == are intuitive. Just type +, -, or =.

Example
1 + 1 - 1 = 1
1+11=11 + 1 - 1 = 1

Multiply and divide use symbols that you can’t normally type on the keyboard, so instead, you type \times or \div instead.

Don’t forget the \ at the beginning! This is the ‘escape character’ and is how you type most symbols.

Example
4 \times 2 \div 3 = 2.6666667...
4×2÷3=2.666666...4 \times 2 \div 3 = 2.666666...

Note that you won’t be using ÷\div much, as most of the time you use fractions. We’ll show fractions later in this document.

Superscript and subscript

This is pretty intuitive too – you probably already use these symbols.

^ for superscript

_ for subscript

Example
y = v_i t + a_g t^2 \div 2
y=vit+agt2÷2y = v_i t + a_g t^2 \div 2

You can combine them too. Order doesn’t matter.

Example
v^2_1 and v_1^2 are the same.
v12v^2_1 and v12v_1^2 are the same.

Note that LaTeX doesn’t care about spaces.

Example
x = v_1t and x = v_1 t are the same.
x=v1tx = v_1t and x=v1tx = v_1 t are the same.

Example (bad)
v^42
v42v^42

If your superscript or subscript is longer than 1 character, you must use { curly braces } to surround them.

Example (fixed)
v^{42}
v42v^{42}

Example
v_{1 f}
v1fv_{1 f}

Example
v^{42}_{final\ of\ the\ first\ object}
vfinal of the first object42v^{42}_{final\ of\ the\ first\ object}

Notice the \ before the spaces. Inserting a backslash before a space tells LaTeX that you want to insert the space character.

Fractions

Fractions use \frac, and require 2 parameters (a numerator and denominator).

Example
\frac 12
12\frac 12

If you want more than 1 character in the fraction, you need to surround them in curly braces.

Example
\frac{42}{18}
4218\frac{42}{18}

Example
\frac{x^2 - 1}{(x + 1)(x - 4)} = \frac{x - 1}{x - 4}
x21(x+1)(x4)=x1x4\frac{x^2 - 1}{(x + 1)(x - 4)} = \frac{x - 1}{x - 4}

Exercise 1

Try to copy this equation exactly:

m1v1i2r=qv×Bm1g m_1\frac{v_{1i}^2}{r} = qv \times B - m_1g

See answer

Square root

Uses \sqrt

Example
\sqrt{x^2 + y^2}
x2+y2\sqrt{x^2 + y^2}

You can also do cube root (or any root) using \sqrt[n]{...}

Example
\sqrt[3]{x^2 + y^2 + z^2}
x2+y2+z23\sqrt[3]{x^2 + y^2 + z^2}

Dot multiply

People don’t really use ×\times that much either… you tend to see \cdot instead.

You can type that thing with \cdot. (center dot)

Example
4 N \cdot m
4Nm4 N \cdot m

Vectors

You can add \vec to add a vector arrow above your variables\vec {\textup{variables}}

Example
\vec F = q \vec v \times \vec B
F=qv×B\vec F = q \vec v \times \vec B

Other symbols

You can type other symbols by remembering their (greek) names.

Note that if you capitalize the code, you will get the capitalized letter.

Symbol Code
δ\delta \delta
Δ\Delta \Delta
θ\theta \theta
Θ\Theta \Theta
μ\mu \mu
M\Mu \Mu
ν\nu \nu
ε\varepsilon \varepsilon
ω\omega \omega
α\alpha \alpha

etc…

Other math symbols you might find useful:

Symbol Code Mnemonic
\approx \approx approximately equal
\sum \sum
\neq \neq not equal
±\pm \pm plus or minus
\int \int integral
\therefore \therefore

Exercise 2

Copy this equation exactly:

v=±2mgEarthhkspx2m v = \pm \sqrt{\frac{2mg_{Earth}h - k_{sp}x^2}{m}}

See answer

Trig functions

While you can just type sin, it’ll look slightly better if you type \sin or \cos or \tan, etc.

Example (bad)
sin \theta = \frac{opp}{adj}
sinθ=oppadjsin \theta = \frac{opp}{adj}

Example (fixed)
\sin \theta = \frac{opp}{adj}
sinθ=oppadj\sin \theta = \frac{opp}{adj}

Adding \ before trig functions removes the italics that LaTeX applies on variables.

Without \ With \
sinsin sin\sin
tantan tan\tan
arctanarctan arctan\arctan

Big brackets

Sometimes, you just need big brackets.

Example (bad)
x \cdot (\frac{a}{d} + v_i)
x(ad+vi)x \cdot (\frac{a}{d} + v_i)

LaTeX will auto-size brackets for you if you do \left ( ... \right )

Example
x \cdot \left ( \frac{a}{d} + v_i \right )
x(ad+vi)x \cdot \left ( \frac{a}{d} + v_i \right )

Units

Units aren’t variables, and therefore are usually not in italics. You can remove italics yourself using \textup

Example (bad)
4 N \cdot m
4Nm4 N \cdot m

yes that is the same example for dot multiply

Example (fixed)
4 \textup N \cdot \textup m
4Nm4 \textup N \cdot \textup m

Colors

Colors are nice sometimes.

Some escape codes have already been defined for you.

Result Code
red\red{red} \red{red}
green\green{green} \green{green}
blue\blue{blue} \blue{blue}

There are lots more you can discover yourself.

Exercise 3

Copy this equation exactly:

Etan[sin(Mα)]\red{\textup E} \green{\tan \left [ \blue{\sin \left ( \frac \Mu \alpha \right )} \right ]}

See answer

Cancel

You can cross out stuff to show cancelling out.

Example
\frac{1}{\cancel{22}} \times \cancel{22} = 1
122×22=1\frac{1}{\cancel{22}} \times \cancel{22} = 1

Appendix

Deriving exercise 2

I made up a question in my head where you’re asked to calculate the velocity of some object on a vertical spring. (These equations don’t come from thin air, you know!)

mgEarthh=12kspx2+12mv2 mg_{Earth}h = \frac 1 2 k_{sp}x^2 + \frac 1 2 mv^2
mgEarthh12kspx2=12mv2 mg_{Earth}h - \frac 1 2 k_{sp}x^2 = \frac 1 2 mv^2
2mgEarthhkspx2=mv2 2mg_{Earth}h - k_{sp}x^2 = mv^2
2mgEarthhkspx2m=v2 \frac{2mg_{Earth}h - k_{sp}x^2}{m} = v^2
±2mgEarthhkspx2m=v \pm\sqrt{ \frac{2mg_{Earth}h - k_{sp}x^2}{m}} = v
v=±2mgEarthhkspx2m v = \pm \sqrt{\frac{2mg_{Earth}h - k_{sp}x^2}{m}}

Answers to exercises

Answer 1

m1v1i2r=qv×Bm1gm_1\frac{v_{1i}^2}{r} = qv \times B - m_1g

m_1\frac{v_{1i}^2}{r} = qv \times B - m_1g

Go back to exercise 1

Answer 2

v=±2mgEarthhkspx2mv = \pm \sqrt{\frac{2mg_{Earth}h - k_{sp}x^2}{m}}

v = \pm \sqrt{\frac{2mg_{Earth}h - k_{sp}x^2}{m}}

Go back to exercise 2

Answer 3

Etan[sin(Mα)]\red{\textup E} \green{\tan \left [ \blue{\sin \left ( \frac \Mu \alpha \right )} \right ]}

\red{\textup E} \green{\tan \left [ \blue{\sin \left ( \frac \Mu \alpha \right )} \right ]}

Go back to exercise 3

Comments

Popular posts from this blog

Stuff I hate

 There are some stuff in the world that I hate. underline 'former' and 'latter' 12 AM and 12 PM One may call these 'pet peeves.' I would like to go through each thing and explain why I hate them. Underline Underline is a common formatting option available on many text-editing platforms. Unlike bold or italics , color of the text, which modifies the way the text is presented, the underline formatting option adds a line below the text. Why do I hate it? One reason, is that it could be mistaken for a link . Look at the underlined text above -- don't you feel like you could click it? (Although, the this argument could also be made about color.) But the main reason I hate underline: It looks bad . I understand the use of underline in handwritten text -- it's a convenient and easy way for you to make a piece of text stand out, and it doesn't require other tools (like a highlighter). However, we are in the digital age. Compare...