LaTeX and Jekyll
10 May 2014This is my first website and as a result I am learning something new with every post. I am using Jekyll, a static site generator build on ruby, for two reasons.
- I have heard wonderful things about it.
- It works with github pages, so you can host your Jekyll site for free.
The setup has been pretty painless, even for someone with little prior experience with HTML, CSS, or Ruby. I am familiar with git however, which has been a huge help. I simply cloned someone else’s code, and began to modify it to my own liking.
For those unfamiliar with git, there are many wonderful online tutorials. I have a github account—capecodcid (which I use less than I should). On my own computer I use a combination of the command line and gitbox to manage my repositories.
My advice is to start with something simple. There are some really beautiful Jekyll themes, but start simple.
The first thing I needed to figure out how to do is to use MathJax to render LaTeX equations. I will be writing a lot of math and I want it to look good!
This is the famous Einstein Field Equation, which captures the key idea of General Relativity—local curvature in spacetime is equal to the local momentum and energy in that spacetime. Matter and energy bend space!
Boom! I am not sure why things are orange, but at least everything is typesetting correctly. So what did I have to do to get this to work? There are two parts. First, you need to tell your webpage where to find MathJax. Second, you need to make sure that your markdown parser recognizes that something is LaTeX. So here was my procedure:
- I added the following line of code to
head.html
in my_includes
folder. It could equivalently go indefault.html
. It just needs to be somewhere it will get run. This simply instructs the browser to go grab the latest MathJax javascript.
- I changed the markdown parser to
kramdown
which recognizes anything between two sets of$$
as a LaTeX equation and not regular markdown. To do this I first had to install kramdown,
and then I added the following line to my _config.yml
file.
Voila! It works. It even supports inline equations like . Now I just need to figure out how to change the coloring.
###Addendum
The color problem has been solved! It turns out that
pygments
—our syntax highlighter for code like the javascript above—andMathJax
use some of the samecss
classes. Specifically.mi
and.mo
. To fix this we can simply precede their definitions insyntax.css
with.highlight
so those definitions only apply topygments
. If we wanted to create definitions only forMathJax
we could do something like:
For more see the github issue