Math

Arrr! Pirrrates

Fello' pirrrates, grog made us dizzy! Be awarrre some stuff may look weird in this trrranslat'n. Like Merrrmaids, do'n math or chemistrrry and stuff.

Th' math shortcode generates beautiful formatted math an' chemical formulae us'n th' MathJax library.

Math be also us'ble without enclos'n it 'n a shortcode or codefence but requires configurat'n by ye.

$$\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

While th' examples be us'n shorrrtcodes wit' named parameter it be recommended t' use codefences instead. This be because more an' more other software supports Math codefences (eg. GitHub) an' so yer markdown becomes more port'ble.

Ye be free t' also call this shortcode from yer own partials.

```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"    .
  "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)$$"
  "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)$$

Parameter

Name Default Notes
align center Allowed values be left, center or right.
<content> <empty> Yer formulae.

Configurat'n

MathJax be configured wit' default sett'ns but ye can cust'mize MathJax’s default sett'ns fer all o' yer files through a JSON object 'n yer hugo.toml or override these sett'ns per plank through yer planks frontmatter.

Th' JSON object o' yer hugo.toml / frontmatter be forwarded into MathJax’s configurat'n object.

See MathJax documentat'n fer all allowed sett'ns.

Global Configurat'n File

This example reflects th' default configurat'n also used if ye don’t define mathJaxInitialize

hugo.
[params]
  mathJaxInitialize = '{ "tex": { "inlineMath": [["\(", "\)"], ["$", "$"]], displayMath: [["\[", "\]"], ["$$", "$$"]] }, "options": { "enableMenu": false }'
params:
  mathJaxInitialize: '{ "tex": { "inlineMath": [["\(", "\)"], ["$", "$"]], displayMath:
    [["\[", "\]"], ["$$", "$$"]] }, "options": { "enableMenu": false }'
{
   "params": {
      "mathJaxInitialize": "{ \"tex\": { \"inlineMath\": [[\"\\(\", \"\\)\"], [\"$\", \"$\"]], displayMath: [[\"\\[\", \"\\]\"], [\"$$\", \"$$\"]] }, \"options\": { \"enableMenu\": false }"
   }
}

Page’s Frontmatter

Usually ye don’t need t' redefine th' global initializat'n sett'ns fer a single plank. But if ye do, ye have repeat all th' values from yer global configurat'n ye want t' keep fer a single plank as well.

Eg. If ye have redefined th' delimiters t' someth'n exotic like @ symbols 'n yer global config, but want t' additionally align yer math t' th' left fer a specific plank, ye have t' put this t' yer frontmatter:

+++
mathJaxInitialize = '{ "chtml": { "displayAlign": "left" }, { "tex": { "inlineMath": [["\(", "\)"], ["@", "@"]], displayMath: [["\[", "\]"], ["@@", "@@"]] }, "options": { "enableMenu": false }'
+++
---
mathJaxInitialize: '{ "chtml": { "displayAlign": "left" }, { "tex": { "inlineMath":
  [["\(", "\)"], ["@", "@"]], displayMath: [["\[", "\]"], ["@@", "@@"]] }, "options":
  { "enableMenu": false }'
---
{
   "mathJaxInitialize": "{ \"chtml\": { \"displayAlign\": \"left\" }, { \"tex\": { \"inlineMath\": [[\"\\(\", \"\\)\"], [\"@\", \"@\"]], displayMath: [[\"\\[\", \"\\]\"], [\"@@\", \"@@\"]] }, \"options\": { \"enableMenu\": false }"
}

Passthrough Configurat'n

Since 0.120.0 ye can use yer math without enclos'n it 'n a shortcode or codefence by us'n a passthrough configurat'n 'n yer hugo.toml:

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
            }
         }
      }
   }
}

In this case ye have t' tell th' theme that yer plank contains math by sett'n this 'n yer page’s frontmatter:

+++
disableMathJax = false
+++
---
disableMathJax: false
---
{
   "disableMathJax": false
}

Examples

Inline Math

Inline math be generated if ye use a single `$` as a delimiter around yer formulae: {{< math >}}$\sqrt{3}${{< /math >}}

Inline math be generated if ye use a single $ as a delimiter around yer formulae: $\sqrt{3}$

Blocklevel Math wit' Right Alignment

If ye delimit yer formulae by two consecutive `$$` it generates a new block.

{{< 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 >}}

If ye delimit yer formulae by two consecutive $$ it generates a new block.

$$\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)$$

Codefence

Ye can also use codefences.

```math
$$\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)$$
```
$$\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)$$

Passthrough

$$\left|
\begin{array}{cc}
a & b \\
c & d
\end{array}\right|$$
$$\left| \begin{array}{cc} a & b \\ c & d \end{array}\right|$$

Chemical Formulae

{{< math >}}
$$\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}$$
{{< /math >}}
$$\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}$$