I need to have a string as a paramters to a shortcode that has double backslashes in it. How do I escape a DOUBLE backslash?
for example… {{<math `line 1\\line2`>}}
(I want the two back slashes to get passed in the string)
This generates a build error:
failed to render shortcode “math”: failed to process shortcode: “/Users/gleicher/Projects/559/Workbooks25/common/themes/Workbook/layouts/shortcodes/math.html:5:13”: execute of template failed at <transform.ToMath>: error calling ToMath: not a function
The shortcode seems to work for everything else - other than double backslashes.
I’ve tried using 4 backslashes, but that creates the same problem.
no solution , just a hint for someone for analysis:
no shortcode used, just called in “main” block of home template
that errors out:
{{- transform.ToMath `line1\\line2` (dict "displayMode" true) -}}
Error: error building site: render: failed to render pages:
render of "/content/_index.md" failed: "\layouts\home.html:3:16":
execute of template failed: template: home.html:3:16:
executing "main" at <transform.ToMath>:
error calling ToMath: not a function
There seem to be some uses of the double backslash in KaTeX that cause Hugo to forget that ToMath is a function - but only in display mode.
My examples that break (I have several) are valid LaTeX (and could be rendered correctly by MathJax or LaTeX). This all happened when switching from MathJax to KaTeX.
When I look at the Hugo source code, I see nothing… I don’t even see the “display” parameter in the code (I am looking at transform.go around 221)
If it’s a KaTeX problem… why does Hugo forget that KaTeX exists (that ToMath isn’t a function)?
Actually, the plot thickens…
LaTeX & KaTeX Math Rendering: The Double Backslash \\ in Markdown - upyesp - suggests that “\cr” is a synonym for \ - and indeed, Supported Functions · KaTeX suggests that it is a valid line separator. But, if I try to use it (in a place where the double backslash breaks), I get a valid error message: execute of template failed: template: _shortcodes/math.html:5:13: executing “_shortcodes/math.html” at <transform.ToMath>: error calling ToMath: KaTeX parse error: Undefined control sequence: \cr at position 7: line 1\̲c̲r̲ ̲line2
So, there is both a KaTeX problem (why doesn’t it like line separators in display mode some of the time) and a Hugo problem (why do the error messages sometimes get replaced by ToMath is not a function).
Ugh.
I guess I should re-open the problem with a more descriptive title.
It seems like KaTeX doesn’t like the line break in an outer environment in display mode. If you look at the example from @irkode , the line break is within the substack environment.
My workaround: put the multiline equation inside of an align environment - and it seems to work just fine.
So…
don’t use a KaTeX line break in an outer level environment in display mode because it causes Hugo to break in a way that forgets that ToMath is a function.
Hugo knows “ToMath” is a function. The error message is unclear; there either isn’t a an object of the “not a function” portion of the message, or its not printable, or there isn’t one.
Regardless, since katex handles this as expected with client side rendering, and in the sandbox on their website, Hugo’s transform.ToMath should handle it as well.