feat(math): add optional MathJax support (#707)

* feat: add MathJax option

* docs: move math engine note

* refactor: update LaTeX documentation and improve MathJax integration

- Adjusted LaTeX documentation for clarity and formatting.
- Enhanced MathJax configuration in the templates to support both KaTeX and MathJax rendering.
- Removed deprecated comments and streamlined the script loading process for MathJax.
- Updated the passthrough extension settings in the Hugo configuration for better compatibility with LaTeX math expressions.

* docs: simplify LaTeX documentation and clarify configuration steps

- Updated LaTeX documentation to reflect that KaTeX is enabled by default, removing the need for manual activation.
- Added examples for using LaTeX math expressions and clarified the configuration for the passthrough extension in Hugo.
- Enhanced MathJax section to emphasize its use as an alternative rendering engine.
This commit is contained in:
Xin
2025-06-14 14:36:10 +01:00
committed by GitHub
parent e22b8d5c0e
commit 7031718449
9 changed files with 236 additions and 102 deletions

View File

@ -1,22 +1,10 @@
---
title: "LaTeX"
weight: 4
math: true
---
\(\KaTeX\) LaTeX 数式レンダリングするために使用されます。ページのフロントマターで `math``true` に設定することで、ページごとに有効にすることができます。
<!--more-->
```yaml {filename="page.md"}
---
title: "LaTeX を使用した私のページ"
math: true
---
```
有効にすると、KaTeX のスクリプト、スタイルシート、フォントが自動的にサイトに含まれます。Markdown コンテンツ内で LaTeX 数式を使用できます。
デフォルトでは、\(\KaTeX\) LaTeX 数式レンダリングに使用されます。
手動での有効化は不要で、Markdown コンテンツで LaTeX 数式をすぐに使い始めることができます。
## 例
@ -40,20 +28,6 @@ $$F(\omega) = \int_{-\infty}^{\infty} f(t) e^{-j\omega t} \, dt$$
$$F(\omega) = \int_{-\infty}^{\infty} f(t) e^{-j\omega t} \, dt$$
> [!IMPORTANT]
> Hugo 設定ファイルで [パススルー拡張機能](https://gohugo.io/content-management/mathematics/) を有効にして設定してください。これにより、複雑な式のレンダリング問題を回避するために、デリミタ内の生のコンテンツが保持されます。
```yaml {filename="hugo.yaml"}
markup:
goldmark:
extensions:
passthrough:
delimiters:
block: [['\[', '\]'], ['$$', '$$']]
inline: [['\(', '\)']]
enable: true
```
例えば、aligned 環境を使用する場合:
```latex {filename="page.md"}
@ -78,6 +52,23 @@ $$
\end{aligned}
$$
## 設定
> [!IMPORTANT]
> Hugo が Markdown コンテンツ内の LaTeX 数式を検出できるように、Hugo 設定ファイルで [パススルー拡張機能](https://gohugo.io/content-management/mathematics/) を有効にして設定してください。
```yaml {filename="hugo.yaml"}
markup:
goldmark:
extensions:
passthrough:
delimiters:
block: [['\[', '\]'], ["$$", "$$"]]
inline: [['\(', '\)']]
enable: true
```
## サポートされている関数
サポートされている関数の一覧については、[KaTeX サポートされている関数](https://katex.org/docs/supported.html) を参照してください。
@ -94,4 +85,25 @@ $$
$$\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}$$
```
$$\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}$$
次のようにレンダリングされます:
$$\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}$$
## 数式エンジン
### MathJax
デフォルトでは、ビルドプロセス中に LaTeX 数式をレンダリングするために [KaTeX][katex] が使用されます(推奨)。
代替として、[MathJax][mathjax] を使用して数式をレンダリングすることもできます。
MathJax を使用するには、`hugo.yaml` 設定ファイルに以下を追加してください:
```yaml {filename="hugo.yaml"}
params:
math:
engine: mathjax
```
[katex]: https://katex.org/
[mathjax]: https://www.mathjax.org/