latex - Typesetting Math in Latex - latex tutorial
What is Typesetting math in Latex ?
- Inline math
- Equations
- Fractions
- Matrices
- Scaling of Parentheses, Brackets etc.
- There are two major modes of typesetting math in LaTeX one is embedding the math directly into your text by encapsulating your formula in dollar signs and the other is using a predefined math environment.
- You can follow along and try the code in the sandbox below. I also prepared a quick reference of math symbols.
Using inline math - embed formulas in your text:
- To make use of the inline math feature, simply write your text and if you need to typeset a single math symbol or formula, surround it with dollar signs:
Sample Code:
Output Equation:
The equation and align environment:
- The most useful math environments are the equation environment for typesetting single equations and the align environment for multiple equations and automatic alignment:
Sample Code:
Output Equation:
Output Align:
- The align environment will align the equations at the ampersand &. Single equations have to be separated by a line break \\.
- There is no alignment when using the simple equation environment. Furthermore it is not even possible to enter two equations in that environment, it will result in a compilation error.
- The asterisk only indicates that I don't want the equations to be numbered.
Fractions and more:
- LaTeX is capable of displaying any mathematical notation. It's possible to typeset integrals, fractions and more.
- Every command has a specific syntax to use.
- I will demonstrate some of the most common LaTeX math features:
Sample Code:
Output:
- It is also possible to combine various commands to create more sophisticated expressions such as:
Output:
- The more complex the expression, the more error prone this is, it's important to take care of opening and closing the braces {}.
- It can take a long time to debug such errors.
- The Lyx program offers a great formula editor, which can ease this work a bit.
- I write all code by hand though, since it's faster than messing around with the formula editor.
Matrices:
- Furthermore it's possible to display matrices in LaTeX. There is a special matrix environment for this purpose.
Sample Code:
Output:
Brackets in math mode - Scaling:
- To surround the matrix by brackets, it's necessary to use special statements, because the plain [ ] symbols do not scale as the matrix grows.
Sample Code:
Output:
Sample Code:
Output:
- This does also work for parentheses and braces and is not limited to matrices. It can be used to scale for fractions.