Math
Mathematics is rendered by KaTeX at build time into HTML + MathML. A page with
formulas gains one local KaTeX stylesheet and nothing else — no JavaScript, no
request to a remote maths service. Inline formulas are \(…\), display
formulas are $$…$$ or \[…\], and there are math and chem fences. For
TikZ drawings or macro packages KaTeX does not support, use a pre-rendered
image.
Shortest form
An inline formula sits inside a sentence, with the surrounding spaces and punctuation outside the delimiters.
The shared buffer hit ratio is , where is blks_hit and is blks_read.
Display formulas
A formula in its own paragraph goes between $$, centred and set larger.
\[…\] is equivalent.
A B-tree with fan-out over keys has height:
A formula too long for one line scrolls horizontally inside the reading column rather than widening the layout; in print it stays static.
The math fence
The math fence is another way to write a display formula, and it does not
depend on the site’s passthrough configuration. On GitHub the source is an
ordinary code block.
That is Little’s law applied to a connection pool: in steady state, the concurrency you need is the arrival rate times the mean response time. A pool is usually far smaller than the number of clients.
Chemistry and units
The chem fence uses KaTeX’s mhchem extension, and its body is written
\ce{…}. The same extension typesets physical units.
For the syntax see the mhchem manual.
Numbered equations
An attribute line under a display formula makes it a numbered equation. num is
a string the author writes (3-1, 5.3) — the theme never counts — and #id
defaults to eq-<num>. The number shows to the right of the formula with a
localized “Equation” prefix.
See Equation 3-1: multiply by the retention period for the floor on archive disk size.
caption (plain text) is optional. #id and caption must appear with num —
there is no half-numbered equation. A duplicate ID on one page, or one number
pointing at two IDs, fails the build.
Cross references
The prose can reference a numbered equation with an ordinary link, as the
previous section does. For a cross-page reference, or when the “Equation N”
label should be filled in automatically, use xref:
Capacity planning starts from Equation 3-1.
xref may appear before its target; forward references are legal. For a
book-wide list of equations and the book-equations index, see
publishing books.
The eq shortcode
eq exists for sites that cannot enable passthrough; its body goes to the same
KaTeX renderer. Without parameters it is a display formula that registers no
number; with num it is equivalent to the attribute-line form above.
This site has passthrough on, so day-to-day writing uses $$. eq is for
migrated manuscripts and for sites that cannot change hugo.yml.
Site prerequisites
The math and chem fences need no configuration. The $$, \[…\] and
\(…\) delimiters depend on Goldmark’s passthrough extension. Hugo does not
merge a theme’s markup configuration, so this block has to live in the site’s
own configuration file. This site uses:
Every key is defined in
Configuration. Delimiters must
not collide with the prose: a single $ is deliberately not configured, so a
price like “$5” is never read as mathematics.
Output
| Output | Shape |
|---|---|
| HTML | KaTeX HTML + MathML rendered at build time; this page also loads a local katex.min.css, which pages without formulas never load |
| Same as HTML, static, long formulas do not scroll | |
| Markdown | The source as written: $$ blocks with their attribute line, math / chem fences, \(…\); the eq shortcode emits **Equation 3-2.** caption plus a $$ block |
| RSS | The same static text as Markdown |
No form loads JavaScript.
Parameter reference
Four spellings:
The attribute line {…} under a display formula:
The eq shortcode:
Broken TeX — an unknown command, unbalanced braces — fails the build, and the error carries KaTeX’s message and the source position.
Limits
- Delimiters are a site decision: whether
$$,\[…\]and\(…\)render depends solely on the passthrough extension in the site’smarkup.goldmark. The theme does not read amath: truefront matter key, and without the configuration$$shows literally. Themathfence andeqroute around it. - Only
$$blocks andeqcan be numbered: themathfence takes no attribute line, so switch spelling when you need a number. - Numbers are hand-written: the theme neither counts nor renumbers, so
reordering chapters means editing
num. - Inline formulas take no attributes: the attribute line applies to display formulas only.
captionis plain text: Markdown inside it is not parsed.
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