KaTeX Extension

Rendering math is enabled using KaTeX. The extension adds the ability to create numbered equations as well as reference the equations with traditional shortcut syntax: e.g., [eq-heat].

Table 1: Available configure options for the KatexExtension object.

KeyDefaultDescription
activeTrueToggle for disabling the extension. This only changes the initial active state, use setActive to control at runtime.
macrosNoneMacro definitions to apply to equations.
prefixEq.The prefix to used when referring to an equation by the \\label content.

Block Equations

Numbered and non-numbered equations are defined using the \begin{equation} and \end{equation} environment common to LaTeX mathematics, as shown in Example 1.

Example 1: Example of syntax for creating numbered equations with KaTeX.

\begin{equation}
y = a\cdot x + b
\end{equation}

(1)

To include a non-numbered equation, simply use the * version of the environment, as shown in Example 2.

Example 2: Example of syntax for creating non-numbered equations with Katex.

\begin{equation*}
c^2 = a^2 + b^2
\end{equation*}

It is possible to reference numbered block equations. First, the equation must contain a label. A label is added using traditional \label{my-eq} command. Then within the text this label can be used within a shortcut link, e.g. [my-eq] (see Shortcut links).

Example 3 provides a complete example of creating and referencing an equation. The prefix is dictated by the extension prefix configuration option (see Table 1).

Example 3: Example that references a labeled, numbered block equation.

[eq-label] is a famous equation.

\begin{equation}
\label{eq-label}
E = mc^2
\end{equation}

Eq. (2) is a famous equation.

(2)

Inline Equations

Inline equations also use traditional LaTeX syntax, i.e., the content is wrapped in single $ as shown below.

Example 4: Example of an inline LaTeX equation.

This $y=2\phi$ is inline.

This is inline.

Macros

It is possible to define macros within extension configuration. This is done using the 'macros' configuration parameter (see Table 1). For example, the main configuration file for contains the following allowing for equation in Example 5 to be defined.

    MooseDocs.extensions.katex:
        macros:
            \pf: "\\frac{\\partial #1}{\\partial #2}"
(modules/doc/config.yml)

Example 5: Example use of a macro defined in configuration file.

$\pf{T}{t} = c$