Getting LaTeX into a Jekyll site
Author: | Admin |
Title: | Getting LaTeX into Jekyll |
Language: | en-US |
Number of words: | 40 |
Category: | Jekyll |
Created: | 01:22 on Monday, 06. May 2024 |
Modified: | 01:22 on Monday, 06. May 2024 |
Keywords: | jekyll, liquid, latex, tex, markdown |
Excerpt: | A simple and easy way to allow LaTeX in a markdown document within a Jekyll website |
Tags: | Jekyll |
Page layout: | nonav |
This is just a quick reminder for myself how to render \( \LaTeX \) in a markdown page using MathJax1. First, embed the MathJax script somewhere in your page header. Using the CDN is the easiest solution, but it’s also possible to host MathJax locally. The MathJax docs explain how.
I’ve wrapped the script loading fragment into a page variable, so only pages with the variable latex
in
its frontmatter will include the script. This is a performance optimization and completely optional
though — if you need the script on the majority of your pages you can just include it on every page.
Browsers will cache it anyway and not always reload a fresh copy.
{% if page.latex != blank %}
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
{% endif %}
And then write the LaTeX formula. Note that in markdown, the standard delimiters like \[ and \( must be
double-escaped with two backslashes.
Example showing a formula and some inline \( \LaTeX \)
Given the rest mass \( \color{green}{m_0} \), the relativistic mass is calculated as \( \color{green}{m_{rel}} \)
\[\large{\color{white}{m_{rel} = \frac{m_0}{\sqrt{1 - \frac{v^2}{c^2}}}}}\]Where \( \color{green}{v} \) is the speed relative to the observer and \( \color{green}{c} \) is the speed of light.
The \( \LaTeX \) code for this formula looks as follows in the markdown document:
\large{\color{white}{m_{rel} = \frac{m_0}{\sqrt{1 - \frac{v^2}{c^2}}}}}
Summary
MathJAX is an easy solution for getting \( \LaTeX \) typesetting into simple HTML documents and works well with a static Jekyll website where documents are written in the Markdown language. It is very easy to integrate and requires only minimal configuration. Including a single JavaScript file is usually sufficient.
-
A display engine to render mathematical formulas, written in JavaScript. Easy to install, integrate and use. ↩