Skip to content

Commit

Permalink
Merge pull request #45 from deining/latex-standard-syntax
Browse files Browse the repository at this point in the history
feat: support LaTeX formulae via standard syntax or math code block
  • Loading branch information
markdumay authored Feb 24, 2024
2 parents 1aef038 + 0c1ede6 commit 029d396
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
26 changes: 26 additions & 0 deletions exampleSite/content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,29 @@ This is not an inline formula:

$$x = a_0 + \frac{1}{a_1 + \frac{1}{a_2 + \frac{1}{a_3 + a_4}}}$$
$$\forall x \in X, \quad \exists y \leq \epsilon$$

As of Hugo v0.122.0, you may author LaTeX formulae using the standard syntax directly in Markdown

````markdown
The probability of getting \(k\) heads when flipping \(n\) coins is:
\[
\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k}
\]
````

For details, please have a look at the section [Mathematics in Markdown ](https://gohugo.io/content-management/mathematics/) of the official hugo documentation.

As an alternative to the standard syntax used above, formulae can also be authored using a [GLFM math block](https://docs.gitlab.com/ee/user/markdown.html#math):

````markdown
The probability of getting \(k\) heads when flipping \(n\) coins is:
```math
\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k}
```
````
Both standard syntax and `math` block render to the same formula:

The probability of getting \(k\) heads when flipping \(n\) coins is:
```math
\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k}
```
14 changes: 13 additions & 1 deletion exampleSite/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ title = 'Test site for mod-katex'
target = "static/js/auto-render.js"
[[module.imports.mounts]]
source = "assets/js/modules/katex/katex-autoload.js"
target = "static/js/katex-autoload.js"
target = "static/js/katex-autoload.js"
[[module.imports.mounts]]
source = 'layouts'
target = 'layouts'

[markup]
[markup.goldmark]
[markup.goldmark.extensions]
[markup.goldmark.extensions.passthrough]
enable = true
[markup.goldmark.extensions.passthrough.delimiters]
block = [['\[', '\]'], ['$$', '$$']]
inline = [['\(', '\)']]
3 changes: 3 additions & 0 deletions layouts/_default/_markup/render-codeblock-math.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="math">$$
{{ .Inner | safeHTML -}}
$$</div>{{ "" -}}

0 comments on commit 029d396

Please sign in to comment.