

<a href="https://hub.callysto.ca/jupyter/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fcallysto%2Fcallysto-sample-notebooks&branch=master&subPath=notebooks/Demonstrations/tutorials/JupyterTestdrive-LateX.ipynb&depth=1" target="_parent"></a>

## Mathematical Typesetting With Latex

This will only serve as a brief introduction to mathematical typesetting with latex as a full guide could take a few notebooks on its own. However, most of these commands are easy to find if you need to do something special. The basics are as follows:

1. To put a variable in-line, surround it in dollar signs like so: `$variable$`.
1. To typeset an equation, surround it (on a new line) in double dollar signs: `$$equation$$`
1. you could also use this syntax
   ```latex
    \begin{equation}
       equation
   \end{equation}
    ```
1. Special symbols start with a backslash (`\`). For example, the greek letter $\alpha$ would be called like this `$\alpha$`. 

1. Fractions can be typeset with `\frac{numerator}{denominator}`
1. Square roots are `\sqrt{stuff inside square root}`

Change the cell below to markdown format and run it to see some of these in action.

If you want to type inline variables it's as easy as $x$. If you want special symbols in line, simply call it by its name, such as $\alpha$, $\gamma$, $\epsilon$, $\Delta$, $\nabla$ and so on. [here](http://tug.ctan.org/info/symbols/comprehensive/symbols-a4.pdf) is a link to a comprehensive symbol list, and the command you have to call to render it. Of course, sometimes a Google search is faster. 

You can start equations easily
$$ c  = \sqrt{a^2 + b^2}$$
notice how in the above, the variables appearing under the square root are surrounded by curly brackets, and powers are done with carrots.

You can also type equations like this
\begin{equation}
a = \frac{x^3 +\Gamma}{\int e^{-x^2} dx}
\end{equation}

Notice here how the numerator of the fraction appears in curly braces, and the denominator appears in separate curly braces. Notice how to find a capital gamma, we simply wrote the first letter as a capital. Also notice how in the exponent, this time we included curly brackets. This is because without them only the first character will become a superscript. 

\begin{equation}
a = x^-10
\end{equation}

The above doesn't render how you want it to, but 
\begin{equation}
a = x^{-10}
\end{equation}
does once you include the curly braces.

You can also include vectors on variables
\begin{equation}
\vec{F} = m \vec{a}
\end{equation}
### Latex Common Errors

You'll need to convert the cells below to markdown in order to see how these common mistakes render, and their solutions. 

##### Exponents need to be wrapped in curly braces if they're more than one character long.
\begin{equation}
a = x^-10
\end{equation}

Doesn't render how you want it to, but 
\begin{equation}
a = x^{-10}
\end{equation}
does once you include the curly braces.

##### The same is true for subscripts
\begin{equation}
a = x_10
\end{equation}

Doesn't render how you want it to, but 
\begin{equation}
a = x_{10}
\end{equation}
does once you include the curly braces.


##### Spaces in equations are ignored
$$
If you use words as a varable, they become hard to read = x_a^2
$$

If you need to include words in your equations, you can do so with `\text{}`
$$
\text{Now we can read this easily once we've rendered the math} = x_a^2
$$
##### You cannot include percent signs without a little extra work
$$
100 % That's because a percent sign is a comment in latex!
$$
To escape the comment, simply add a backslash
$$ 100 \% $$
Latex is very extensive for mathematical typesetting, and we can't cover it all here. However, it's fairly intuitive and with a little practice significantly faster than using the equation editors in other tools. Feel free to try creating your own equations now. 

---
### Exercises
1. Fix the following to correctly represent the formula for calculating the surface area of a sphere
$$
Area = 4 pi r_2
$$  
  
2. Fix the following to correctly represent the formula for calculating the volume of a sphere
\begin{equation}
Volume = \frac{4} / {3} pi r3
\end{equation}
3. Make sure pi is showing up as a symbol in questions 1 & 2.
4. In this sentence, change the variables x, Y, and y to ensure they render as LateX variables.
5. In a new cell below, write out the following formula in LateX. 

---


[](https://github.com/callysto/curriculum-notebooks/blob/master/LICENSE.md)

a6a1ae5445f65315a55aeb5ef22de9c6ca8869b2
ipynb
Jupyter Notebook
notebooks/Demonstrations/tutorials/JupyterTestdrive-LateX.ipynb
callysto/callysto-sample-notebooks
1e441a08687243030b5dec3b763e5ec883ee6c20
CC-BY-4.0
2018-04-04T19:14:48.000Z
2018-04-04T19:14:48.000Z
notebooks/Demonstrations/tutorials/JupyterTestdrive-LateX.ipynb
callysto/callysto-sample-notebooks
1e441a08687243030b5dec3b763e5ec883ee6c20
CC-BY-4.0
2018-04-05T13:34:33.000Z
2019-01-25T01:02:30.000Z
notebooks/Demonstrations/tutorials/JupyterTestdrive-LateX.ipynb
callysto/callysto-sample-notebooks
1e441a08687243030b5dec3b763e5ec883ee6c20
CC-BY-4.0
2018-04-04T19:25:16.000Z
2021-09-20T04:43:51.000Z
Qwen/Qwen-72B
1. YES
2. YES