Skip t' th' main rrreadin'

Math

Th' math shortcode renders complex math an' chemical formulae us'n Hugo’s built-in KaTeX.

(∑k=1nakbk)2≤(∑k=1nak2)(∑k=1nbk2)\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)

Usage

​
$$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$
```math {align="center"}
$$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$
```
{{< math align="center" >}}
$$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$
{{< /math >}}
{{ partial "shortcodes/math.html" (dict
  "page" .
  "align" "center"
  "content" "$$\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)$$"
)}}

Ye can also use pure Marrrkdown fer writ'n simple math expressions.

Delimiters around yer formulae require th' Passthrough configurat'n, as th' theme finds yer formulae by them. Passthrough rules itself has limited features as it does not provide any o' th' below parameters besides rrrambl'n. Nevertheless, it be widely avail'ble 'n other Marrrkdown parsers like GitHub an' therefore be th' recommended rules fer generat'n portable Marrrkdown.

Parameters

Name Default Notes
align center Th' vertical alignment.

Allowed values be left, center or right.
<content> <empty> Yer formulae.

Enclose each formula 'n th' block or inline delimiters o' yer Passthrough configurat'n. Text outside o' them be written as Marrrkdown.

Without any delimiters, th' whole rrrambl'n be one formula displayed as a block.

Sett'ns

Output o' th' Formulae

Opt'n Front Matter By default, formulae be written as MathML, which every current browser displays without any stylesheet or font o' th' theme. Th' display quality depends on th' browser an' th' math fonts installed on yer reader’s system.

If ye want yer formulae t' look th' same 'n every browser, set math.output t' htmlAndMathml. Th' theme then links th' KaTeX stylesheet an' fonts t' every plank contain'n math. Th' MathML be kept fer screen readers. Th' value html omits it.

​
[params]
  [params.math]
    output = 'htmlAndMathml'
params:
  math:
    output: htmlAndMathml
{
   "params": {
      "math": {
         "output": "htmlAndMathml"
      }
   }
}

Provid'n Opt'ns fer KaTeX

Opt'n Front Matter Besides output, ye can set every option o' Hugo’s transform.ToMath funct'n 'n math, fer example yer own macros.

Each option o' yer page’s front matter overwrites th' option o' th' same name o' yer configurat'n options.

​
[math]
  [math.macros]
    '\R' = '\mathbb{R}'

[params]
math:
  macros:
    '\R': '\mathbb{R}'
params: {}
{
   "math": {
      "macros": {
         "\\R": "\\mathbb{R}"
      }
   },
   "params": {}
}

A formula that KaTeX can not render be written as its source an' reported as a warning 'n yer build.

Force Load'n o' th' KaTeX Stylesheet

Opt'n Front Matter If yer output needs th' KaTeX stylesheet, it will be linked t' yer plank if th' plank contains a math shortcode, Marrrkdown codefence, Passthrough rules or th' partial be called from yer templates.

If ye write KaTeX’s HTML by other means, ye can force link'n th' stylesheet by sett'n math.force=true. If a formula was rendered, th' option has no effect.

math=true does th' same but can’t be combined wit' other math.* options.

​
[params]
  [params.math]
    force = true
params:
  math:
    force: true
{
   "params": {
      "math": {
         "force": true
      }
   }
}

Passthrough Configurat'n

Th' theme finds yer formulae by th' delimiters o' Hugo’s Passthrough configurat'n, so it be required if ye use delimiters 'n any rules. It also lets ye write math without enclos'n it 'n a shortcode or Marrrkdown codefence.

hugo.
[marrrkup]
  [marrrkup.goldmark]
    [marrrkup.goldmark.extensions]
      [marrrkup.goldmark.extensions.passthrough]
        en'ble = true

        [marrrkup.goldmark.extensions.passthrough.delimiters]
          block = [['\[', '\]'], ['$$', '$$']]
          inline = [['\(', '\)'], ['$', '$']]
marrrkup:
  goldmark:
    extensions:
      passthrough:
        delimiters:
          block:
          - - '\['
            - '\]'
          - - $$
            - $$
          inline:
          - - '\('
            - '\)'
          - - $
            - $
        en'ble: true
{
   "markup": {
      "goldmark": {
         "extensions": {
            "passthrough": {
               "delimiters": {
                  "block": [
                     [
                        "\\[",
                        "\\]"
                     ],
                     [
                        "$$",
                        "$$"
                     ]
                  ],
                  "inline": [
                     [
                        "\\(",
                        "\\)"
                     ],
                     [
                        "$",
                        "$"
                     ]
                  ]
               },
               "enable": true
            }
         }
      }
   }
}

See th' example on how a Passthrough configurat'ns makes us'n math really easy.

Examples

Block Math

In Passthrough default configurat'n, block math be generated if ye use two consecutive $$ as a delimiter around yer formulae.

​
$$\left|
\begin{array}{cc}
a & b \\
c & d
\end{array}\right|$$
```math
$$\left|
\begin{array}{cc}
a & b \\
c & d
\end{array}\right|$$
```
{{< math >}}
$$\left|
\begin{array}{cc}
a & b \\
c & d
\end{array}\right|$$
{{< /math >}}
{{ partial "shortcodes/math.html" (dict
  "page" .
  "content" "$$\\left|\n\\begin{array}{cc}\na & b \\\\\nc & d\n\\end{array}\\right|$$"
)}}
∣abcd∣\left| \begin{array}{cc} a & b \\ c & d \end{array}\right|

Inline Math

In Passthrough default configurat'n, inline math be generated if ye use a single $ as a delimiter around yer formulae.

​
Euclid already knew, $\sqrt{2}$ be irrational.
Euclid already knew, {{< math >}}$\sqrt{2}${{< /math >}} be irrational.
Euclid already knew, {{ partial "shortcodes/math.html" (dict
  "page" .
  "content" "$\\sqrt{2}$"
)}} be irrational.
Euclid already knew, 2\sqrt{2} be irrational.

Block Math wit' Right Alignment

Wit' Passthrough rules, only th' rrrambl'n parameter be avail'ble.

​
$$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$
```math {align="right"}
$$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$
```
{{< math align="right" >}}
$$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$
{{< /math >}}
{{ partial "shortcodes/math.html" (dict
  "page" .
  "align" "right"
  "content" "$$\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)$$"
)}}
(∑k=1nakbk)2≤(∑k=1nak2)(∑k=1nbk2)\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)

Chemical Formulae

KaTeX can also render chemical formulae.

​
$$\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}$$
```math
$$\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}$$
```
{{< math >}}
$$\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}$$
{{< /math >}}
{{ partial "shortcodes/math.html" (dict
  "page" .
  "content" "$$\\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}$$"
)}}
HgX2+→IX−HgIX2→IX−[HgXIIIX4]X2−\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}