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.

Passthrough rules finds yer formulae by their delimiters an' requires th' Passthrough configurat'n. It 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.

Th' codefence, shortcode an' partial rules take yer formula without delimiters.

Parameters

Name Default Notes
align center Th' horizontal alignment.

Allowed values be left, center or right.
<option> <empty> Any option o' Hugo’s transform.ToMath funct'n fer this formula. It overwrites th' option o' th' same name o' yer configurat'n.

displayMode defaults t' true, display'n th' formula as a block. Set it t' false t' display th' formula inline. Wit' Passthrough rules, it be decided by th' delimiters around yer formula.

Not avail'ble fer th' codefence rules, which always displays th' formula as a block.
<content> <empty> Yer formula without delimiters.

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.toMath.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:
  math:
    toMath:
      output: htmlAndMathml
[params]
  [params.math]
    [params.math.toMath]
      output = 'htmlAndMathml'
{
   "params": {
      "math": {
         "toMath": {
            "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.toMath, fer example yer own macros. displayMode be ignored here, as it be decided fer each formula by its delimiters or th' parameters o' its call.

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

Cap'n Hugo lowercases th' names o' a map 'n yer configurat'n an' front matter, so a macro \Field would be known as \field. Give yer macros as a list o' name an' definit'n pairs instead.

​
params:
  math:
    toMath:
      macros:
      - - '\Field'
        - '\mathbb{F}'
[params]
  [params.math]
    [params.math.toMath]
      macros = [['\Field', '\mathbb{F}']]
{
   "params": {
      "math": {
         "toMath": {
            "macros": [
               [
                  "\\Field",
                  "\\mathbb{F}"
               ]
            ]
         }
      }
   }
}

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 t' true. If a formula was rendered, th' option has no effect.

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

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

Passthrough Configurat'n

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

hugo.
marrrkup:
  goldmark:
    extensions:
      passthrough:
        delimiters:
          block:
          - - $$
            - $$
          inline:
          - - $
            - $
        en'ble: true
[marrrkup]
  [marrrkup.goldmark]
    [marrrkup.goldmark.extensions]
      [marrrkup.goldmark.extensions.passthrough]
        en'ble = true

        [marrrkup.goldmark.extensions.passthrough.delimiters]
          block = [['$$', '$$']]
          inline = [['$', '$']]
{
   "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

Wit' th' above Passthrough 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

Wit' th' above Passthrough configurat'n, inline math be generated if ye use a single $ as a delimiter around yer formulae. Wit' th' shortcode an' partial, set displayMode t' false.

​
Euclid already knew, $\sqrt{2}$ be irrational.
Euclid already knew, {{< math displayMode="false" >}}\sqrt{2}{{< /math >}} be irrational.
Euclid already knew, {{ partial "shortcodes/math.html" (dict
  "page" .
  "content" "\\sqrt{2}"
  "displayMode" "false"
)}} 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-}