Open jmooring opened 3 days ago
{{- transform.ToMath .Inner (dict "displayMode" (eq .Type "block")) -}}
We should fix this, but you can do:
{{ $result := transform.ToMath .Inner (dict "displayMode" (eq .Type "block")) }}
{{ with $result.Error }}
// Print error.
{{ with else $result.Value }}
{{ end }}
... I'm not totally sure I got the with else syntax correct.
If I remember correctly, there's also an option to print syntax errors in the rendered output.
This:
{{ with transform.ToMath `\\frac 1 2` (dict "displayMode" true) }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ . }}
{{ end }}
{{ end }}
Throws this error:
ERROR not a function
So... that one's not much help either.
So... that one's not much help either.
Well, it's more ... to the point.
I have done some investigating, and the very short not a function
error message is thrown by katex.renderToString
, which smells like an upstream parser bug.
at useStrictBehavior (function.mjs:407:51)\n at handler (function.mjs:6942:70)\n at callFunction (function.mjs:13933:21)\n at parseFunction (function.mjs:13919:19)\n at parseGroup (function.mjs:14206:23)\n at parseAtom (function.mjs:13796:23)\n at parseExpression (function.mjs:13686:25)\n at parse (function.mjs:13635:26)\n at parseTree2 (function.mjs:14376:23)\n at renderToDomTree2 (function.mjs:14425:18)\n at renderToString2 (function.mjs:14406:18)\n at render3 (function.mjs:14532:26)\n at readInput (function.mjs:41:13)\n at <anonymous> (function.mjs:14535:3)\n at <anonymous> (function.mjs:14536:1)\n
markdown (note the erroneous double-escape before "frac"):
This works fine:
Another example that triggers the error:
In this case, the
text{Ω}
bit is the the problem. This works fine:Note that the KaTeX engine renders both of the above without error.
test case (the last three assertions need some work)
```go func TestFoo(t *testing.T) { t.Parallel() files := ` -- hugo.toml -- disableKinds = ['home','rss','section','sitemap','taxonomy','term'] [markup.goldmark.extensions.passthrough] enable = true [markup.goldmark.extensions.passthrough.delimiters] block = [['\[', '\]']] inline = [['\(', '\)']] -- layouts/_default/single.html -- {{ .Content }} -- layouts/_default/_markup/render-passthrough.html -- {{- transform.ToMath .Inner (dict "displayMode" (eq .Type "block")) -}} -- content/p1.md -- --- title: p1 --- \(\\frac 1 2\) -- content/p2.md -- --- title: p2 --- \[\\frac 1 2\] -- content/p3.md -- --- title: p3 --- \(I = \frac{ 12 \text{V} }{ 4 \text{Ω} }\) -- content/p43.md -- --- title: p4 --- \[I = \frac{ 12 \text{V} }{ 4 \text{Ω} }\] ` b := hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", ``) b.AssertFileContent("public/p2/index.html", `TBD`) b.AssertFileContent("public/p3/index.html", `TBD`) b.AssertFileContent("public/p4/index.html", `TBD`) } ```