-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update math-typesetting.md (#21)
- Simplify the content - Give examples of how to enable KaTeX - Give an example of inline math
- Loading branch information
Peng-Yu Chen
authored
Apr 1, 2023
1 parent
64bfa09
commit b2fcfc5
Showing
1 changed file
with
34 additions
and
33 deletions.
There are no files selected for viewing
67 changes: 34 additions & 33 deletions
67
exampleSite/content/posts/math-typesetting/math-typesetting.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,50 @@ | ||
--- | ||
author: Hugo Authors | ||
title: Math Typesetting | ||
date: 2023-02-05 | ||
date: 2023-04-01 | ||
description: A brief guide to setup KaTeX | ||
math: true | ||
--- | ||
|
||
Mathematical notation in a Hugo project can be enabled by using third party JavaScript libraries. | ||
Mathematical notation in a Hugo project can be enabled by using | ||
[third party JavaScript libraries](https://github.com/hugo-sid/hugo-blog-awesome/blob/main/layouts/partials/helpers/katex.html). | ||
|
||
<!--more--> | ||
|
||
In this example we will be using [KaTeX](https://katex.org/) | ||
|
||
- Create a partial under `/layouts/partials/math.html` | ||
- Within this partial reference the [Auto-render Extension](https://katex.org/docs/autorender.html) or host these scripts locally. | ||
- Include the partial in your templates like so: | ||
|
||
```bash | ||
{{ if or .Params.math .Site.Params.math }} | ||
{{ partial "math.html" . }} | ||
{{ end }} | ||
``` | ||
- To enable KaTex globally set the parameter `math` to `true` in a project's configuration | ||
- To enable KaTex on a per page basis include the parameter `math: true` in content files | ||
- To enable KaTeX globally, set the parameter `math` to `true` in a project's | ||
configuration: | ||
- `config.toml` | ||
```toml | ||
[params] | ||
math = true | ||
``` | ||
- `config.yaml` | ||
```yaml | ||
params: | ||
math: true | ||
``` | ||
- To enable KaTeX on a per page basis, include the parameter `math: true` in | ||
Front Matter of Markdown content files: | ||
|
||
``` | ||
--- | ||
math: true | ||
--- | ||
``` | ||
|
||
**Note:** Use the online reference of | ||
[Supported TeX Functions](https://katex.org/docs/supported.html) | ||
|
||
**Note:** Use the online reference of [Supported TeX Functions](https://katex.org/docs/supported.html) | ||
### Examples | ||
|
||
{{< math.inline >}} | ||
{{ if or .Page.Params.math .Site.Params.math }} | ||
<!-- KaTeX --> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous"> | ||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script> | ||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script> | ||
{{ end }} | ||
{{</ math.inline >}} | ||
- Block math: | ||
|
||
### Examples | ||
$$ | ||
\varphi = 1+\frac{1} {1+\frac{1} {1+\frac{1} {1+\cdots} } } | ||
$$ | ||
|
||
{{< math.inline >}} | ||
<p> | ||
Inline math: \(\varphi = \dfrac{1+\sqrt5}{2}= 1.6180339887…\) | ||
</p> | ||
{{</ math.inline >}} | ||
- Inline math: | ||
|
||
Block math: | ||
$$ | ||
\varphi = 1+\frac{1} {1+\frac{1} {1+\frac{1} {1+\cdots} } } | ||
$$ | ||
This is an inline polynomial: $5x^2 + 2y -7$. |