Create Beautiful Math Homework
Tags: latex, katex, python
Published: 2019-09-27 02:20:51

---
title: Create Beautiful Math Homework
published: true
tags: latex, katex, python
canonical_url: https://pianomanfrazier.com/post/create-beautiful-math-homework/
---

Throughout my Computer Science degree I have been doing a lot my homework in Latex. It has a steep learning curve but the results are amazing.

For my technical writing class I convinced my group to use Latex instead of Word or Google Docs. In hindsight this created a lot of extra work for me but I learned a lot about customizing a Latex document.

See [here](https://github.com/pianomanfrazier/ENGR_3080_latex) for the Latex template I generated.

The things I really liked about this setup was the ability to modularize the document and assign different team members a section. We then collaborated on the document using [https://www.overleaf.com](https://www.overleaf.com). Overleaf has git integration so I could edit the document on my laptop and push the changes back up to overleaf. The downside to this was that my other team members were not programmers and did not know how to use git and had to use the web interface for editing. Generating and managing the bibliography was also very easy using Bibliotex.

For my personal homework I wrote a bash script that reads a config file for the class I am in that has data like the teacher, semester, class name and so forth and generates a new Latex project with a makefile. I have been using this system for 2 semesters and it has been working great. See [homework-generator](https://github.com/pianomanfrazier/homework-generator).

For my probability class this semester I also wanted to produce graphs and charts. I have been using the python libraries [matplotlib](https://matplotlib.org) and [seaborn](https://seaborn.pydata.org/index.html) to create awesome graphs. My homework often looks better than my textbook (imho).

Here are some highlights of the graphs I did for my homework. The visualizations helped me see what was going on with the math.

![Poisson distribution](https://pianomanfrazier.com/img/math_homework/poisson.svg "Poisson distribution")<figcaption>Poisson Distribution where $$ \lambda = 10 $$ <a href="https://pianomanfrazier.com/files/plots/poisson.py">[download poisson.py]</a></figcaption>

![Lognormal Distribution](https://pianomanfrazier.com/img/math_homework/lognorm.svg "Lognormal Distribution")<figcaption>Lognormal Distribution $$ f(x) = \frac{1}{\sigma x \sqrt{2 \pi}} e^{- (\ln x - \mu)^2 / 2 \sigma^2 }$$ <a href="https://pianomanfrazier.com/files/plots/lognorm.py">[download lognorm.py]</a></figcaption>

Using [moviepy](https://zulko.github.io/moviepy/) we can create a nice video of this graph where \(\sigma\) varies over time.[[download lognorm\_video.py]](https://pianomanfrazier.com/files/plots/lognorm_video.py)

<video controls loop autoplay>
<source src="https://pianomanfrazier.com/video/lognormal.mp4" type="video/mp4"></source>
Your browser does not support this video.
</video>

![Normal Distribution](https://pianomanfrazier.com/img/math_homework/velocity.svg "Normal Distribution")<figcaption>Normal Distribution of the Velocity of a Particle $$ f(x) = 2 \frac{mv}{\sigma \sqrt{2 \pi}} e^{- ( \frac{1}{2} mv^2 - \mu)^2 / 2 \sigma ^2} $$ <a href="https://pianomanfrazier.com/files/plots/velocity.py">[download velocity.py]</a></figcaption>

![Bivariate](https://pianomanfrazier.com/img/math_homework/bivariate.svg "Bivariate")<figcaption>Plot of a Bivariate Distribution $$f_{XY}(x,y) = x e^{-x(y+1)}$$ <a href="https://pianomanfrazier.com/files/plots/bivariate.py">[download bivariate.py]</a></figcaption>

And just for fun let's plot a torus and make a video out of it. [[download torus.py]](https://pianomanfrazier.com/files/plots/torus.py)

<video controls loop autoplay>
<source src="https://pianomanfrazier.com/video/torus.mp4" type="video/mp4"></source>
Your browser does not support this video.
</video>