a49697e53Add private use subtag requirements to multilingual pagea5c6bb4daAdd INFINI Pizza search engine45b732efaFix template lookup order for AMP pages30c672d0bnetlify: Hugo 0.133.17c766e724Update page resources documentationca802fbecDocument how to enable AsciiDoc syntax highlightingc3350f4cfUpdate definition of falsy to include zero time.Time valuesb0e5ab051Fir typo60f6cb63bUpdate migrations.mdec52c7ba1Improve formatting of example codee5681ad01Improve formatting of example codebdf3ffc73Clarify the various next/prev methodsb5505d22aClarify template lookup order for shortcodescf8dd7034Improve embedded.mde5dee2651Update transform.ToMath4d419a128Update pagination configuration to use new struct05d4fd597Update PrevInSection.mdfd33370edAdd new-in 0.133.0f9062042fAdd the new page config section205645e97Remove out-dated new-in3ed3673f7Fix typo41df91659Document the 'else with' construct introduced with Go 1.239c4697ab3netlify: Hugo 0.133.062506b052Merge branch 'temp133'877e1bfcdAdd config options page.nextPrevSortOrder/nextPrevInSectionSortOrdereb159fe62Update menu.mdefa7795a0Update themedbe8911adnetlify: Hugo 0.132.22f793d328Document passthrough render hooksa7ce9a5e8netlify: Hugo 0.132.12c137cb48Update blockquotes.mde0fa2f0d1Add new-in badge to blockquote render hook pagebf42bbe6bUpdate references to render hooks85a3d9958Update theme2dae72128Document blockquote render hooks8f5afb55dUpdate plainify return type160f22d0enetlify: Hugo 0.132.082b5586fbDocument transform.ToMath1efcbcddbtpl/transform: Make Plainify and ToMath return template.HTML31727be2edocs: Regen docshelper88a421426Merge commit 'a6e635ca7d905d9ec3ffd708db2694f680b03aae' git-subtree-dir: docs git-subtree-split:a49697e536
3.3 KiB
title, description, categories, keywords, action, aliases, toc
| title | description | categories | keywords | action | aliases | toc | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| transform.ToMath | Renders a math expression using KaTeX. |
|
|
true |
{{< new-in "0.132.0" >}}
{{% note %}} This feature was introduced in Hugo 0.132.0 and is marked as experimental.
This does not mean that it's going to be removed, but this is our first use of WASI/Wasm in Hugo, and we need to see how it works in the wild before we can set it in stone. {{% /note %}}
Arguments
- EXPRESSION
- The math expression to render using KaTeX.
- OPTIONS
- A map of zero or more options.
Options
These are a subset of the KaTeX options.
- output
- (
string). Determines the markup language of the output. One ofhtml,mathml, orhtmlAndMathml. Default ismathml.With
htmlandhtmlAndMathmlyou must include KaTeX CSS within theheadelement of your base template. For example:<head> ... <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css" integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous"> ... </head> - displayMode
- (
bool) Iftruerender in display mode, else render in inline mode. Default isfalse. - leqno
- (
bool) Iftruerender with the equation numbers on the left. Default isfalse. - fleqn
- (
bool) Iftruerender flush left with a 2em left margin. Default isfalse. - minRuleThickness
- (
float) The minimum thickness of the fraction lines inem. Default is0.04. - macros
- (
map) A map of macros to be used in the math expression. Default is{}. - throwOnError
- (
bool) Iftruethrow aParseErrorwhen KaTeX encounters an unsupported command or invalid LaTex. See error handling. Default istrue. - errorColor
- (
string) The color of the error messages expressed as an RGB hexadecimal color. Default is#cc0000.
Examples
Basic
{{ transform.ToMath "c = \\pm\\sqrt{a^2 + b^2}" }}
Macros
{{ $macros := dict
"\\addBar" "\\bar{#1}"
"\\bold" "\\mathbf{#1}"
}}
{{ $opts := dict "macros" $macros }}
{{ transform.ToMath "\\addBar{y} + \\bold{H}" $opts }}
Error handling
There are 3 ways to handle errors from KaTeX:
- Let KaTeX throw an error and make the build fail. This is the default behavior.
- Handle the error in your template. See the render hook example below.
- Set the
throwOnErroroption tofalseto make KaTeX render the expression as an error instead of throwing an error. See [options].
{{< code file=layouts/_default/_markup/render-passthrough-inline.html copy=true >}} {{ with transform.ToMath .Inner }} {{ with .Err }} {{ errorf "Failed to render KaTeX: %q. See %s" . $.Position }} {{ else }} {{ . }} {{ end }} {{ end }} {{- /* chomp trailing newline */ -}} {{< /code >}}