aboutsummaryrefslogtreecommitdiffhomepage
path: root/content/en/functions
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-09-01 14:51:15 +0200
committerBjørn Erik Pedersen <[email protected]>2024-09-01 14:51:15 +0200
commitdec8cd4ada29218971743333f8ac662a9c06aad8 (patch)
tree061b7bf51a4a1dd2e5730c3d65a3901c2c5ed04c /content/en/functions
parenta6e635ca7d905d9ec3ffd708db2694f680b03aae (diff)
downloadhugo-dec8cd4ada29218971743333f8ac662a9c06aad8.tar.gz
hugo-dec8cd4ada29218971743333f8ac662a9c06aad8.zip
Squashed 'docs/' changes from fcc3ed651..a49697e53
a49697e53 Add private use subtag requirements to multilingual page a5c6bb4da Add INFINI Pizza search engine 45b732efa Fix template lookup order for AMP pages 30c672d0b netlify: Hugo 0.133.1 7c766e724 Update page resources documentation ca802fbec Document how to enable AsciiDoc syntax highlighting c3350f4cf Update definition of falsy to include zero time.Time values b0e5ab051 Fir typo 60f6cb63b Update migrations.md ec52c7ba1 Improve formatting of example code e5681ad01 Improve formatting of example code bdf3ffc73 Clarify the various next/prev methods b5505d22a Clarify template lookup order for shortcodes cf8dd7034 Improve embedded.md e5dee2651 Update transform.ToMath 4d419a128 Update pagination configuration to use new struct 05d4fd597 Update PrevInSection.md fd33370ed Add new-in 0.133.0 f9062042f Add the new page config section 205645e97 Remove out-dated new-in 3ed3673f7 Fix typo 41df91659 Document the 'else with' construct introduced with Go 1.23 9c4697ab3 netlify: Hugo 0.133.0 62506b052 Merge branch 'temp133' 877e1bfcd Add config options page.nextPrevSortOrder/nextPrevInSectionSortOrder eb159fe62 Update menu.md efa7795a0 Update theme dbe8911ad netlify: Hugo 0.132.2 2f793d328 Document passthrough render hooks a7ce9a5e8 netlify: Hugo 0.132.1 2c137cb48 Update blockquotes.md e0fa2f0d1 Add new-in badge to blockquote render hook page bf42bbe6b Update references to render hooks 85a3d9958 Update theme 2dae72128 Document blockquote render hooks 8f5afb55d Update plainify return type 160f22d0e netlify: Hugo 0.132.0 82b5586fb Document transform.ToMath 1efcbcddb tpl/transform: Make Plainify and ToMath return template.HTML 31727be2e docs: Regen docshelper 88a421426 Merge commit 'a6e635ca7d905d9ec3ffd708db2694f680b03aae' git-subtree-dir: docs git-subtree-split: a49697e536ee0d477ab4e552cfa8dc74debeff27
Diffstat (limited to 'content/en/functions')
-rw-r--r--content/en/functions/go-template/_common/truthy-falsy.md4
-rw-r--r--content/en/functions/go-template/if.md2
-rw-r--r--content/en/functions/go-template/with.md14
-rw-r--r--content/en/functions/transform/Plainify.md2
-rw-r--r--content/en/functions/transform/ToMath.md112
5 files changed, 131 insertions, 3 deletions
diff --git a/content/en/functions/go-template/_common/truthy-falsy.md b/content/en/functions/go-template/_common/truthy-falsy.md
index c8fc9e09e..c41bb6561 100644
--- a/content/en/functions/go-template/_common/truthy-falsy.md
+++ b/content/en/functions/go-template/_common/truthy-falsy.md
@@ -2,4 +2,6 @@
# Do not remove front matter.
---
-In Go templates, the falsy values are `false`, `0`, any nil pointer or interface value, and any array, slice, map, or string of length zero. Everything else is truthy.
+The falsy values are `false`, `0`, any `nil` pointer or interface value, any array, slice, map, or string of length zero, and zero `time.Time` values.
+
+Everything else is truthy.
diff --git a/content/en/functions/go-template/if.md b/content/en/functions/go-template/if.md
index 19c887f25..9fdf80e99 100644
--- a/content/en/functions/go-template/if.md
+++ b/content/en/functions/go-template/if.md
@@ -34,7 +34,7 @@ Use with the [`else`] statement:
{{ end }}
```
-Use `else if` to check multiple conditions.
+Use `else if` to check multiple conditions:
```go-html-template
{{ $var := 12 }}
diff --git a/content/en/functions/go-template/with.md b/content/en/functions/go-template/with.md
index 3a73d54bb..3d628e28d 100644
--- a/content/en/functions/go-template/with.md
+++ b/content/en/functions/go-template/with.md
@@ -36,6 +36,20 @@ Use with the [`else`] statement:
{{ end }}
```
+Use `else with` to check multiple conditions:
+
+```go-html-template
+{{ $v1 := 0 }}
+{{ $v2 := 42 }}
+{{ with $v1 }}
+ {{ . }}
+{{ else with $v2 }}
+ {{ . }} → 42
+{{ else }}
+ {{ print "v1 and v2 are falsy" }}
+{{ end }}
+```
+
Initialize a variable, scoped to the current block:
```go-html-template
diff --git a/content/en/functions/transform/Plainify.md b/content/en/functions/transform/Plainify.md
index 040145170..681d41f72 100644
--- a/content/en/functions/transform/Plainify.md
+++ b/content/en/functions/transform/Plainify.md
@@ -6,7 +6,7 @@ keywords: []
action:
aliases: [plainify]
related: []
- returnType: string
+ returnType: template.HTML
signatures: [transform.Plainify INPUT]
aliases: [/functions/plainify]
---
diff --git a/content/en/functions/transform/ToMath.md b/content/en/functions/transform/ToMath.md
new file mode 100644
index 000000000..db93a7382
--- /dev/null
+++ b/content/en/functions/transform/ToMath.md
@@ -0,0 +1,112 @@
+---
+title: transform.ToMath
+description: Renders a math expression using KaTeX.
+categories: []
+keywords: []
+action:
+ aliases: []
+ related:
+ - content-management/mathematics
+ returnType: types.Result[template.HTML]
+ signatures: ['transform.ToMath EXPRESSION [OPTIONS]']
+aliases: [/functions/tomath]
+toc: 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](https://github.com/gohugoio/hugo/issues/12736) 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 of `html`, `mathml`, or `htmlAndMathml`. Default is `mathml`.
+
+ <!-- Indent to prevent spliting the description list. -->
+
+ With `html` and `htmlAndMathml` you must include KaTeX CSS within the `head` element of your base template. For example:
+
+ ```html
+ <head>
+ ...
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous">
+ ...
+ </head>
+ ```
+
+displayMode
+: (`bool`) If `true` render in display mode, else render in inline mode. Default is `false`.
+
+leqno
+: (`bool`) If `true` render with the equation numbers on the left. Default is `false`.
+
+fleqn
+: (`bool`) If `true` render flush left with a 2em left margin. Default is `false`.
+
+minRuleThickness
+: (`float`) The minimum thickness of the fraction lines in `em`. Default is `0.04`.
+
+macros
+: (`map`) A map of macros to be used in the math expression. Default is `{}`.
+
+throwOnError
+: (`bool`) If `true` throw a `ParseError` when KaTeX encounters an unsupported command or invalid LaTex. See [error handling]. Default is `true`.
+
+errorColor
+: (`string`) The color of the error messages expressed as an RGB [hexadecimal color]. Default is `#cc0000`.
+
+## Examples
+
+### Basic
+
+```go-html-template
+{{ transform.ToMath "c = \\pm\\sqrt{a^2 + b^2}" }}
+```
+
+### Macros
+
+```go-html-template
+{{ $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:
+
+1. Let KaTeX throw an error and make the build fail. This is the default behavior.
+1. Handle the error in your template. See the render hook example below.
+1. Set the `throwOnError` option to `false` to 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 >}}
+
+[error handling]: #error-handling
+[KaTeX options]: https://katex.org/docs/options.html
+[hexadecimal color]: https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color