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 MathJax.
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 this into a page
variable so only pages with the variable latex
in its frontmatter will include the script.
{% 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_r} \)
\[\large{\color{white}{m_r = \frac{m_0}{\sqrt{1 - \frac{v^2}{c^2}}}}}\]Where \( \color{green}{v} \) is the speed and \( \color{green}{c} \) is the speed of light.
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.
You can write a comment
Please stick to common netiquette when posting comments. Avoid any form of personal attacks, harassment, hate speech, sexism, racism or otherwise inappropriate content. Comments that violate common rules of civilized communication among humans will be deleted without further notice.
Note: if you do not provide a user name, your comment will be posted as AnonymousBasic Markdown formatting is enabled