43. 【GitHub Pages】🧮 How to Render Math (MathJax) on GitHub Pages (Jekyll)

topics: [“GitHubPages”, “Jekyll”, “MathJax”, “LaTeX”, “Qiita”]


On Qiita, mathematical expressions (LaTeX) are rendered automatically
just by writing them in Markdown.

On the other hand, GitHub Pages (Jekyll)
does not render math expressions by default.

In this article, we explain how to:

Keep the same syntax as Qiita ($...$, $$...$$)
and render mathematical expressions correctly on GitHub Pages

using a minimal, copy-and-paste–friendly configuration.


🎯 Goal

We aim to achieve the following:


🧩 Prerequisites


⚙️ Configure _config.yml

First, configure Jekyll to assume MathJax-based math rendering.

markdown: kramdown
kramdown:
  input: GFM
  syntax_highlighter: rouge
  math_engine: mathjax

📌 Notes


🧠 Add MathJax to head.html

Next, load MathJax in _includes/head.html.

<script>
  window.MathJax = {
    tex: {
      inlineMath: [['$', '$'], ['\\(', '\\)']],
      displayMath: [['$$', '$$'], ['\\[', '\\]']]
    }
  };
</script>
<script defer src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>

📌 Notes


✏️ Writing Math in Markdown

Inline Math

Ohm’s law is expressed as:

$V = IR$

(This is the basic V–I characteristic, voltage vs. current.)


Block Math

A representative transfer function of a second-order system is:

\[G(s) = \frac{\omega_n^2}{s^2 + 2\zeta\omega_n s + \omega_n^2}\]

You can write it exactly the same way as on Qiita.


🔍 Live Demo (Rendered Output)

You can verify that math expressions are actually rendered
using this real demo page:


⚠️ Common Pitfalls


📝 Summary