jekyll에서 mathjax 사용하기

1 분 소요

설치 방법

jekyll이 나의 mathjax를 알까?
다음과 같이 파일들을 생성 또는 수정해야 mathjax 문법을 렌더링할 수 있다.

mathjax_support.html

/_includes/mathjax_support.html 파일을 생성하여 다음과 같이 입력하고 저장한다.

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        TeX: {
            equationNumbers: {
                autoNumber: "AMS"
              }
          },
          tex2jax: {
              inlineMath: [ ["$","$"], ["\\(","\\)"] ],
              displayMath: [ ["$$","$$"], ["\\[","\\]"] ],
              processEscapes: true
          }
    });
    MathJax.Hub.Register.MessageHook("Math Processing Error",function (message) {
        alert("Math Processing Error: "+message[1]);
      });
    MathJax.Hub.Register.MessageHook("TeX Jax - parse error",function (message) {
        alert("Math Processing Error: "+message[1]);
      });
</script>

<script type="text/javascript" async
  src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"></script>

default.html

/_layouts/default.html 의 <head>의 마지막 부분에 다음을 추가한다.
현재 page에 mathjax라는 이름의 속성이 존재하면 mathjax_support.html을 include 하겠다는 의미이다.

{% if page.mathjax %}
    {% include mathjax_support.html %}
{% endif %}

minimal mistakes theme의 경우, 추가된 모습은 다음과 같다.

<head>
    {% include head.html %}
    {% include head/custom.html %}
    <!-- head의 마지막 부분에 -->
    {% if page.mathjax %}
      {% include mathjax_support.html %}
    {% endif %}
</head>

포스트 작성하기

이제 mathjax를 적용하고 싶은 post의 yaml block에 mathjax: true를 추가하면 된다.

---
title:  "github page jekyll theme 에서 mathjax 사용하기"
categories:
    - mathjax
<!-- 이렇게 -->
mathjax: true
---

사용 패턴

Inline

inline 방식은 문장 안에 포함될 수 있다.

$y = \sum_{i}{x^i}$

이렇게 $y = \sum_{i}{x^i}$ 문장 안에 나타난다.

Display

display 방식은 그 자체로 block이 되어 중앙 정렬된다.

(공백)
$$
    f : \theta\to 
    \begin{pmatrix}
    \cos\theta & -\sin\theta \\
    \sin\theta & \cos\theta \\
    \end{pmatrix}
$$
(공백)
\[y = \sum_{i}{x^i}\] \[f : \theta\to \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \\ \end{pmatrix}\]

반드시 delimiters로 \\(, \\[ 쌍을 설정하고 processEscapes: true 를 설정해야 한다. 그렇지 않으면 mathjax 구문 내에서 \\ 가 인식되지 않는다.

참고

tex2jax 전처리 설명
kramdown 이슈
minimal-mistakes 이슈

댓글남기기