# Python and $\LaTeX$


```python
%matplotlib inline

import sympy as sp
import numpy as np
import matplotlib.pyplot as plt
```

## Python uses the $\LaTeX$ language to typeset equations.
Most LaTeX commands are prefixed with a "\". For example \pi is the
command to produce the lower case Greek letter pi.

The characters  # $ % & ~ _ ^ \ { } are special characters in LaTeX. If
you want to typeset them you need to put a \ in front of them. For
example \$ will typeset the symbol $

% - comment. Everything is ignored after a %
$ - Math mode. Start and Stop math mode. $\pi$
^ - Superscript in Math mode. $2^2$
_ - Subscript in Math mode. $2_2$
### Use a single set of `$` to make your $\LaTeX$ inline and a double set `$$` to center
$$ \int \cos(x)\ dx = \sin(x) $$
### This code will produce the output:

### $$ \int \cos(x)\ dx = \sin(x) $$

## Use can use $\LaTeX$ in plots:


```python
plt.style.use('ggplot')

x = np.linspace(0,2*np.pi,100)
y = np.sin(5*x) * np.exp(-x)

plt.plot(x,y)
plt.title("The function $y\ =\ \sin(5x)\ e^{-x}$")
plt.xlabel("This is in units of 2$\pi$")

plt.text(2.0, 0.4, '$\Delta t = \gamma\, \Delta t$', color='green', fontsize=36)
```

## Use can use `sympy` to make $\LaTeX$ equations for you!


```python
z = sp.symbols('z')
```


```python
a =  1/( (z+2)*(z+1) )

print(sp.latex(a))
```

$$ \frac{1}{\left(z + 1\right) \left(z + 2\right)} $$


```python
print(sp.latex(sp.Integral(z**2,z)))
```

$$ \int z^{2}\, dz $$

## `Astropy` can output $\LaTeX$ tables


```python
from astropy.io import ascii
from astropy.table import QTable
```


```python
T = QTable.read('Zodiac.csv', format='ascii.csv')
```


```python
T[0:3]
```


```python
ascii.write(T, format='latex')
```

---

## Some websites to open up for class:

- ## [Special Relativity](https://en.wikipedia.org/wiki/Special_relativity)

---

- ## [ShareLatex](https://www.sharelatex.com/)

- ## [ShareLatex Docs and Help](https://www.sharelatex.com/learn)

- ## [Latex Symbols](https://en.wikipedia.org/wiki/Wikipedia:LaTeX_symbols)

- ## [Latex draw symbols](http://detexify.kirelabs.org/classify.html)

- ## [The SAO/NASA Astrophysics Data System](https://ui.adsabs.harvard.edu/#classic-form)

---

- ## [Latex wikibook](https://en.wikibooks.org/wiki/LaTeX)

---

# Assignment for Week 8
-----------------------------------------------------------------------------
LaTeX homework - Create a LaTeX document with references.
-----------------------------------------------------------------------------

Start with the file: Example.tex

Minimum required elements:

* Between 2 and 4 pages in length (pages > 4 will be ignored).

* At least two paragraphs of text (the text should be coherent).

* At least 5 references from ADS                        

  * http://adsabs.harvard.edu/abstract_service.html
  * Make sure to \cite{} the references in your paper

* The equation on the back of the handout                                         

* One (or more) equation(s) of your choice.                 

* One Compulsory plot generated with python (png format)    

  * Start with t = np.linspace(0,12*np.pi,2000)
  * generate a butterfly plot: http://en.wikipedia.org/wiki/Butterfly_curve_(transcendental)
  * I have started it for you im the last cell of this notebook

* One other plot/image (do not reuse and old one!)               

* One table of at least 4 columns and 4 rows.

* Bonus points given for interesting content!

-----------------------------------------------------------------------------

Create a PDF file:

Save the file as FirstLast.pdf  (i.e. TobySmith.pdf)

Upload the PDF to the class canvas site

-----------------------------------------------------------------------------
Deadline: Tuesday Nov 29 - 5pm (-5 pts for each 30 minutes late)
-----------------------------------------------------------------------------

```python
t = np.linspace(0,12*np.pi,2000)

fig,ax = plt.subplots(1,1)                    # One window
fig.set_size_inches(11,8.5)                   # (width,height) - letter paper landscape

fig.tight_layout()                            # Make better use of space on plot


```

17a0bb11c7af2bce7e4f1d9c1022617b541aef12
ipynb
Jupyter Notebook
08_Python_LaTeX.ipynb
UWashington-Astro300/Astro300-A16
bb3ee938c905035dfd1ac123036a140a117e6b95
MIT
08_Python_LaTeX.ipynb
UWashington-Astro300/Astro300-A16
bb3ee938c905035dfd1ac123036a140a117e6b95
MIT
08_Python_LaTeX.ipynb
UWashington-Astro300/Astro300-A16
bb3ee938c905035dfd1ac123036a140a117e6b95
MIT
Qwen/Qwen-72B
1. YES
2. YES