Math
Write formulas in TeX and Hugo turns them into HTML and MathML with KaTeX while
it builds the site, so readers download one local stylesheet and no script,
and nothing is sent to a remote math service. Use \(…\) inside a sentence,
$$…$$ or \[…\] for a formula on its own line, and the math and chem
fences where you cannot change the site configuration. For TikZ drawings or
macro packages KaTeX does not support, use a pre-rendered
image.
Site prerequisites
The $$, \[…\] and \(…\) delimiters work only after you enable Goldmark’s
passthrough extension in your site’s own configuration; Hugo does not inherit
markup settings from a theme, so OINK cannot do it for you. A math: true
key, in front matter or in params, does not enable anything: without this
block, $$ stays on the page as literal text.
A single $ is deliberately left out of the inline delimiters, so a price
such as “$5” in prose is never read as the start of a formula.
Configuration describes each key. The math and
chem fences and the eq shortcode need none of this.
Shortest form
An inline formula sits in the sentence; keep the surrounding spaces and punctuation outside the delimiters.
The shared buffer hit ratio is , where is blks_hit and is blks_read.
Display formulas
Put a formula in its own paragraph between $$ delimiters, or \[…\], to
show it larger and centered.
A B-tree with fan-out over keys has height:
A formula too long for the column scrolls sideways inside it instead of widening the page.
The math fence
A math fence is another way to write a display formula. It needs no
passthrough configuration, and GitHub shows it as an ordinary code block.
This is Little’s law applied to a connection pool: in steady state, the connections you need equal the arrival rate times the mean response time, which is why a pool can be much smaller than the number of clients.
Chemistry and units
A chem fence typesets a \ce{…} body with KaTeX’s mhchem extension, which
also handles physical units.
The mhchem manual documents the syntax.
Numbered equations
Put an attribute line under a display formula to number it. You write the
number yourself in num, such as 3-1 or 5.3, because the theme does not
count; the anchor defaults to #eq-<num>. The number appears at the right of
the formula after a localized “Equation” label.
See Equation 3-1: multiply by the retention period for the floor on archive disk size.
caption is optional plain text, and both #id and caption need num. An
incomplete attribute line warns and drops the parts it cannot use; a duplicate
target warns and keeps the first. On a narrow screen a long caption wraps
inside the column.
Cross references
An ordinary link reaches a numbered equation on the same page, as above. To
link across pages, or to have the “Equation N” label written for you, use
xref:
Capacity planning starts from Equation 3-1.
xref may come before the equation it points to. For a book-wide list of
equations and the book-equations index, see
publishing books.
The eq shortcode
eq renders with the same KaTeX engine for sites that cannot enable
passthrough, such as a migrated manuscript or a site whose hugo.yml you do
not control. Without parameters it is an unnumbered display formula; with
num it matches the attribute-line form. Where you can enable passthrough,
$$ is shorter.
Output
No form loads JavaScript. A page with formulas loads a local katex.min.css
and the WOFF2 fonts it names; a page without formulas loads neither. Print
shows formulas the same way, without scrolling. The Markdown output keeps the
TeX source as written, except that an eq shortcode becomes
**Equation 3-2.** caption followed by a $$ block. RSS carries rendered
KaTeX HTML and MathML; a numbered $$ block gets a bold “Equation N.” line
before it, and a numbered eq keeps its “Equation N” caption below the
formula.
Parameter reference
The four ways to write a formula:
The attribute line {…} under a display formula:
The eq shortcode:
Invalid TeX does not stop the build. It warns with KaTeX’s error message and the source position, and the page shows the expression as written, so search the build log for these warnings before you publish.
Limits
- Only
$$blocks andeqcan be numbered. Themathfence takes no attribute line, so switch forms when you need a number. - The theme never counts or renumbers equations. When you reorder chapters,
update
numyourself. - Inline formulas take no attributes; the attribute line applies only to display formulas.
captionis plain text, so Markdown in it appears literally.
Related
- Code blocks — fence attributes and numbered examples
- Images — figures use the same
{#id num=}numbering - Publishing books — lists of equations and cross-page references
- Configuration — the
markup.goldmarkkeys