记录一下 PaperMod 主题加入 Katex 公式支持的方法,以便之后博文的公式书写。当然,大部分数学的内容还是会写在 Astroid 中。
创建 layouts/partials/math.html
文件,写入以下内容:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.2/dist/katex.min.css" integrity="sha384-bYdxxUwYipFNohQlHt0bjN/LCpueqWz13HufFEV1SUatKs1cm4L6fFgCi1jT643X" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.2/dist/katex.min.js" integrity="sha384-Qsn9KnoKISj6dI8g7p1HBlNpVx0I8p1SvlwOldgi3IorMle61nQy4zEahWYtljaz" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.2/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.body, {
// customised options
// • auto-render specific keys, e.g.:
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false},
{left: '\\(', right: '\\)', display: false},
{left: '\\[', right: '\\]', display: true}
],
// • rendering keys, e.g.:
throwOnError : false
});
});
</script>
然后创建 layouts/partials/extend_head.html
文件,写入以下内容:
{{ if or .Params.math .Site.Params.math }}
{{ partial "math.html" . }}
{{ end }}
当我们确认某一篇博客需要加入数学公式支持时,我们需要在markdown文件键入以下内容:
---
title:
date:
tags:
math: true
---
数学公式测试:
$$x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}$$
$$ q(x,t)= \begin{cases}(t-k+1)x^2,\quad \ \ & t\in\big(k-1,k-\dfrac{1}{2}\big],\\ (k-t)x^2, \quad \ \ & t\in\big(k-\dfrac{1}{2},k\big], \end{cases} $$
$$ \left|\begin{array}{cccc} 1 &6 & 9 \\ 7 &90 & f(x) \\ 9 & \psi(x) &g(x) \\ \end{array}\right| $$
$$ \begin{cases} \ u_{tt}(x,t)= b(t)\triangle u(x,t-4)&\\ \ \hspace{42pt}- q(x,t)f[u(x,t-3)]+te^{-t}\sin^2 x, & t \neq t_k; \\ \ u(x,t_k^+) - u(x,t_k^-) = c_k u(x,t_k), & k=1,2,3\ldots ;\\ \ u_{t}(x,t_k^+) - u_{t}(x,t_k^-) =c_k u_{t}(x,t_k), & k=1,2,3\ldots\ . \end{cases} $$